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 */
1801 /* We may change it->multibyte_p upon unibyte<->multibyte
1802 conversion. So, save the current value now and restore it
1805 Note: It seems that we don't have to record multibyte_p in
1806 struct glyph because the character code itself tells if or
1807 not the character is multibyte. Thus, in the future, we must
1808 consider eliminating the field `multibyte_p' in the struct
1811 int saved_multibyte_p
= it
->multibyte_p
;
1813 /* Maybe translate single-byte characters to multibyte, or the
1815 it
->char_to_display
= it
->c
;
1816 if (!ASCII_BYTE_P (it
->c
))
1818 if (unibyte_display_via_language_environment
1819 && SINGLE_BYTE_CHAR_P (it
->c
)
1821 || !NILP (Vnonascii_translation_table
)))
1823 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1824 it
->multibyte_p
= 1;
1825 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1826 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1828 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1829 && !it
->multibyte_p
)
1831 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1832 it
->multibyte_p
= 0;
1833 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1834 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1838 /* Get font to use. Encode IT->char_to_display. */
1839 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1840 it
->face_id
, &char2b
,
1844 /* When no suitable font found, use the default font. */
1845 font_not_found_p
= font
== NULL
;
1846 if (font_not_found_p
)
1848 font
= FRAME_FONT (it
->f
);
1849 boff
= it
->f
->output_data
.x
->baseline_offset
;
1854 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1855 boff
= font_info
->baseline_offset
;
1856 if (font_info
->vertical_centering
)
1857 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1860 if (it
->char_to_display
>= ' '
1861 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1863 /* Either unibyte or ASCII. */
1868 pcm
= x_per_char_metric (font
, &char2b
);
1869 it
->ascent
= font
->ascent
+ boff
;
1870 it
->descent
= font
->descent
- boff
;
1874 it
->phys_ascent
= pcm
->ascent
+ boff
;
1875 it
->phys_descent
= pcm
->descent
- boff
;
1876 it
->pixel_width
= pcm
->width
;
1880 it
->glyph_not_available_p
= 1;
1881 it
->phys_ascent
= font
->ascent
+ boff
;
1882 it
->phys_descent
= font
->descent
- boff
;
1883 it
->pixel_width
= FONT_WIDTH (font
);
1886 /* If this is a space inside a region of text with
1887 `space-width' property, change its width. */
1888 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1890 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1892 /* If face has a box, add the box thickness to the character
1893 height. If character has a box line to the left and/or
1894 right, add the box line width to the character's width. */
1895 if (face
->box
!= FACE_NO_BOX
)
1897 int thick
= face
->box_line_width
;
1899 it
->ascent
+= thick
;
1900 it
->descent
+= thick
;
1902 if (it
->start_of_box_run_p
)
1903 it
->pixel_width
+= thick
;
1904 if (it
->end_of_box_run_p
)
1905 it
->pixel_width
+= thick
;
1908 /* If face has an overline, add the height of the overline
1909 (1 pixel) and a 1 pixel margin to the character height. */
1910 if (face
->overline_p
)
1913 take_vertical_position_into_account (it
);
1915 /* If we have to actually produce glyphs, do it. */
1920 /* Translate a space with a `space-width' property
1921 into a stretch glyph. */
1922 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1923 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1924 it
->ascent
+ it
->descent
, ascent
);
1927 x_append_glyph (it
);
1929 /* If characters with lbearing or rbearing are displayed
1930 in this line, record that fact in a flag of the
1931 glyph row. This is used to optimize X output code. */
1932 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1933 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1936 else if (it
->char_to_display
== '\n')
1938 /* A newline has no width but we need the height of the line. */
1939 it
->pixel_width
= 0;
1941 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1942 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1944 if (face
->box
!= FACE_NO_BOX
)
1946 int thick
= face
->box_line_width
;
1947 it
->ascent
+= thick
;
1948 it
->descent
+= thick
;
1951 else if (it
->char_to_display
== '\t')
1953 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1954 int x
= it
->current_x
+ it
->continuation_lines_width
;
1955 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1957 /* If the distance from the current position to the next tab
1958 stop is less than a canonical character width, use the
1959 tab stop after that. */
1960 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1961 next_tab_x
+= tab_width
;
1963 it
->pixel_width
= next_tab_x
- x
;
1965 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1966 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1970 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1971 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1972 it
->ascent
+ it
->descent
, ascent
);
1977 /* A multi-byte character. Assume that the display width of the
1978 character is the width of the character multiplied by the
1979 width of the font. */
1981 /* If we found a font, this font should give us the right
1982 metrics. If we didn't find a font, use the frame's
1983 default font and calculate the width of the character
1984 from the charset width; this is what old redisplay code
1986 pcm
= x_per_char_metric (font
, &char2b
);
1987 if (font_not_found_p
|| !pcm
)
1989 int charset
= CHAR_CHARSET (it
->char_to_display
);
1991 it
->glyph_not_available_p
= 1;
1992 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1993 * CHARSET_WIDTH (charset
));
1994 it
->phys_ascent
= font
->ascent
+ boff
;
1995 it
->phys_descent
= font
->descent
- boff
;
1999 it
->pixel_width
= pcm
->width
;
2000 it
->phys_ascent
= pcm
->ascent
+ boff
;
2001 it
->phys_descent
= pcm
->descent
- boff
;
2003 && (pcm
->lbearing
< 0
2004 || pcm
->rbearing
> pcm
->width
))
2005 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2008 it
->ascent
= font
->ascent
+ boff
;
2009 it
->descent
= font
->descent
- boff
;
2010 if (face
->box
!= FACE_NO_BOX
)
2012 int thick
= face
->box_line_width
;
2013 it
->ascent
+= thick
;
2014 it
->descent
+= thick
;
2016 if (it
->start_of_box_run_p
)
2017 it
->pixel_width
+= thick
;
2018 if (it
->end_of_box_run_p
)
2019 it
->pixel_width
+= thick
;
2022 /* If face has an overline, add the height of the overline
2023 (1 pixel) and a 1 pixel margin to the character height. */
2024 if (face
->overline_p
)
2027 take_vertical_position_into_account (it
);
2030 x_append_glyph (it
);
2032 it
->multibyte_p
= saved_multibyte_p
;
2034 else if (it
->what
== IT_COMPOSITION
)
2036 /* Note: A composition is represented as one glyph in the
2037 glyph matrix. There are no padding glyphs. */
2040 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2042 int font_not_found_p
;
2043 struct font_info
*font_info
;
2044 int boff
; /* baseline offset */
2045 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2047 /* Maybe translate single-byte characters to multibyte. */
2048 it
->char_to_display
= it
->c
;
2049 if (unibyte_display_via_language_environment
2050 && SINGLE_BYTE_CHAR_P (it
->c
)
2053 && !NILP (Vnonascii_translation_table
))))
2055 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2058 /* Get face and font to use. Encode IT->char_to_display. */
2059 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2060 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2061 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2062 it
->face_id
, &char2b
, it
->multibyte_p
);
2065 /* When no suitable font found, use the default font. */
2066 font_not_found_p
= font
== NULL
;
2067 if (font_not_found_p
)
2069 font
= FRAME_FONT (it
->f
);
2070 boff
= it
->f
->output_data
.x
->baseline_offset
;
2075 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2076 boff
= font_info
->baseline_offset
;
2077 if (font_info
->vertical_centering
)
2078 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2081 /* There are no padding glyphs, so there is only one glyph to
2082 produce for the composition. Important is that pixel_width,
2083 ascent and descent are the values of what is drawn by
2084 draw_glyphs (i.e. the values of the overall glyphs composed). */
2087 /* If we have not yet calculated pixel size data of glyphs of
2088 the composition for the current face font, calculate them
2089 now. Theoretically, we have to check all fonts for the
2090 glyphs, but that requires much time and memory space. So,
2091 here we check only the font of the first glyph. This leads
2092 to incorrect display very rarely, and C-l (recenter) can
2093 correct the display anyway. */
2094 if (cmp
->font
!= (void *) font
)
2096 /* Ascent and descent of the font of the first character of
2097 this composition (adjusted by baseline offset). Ascent
2098 and descent of overall glyphs should not be less than
2099 them respectively. */
2100 int font_ascent
= font
->ascent
+ boff
;
2101 int font_descent
= font
->descent
- boff
;
2102 /* Bounding box of the overall glyphs. */
2103 int leftmost
, rightmost
, lowest
, highest
;
2104 int i
, width
, ascent
, descent
;
2106 cmp
->font
= (void *) font
;
2108 /* Initialize the bounding box. */
2109 pcm
= x_per_char_metric (font
, &char2b
);
2113 ascent
= pcm
->ascent
;
2114 descent
= pcm
->descent
;
2118 width
= FONT_WIDTH (font
);
2119 ascent
= font
->ascent
;
2120 descent
= font
->descent
;
2124 lowest
= - descent
+ boff
;
2125 highest
= ascent
+ boff
;
2129 && font_info
->default_ascent
2130 && CHAR_TABLE_P (Vuse_default_ascent
)
2131 && !NILP (Faref (Vuse_default_ascent
,
2132 make_number (it
->char_to_display
))))
2133 highest
= font_info
->default_ascent
+ boff
;
2135 /* Draw the first glyph at the normal position. It may be
2136 shifted to right later if some other glyphs are drawn at
2138 cmp
->offsets
[0] = 0;
2139 cmp
->offsets
[1] = boff
;
2141 /* Set cmp->offsets for the remaining glyphs. */
2142 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2144 int left
, right
, btm
, top
;
2145 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2146 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2148 face
= FACE_FROM_ID (it
->f
, face_id
);
2149 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2154 font
= FRAME_FONT (it
->f
);
2155 boff
= it
->f
->output_data
.x
->baseline_offset
;
2161 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2162 boff
= font_info
->baseline_offset
;
2163 if (font_info
->vertical_centering
)
2164 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2167 pcm
= x_per_char_metric (font
, &char2b
);
2171 ascent
= pcm
->ascent
;
2172 descent
= pcm
->descent
;
2176 width
= FONT_WIDTH (font
);
2177 ascent
= font
->ascent
;
2178 descent
= font
->descent
;
2181 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2183 /* Relative composition with or without
2185 left
= (leftmost
+ rightmost
- width
) / 2;
2186 btm
= - descent
+ boff
;
2187 if (font_info
&& font_info
->relative_compose
2188 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2189 || NILP (Faref (Vignore_relative_composition
,
2190 make_number (ch
)))))
2193 if (- descent
>= font_info
->relative_compose
)
2194 /* One extra pixel between two glyphs. */
2196 else if (ascent
<= 0)
2197 /* One extra pixel between two glyphs. */
2198 btm
= lowest
- 1 - ascent
- descent
;
2203 /* A composition rule is specified by an integer
2204 value that encodes global and new reference
2205 points (GREF and NREF). GREF and NREF are
2206 specified by numbers as below:
2214 ---3---4---5--- baseline
2216 6---7---8 -- descent
2218 int rule
= COMPOSITION_RULE (cmp
, i
);
2219 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2221 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2222 grefx
= gref
% 3, nrefx
= nref
% 3;
2223 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2226 + grefx
* (rightmost
- leftmost
) / 2
2227 - nrefx
* width
/ 2);
2228 btm
= ((grefy
== 0 ? highest
2230 : grefy
== 2 ? lowest
2231 : (highest
+ lowest
) / 2)
2232 - (nrefy
== 0 ? ascent
+ descent
2233 : nrefy
== 1 ? descent
- boff
2235 : (ascent
+ descent
) / 2));
2238 cmp
->offsets
[i
* 2] = left
;
2239 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2241 /* Update the bounding box of the overall glyphs. */
2242 right
= left
+ width
;
2243 top
= btm
+ descent
+ ascent
;
2244 if (left
< leftmost
)
2246 if (right
> rightmost
)
2254 /* If there are glyphs whose x-offsets are negative,
2255 shift all glyphs to the right and make all x-offsets
2259 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2260 cmp
->offsets
[i
* 2] -= leftmost
;
2261 rightmost
-= leftmost
;
2264 cmp
->pixel_width
= rightmost
;
2265 cmp
->ascent
= highest
;
2266 cmp
->descent
= - lowest
;
2267 if (cmp
->ascent
< font_ascent
)
2268 cmp
->ascent
= font_ascent
;
2269 if (cmp
->descent
< font_descent
)
2270 cmp
->descent
= font_descent
;
2273 it
->pixel_width
= cmp
->pixel_width
;
2274 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2275 it
->descent
= it
->phys_descent
= cmp
->descent
;
2277 if (face
->box
!= FACE_NO_BOX
)
2279 int thick
= face
->box_line_width
;
2280 it
->ascent
+= thick
;
2281 it
->descent
+= thick
;
2283 if (it
->start_of_box_run_p
)
2284 it
->pixel_width
+= thick
;
2285 if (it
->end_of_box_run_p
)
2286 it
->pixel_width
+= thick
;
2289 /* If face has an overline, add the height of the overline
2290 (1 pixel) and a 1 pixel margin to the character height. */
2291 if (face
->overline_p
)
2294 take_vertical_position_into_account (it
);
2297 x_append_composite_glyph (it
);
2299 else if (it
->what
== IT_IMAGE
)
2300 x_produce_image_glyph (it
);
2301 else if (it
->what
== IT_STRETCH
)
2302 x_produce_stretch_glyph (it
);
2304 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2305 because this isn't true for images with `:ascent 100'. */
2306 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2307 if (it
->area
== TEXT_AREA
)
2308 it
->current_x
+= it
->pixel_width
;
2310 it
->descent
+= it
->extra_line_spacing
;
2312 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2313 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2314 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2315 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2319 /* Estimate the pixel height of the mode or top line on frame F.
2320 FACE_ID specifies what line's height to estimate. */
2323 x_estimate_mode_line_height (f
, face_id
)
2325 enum face_id face_id
;
2329 /* This function is called so early when Emacs starts that the face
2330 cache and mode line face are not yet initialized. */
2331 if (FRAME_FACE_CACHE (f
))
2333 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2335 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
2342 /***********************************************************************
2344 ***********************************************************************/
2346 /* A sequence of glyphs to be drawn in the same face.
2348 This data structure is not really completely X specific, so it
2349 could possibly, at least partially, be useful for other systems. It
2350 is currently not part of the external redisplay interface because
2351 it's not clear what other systems will need. */
2355 /* X-origin of the string. */
2358 /* Y-origin and y-position of the base line of this string. */
2361 /* The width of the string, not including a face extension. */
2364 /* The width of the string, including a face extension. */
2365 int background_width
;
2367 /* The height of this string. This is the height of the line this
2368 string is drawn in, and can be different from the height of the
2369 font the string is drawn in. */
2372 /* Number of pixels this string overwrites in front of its x-origin.
2373 This number is zero if the string has an lbearing >= 0; it is
2374 -lbearing, if the string has an lbearing < 0. */
2377 /* Number of pixels this string overwrites past its right-most
2378 nominal x-position, i.e. x + width. Zero if the string's
2379 rbearing is <= its nominal width, rbearing - width otherwise. */
2382 /* The frame on which the glyph string is drawn. */
2385 /* The window on which the glyph string is drawn. */
2388 /* X display and window for convenience. */
2392 /* The glyph row for which this string was built. It determines the
2393 y-origin and height of the string. */
2394 struct glyph_row
*row
;
2396 /* The area within row. */
2397 enum glyph_row_area area
;
2399 /* Characters to be drawn, and number of characters. */
2403 /* A face-override for drawing cursors, mouse face and similar. */
2404 enum draw_glyphs_face hl
;
2406 /* Face in which this string is to be drawn. */
2409 /* Font in which this string is to be drawn. */
2412 /* Font info for this string. */
2413 struct font_info
*font_info
;
2415 /* Non-null means this string describes (part of) a composition.
2416 All characters from char2b are drawn composed. */
2417 struct composition
*cmp
;
2419 /* Index of this glyph string's first character in the glyph
2420 definition of CMP. If this is zero, this glyph string describes
2421 the first character of a composition. */
2424 /* 1 means this glyph strings face has to be drawn to the right end
2425 of the window's drawing area. */
2426 unsigned extends_to_end_of_line_p
: 1;
2428 /* 1 means the background of this string has been drawn. */
2429 unsigned background_filled_p
: 1;
2431 /* 1 means glyph string must be drawn with 16-bit functions. */
2432 unsigned two_byte_p
: 1;
2434 /* 1 means that the original font determined for drawing this glyph
2435 string could not be loaded. The member `font' has been set to
2436 the frame's default font in this case. */
2437 unsigned font_not_found_p
: 1;
2439 /* 1 means that the face in which this glyph string is drawn has a
2441 unsigned stippled_p
: 1;
2443 /* 1 means only the foreground of this glyph string must be drawn,
2444 and we should use the physical height of the line this glyph
2445 string appears in as clip rect. */
2446 unsigned for_overlaps_p
: 1;
2448 /* The GC to use for drawing this glyph string. */
2451 /* A pointer to the first glyph in the string. This glyph
2452 corresponds to char2b[0]. Needed to draw rectangles if
2453 font_not_found_p is 1. */
2454 struct glyph
*first_glyph
;
2456 /* Image, if any. */
2459 struct glyph_string
*next
, *prev
;
2466 x_dump_glyph_string (s
)
2467 struct glyph_string
*s
;
2469 fprintf (stderr
, "glyph string\n");
2470 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2471 s
->x
, s
->y
, s
->width
, s
->height
);
2472 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2473 fprintf (stderr
, " hl = %d\n", s
->hl
);
2474 fprintf (stderr
, " left overhang = %d, right = %d\n",
2475 s
->left_overhang
, s
->right_overhang
);
2476 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2477 fprintf (stderr
, " extends to end of line = %d\n",
2478 s
->extends_to_end_of_line_p
);
2479 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2480 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2483 #endif /* GLYPH_DEBUG */
2487 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2488 struct glyph_string
**,
2489 struct glyph_string
*,
2490 struct glyph_string
*));
2491 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2492 struct glyph_string
**,
2493 struct glyph_string
*,
2494 struct glyph_string
*));
2495 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2496 struct glyph_string
**,
2497 struct glyph_string
*));
2498 static int x_left_overwritten
P_ ((struct glyph_string
*));
2499 static int x_left_overwriting
P_ ((struct glyph_string
*));
2500 static int x_right_overwritten
P_ ((struct glyph_string
*));
2501 static int x_right_overwriting
P_ ((struct glyph_string
*));
2502 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2504 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2505 XChar2b
*, struct window
*,
2507 enum glyph_row_area
, int,
2508 enum draw_glyphs_face
));
2509 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2510 enum glyph_row_area
, int, int,
2511 enum draw_glyphs_face
, int *, int *, int));
2512 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2513 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2514 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2516 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2517 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2518 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2519 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2520 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2521 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2522 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2523 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2524 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2526 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2527 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2528 unsigned long *, double, int));
2529 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2530 double, int, unsigned long));
2531 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2532 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2533 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2534 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2535 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2536 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2537 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2539 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2540 int, int, int, int, XRectangle
*));
2541 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2542 int, int, int, XRectangle
*));
2543 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2544 enum glyph_row_area
));
2545 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2547 enum glyph_row_area
, int, int));
2550 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2554 /* Append the list of glyph strings with head H and tail T to the list
2555 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2558 x_append_glyph_string_lists (head
, tail
, h
, t
)
2559 struct glyph_string
**head
, **tail
;
2560 struct glyph_string
*h
, *t
;
2574 /* Prepend the list of glyph strings with head H and tail T to the
2575 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2579 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2580 struct glyph_string
**head
, **tail
;
2581 struct glyph_string
*h
, *t
;
2595 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2596 Set *HEAD and *TAIL to the resulting list. */
2599 x_append_glyph_string (head
, tail
, s
)
2600 struct glyph_string
**head
, **tail
;
2601 struct glyph_string
*s
;
2603 s
->next
= s
->prev
= NULL
;
2604 x_append_glyph_string_lists (head
, tail
, s
, s
);
2608 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2613 struct glyph_string
*s
;
2615 if (s
->font
== FRAME_FONT (s
->f
)
2616 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2617 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2619 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2622 /* Cursor on non-default face: must merge. */
2626 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2627 xgcv
.foreground
= s
->face
->background
;
2629 /* If the glyph would be invisible, try a different foreground. */
2630 if (xgcv
.foreground
== xgcv
.background
)
2631 xgcv
.foreground
= s
->face
->foreground
;
2632 if (xgcv
.foreground
== xgcv
.background
)
2633 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2634 if (xgcv
.foreground
== xgcv
.background
)
2635 xgcv
.foreground
= s
->face
->foreground
;
2637 /* Make sure the cursor is distinct from text in this face. */
2638 if (xgcv
.background
== s
->face
->background
2639 && xgcv
.foreground
== s
->face
->foreground
)
2641 xgcv
.background
= s
->face
->foreground
;
2642 xgcv
.foreground
= s
->face
->background
;
2645 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2646 xgcv
.font
= s
->font
->fid
;
2647 xgcv
.graphics_exposures
= False
;
2648 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2650 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2651 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2654 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2655 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2657 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2662 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2665 x_set_mouse_face_gc (s
)
2666 struct glyph_string
*s
;
2671 /* What face has to be used for the mouse face? */
2672 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2673 face
= FACE_FROM_ID (s
->f
, face_id
);
2674 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2675 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2677 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2678 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2679 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2681 /* If font in this face is same as S->font, use it. */
2682 if (s
->font
== s
->face
->font
)
2683 s
->gc
= s
->face
->gc
;
2686 /* Otherwise construct scratch_cursor_gc with values from FACE
2691 xgcv
.background
= s
->face
->background
;
2692 xgcv
.foreground
= s
->face
->foreground
;
2693 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2694 xgcv
.font
= s
->font
->fid
;
2695 xgcv
.graphics_exposures
= False
;
2696 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2698 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2699 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2702 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2703 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2705 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2708 xassert (s
->gc
!= 0);
2712 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2713 Faces to use in the mode line have already been computed when the
2714 matrix was built, so there isn't much to do, here. */
2717 x_set_mode_line_face_gc (s
)
2718 struct glyph_string
*s
;
2720 s
->gc
= s
->face
->gc
;
2724 /* Set S->gc of glyph string S for drawing that glyph string. Set
2725 S->stippled_p to a non-zero value if the face of S has a stipple
2729 x_set_glyph_string_gc (s
)
2730 struct glyph_string
*s
;
2732 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2734 if (s
->hl
== DRAW_NORMAL_TEXT
)
2736 s
->gc
= s
->face
->gc
;
2737 s
->stippled_p
= s
->face
->stipple
!= 0;
2739 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2741 x_set_mode_line_face_gc (s
);
2742 s
->stippled_p
= s
->face
->stipple
!= 0;
2744 else if (s
->hl
== DRAW_CURSOR
)
2746 x_set_cursor_gc (s
);
2749 else if (s
->hl
== DRAW_MOUSE_FACE
)
2751 x_set_mouse_face_gc (s
);
2752 s
->stippled_p
= s
->face
->stipple
!= 0;
2754 else if (s
->hl
== DRAW_IMAGE_RAISED
2755 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2757 s
->gc
= s
->face
->gc
;
2758 s
->stippled_p
= s
->face
->stipple
!= 0;
2762 s
->gc
= s
->face
->gc
;
2763 s
->stippled_p
= s
->face
->stipple
!= 0;
2766 /* GC must have been set. */
2767 xassert (s
->gc
!= 0);
2771 /* Return in *R the clipping rectangle for glyph string S. */
2774 x_get_glyph_string_clip_rect (s
, r
)
2775 struct glyph_string
*s
;
2778 if (s
->row
->full_width_p
)
2780 /* Draw full-width. X coordinates are relative to S->w->left. */
2781 int canon_x
= CANON_X_UNIT (s
->f
);
2783 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2784 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2786 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2788 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2789 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2793 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2795 /* Unless displaying a mode or menu bar line, which are always
2796 fully visible, clip to the visible part of the row. */
2797 if (s
->w
->pseudo_window_p
)
2798 r
->height
= s
->row
->visible_height
;
2800 r
->height
= s
->height
;
2804 /* This is a text line that may be partially visible. */
2805 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2806 r
->width
= window_box_width (s
->w
, s
->area
);
2807 r
->height
= s
->row
->visible_height
;
2810 /* Don't use S->y for clipping because it doesn't take partially
2811 visible lines into account. For example, it can be negative for
2812 partially visible lines at the top of a window. */
2813 if (!s
->row
->full_width_p
2814 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2815 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2817 r
->y
= max (0, s
->row
->y
);
2819 /* If drawing a tool-bar window, draw it over the internal border
2820 at the top of the window. */
2821 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2822 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2824 /* If S draws overlapping rows, it's sufficient to use the top and
2825 bottom of the window for clipping because this glyph string
2826 intentionally draws over other lines. */
2827 if (s
->for_overlaps_p
)
2829 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2830 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2833 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2837 /* Set clipping for output of glyph string S. S may be part of a mode
2838 line or menu if we don't have X toolkit support. */
2841 x_set_glyph_string_clipping (s
)
2842 struct glyph_string
*s
;
2845 x_get_glyph_string_clip_rect (s
, &r
);
2846 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2850 /* Compute left and right overhang of glyph string S. If S is a glyph
2851 string for a composition, assume overhangs don't exist. */
2854 x_compute_glyph_string_overhangs (s
)
2855 struct glyph_string
*s
;
2858 && s
->first_glyph
->type
== CHAR_GLYPH
)
2861 int direction
, font_ascent
, font_descent
;
2862 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2863 &font_ascent
, &font_descent
, &cs
);
2864 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2865 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2870 /* Compute overhangs and x-positions for glyph string S and its
2871 predecessors, or successors. X is the starting x-position for S.
2872 BACKWARD_P non-zero means process predecessors. */
2875 x_compute_overhangs_and_x (s
, x
, backward_p
)
2876 struct glyph_string
*s
;
2884 x_compute_glyph_string_overhangs (s
);
2894 x_compute_glyph_string_overhangs (s
);
2903 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2904 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2905 assumed to be zero. */
2908 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2909 struct glyph
*glyph
;
2915 if (glyph
->type
== CHAR_GLYPH
)
2919 struct font_info
*font_info
;
2923 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2925 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2927 && (pcm
= x_per_char_metric (font
, &char2b
)))
2929 if (pcm
->rbearing
> pcm
->width
)
2930 *right
= pcm
->rbearing
- pcm
->width
;
2931 if (pcm
->lbearing
< 0)
2932 *left
= -pcm
->lbearing
;
2938 /* Return the index of the first glyph preceding glyph string S that
2939 is overwritten by S because of S's left overhang. Value is -1
2940 if no glyphs are overwritten. */
2943 x_left_overwritten (s
)
2944 struct glyph_string
*s
;
2948 if (s
->left_overhang
)
2951 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2952 int first
= s
->first_glyph
- glyphs
;
2954 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2955 x
-= glyphs
[i
].pixel_width
;
2966 /* Return the index of the first glyph preceding glyph string S that
2967 is overwriting S because of its right overhang. Value is -1 if no
2968 glyph in front of S overwrites S. */
2971 x_left_overwriting (s
)
2972 struct glyph_string
*s
;
2975 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2976 int first
= s
->first_glyph
- glyphs
;
2980 for (i
= first
- 1; i
>= 0; --i
)
2983 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2986 x
-= glyphs
[i
].pixel_width
;
2993 /* Return the index of the last glyph following glyph string S that is
2994 not overwritten by S because of S's right overhang. Value is -1 if
2995 no such glyph is found. */
2998 x_right_overwritten (s
)
2999 struct glyph_string
*s
;
3003 if (s
->right_overhang
)
3006 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3007 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3008 int end
= s
->row
->used
[s
->area
];
3010 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3011 x
+= glyphs
[i
].pixel_width
;
3020 /* Return the index of the last glyph following glyph string S that
3021 overwrites S because of its left overhang. Value is negative
3022 if no such glyph is found. */
3025 x_right_overwriting (s
)
3026 struct glyph_string
*s
;
3029 int end
= s
->row
->used
[s
->area
];
3030 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3031 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3035 for (i
= first
; i
< end
; ++i
)
3038 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3041 x
+= glyphs
[i
].pixel_width
;
3048 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3051 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3052 struct glyph_string
*s
;
3056 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3057 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3058 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3059 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3063 /* Draw the background of glyph_string S. If S->background_filled_p
3064 is non-zero don't draw it. FORCE_P non-zero means draw the
3065 background even if it wouldn't be drawn normally. This is used
3066 when a string preceding S draws into the background of S, or S
3067 contains the first component of a composition. */
3070 x_draw_glyph_string_background (s
, force_p
)
3071 struct glyph_string
*s
;
3074 /* Nothing to do if background has already been drawn or if it
3075 shouldn't be drawn in the first place. */
3076 if (!s
->background_filled_p
)
3080 /* Fill background with a stipple pattern. */
3081 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3082 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3083 s
->y
+ s
->face
->box_line_width
,
3084 s
->background_width
,
3085 s
->height
- 2 * s
->face
->box_line_width
);
3086 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3087 s
->background_filled_p
= 1;
3089 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
3090 || s
->font_not_found_p
3091 || s
->extends_to_end_of_line_p
3094 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
3095 s
->background_width
,
3096 s
->height
- 2 * s
->face
->box_line_width
);
3097 s
->background_filled_p
= 1;
3103 /* Draw the foreground of glyph string S. */
3106 x_draw_glyph_string_foreground (s
)
3107 struct glyph_string
*s
;
3111 /* If first glyph of S has a left box line, start drawing the text
3112 of S to the right of that box line. */
3113 if (s
->face
->box
!= FACE_NO_BOX
3114 && s
->first_glyph
->left_box_line_p
)
3115 x
= s
->x
+ s
->face
->box_line_width
;
3119 /* Draw characters of S as rectangles if S's font could not be
3121 if (s
->font_not_found_p
)
3123 for (i
= 0; i
< s
->nchars
; ++i
)
3125 struct glyph
*g
= s
->first_glyph
+ i
;
3126 XDrawRectangle (s
->display
, s
->window
,
3127 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3129 x
+= g
->pixel_width
;
3134 char *char1b
= (char *) s
->char2b
;
3135 int boff
= s
->font_info
->baseline_offset
;
3137 if (s
->font_info
->vertical_centering
)
3138 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3140 /* If we can use 8-bit functions, condense S->char2b. */
3142 for (i
= 0; i
< s
->nchars
; ++i
)
3143 char1b
[i
] = s
->char2b
[i
].byte2
;
3145 /* Draw text with XDrawString if background has already been
3146 filled. Otherwise, use XDrawImageString. (Note that
3147 XDrawImageString is usually faster than XDrawString.) Always
3148 use XDrawImageString when drawing the cursor so that there is
3149 no chance that characters under a box cursor are invisible. */
3150 if (s
->for_overlaps_p
3151 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3153 /* Draw characters with 16-bit or 8-bit functions. */
3155 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3156 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3158 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3159 s
->ybase
- boff
, char1b
, s
->nchars
);
3164 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3165 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3167 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3168 s
->ybase
- boff
, char1b
, s
->nchars
);
3173 /* Draw the foreground of composite glyph string S. */
3176 x_draw_composite_glyph_string_foreground (s
)
3177 struct glyph_string
*s
;
3181 /* If first glyph of S has a left box line, start drawing the text
3182 of S to the right of that box line. */
3183 if (s
->face
->box
!= FACE_NO_BOX
3184 && s
->first_glyph
->left_box_line_p
)
3185 x
= s
->x
+ s
->face
->box_line_width
;
3189 /* S is a glyph string for a composition. S->gidx is the index of
3190 the first character drawn for glyphs of this composition.
3191 S->gidx == 0 means we are drawing the very first character of
3192 this composition. */
3194 /* Draw a rectangle for the composition if the font for the very
3195 first character of the composition could not be loaded. */
3196 if (s
->font_not_found_p
)
3199 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3200 s
->width
- 1, s
->height
- 1);
3204 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3205 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3206 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3207 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3213 #ifdef USE_X_TOOLKIT
3215 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3218 /* Return the frame on which widget WIDGET is used.. Abort if frame
3219 cannot be determined. */
3221 static struct frame
*
3222 x_frame_of_widget (widget
)
3225 struct x_display_info
*dpyinfo
;
3229 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3231 /* Find the top-level shell of the widget. Note that this function
3232 can be called when the widget is not yet realized, so XtWindow
3233 (widget) == 0. That's the reason we can't simply use
3234 x_any_window_to_frame. */
3235 while (!XtIsTopLevelShell (widget
))
3236 widget
= XtParent (widget
);
3238 /* Look for a frame with that top-level widget. Allocate the color
3239 on that frame to get the right gamma correction value. */
3240 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3241 if (GC_FRAMEP (XCAR (tail
))
3242 && (f
= XFRAME (XCAR (tail
)),
3243 (f
->output_data
.nothing
!= 1
3244 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3245 && f
->output_data
.x
->widget
== widget
)
3252 /* Allocate the color COLOR->pixel on the screen and display of
3253 widget WIDGET in colormap CMAP. If an exact match cannot be
3254 allocated, try the nearest color available. Value is non-zero
3255 if successful. This is called from lwlib. */
3258 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3263 struct frame
*f
= x_frame_of_widget (widget
);
3264 return x_alloc_nearest_color (f
, cmap
, color
);
3268 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3269 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3270 If this produces the same color as PIXEL, try a color where all RGB
3271 values have DELTA added. Return the allocated color in *PIXEL.
3272 DISPLAY is the X display, CMAP is the colormap to operate on.
3273 Value is non-zero if successful. */
3276 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3280 unsigned long *pixel
;
3284 struct frame
*f
= x_frame_of_widget (widget
);
3285 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3289 #endif /* USE_X_TOOLKIT */
3292 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3293 CMAP. If an exact match can't be allocated, try the nearest color
3294 available. Value is non-zero if successful. Set *COLOR to the
3298 x_alloc_nearest_color (f
, cmap
, color
)
3303 Display
*display
= FRAME_X_DISPLAY (f
);
3304 Screen
*screen
= FRAME_X_SCREEN (f
);
3307 gamma_correct (f
, color
);
3308 rc
= XAllocColor (display
, cmap
, color
);
3311 /* If we got to this point, the colormap is full, so we're going
3312 to try to get the next closest color. The algorithm used is
3313 a least-squares matching, which is what X uses for closest
3314 color matching with StaticColor visuals. */
3316 unsigned long nearest_delta
= ~0;
3317 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3318 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3320 for (i
= 0; i
< ncells
; ++i
)
3322 XQueryColors (display
, cmap
, cells
, ncells
);
3324 for (nearest
= i
= 0; i
< ncells
; ++i
)
3326 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3327 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3328 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3329 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3331 if (delta
< nearest_delta
)
3334 nearest_delta
= delta
;
3338 color
->red
= cells
[nearest
].red
;
3339 color
->green
= cells
[nearest
].green
;
3340 color
->blue
= cells
[nearest
].blue
;
3341 rc
= XAllocColor (display
, cmap
, color
);
3344 #ifdef DEBUG_X_COLORS
3346 register_color (color
->pixel
);
3347 #endif /* DEBUG_X_COLORS */
3353 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3354 It's necessary to do this instead of just using PIXEL directly to
3355 get color reference counts right. */
3358 x_copy_color (f
, pixel
)
3360 unsigned long pixel
;
3364 color
.pixel
= pixel
;
3366 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3367 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3369 #ifdef DEBUG_X_COLORS
3370 register_color (pixel
);
3376 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3377 It's necessary to do this instead of just using PIXEL directly to
3378 get color reference counts right. */
3381 x_copy_dpy_color (dpy
, cmap
, pixel
)
3384 unsigned long pixel
;
3388 color
.pixel
= pixel
;
3390 XQueryColor (dpy
, cmap
, &color
);
3391 XAllocColor (dpy
, cmap
, &color
);
3393 #ifdef DEBUG_X_COLORS
3394 register_color (pixel
);
3400 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3401 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3402 If this produces the same color as PIXEL, try a color where all RGB
3403 values have DELTA added. Return the allocated color in *PIXEL.
3404 DISPLAY is the X display, CMAP is the colormap to operate on.
3405 Value is non-zero if successful. */
3408 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3412 unsigned long *pixel
;
3419 /* Get RGB color values. */
3420 color
.pixel
= *pixel
;
3421 XQueryColor (display
, cmap
, &color
);
3423 /* Change RGB values by specified FACTOR. Avoid overflow! */
3424 xassert (factor
>= 0);
3425 new.red
= min (0xffff, factor
* color
.red
);
3426 new.green
= min (0xffff, factor
* color
.green
);
3427 new.blue
= min (0xffff, factor
* color
.blue
);
3429 /* Try to allocate the color. */
3430 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3433 if (new.pixel
== *pixel
)
3435 /* If we end up with the same color as before, try adding
3436 delta to the RGB values. */
3437 x_free_colors (f
, &new.pixel
, 1);
3439 new.red
= min (0xffff, delta
+ color
.red
);
3440 new.green
= min (0xffff, delta
+ color
.green
);
3441 new.blue
= min (0xffff, delta
+ color
.blue
);
3442 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3453 /* Set up the foreground color for drawing relief lines of glyph
3454 string S. RELIEF is a pointer to a struct relief containing the GC
3455 with which lines will be drawn. Use a color that is FACTOR or
3456 DELTA lighter or darker than the relief's background which is found
3457 in S->f->output_data.x->relief_background. If such a color cannot
3458 be allocated, use DEFAULT_PIXEL, instead. */
3461 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3463 struct relief
*relief
;
3466 unsigned long default_pixel
;
3469 struct x_output
*di
= f
->output_data
.x
;
3470 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3471 unsigned long pixel
;
3472 unsigned long background
= di
->relief_background
;
3473 Colormap cmap
= FRAME_X_COLORMAP (f
);
3474 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3475 Display
*dpy
= FRAME_X_DISPLAY (f
);
3477 xgcv
.graphics_exposures
= False
;
3478 xgcv
.line_width
= 1;
3480 /* Free previously allocated color. The color cell will be reused
3481 when it has been freed as many times as it was allocated, so this
3482 doesn't affect faces using the same colors. */
3484 && relief
->allocated_p
)
3486 x_free_colors (f
, &relief
->pixel
, 1);
3487 relief
->allocated_p
= 0;
3490 /* Allocate new color. */
3491 xgcv
.foreground
= default_pixel
;
3493 if (dpyinfo
->n_planes
!= 1
3494 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3496 relief
->allocated_p
= 1;
3497 xgcv
.foreground
= relief
->pixel
= pixel
;
3500 if (relief
->gc
== 0)
3502 xgcv
.stipple
= dpyinfo
->gray
;
3504 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3507 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3511 /* Set up colors for the relief lines around glyph string S. */
3514 x_setup_relief_colors (s
)
3515 struct glyph_string
*s
;
3517 struct x_output
*di
= s
->f
->output_data
.x
;
3518 unsigned long color
;
3520 if (s
->face
->use_box_color_for_shadows_p
)
3521 color
= s
->face
->box_color
;
3526 /* Get the background color of the face. */
3527 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3528 color
= xgcv
.background
;
3531 if (di
->white_relief
.gc
== 0
3532 || color
!= di
->relief_background
)
3534 di
->relief_background
= color
;
3535 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3536 WHITE_PIX_DEFAULT (s
->f
));
3537 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3538 BLACK_PIX_DEFAULT (s
->f
));
3543 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3544 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3545 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3546 relief. LEFT_P non-zero means draw a relief on the left side of
3547 the rectangle. RIGHT_P non-zero means draw a relief on the right
3548 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3552 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3553 raised_p
, left_p
, right_p
, clip_rect
)
3555 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3556 XRectangle
*clip_rect
;
3562 gc
= f
->output_data
.x
->white_relief
.gc
;
3564 gc
= f
->output_data
.x
->black_relief
.gc
;
3565 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3568 for (i
= 0; i
< width
; ++i
)
3569 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3570 left_x
+ i
* left_p
, top_y
+ i
,
3571 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3575 for (i
= 0; i
< width
; ++i
)
3576 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3577 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3579 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3581 gc
= f
->output_data
.x
->black_relief
.gc
;
3583 gc
= f
->output_data
.x
->white_relief
.gc
;
3584 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3587 for (i
= 0; i
< width
; ++i
)
3588 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3589 left_x
+ i
* left_p
, bottom_y
- i
,
3590 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3594 for (i
= 0; i
< width
; ++i
)
3595 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3596 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3598 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3602 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3603 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3604 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3605 left side of the rectangle. RIGHT_P non-zero means draw a line
3606 on the right side of the rectangle. CLIP_RECT is the clipping
3607 rectangle to use when drawing. */
3610 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3611 left_p
, right_p
, clip_rect
)
3612 struct glyph_string
*s
;
3613 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3614 XRectangle
*clip_rect
;
3618 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3619 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3620 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3623 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3624 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3628 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3629 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3632 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3633 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3637 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3638 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3640 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3641 XSetClipMask (s
->display
, s
->gc
, None
);
3645 /* Draw a box around glyph string S. */
3648 x_draw_glyph_string_box (s
)
3649 struct glyph_string
*s
;
3651 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3652 int left_p
, right_p
;
3653 struct glyph
*last_glyph
;
3654 XRectangle clip_rect
;
3656 last_x
= window_box_right (s
->w
, s
->area
);
3657 if (s
->row
->full_width_p
3658 && !s
->w
->pseudo_window_p
)
3660 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3661 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3662 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3665 /* The glyph that may have a right box line. */
3666 last_glyph
= (s
->cmp
|| s
->img
3668 : s
->first_glyph
+ s
->nchars
- 1);
3670 width
= s
->face
->box_line_width
;
3671 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3673 right_x
= ((s
->row
->full_width_p
3675 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3677 bottom_y
= top_y
+ s
->height
- 1;
3679 left_p
= (s
->first_glyph
->left_box_line_p
3680 || (s
->hl
== DRAW_MOUSE_FACE
3682 || s
->prev
->hl
!= s
->hl
)));
3683 right_p
= (last_glyph
->right_box_line_p
3684 || (s
->hl
== DRAW_MOUSE_FACE
3686 || s
->next
->hl
!= s
->hl
)));
3688 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3690 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3691 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3692 left_p
, right_p
, &clip_rect
);
3695 x_setup_relief_colors (s
);
3696 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3697 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3702 /* Draw foreground of image glyph string S. */
3705 x_draw_image_foreground (s
)
3706 struct glyph_string
*s
;
3709 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3711 /* If first glyph of S has a left box line, start drawing it to the
3712 right of that line. */
3713 if (s
->face
->box
!= FACE_NO_BOX
3714 && s
->first_glyph
->left_box_line_p
)
3715 x
= s
->x
+ s
->face
->box_line_width
;
3719 /* If there is a margin around the image, adjust x- and y-position
3723 x
+= s
->img
->margin
;
3724 y
+= s
->img
->margin
;
3731 /* We can't set both a clip mask and use XSetClipRectangles
3732 because the latter also sets a clip mask. We also can't
3733 trust on the shape extension to be available
3734 (XShapeCombineRegion). So, compute the rectangle to draw
3736 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3739 XRectangle clip_rect
, image_rect
, r
;
3741 xgcv
.clip_mask
= s
->img
->mask
;
3742 xgcv
.clip_x_origin
= x
;
3743 xgcv
.clip_y_origin
= y
;
3744 xgcv
.function
= GXcopy
;
3745 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3747 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3750 image_rect
.width
= s
->img
->width
;
3751 image_rect
.height
= s
->img
->height
;
3752 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3753 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3754 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3758 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
3760 XRectangle clip_rect
, image_rect
, r
;
3762 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3765 image_rect
.width
= s
->img
->width
;
3766 image_rect
.height
= s
->img
->height
;
3767 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3768 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3769 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3771 /* When the image has a mask, we can expect that at
3772 least part of a mouse highlight or a block cursor will
3773 be visible. If the image doesn't have a mask, make
3774 a block cursor visible by drawing a rectangle around
3775 the image. I believe it's looking better if we do
3776 nothing here for mouse-face. */
3777 if (s
->hl
== DRAW_CURSOR
)
3778 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3779 s
->img
->width
- 1, s
->img
->height
- 1);
3783 /* Draw a rectangle if image could not be loaded. */
3784 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3785 s
->img
->width
- 1, s
->img
->height
- 1);
3789 /* Draw a relief around the image glyph string S. */
3792 x_draw_image_relief (s
)
3793 struct glyph_string
*s
;
3795 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3798 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3800 /* If first glyph of S has a left box line, start drawing it to the
3801 right of that line. */
3802 if (s
->face
->box
!= FACE_NO_BOX
3803 && s
->first_glyph
->left_box_line_p
)
3804 x
= s
->x
+ s
->face
->box_line_width
;
3808 /* If there is a margin around the image, adjust x- and y-position
3812 x
+= s
->img
->margin
;
3813 y
+= s
->img
->margin
;
3816 if (s
->hl
== DRAW_IMAGE_SUNKEN
3817 || s
->hl
== DRAW_IMAGE_RAISED
)
3819 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3820 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3824 thick
= abs (s
->img
->relief
);
3825 raised_p
= s
->img
->relief
> 0;
3830 x1
= x
+ s
->img
->width
+ thick
- 1;
3831 y1
= y
+ s
->img
->height
+ thick
- 1;
3833 x_setup_relief_colors (s
);
3834 x_get_glyph_string_clip_rect (s
, &r
);
3835 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3839 /* Draw the foreground of image glyph string S to PIXMAP. */
3842 x_draw_image_foreground_1 (s
, pixmap
)
3843 struct glyph_string
*s
;
3847 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3849 /* If first glyph of S has a left box line, start drawing it to the
3850 right of that line. */
3851 if (s
->face
->box
!= FACE_NO_BOX
3852 && s
->first_glyph
->left_box_line_p
)
3853 x
= s
->face
->box_line_width
;
3857 /* If there is a margin around the image, adjust x- and y-position
3861 x
+= s
->img
->margin
;
3862 y
+= s
->img
->margin
;
3869 /* We can't set both a clip mask and use XSetClipRectangles
3870 because the latter also sets a clip mask. We also can't
3871 trust on the shape extension to be available
3872 (XShapeCombineRegion). So, compute the rectangle to draw
3874 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3878 xgcv
.clip_mask
= s
->img
->mask
;
3879 xgcv
.clip_x_origin
= x
;
3880 xgcv
.clip_y_origin
= y
;
3881 xgcv
.function
= GXcopy
;
3882 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3884 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3885 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3886 XSetClipMask (s
->display
, s
->gc
, None
);
3890 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3891 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3893 /* When the image has a mask, we can expect that at
3894 least part of a mouse highlight or a block cursor will
3895 be visible. If the image doesn't have a mask, make
3896 a block cursor visible by drawing a rectangle around
3897 the image. I believe it's looking better if we do
3898 nothing here for mouse-face. */
3899 if (s
->hl
== DRAW_CURSOR
)
3900 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3901 s
->img
->width
- 1, s
->img
->height
- 1);
3905 /* Draw a rectangle if image could not be loaded. */
3906 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3907 s
->img
->width
- 1, s
->img
->height
- 1);
3911 /* Draw part of the background of glyph string S. X, Y, W, and H
3912 give the rectangle to draw. */
3915 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3916 struct glyph_string
*s
;
3921 /* Fill background with a stipple pattern. */
3922 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3923 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3924 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3927 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3931 /* Draw image glyph string S.
3934 s->x +-------------------------
3937 | +-------------------------
3940 | | +-------------------
3946 x_draw_image_glyph_string (s
)
3947 struct glyph_string
*s
;
3950 int box_line_width
= s
->face
->box_line_width
;
3951 int margin
= s
->img
->margin
;
3953 Pixmap pixmap
= None
;
3955 height
= s
->height
- 2 * box_line_width
;
3957 /* Fill background with face under the image. Do it only if row is
3958 taller than image or if image has a clip mask to reduce
3960 s
->stippled_p
= s
->face
->stipple
!= 0;
3961 if (height
> s
->img
->height
3964 || s
->img
->pixmap
== 0
3965 || s
->width
!= s
->background_width
)
3967 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3968 x
= s
->x
+ box_line_width
;
3972 y
= s
->y
+ box_line_width
;
3976 /* Create a pixmap as large as the glyph string. Fill it
3977 with the background color. Copy the image to it, using
3978 its mask. Copy the temporary pixmap to the display. */
3979 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3980 int depth
= DefaultDepthOfScreen (screen
);
3982 /* Create a pixmap as large as the glyph string. */
3983 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3984 s
->background_width
,
3987 /* Don't clip in the following because we're working on the
3989 XSetClipMask (s
->display
, s
->gc
, None
);
3991 /* Fill the pixmap with the background color/stipple. */
3994 /* Fill background with a stipple pattern. */
3995 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3996 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3997 0, 0, s
->background_width
, s
->height
);
3998 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4003 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4005 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4006 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4007 0, 0, s
->background_width
, s
->height
);
4008 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4012 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4014 s
->background_filled_p
= 1;
4017 /* Draw the foreground. */
4020 x_draw_image_foreground_1 (s
, pixmap
);
4021 x_set_glyph_string_clipping (s
);
4022 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4023 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4024 XFreePixmap (s
->display
, pixmap
);
4027 x_draw_image_foreground (s
);
4029 /* If we must draw a relief around the image, do it. */
4031 || s
->hl
== DRAW_IMAGE_RAISED
4032 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4033 x_draw_image_relief (s
);
4037 /* Draw stretch glyph string S. */
4040 x_draw_stretch_glyph_string (s
)
4041 struct glyph_string
*s
;
4043 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4044 s
->stippled_p
= s
->face
->stipple
!= 0;
4046 if (s
->hl
== DRAW_CURSOR
4047 && !x_stretch_cursor_p
)
4049 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4050 as wide as the stretch glyph. */
4051 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4054 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4056 /* Clear rest using the GC of the original non-cursor face. */
4057 if (width
< s
->background_width
)
4059 GC gc
= s
->face
->gc
;
4060 int x
= s
->x
+ width
, y
= s
->y
;
4061 int w
= s
->background_width
- width
, h
= s
->height
;
4064 x_get_glyph_string_clip_rect (s
, &r
);
4065 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4067 if (s
->face
->stipple
)
4069 /* Fill background with a stipple pattern. */
4070 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4071 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4072 XSetFillStyle (s
->display
, gc
, FillSolid
);
4077 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4078 XSetForeground (s
->display
, gc
, xgcv
.background
);
4079 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4080 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4085 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4088 s
->background_filled_p
= 1;
4092 /* Draw glyph string S. */
4095 x_draw_glyph_string (s
)
4096 struct glyph_string
*s
;
4098 /* If S draws into the background of its successor, draw the
4099 background of the successor first so that S can draw into it.
4100 This makes S->next use XDrawString instead of XDrawImageString. */
4101 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4103 xassert (s
->next
->img
== NULL
);
4104 x_set_glyph_string_gc (s
->next
);
4105 x_set_glyph_string_clipping (s
->next
);
4106 x_draw_glyph_string_background (s
->next
, 1);
4109 /* Set up S->gc, set clipping and draw S. */
4110 x_set_glyph_string_gc (s
);
4111 x_set_glyph_string_clipping (s
);
4113 switch (s
->first_glyph
->type
)
4116 x_draw_image_glyph_string (s
);
4120 x_draw_stretch_glyph_string (s
);
4124 if (s
->for_overlaps_p
)
4125 s
->background_filled_p
= 1;
4127 x_draw_glyph_string_background (s
, 0);
4128 x_draw_glyph_string_foreground (s
);
4131 case COMPOSITE_GLYPH
:
4132 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4133 s
->background_filled_p
= 1;
4135 x_draw_glyph_string_background (s
, 1);
4136 x_draw_composite_glyph_string_foreground (s
);
4143 if (!s
->for_overlaps_p
)
4145 /* Draw underline. */
4146 if (s
->face
->underline_p
)
4148 unsigned long dy
, h
;
4150 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4152 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
4155 if (s
->face
->underline_defaulted_p
)
4156 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4161 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4162 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4163 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4165 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4169 /* Draw overline. */
4170 if (s
->face
->overline_p
)
4172 unsigned long dy
= 0, h
= 1;
4174 if (s
->face
->overline_color_defaulted_p
)
4175 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4180 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4181 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4182 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4184 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4188 /* Draw strike-through. */
4189 if (s
->face
->strike_through_p
)
4191 unsigned long h
= 1;
4192 unsigned long dy
= (s
->height
- h
) / 2;
4194 if (s
->face
->strike_through_color_defaulted_p
)
4195 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4200 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4201 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4202 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4204 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4209 if (s
->face
->box
!= FACE_NO_BOX
)
4210 x_draw_glyph_string_box (s
);
4213 /* Reset clipping. */
4214 XSetClipMask (s
->display
, s
->gc
, None
);
4218 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4219 struct face
**, int));
4222 /* Fill glyph string S with composition components specified by S->cmp.
4224 FACES is an array of faces for all components of this composition.
4225 S->gidx is the index of the first component for S.
4226 OVERLAPS_P non-zero means S should draw the foreground only, and
4227 use its physical height for clipping.
4229 Value is the index of a component not in S. */
4232 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4233 struct glyph_string
*s
;
4234 struct face
**faces
;
4241 s
->for_overlaps_p
= overlaps_p
;
4243 s
->face
= faces
[s
->gidx
];
4244 s
->font
= s
->face
->font
;
4245 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4247 /* For all glyphs of this composition, starting at the offset
4248 S->gidx, until we reach the end of the definition or encounter a
4249 glyph that requires the different face, add it to S. */
4251 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4254 /* All glyph strings for the same composition has the same width,
4255 i.e. the width set for the first component of the composition. */
4257 s
->width
= s
->first_glyph
->pixel_width
;
4259 /* If the specified font could not be loaded, use the frame's
4260 default font, but record the fact that we couldn't load it in
4261 the glyph string so that we can draw rectangles for the
4262 characters of the glyph string. */
4263 if (s
->font
== NULL
)
4265 s
->font_not_found_p
= 1;
4266 s
->font
= FRAME_FONT (s
->f
);
4269 /* Adjust base line for subscript/superscript text. */
4270 s
->ybase
+= s
->first_glyph
->voffset
;
4272 xassert (s
->face
&& s
->face
->gc
);
4274 /* This glyph string must always be drawn with 16-bit functions. */
4277 return s
->gidx
+ s
->nchars
;
4281 /* Fill glyph string S from a sequence of character glyphs.
4283 FACE_ID is the face id of the string. START is the index of the
4284 first glyph to consider, END is the index of the last + 1.
4285 OVERLAPS_P non-zero means S should draw the foreground only, and
4286 use its physical height for clipping.
4288 Value is the index of the first glyph not in S. */
4291 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4292 struct glyph_string
*s
;
4294 int start
, end
, overlaps_p
;
4296 struct glyph
*glyph
, *last
;
4298 int glyph_not_available_p
;
4300 xassert (s
->f
== XFRAME (s
->w
->frame
));
4301 xassert (s
->nchars
== 0);
4302 xassert (start
>= 0 && end
> start
);
4304 s
->for_overlaps_p
= overlaps_p
,
4305 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4306 last
= s
->row
->glyphs
[s
->area
] + end
;
4307 voffset
= glyph
->voffset
;
4309 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4312 && glyph
->type
== CHAR_GLYPH
4313 && glyph
->voffset
== voffset
4314 /* Same face id implies same font, nowadays. */
4315 && glyph
->face_id
== face_id
4316 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4320 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4321 s
->char2b
+ s
->nchars
,
4323 s
->two_byte_p
= two_byte_p
;
4325 xassert (s
->nchars
<= end
- start
);
4326 s
->width
+= glyph
->pixel_width
;
4330 s
->font
= s
->face
->font
;
4331 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4333 /* If the specified font could not be loaded, use the frame's font,
4334 but record the fact that we couldn't load it in
4335 S->font_not_found_p so that we can draw rectangles for the
4336 characters of the glyph string. */
4337 if (s
->font
== NULL
|| glyph_not_available_p
)
4339 s
->font_not_found_p
= 1;
4340 s
->font
= FRAME_FONT (s
->f
);
4343 /* Adjust base line for subscript/superscript text. */
4344 s
->ybase
+= voffset
;
4346 xassert (s
->face
&& s
->face
->gc
);
4347 return glyph
- s
->row
->glyphs
[s
->area
];
4351 /* Fill glyph string S from image glyph S->first_glyph. */
4354 x_fill_image_glyph_string (s
)
4355 struct glyph_string
*s
;
4357 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4358 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4360 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4361 s
->font
= s
->face
->font
;
4362 s
->width
= s
->first_glyph
->pixel_width
;
4364 /* Adjust base line for subscript/superscript text. */
4365 s
->ybase
+= s
->first_glyph
->voffset
;
4369 /* Fill glyph string S from a sequence of stretch glyphs.
4371 ROW is the glyph row in which the glyphs are found, AREA is the
4372 area within the row. START is the index of the first glyph to
4373 consider, END is the index of the last + 1.
4375 Value is the index of the first glyph not in S. */
4378 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4379 struct glyph_string
*s
;
4380 struct glyph_row
*row
;
4381 enum glyph_row_area area
;
4384 struct glyph
*glyph
, *last
;
4385 int voffset
, face_id
;
4387 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4389 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4390 last
= s
->row
->glyphs
[s
->area
] + end
;
4391 face_id
= glyph
->face_id
;
4392 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4393 s
->font
= s
->face
->font
;
4394 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4395 s
->width
= glyph
->pixel_width
;
4396 voffset
= glyph
->voffset
;
4400 && glyph
->type
== STRETCH_GLYPH
4401 && glyph
->voffset
== voffset
4402 && glyph
->face_id
== face_id
);
4404 s
->width
+= glyph
->pixel_width
;
4406 /* Adjust base line for subscript/superscript text. */
4407 s
->ybase
+= voffset
;
4409 xassert (s
->face
&& s
->face
->gc
);
4410 return glyph
- s
->row
->glyphs
[s
->area
];
4414 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4415 of XChar2b structures for S; it can't be allocated in
4416 x_init_glyph_string because it must be allocated via `alloca'. W
4417 is the window on which S is drawn. ROW and AREA are the glyph row
4418 and area within the row from which S is constructed. START is the
4419 index of the first glyph structure covered by S. HL is a
4420 face-override for drawing S. */
4423 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4424 struct glyph_string
*s
;
4427 struct glyph_row
*row
;
4428 enum glyph_row_area area
;
4430 enum draw_glyphs_face hl
;
4432 bzero (s
, sizeof *s
);
4434 s
->f
= XFRAME (w
->frame
);
4435 s
->display
= FRAME_X_DISPLAY (s
->f
);
4436 s
->window
= FRAME_X_WINDOW (s
->f
);
4441 s
->first_glyph
= row
->glyphs
[area
] + start
;
4442 s
->height
= row
->height
;
4443 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4445 /* Display the internal border below the tool-bar window. */
4446 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4447 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4449 s
->ybase
= s
->y
+ row
->ascent
;
4453 /* Set background width of glyph string S. START is the index of the
4454 first glyph following S. LAST_X is the right-most x-position + 1
4455 in the drawing area. */
4458 x_set_glyph_string_background_width (s
, start
, last_x
)
4459 struct glyph_string
*s
;
4463 /* If the face of this glyph string has to be drawn to the end of
4464 the drawing area, set S->extends_to_end_of_line_p. */
4465 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4467 if (start
== s
->row
->used
[s
->area
]
4468 && s
->hl
== DRAW_NORMAL_TEXT
4469 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4470 || s
->face
->background
!= default_face
->background
4471 || s
->face
->stipple
!= default_face
->stipple
))
4472 s
->extends_to_end_of_line_p
= 1;
4474 /* If S extends its face to the end of the line, set its
4475 background_width to the distance to the right edge of the drawing
4477 if (s
->extends_to_end_of_line_p
)
4478 s
->background_width
= last_x
- s
->x
+ 1;
4480 s
->background_width
= s
->width
;
4484 /* Add a glyph string for a stretch glyph to the list of strings
4485 between HEAD and TAIL. START is the index of the stretch glyph in
4486 row area AREA of glyph row ROW. END is the index of the last glyph
4487 in that glyph row area. X is the current output position assigned
4488 to the new glyph string constructed. HL overrides that face of the
4489 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4490 is the right-most x-position of the drawing area. */
4492 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4493 and below -- keep them on one line. */
4494 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4497 s = (struct glyph_string *) alloca (sizeof *s); \
4498 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4499 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4500 x_append_glyph_string (&HEAD, &TAIL, s); \
4506 /* Add a glyph string for an image glyph to the list of strings
4507 between HEAD and TAIL. START is the index of the image glyph in
4508 row area AREA of glyph row ROW. END is the index of the last glyph
4509 in that glyph row area. X is the current output position assigned
4510 to the new glyph string constructed. HL overrides that face of the
4511 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4512 is the right-most x-position of the drawing area. */
4514 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4517 s = (struct glyph_string *) alloca (sizeof *s); \
4518 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4519 x_fill_image_glyph_string (s); \
4520 x_append_glyph_string (&HEAD, &TAIL, s); \
4527 /* Add a glyph string for a sequence of character glyphs to the list
4528 of strings between HEAD and TAIL. START is the index of the first
4529 glyph in row area AREA of glyph row ROW that is part of the new
4530 glyph string. END is the index of the last glyph in that glyph row
4531 area. X is the current output position assigned to the new glyph
4532 string constructed. HL overrides that face of the glyph; e.g. it
4533 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4534 right-most x-position of the drawing area. */
4536 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4542 c = (ROW)->glyphs[AREA][START].u.ch; \
4543 face_id = (ROW)->glyphs[AREA][START].face_id; \
4545 s = (struct glyph_string *) alloca (sizeof *s); \
4546 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4547 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4548 x_append_glyph_string (&HEAD, &TAIL, s); \
4550 START = x_fill_glyph_string (s, face_id, START, END, \
4556 /* Add a glyph string for a composite sequence to the list of strings
4557 between HEAD and TAIL. START is the index of the first glyph in
4558 row area AREA of glyph row ROW that is part of the new glyph
4559 string. END is the index of the last glyph in that glyph row area.
4560 X is the current output position assigned to the new glyph string
4561 constructed. HL overrides that face of the glyph; e.g. it is
4562 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4563 x-position of the drawing area. */
4565 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4567 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4568 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4569 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4570 struct composition *cmp = composition_table[cmp_id]; \
4571 int glyph_len = cmp->glyph_len; \
4573 struct face **faces; \
4574 struct glyph_string *first_s = NULL; \
4577 base_face = base_face->ascii_face; \
4578 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4579 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4580 /* At first, fill in `char2b' and `faces'. */ \
4581 for (n = 0; n < glyph_len; n++) \
4583 int c = COMPOSITION_GLYPH (cmp, n); \
4584 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4585 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4586 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4587 this_face_id, char2b + n, 1); \
4590 /* Make glyph_strings for each glyph sequence that is drawable by \
4591 the same face, and append them to HEAD/TAIL. */ \
4592 for (n = 0; n < cmp->glyph_len;) \
4594 s = (struct glyph_string *) alloca (sizeof *s); \
4595 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4596 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4604 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4612 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4613 of AREA of glyph row ROW on window W between indices START and END.
4614 HL overrides the face for drawing glyph strings, e.g. it is
4615 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4616 x-positions of the drawing area.
4618 This is an ugly monster macro construct because we must use alloca
4619 to allocate glyph strings (because x_draw_glyphs can be called
4622 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4625 HEAD = TAIL = NULL; \
4626 while (START < END) \
4628 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4629 switch (first_glyph->type) \
4632 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4633 TAIL, HL, X, LAST_X, \
4637 case COMPOSITE_GLYPH: \
4638 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4639 HEAD, TAIL, HL, X, LAST_X,\
4643 case STRETCH_GLYPH: \
4644 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4645 HEAD, TAIL, HL, X, LAST_X); \
4649 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4650 TAIL, HL, X, LAST_X); \
4657 x_set_glyph_string_background_width (s, START, LAST_X); \
4664 /* Draw glyphs between START and END in AREA of ROW on window W,
4665 starting at x-position X. X is relative to AREA in W. HL is a
4666 face-override with the following meaning:
4668 DRAW_NORMAL_TEXT draw normally
4669 DRAW_CURSOR draw in cursor face
4670 DRAW_MOUSE_FACE draw in mouse face.
4671 DRAW_INVERSE_VIDEO draw in mode line face
4672 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4673 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4675 If REAL_START is non-null, return in *REAL_START the real starting
4676 position for display. This can be different from START in case
4677 overlapping glyphs must be displayed. If REAL_END is non-null,
4678 return in *REAL_END the real end position for display. This can be
4679 different from END in case overlapping glyphs must be displayed.
4681 If OVERLAPS_P is non-zero, draw only the foreground of characters
4682 and clip to the physical height of ROW.
4684 Value is the x-position reached, relative to AREA of W. */
4687 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4691 struct glyph_row
*row
;
4692 enum glyph_row_area area
;
4694 enum draw_glyphs_face hl
;
4695 int *real_start
, *real_end
;
4698 struct glyph_string
*head
, *tail
;
4699 struct glyph_string
*s
;
4700 int last_x
, area_width
;
4704 /* Let's rather be paranoid than getting a SEGV. */
4705 end
= min (end
, row
->used
[area
]);
4706 start
= max (0, start
);
4707 start
= min (end
, start
);
4709 *real_start
= start
;
4713 /* Translate X to frame coordinates. Set last_x to the right
4714 end of the drawing area. */
4715 if (row
->full_width_p
)
4717 /* X is relative to the left edge of W, without scroll bars
4719 struct frame
*f
= XFRAME (w
->frame
);
4720 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4721 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4724 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4725 last_x
= window_left_x
+ area_width
;
4727 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4729 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4730 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4736 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4737 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4741 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4742 area_width
= window_box_width (w
, area
);
4743 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4746 /* Build a doubly-linked list of glyph_string structures between
4747 head and tail from what we have to draw. Note that the macro
4748 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4749 the reason we use a separate variable `i'. */
4751 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4754 x_reached
= tail
->x
+ tail
->background_width
;
4758 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4759 the row, redraw some glyphs in front or following the glyph
4760 strings built above. */
4761 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4764 struct glyph_string
*h
, *t
;
4766 /* Compute overhangs for all glyph strings. */
4767 for (s
= head
; s
; s
= s
->next
)
4768 x_compute_glyph_string_overhangs (s
);
4770 /* Prepend glyph strings for glyphs in front of the first glyph
4771 string that are overwritten because of the first glyph
4772 string's left overhang. The background of all strings
4773 prepended must be drawn because the first glyph string
4775 i
= x_left_overwritten (head
);
4779 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4780 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4784 *real_start
= start
;
4785 x_compute_overhangs_and_x (t
, head
->x
, 1);
4786 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4789 /* Prepend glyph strings for glyphs in front of the first glyph
4790 string that overwrite that glyph string because of their
4791 right overhang. For these strings, only the foreground must
4792 be drawn, because it draws over the glyph string at `head'.
4793 The background must not be drawn because this would overwrite
4794 right overhangs of preceding glyphs for which no glyph
4796 i
= x_left_overwriting (head
);
4799 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4800 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4802 for (s
= h
; s
; s
= s
->next
)
4803 s
->background_filled_p
= 1;
4806 x_compute_overhangs_and_x (t
, head
->x
, 1);
4807 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4810 /* Append glyphs strings for glyphs following the last glyph
4811 string tail that are overwritten by tail. The background of
4812 these strings has to be drawn because tail's foreground draws
4814 i
= x_right_overwritten (tail
);
4817 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4818 DRAW_NORMAL_TEXT
, x
, last_x
,
4820 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4821 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4826 /* Append glyph strings for glyphs following the last glyph
4827 string tail that overwrite tail. The foreground of such
4828 glyphs has to be drawn because it writes into the background
4829 of tail. The background must not be drawn because it could
4830 paint over the foreground of following glyphs. */
4831 i
= x_right_overwriting (tail
);
4834 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4835 DRAW_NORMAL_TEXT
, x
, last_x
,
4837 for (s
= h
; s
; s
= s
->next
)
4838 s
->background_filled_p
= 1;
4839 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4840 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4846 /* Draw all strings. */
4847 for (s
= head
; s
; s
= s
->next
)
4848 x_draw_glyph_string (s
);
4850 /* Value is the x-position up to which drawn, relative to AREA of W.
4851 This doesn't include parts drawn because of overhangs. */
4852 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4853 if (!row
->full_width_p
)
4855 if (area
> LEFT_MARGIN_AREA
)
4856 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4857 if (area
> TEXT_AREA
)
4858 x_reached
-= window_box_width (w
, TEXT_AREA
);
4865 /* Fix the display of area AREA of overlapping row ROW in window W. */
4868 x_fix_overlapping_area (w
, row
, area
)
4870 struct glyph_row
*row
;
4871 enum glyph_row_area area
;
4877 if (area
== LEFT_MARGIN_AREA
)
4879 else if (area
== TEXT_AREA
)
4880 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4882 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4883 + window_box_width (w
, TEXT_AREA
));
4885 for (i
= 0; i
< row
->used
[area
];)
4887 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4889 int start
= i
, start_x
= x
;
4893 x
+= row
->glyphs
[area
][i
].pixel_width
;
4896 while (i
< row
->used
[area
]
4897 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4899 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4901 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4906 x
+= row
->glyphs
[area
][i
].pixel_width
;
4915 /* Output LEN glyphs starting at START at the nominal cursor position.
4916 Advance the nominal cursor over the text. The global variable
4917 updated_window contains the window being updated, updated_row is
4918 the glyph row being updated, and updated_area is the area of that
4919 row being updated. */
4922 x_write_glyphs (start
, len
)
4923 struct glyph
*start
;
4926 int x
, hpos
, real_start
, real_end
;
4928 xassert (updated_window
&& updated_row
);
4933 hpos
= start
- updated_row
->glyphs
[updated_area
];
4934 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4935 updated_row
, updated_area
,
4937 (updated_row
->inverse_p
4938 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4939 &real_start
, &real_end
, 0);
4941 /* If we drew over the cursor, note that it is not visible any more. */
4942 note_overwritten_text_cursor (updated_window
, real_start
,
4943 real_end
- real_start
);
4947 /* Advance the output cursor. */
4948 output_cursor
.hpos
+= len
;
4949 output_cursor
.x
= x
;
4953 /* Insert LEN glyphs from START at the nominal cursor position. */
4956 x_insert_glyphs (start
, len
)
4957 struct glyph
*start
;
4962 int line_height
, shift_by_width
, shifted_region_width
;
4963 struct glyph_row
*row
;
4964 struct glyph
*glyph
;
4965 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4967 xassert (updated_window
&& updated_row
);
4970 f
= XFRAME (WINDOW_FRAME (w
));
4972 /* Get the height of the line we are in. */
4974 line_height
= row
->height
;
4976 /* Get the width of the glyphs to insert. */
4978 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4979 shift_by_width
+= glyph
->pixel_width
;
4981 /* Get the width of the region to shift right. */
4982 shifted_region_width
= (window_box_width (w
, updated_area
)
4987 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4988 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4989 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4990 f
->output_data
.x
->normal_gc
,
4992 shifted_region_width
, line_height
,
4993 frame_x
+ shift_by_width
, frame_y
);
4995 /* Write the glyphs. */
4996 hpos
= start
- row
->glyphs
[updated_area
];
4997 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4998 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4999 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5001 /* Advance the output cursor. */
5002 output_cursor
.hpos
+= len
;
5003 output_cursor
.x
+= shift_by_width
;
5008 /* Delete N glyphs at the nominal cursor position. Not implemented
5019 /* Erase the current text line from the nominal cursor position
5020 (inclusive) to pixel column TO_X (exclusive). The idea is that
5021 everything from TO_X onward is already erased.
5023 TO_X is a pixel position relative to updated_area of
5024 updated_window. TO_X == -1 means clear to the end of this area. */
5027 x_clear_end_of_line (to_x
)
5031 struct window
*w
= updated_window
;
5032 int max_x
, min_y
, max_y
;
5033 int from_x
, from_y
, to_y
;
5035 xassert (updated_window
&& updated_row
);
5036 f
= XFRAME (w
->frame
);
5038 if (updated_row
->full_width_p
)
5040 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5041 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5042 && !w
->pseudo_window_p
)
5043 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5046 max_x
= window_box_width (w
, updated_area
);
5047 max_y
= window_text_bottom_y (w
);
5049 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5050 of window. For TO_X > 0, truncate to end of drawing area. */
5056 to_x
= min (to_x
, max_x
);
5058 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5060 /* Notice if the cursor will be cleared by this operation. */
5061 if (!updated_row
->full_width_p
)
5062 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5064 from_x
= output_cursor
.x
;
5066 /* Translate to frame coordinates. */
5067 if (updated_row
->full_width_p
)
5069 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5070 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5074 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5075 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5078 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5079 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5080 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5082 /* Prevent inadvertently clearing to end of the X window. */
5083 if (to_x
> from_x
&& to_y
> from_y
)
5086 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5087 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5094 /* Clear entire frame. If updating_frame is non-null, clear that
5095 frame. Otherwise clear the selected frame. */
5105 f
= SELECTED_FRAME ();
5107 /* Clearing the frame will erase any cursor, so mark them all as no
5109 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5110 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5111 output_cursor
.x
= -1;
5113 /* We don't set the output cursor here because there will always
5114 follow an explicit cursor_to. */
5116 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5118 /* We have to clear the scroll bars, too. If we have changed
5119 colors or something like that, then they should be notified. */
5120 x_scroll_bar_clear (f
);
5122 XFlush (FRAME_X_DISPLAY (f
));
5128 /* Invert the middle quarter of the frame for .15 sec. */
5130 /* We use the select system call to do the waiting, so we have to make
5131 sure it's available. If it isn't, we just won't do visual bells. */
5133 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5136 /* Subtract the `struct timeval' values X and Y, storing the result in
5137 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5140 timeval_subtract (result
, x
, y
)
5141 struct timeval
*result
, x
, y
;
5143 /* Perform the carry for the later subtraction by updating y. This
5144 is safer because on some systems the tv_sec member is unsigned. */
5145 if (x
.tv_usec
< y
.tv_usec
)
5147 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5148 y
.tv_usec
-= 1000000 * nsec
;
5152 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5154 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5155 y
.tv_usec
+= 1000000 * nsec
;
5159 /* Compute the time remaining to wait. tv_usec is certainly
5161 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5162 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5164 /* Return indication of whether the result should be considered
5166 return x
.tv_sec
< y
.tv_sec
;
5178 /* Create a GC that will use the GXxor function to flip foreground
5179 pixels into background pixels. */
5183 values
.function
= GXxor
;
5184 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5185 ^ f
->output_data
.x
->background_pixel
);
5187 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5188 GCFunction
| GCForeground
, &values
);
5192 /* Get the height not including a menu bar widget. */
5193 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5194 /* Height of each line to flash. */
5195 int flash_height
= FRAME_LINE_HEIGHT (f
);
5196 /* These will be the left and right margins of the rectangles. */
5197 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5198 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5202 /* Don't flash the area between a scroll bar and the frame
5203 edge it is next to. */
5204 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5206 case vertical_scroll_bar_left
:
5207 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5210 case vertical_scroll_bar_right
:
5211 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5218 width
= flash_right
- flash_left
;
5220 /* If window is tall, flash top and bottom line. */
5221 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5223 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5225 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5226 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5227 width
, flash_height
);
5228 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5230 (height
- flash_height
5231 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5232 width
, flash_height
);
5235 /* If it is short, flash it all. */
5236 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5237 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5238 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5243 struct timeval wakeup
;
5245 EMACS_GET_TIME (wakeup
);
5247 /* Compute time to wait until, propagating carry from usecs. */
5248 wakeup
.tv_usec
+= 150000;
5249 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5250 wakeup
.tv_usec
%= 1000000;
5252 /* Keep waiting until past the time wakeup. */
5255 struct timeval timeout
;
5257 EMACS_GET_TIME (timeout
);
5259 /* In effect, timeout = wakeup - timeout.
5260 Break if result would be negative. */
5261 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5264 /* Try to wait that long--but we might wake up sooner. */
5265 select (0, NULL
, NULL
, NULL
, &timeout
);
5269 /* If window is tall, flash top and bottom line. */
5270 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5272 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5274 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5275 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5276 width
, flash_height
);
5277 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5279 (height
- flash_height
5280 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5281 width
, flash_height
);
5284 /* If it is short, flash it all. */
5285 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5286 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5287 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5289 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5297 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5300 /* Make audible bell. */
5305 struct frame
*f
= SELECTED_FRAME ();
5307 if (FRAME_X_DISPLAY (f
))
5309 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5316 XBell (FRAME_X_DISPLAY (f
), 0);
5317 XFlush (FRAME_X_DISPLAY (f
));
5324 /* Specify how many text lines, from the top of the window,
5325 should be affected by insert-lines and delete-lines operations.
5326 This, and those operations, are used only within an update
5327 that is bounded by calls to x_update_begin and x_update_end. */
5330 XTset_terminal_window (n
)
5333 /* This function intentionally left blank. */
5338 /***********************************************************************
5340 ***********************************************************************/
5342 /* Perform an insert-lines or delete-lines operation, inserting N
5343 lines or deleting -N lines at vertical position VPOS. */
5346 x_ins_del_lines (vpos
, n
)
5353 /* Scroll part of the display as described by RUN. */
5356 x_scroll_run (w
, run
)
5360 struct frame
*f
= XFRAME (w
->frame
);
5361 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5363 /* Get frame-relative bounding box of the text display area of W,
5364 without mode lines. Include in this box the flags areas to the
5365 left and right of W. */
5366 window_box (w
, -1, &x
, &y
, &width
, &height
);
5367 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5368 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5370 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5371 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5372 bottom_y
= y
+ height
;
5376 /* Scrolling up. Make sure we don't copy part of the mode
5377 line at the bottom. */
5378 if (from_y
+ run
->height
> bottom_y
)
5379 height
= bottom_y
- from_y
;
5381 height
= run
->height
;
5385 /* Scolling down. Make sure we don't copy over the mode line.
5387 if (to_y
+ run
->height
> bottom_y
)
5388 height
= bottom_y
- to_y
;
5390 height
= run
->height
;
5395 /* Cursor off. Will be switched on again in x_update_window_end. */
5399 XCopyArea (FRAME_X_DISPLAY (f
),
5400 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5401 f
->output_data
.x
->normal_gc
,
5411 /***********************************************************************
5413 ***********************************************************************/
5415 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5416 corner of the exposed rectangle. W and H are width and height of
5417 the exposed area. All are pixel values. W or H zero means redraw
5418 the entire frame. */
5421 expose_frame (f
, x
, y
, w
, h
)
5427 TRACE ((stderr
, "expose_frame "));
5429 /* No need to redraw if frame will be redrawn soon. */
5430 if (FRAME_GARBAGED_P (f
))
5432 TRACE ((stderr
, " garbaged\n"));
5436 /* If basic faces haven't been realized yet, there is no point in
5437 trying to redraw anything. This can happen when we get an expose
5438 event while Emacs is starting, e.g. by moving another window. */
5439 if (FRAME_FACE_CACHE (f
) == NULL
5440 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5442 TRACE ((stderr
, " no faces\n"));
5446 if (w
== 0 || h
== 0)
5449 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5450 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5460 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5461 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5463 if (WINDOWP (f
->tool_bar_window
))
5465 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5466 XRectangle window_rect
;
5467 XRectangle intersection_rect
;
5468 int window_x
, window_y
, window_width
, window_height
;
5471 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5472 window_rect
.x
= window_x
;
5473 window_rect
.y
= window_y
;
5474 window_rect
.width
= window_width
;
5475 window_rect
.height
= window_height
;
5477 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5478 expose_window (w
, &intersection_rect
);
5481 #ifndef USE_X_TOOLKIT
5482 if (WINDOWP (f
->menu_bar_window
))
5484 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5485 XRectangle window_rect
;
5486 XRectangle intersection_rect
;
5487 int window_x
, window_y
, window_width
, window_height
;
5490 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5491 window_rect
.x
= window_x
;
5492 window_rect
.y
= window_y
;
5493 window_rect
.width
= window_width
;
5494 window_rect
.height
= window_height
;
5496 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5497 expose_window (w
, &intersection_rect
);
5499 #endif /* not USE_X_TOOLKIT */
5503 /* Redraw (parts) of all windows in the window tree rooted at W that
5504 intersect R. R contains frame pixel coordinates. */
5507 expose_window_tree (w
, r
)
5513 if (!NILP (w
->hchild
))
5514 expose_window_tree (XWINDOW (w
->hchild
), r
);
5515 else if (!NILP (w
->vchild
))
5516 expose_window_tree (XWINDOW (w
->vchild
), r
);
5519 XRectangle window_rect
;
5520 XRectangle intersection_rect
;
5521 struct frame
*f
= XFRAME (w
->frame
);
5522 int window_x
, window_y
, window_width
, window_height
;
5524 /* Frame-relative pixel rectangle of W. */
5525 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5529 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5530 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5531 window_rect
.y
= window_y
;
5534 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5535 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5537 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5539 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5540 expose_window (w
, &intersection_rect
);
5543 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5548 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5549 which intersects rectangle R. R is in window-relative coordinates. */
5552 expose_area (w
, row
, r
, area
)
5554 struct glyph_row
*row
;
5556 enum glyph_row_area area
;
5559 struct glyph
*first
= row
->glyphs
[area
];
5560 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5564 /* Set x to the window-relative start position for drawing glyphs of
5565 AREA. The first glyph of the text area can be partially visible.
5566 The first glyphs of other areas cannot. */
5567 if (area
== LEFT_MARGIN_AREA
)
5569 else if (area
== TEXT_AREA
)
5570 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5572 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5573 + window_box_width (w
, TEXT_AREA
));
5575 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5576 /* If row extends face to end of line write the whole line. */
5577 x_draw_glyphs (w
, x
, row
, area
,
5579 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5583 /* Find the first glyph that must be redrawn. */
5585 && x
+ first
->pixel_width
< r
->x
)
5587 x
+= first
->pixel_width
;
5591 /* Find the last one. */
5595 && x
< r
->x
+ r
->width
)
5597 x
+= last
->pixel_width
;
5603 x_draw_glyphs (w
, first_x
, row
, area
,
5604 first
- row
->glyphs
[area
],
5605 last
- row
->glyphs
[area
],
5606 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5612 /* Redraw the parts of the glyph row ROW on window W intersecting
5613 rectangle R. R is in window-relative coordinates. */
5616 expose_line (w
, row
, r
)
5618 struct glyph_row
*row
;
5621 xassert (row
->enabled_p
);
5623 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5624 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5625 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5629 if (row
->used
[LEFT_MARGIN_AREA
])
5630 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5631 if (row
->used
[TEXT_AREA
])
5632 expose_area (w
, row
, r
, TEXT_AREA
);
5633 if (row
->used
[RIGHT_MARGIN_AREA
])
5634 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5635 x_draw_row_bitmaps (w
, row
);
5640 /* Return non-zero if W's cursor intersects rectangle R. */
5643 x_phys_cursor_in_rect_p (w
, r
)
5647 XRectangle cr
, result
;
5648 struct glyph
*cursor_glyph
;
5650 cursor_glyph
= get_phys_cursor_glyph (w
);
5653 cr
.x
= w
->phys_cursor
.x
;
5654 cr
.y
= w
->phys_cursor
.y
;
5655 cr
.width
= cursor_glyph
->pixel_width
;
5656 cr
.height
= w
->phys_cursor_height
;
5657 return x_intersect_rectangles (&cr
, r
, &result
);
5664 /* Redraw a rectangle of window W. R is a rectangle in window
5665 relative coordinates. Call this function with input blocked. */
5668 expose_window (w
, r
)
5672 struct glyph_row
*row
;
5674 int yb
= window_text_bottom_y (w
);
5675 int cursor_cleared_p
;
5677 /* If window is not yet fully initialized, do nothing. This can
5678 happen when toolkit scroll bars are used and a window is split.
5679 Reconfiguring the scroll bar will generate an expose for a newly
5681 if (w
->current_matrix
== NULL
)
5684 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5685 r
->x
, r
->y
, r
->width
, r
->height
));
5687 /* Convert to window coordinates. */
5688 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5689 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5691 /* Turn off the cursor. */
5692 if (!w
->pseudo_window_p
5693 && x_phys_cursor_in_rect_p (w
, r
))
5696 cursor_cleared_p
= 1;
5699 cursor_cleared_p
= 0;
5701 /* Find the first row intersecting the rectangle R. */
5702 row
= w
->current_matrix
->rows
;
5704 while (row
->enabled_p
5706 && y
+ row
->height
< r
->y
)
5712 /* Display the text in the rectangle, one text line at a time. */
5713 while (row
->enabled_p
5715 && y
< r
->y
+ r
->height
)
5717 expose_line (w
, row
, r
);
5722 /* Display the mode line if there is one. */
5723 if (WINDOW_WANTS_MODELINE_P (w
)
5724 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5726 && row
->y
< r
->y
+ r
->height
)
5727 expose_line (w
, row
, r
);
5729 if (!w
->pseudo_window_p
)
5731 /* Draw border between windows. */
5732 x_draw_vertical_border (w
);
5734 /* Turn the cursor on again. */
5735 if (cursor_cleared_p
)
5736 x_update_window_cursor (w
, 1);
5741 /* Determine the intersection of two rectangles R1 and R2. Return
5742 the intersection in *RESULT. Value is non-zero if RESULT is not
5746 x_intersect_rectangles (r1
, r2
, result
)
5747 XRectangle
*r1
, *r2
, *result
;
5749 XRectangle
*left
, *right
;
5750 XRectangle
*upper
, *lower
;
5751 int intersection_p
= 0;
5753 /* Rearrange so that R1 is the left-most rectangle. */
5755 left
= r1
, right
= r2
;
5757 left
= r2
, right
= r1
;
5759 /* X0 of the intersection is right.x0, if this is inside R1,
5760 otherwise there is no intersection. */
5761 if (right
->x
<= left
->x
+ left
->width
)
5763 result
->x
= right
->x
;
5765 /* The right end of the intersection is the minimum of the
5766 the right ends of left and right. */
5767 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5770 /* Same game for Y. */
5772 upper
= r1
, lower
= r2
;
5774 upper
= r2
, lower
= r1
;
5776 /* The upper end of the intersection is lower.y0, if this is inside
5777 of upper. Otherwise, there is no intersection. */
5778 if (lower
->y
<= upper
->y
+ upper
->height
)
5780 result
->y
= lower
->y
;
5782 /* The lower end of the intersection is the minimum of the lower
5783 ends of upper and lower. */
5784 result
->height
= (min (lower
->y
+ lower
->height
,
5785 upper
->y
+ upper
->height
)
5791 return intersection_p
;
5802 /* We used to only do this if Vx_no_window_manager was non-nil, but
5803 the ICCCM (section 4.1.6) says that the window's border pixmap
5804 and border pixel are window attributes which are "private to the
5805 client", so we can always change it to whatever we want. */
5807 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5808 f
->output_data
.x
->border_pixel
);
5810 x_update_cursor (f
, 1);
5814 frame_unhighlight (f
)
5817 /* We used to only do this if Vx_no_window_manager was non-nil, but
5818 the ICCCM (section 4.1.6) says that the window's border pixmap
5819 and border pixel are window attributes which are "private to the
5820 client", so we can always change it to whatever we want. */
5822 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5823 f
->output_data
.x
->border_tile
);
5825 x_update_cursor (f
, 1);
5828 /* The focus has changed. Update the frames as necessary to reflect
5829 the new situation. Note that we can't change the selected frame
5830 here, because the Lisp code we are interrupting might become confused.
5831 Each event gets marked with the frame in which it occurred, so the
5832 Lisp code can tell when the switch took place by examining the events. */
5835 x_new_focus_frame (dpyinfo
, frame
)
5836 struct x_display_info
*dpyinfo
;
5837 struct frame
*frame
;
5839 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5841 if (frame
!= dpyinfo
->x_focus_frame
)
5843 /* Set this before calling other routines, so that they see
5844 the correct value of x_focus_frame. */
5845 dpyinfo
->x_focus_frame
= frame
;
5847 if (old_focus
&& old_focus
->auto_lower
)
5848 x_lower_frame (old_focus
);
5851 selected_frame
= frame
;
5852 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5854 Fselect_window (selected_frame
->selected_window
);
5855 choose_minibuf_frame ();
5858 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5859 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5861 pending_autoraise_frame
= 0;
5864 x_frame_rehighlight (dpyinfo
);
5867 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5870 x_mouse_leave (dpyinfo
)
5871 struct x_display_info
*dpyinfo
;
5873 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5876 /* The focus has changed, or we have redirected a frame's focus to
5877 another frame (this happens when a frame uses a surrogate
5878 mini-buffer frame). Shift the highlight as appropriate.
5880 The FRAME argument doesn't necessarily have anything to do with which
5881 frame is being highlighted or un-highlighted; we only use it to find
5882 the appropriate X display info. */
5885 XTframe_rehighlight (frame
)
5886 struct frame
*frame
;
5888 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5892 x_frame_rehighlight (dpyinfo
)
5893 struct x_display_info
*dpyinfo
;
5895 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5897 if (dpyinfo
->x_focus_frame
)
5899 dpyinfo
->x_highlight_frame
5900 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5901 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5902 : dpyinfo
->x_focus_frame
);
5903 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5905 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5906 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5910 dpyinfo
->x_highlight_frame
= 0;
5912 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5915 frame_unhighlight (old_highlight
);
5916 if (dpyinfo
->x_highlight_frame
)
5917 frame_highlight (dpyinfo
->x_highlight_frame
);
5923 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5925 /* Initialize mode_switch_bit and modifier_meaning. */
5927 x_find_modifier_meanings (dpyinfo
)
5928 struct x_display_info
*dpyinfo
;
5930 int min_code
, max_code
;
5933 XModifierKeymap
*mods
;
5935 dpyinfo
->meta_mod_mask
= 0;
5936 dpyinfo
->shift_lock_mask
= 0;
5937 dpyinfo
->alt_mod_mask
= 0;
5938 dpyinfo
->super_mod_mask
= 0;
5939 dpyinfo
->hyper_mod_mask
= 0;
5942 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5944 min_code
= dpyinfo
->display
->min_keycode
;
5945 max_code
= dpyinfo
->display
->max_keycode
;
5948 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5949 min_code
, max_code
- min_code
+ 1,
5951 mods
= XGetModifierMapping (dpyinfo
->display
);
5953 /* Scan the modifier table to see which modifier bits the Meta and
5954 Alt keysyms are on. */
5956 int row
, col
; /* The row and column in the modifier table. */
5958 for (row
= 3; row
< 8; row
++)
5959 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5962 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5964 /* Zeroes are used for filler. Skip them. */
5968 /* Are any of this keycode's keysyms a meta key? */
5972 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5974 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5980 dpyinfo
->meta_mod_mask
|= (1 << row
);
5985 dpyinfo
->alt_mod_mask
|= (1 << row
);
5990 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5995 dpyinfo
->super_mod_mask
|= (1 << row
);
5999 /* Ignore this if it's not on the lock modifier. */
6000 if ((1 << row
) == LockMask
)
6001 dpyinfo
->shift_lock_mask
= LockMask
;
6009 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6010 if (! dpyinfo
->meta_mod_mask
)
6012 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6013 dpyinfo
->alt_mod_mask
= 0;
6016 /* If some keys are both alt and meta,
6017 make them just meta, not alt. */
6018 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6020 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6023 XFree ((char *) syms
);
6024 XFreeModifiermap (mods
);
6027 /* Convert between the modifier bits X uses and the modifier bits
6031 x_x_to_emacs_modifiers (dpyinfo
, state
)
6032 struct x_display_info
*dpyinfo
;
6035 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6036 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6037 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6038 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6039 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6040 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6044 x_emacs_to_x_modifiers (dpyinfo
, state
)
6045 struct x_display_info
*dpyinfo
;
6048 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6049 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6050 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6051 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6052 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6053 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6056 /* Convert a keysym to its name. */
6059 x_get_keysym_name (keysym
)
6065 value
= XKeysymToString (keysym
);
6073 /* Mouse clicks and mouse movement. Rah. */
6075 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6076 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6077 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6078 not force the value into range. */
6081 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6083 register int pix_x
, pix_y
;
6084 register int *x
, *y
;
6088 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6089 even for negative values. */
6091 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6093 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6095 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6096 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6100 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6101 bounds
->height
= f
->output_data
.x
->line_height
;
6102 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6103 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6110 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6111 pix_x
= FRAME_WINDOW_WIDTH (f
);
6115 else if (pix_y
> f
->height
)
6124 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6125 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6126 can't tell the positions because W's display is not up to date,
6130 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6133 int *frame_x
, *frame_y
;
6137 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6138 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6140 if (display_completed
)
6142 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6143 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6144 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6150 *frame_x
+= glyph
->pixel_width
;
6158 *frame_y
= *frame_x
= 0;
6162 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6163 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6168 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6170 If the event is a button press, then note that we have grabbed
6174 construct_mouse_click (result
, event
, f
)
6175 struct input_event
*result
;
6176 XButtonEvent
*event
;
6179 /* Make the event type no_event; we'll change that when we decide
6181 result
->kind
= mouse_click
;
6182 result
->code
= event
->button
- Button1
;
6183 result
->timestamp
= event
->time
;
6184 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6186 | (event
->type
== ButtonRelease
6190 XSETINT (result
->x
, event
->x
);
6191 XSETINT (result
->y
, event
->y
);
6192 XSETFRAME (result
->frame_or_window
, f
);
6198 /* Function to report a mouse movement to the mainstream Emacs code.
6199 The input handler calls this.
6201 We have received a mouse movement event, which is given in *event.
6202 If the mouse is over a different glyph than it was last time, tell
6203 the mainstream emacs code by setting mouse_moved. If not, ask for
6204 another motion event, so we can check again the next time it moves. */
6206 static XMotionEvent last_mouse_motion_event
;
6207 static Lisp_Object last_mouse_motion_frame
;
6210 note_mouse_movement (frame
, event
)
6212 XMotionEvent
*event
;
6214 last_mouse_movement_time
= event
->time
;
6215 last_mouse_motion_event
= *event
;
6216 XSETFRAME (last_mouse_motion_frame
, frame
);
6218 if (event
->window
!= FRAME_X_WINDOW (frame
))
6220 frame
->mouse_moved
= 1;
6221 last_mouse_scroll_bar
= Qnil
;
6222 note_mouse_highlight (frame
, -1, -1);
6225 /* Has the mouse moved off the glyph it was on at the last sighting? */
6226 else if (event
->x
< last_mouse_glyph
.x
6227 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6228 || event
->y
< last_mouse_glyph
.y
6229 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6231 frame
->mouse_moved
= 1;
6232 last_mouse_scroll_bar
= Qnil
;
6233 note_mouse_highlight (frame
, event
->x
, event
->y
);
6237 /* This is used for debugging, to turn off note_mouse_highlight. */
6239 int disable_mouse_highlight
;
6243 /************************************************************************
6245 ************************************************************************/
6247 /* Find the glyph under window-relative coordinates X/Y in window W.
6248 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6249 strings. Return in *HPOS and *VPOS the row and column number of
6250 the glyph found. Return in *AREA the glyph area containing X.
6251 Value is a pointer to the glyph found or null if X/Y is not on
6252 text, or we can't tell because W's current matrix is not up to
6255 static struct glyph
*
6256 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6259 int *hpos
, *vpos
, *area
;
6261 struct glyph
*glyph
, *end
;
6262 struct glyph_row
*row
= NULL
;
6263 int x0
, i
, left_area_width
;
6265 /* Find row containing Y. Give up if some row is not enabled. */
6266 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6268 row
= MATRIX_ROW (w
->current_matrix
, i
);
6269 if (!row
->enabled_p
)
6271 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6278 /* Give up if Y is not in the window. */
6279 if (i
== w
->current_matrix
->nrows
)
6282 /* Get the glyph area containing X. */
6283 if (w
->pseudo_window_p
)
6290 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6291 if (x
< left_area_width
)
6293 *area
= LEFT_MARGIN_AREA
;
6296 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6299 x0
= row
->x
+ left_area_width
;
6303 *area
= RIGHT_MARGIN_AREA
;
6304 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6308 /* Find glyph containing X. */
6309 glyph
= row
->glyphs
[*area
];
6310 end
= glyph
+ row
->used
[*area
];
6313 if (x
< x0
+ glyph
->pixel_width
)
6315 if (w
->pseudo_window_p
)
6317 else if (BUFFERP (glyph
->object
))
6321 x0
+= glyph
->pixel_width
;
6328 *hpos
= glyph
- row
->glyphs
[*area
];
6333 /* Convert frame-relative x/y to coordinates relative to window W.
6334 Takes pseudo-windows into account. */
6337 frame_to_window_pixel_xy (w
, x
, y
)
6341 if (w
->pseudo_window_p
)
6343 /* A pseudo-window is always full-width, and starts at the
6344 left edge of the frame, plus a frame border. */
6345 struct frame
*f
= XFRAME (w
->frame
);
6346 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6347 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6351 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6352 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6357 /* Take proper action when mouse has moved to the mode or top line of
6358 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6359 mode line. X is relative to the start of the text display area of
6360 W, so the width of bitmap areas and scroll bars must be subtracted
6361 to get a position relative to the start of the mode line. */
6364 note_mode_line_highlight (w
, x
, mode_line_p
)
6368 struct frame
*f
= XFRAME (w
->frame
);
6369 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6370 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6371 struct glyph_row
*row
;
6374 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6376 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6380 struct glyph
*glyph
, *end
;
6381 Lisp_Object help
, map
;
6384 /* Find the glyph under X. */
6385 glyph
= row
->glyphs
[TEXT_AREA
];
6386 end
= glyph
+ row
->used
[TEXT_AREA
];
6387 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6388 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6390 && x
>= x0
+ glyph
->pixel_width
)
6392 x0
+= glyph
->pixel_width
;
6397 && STRINGP (glyph
->object
)
6398 && XSTRING (glyph
->object
)->intervals
6399 && glyph
->charpos
>= 0
6400 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6402 /* If we're on a string with `help-echo' text property,
6403 arrange for the help to be displayed. This is done by
6404 setting the global variable help_echo to the help string. */
6405 help
= Fget_text_property (make_number (glyph
->charpos
),
6406 Qhelp_echo
, glyph
->object
);
6410 XSETWINDOW (help_echo_window
, w
);
6411 help_echo_object
= glyph
->object
;
6412 help_echo_pos
= glyph
->charpos
;
6415 /* Change the mouse pointer according to what is under X/Y. */
6416 map
= Fget_text_property (make_number (glyph
->charpos
),
6417 Qlocal_map
, glyph
->object
);
6418 if (!NILP (Fkeymapp (map
)))
6419 cursor
= f
->output_data
.x
->nontext_cursor
;
6422 map
= Fget_text_property (make_number (glyph
->charpos
),
6423 Qkeymap
, glyph
->object
);
6424 if (!NILP (Fkeymapp (map
)))
6425 cursor
= f
->output_data
.x
->nontext_cursor
;
6430 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6434 /* Take proper action when the mouse has moved to position X, Y on
6435 frame F as regards highlighting characters that have mouse-face
6436 properties. Also de-highlighting chars where the mouse was before.
6437 X and Y can be negative or out of range. */
6440 note_mouse_highlight (f
, x
, y
)
6444 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6449 /* When a menu is active, don't highlight because this looks odd. */
6450 #ifdef USE_X_TOOLKIT
6451 if (popup_activated ())
6455 if (disable_mouse_highlight
6456 || !f
->glyphs_initialized_p
)
6459 dpyinfo
->mouse_face_mouse_x
= x
;
6460 dpyinfo
->mouse_face_mouse_y
= y
;
6461 dpyinfo
->mouse_face_mouse_frame
= f
;
6463 if (dpyinfo
->mouse_face_defer
)
6468 dpyinfo
->mouse_face_deferred_gc
= 1;
6472 /* Which window is that in? */
6473 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6475 /* If we were displaying active text in another window, clear that. */
6476 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6477 clear_mouse_face (dpyinfo
);
6479 /* Not on a window -> return. */
6480 if (!WINDOWP (window
))
6483 /* Convert to window-relative pixel coordinates. */
6484 w
= XWINDOW (window
);
6485 frame_to_window_pixel_xy (w
, &x
, &y
);
6487 /* Handle tool-bar window differently since it doesn't display a
6489 if (EQ (window
, f
->tool_bar_window
))
6491 note_tool_bar_highlight (f
, x
, y
);
6495 if (portion
== 1 || portion
== 3)
6497 /* Mouse is on the mode or top line. */
6498 note_mode_line_highlight (w
, x
, portion
== 1);
6502 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6503 f
->output_data
.x
->text_cursor
);
6505 /* Are we in a window whose display is up to date?
6506 And verify the buffer's text has not changed. */
6507 if (/* Within text portion of the window. */
6509 && EQ (w
->window_end_valid
, w
->buffer
)
6510 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6511 && (XFASTINT (w
->last_overlay_modified
)
6512 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6514 int hpos
, vpos
, pos
, i
, area
;
6515 struct glyph
*glyph
;
6517 /* Find the glyph under X/Y. */
6518 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6520 /* Clear mouse face if X/Y not over text. */
6522 || area
!= TEXT_AREA
6523 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6525 clear_mouse_face (dpyinfo
);
6529 pos
= glyph
->charpos
;
6530 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6532 /* Check for mouse-face and help-echo. */
6534 Lisp_Object mouse_face
, overlay
, position
;
6535 Lisp_Object
*overlay_vec
;
6537 struct buffer
*obuf
;
6540 /* If we get an out-of-range value, return now; avoid an error. */
6541 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6544 /* Make the window's buffer temporarily current for
6545 overlays_at and compute_char_face. */
6546 obuf
= current_buffer
;
6547 current_buffer
= XBUFFER (w
->buffer
);
6553 /* Is this char mouse-active or does it have help-echo? */
6554 XSETINT (position
, pos
);
6556 /* Put all the overlays we want in a vector in overlay_vec.
6557 Store the length in len. If there are more than 10, make
6558 enough space for all, and try again. */
6560 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6561 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6562 if (noverlays
> len
)
6565 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6566 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6569 /* Sort overlays into increasing priority order. */
6570 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6572 /* Check mouse-face highlighting. */
6573 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6574 && vpos
>= dpyinfo
->mouse_face_beg_row
6575 && vpos
<= dpyinfo
->mouse_face_end_row
6576 && (vpos
> dpyinfo
->mouse_face_beg_row
6577 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6578 && (vpos
< dpyinfo
->mouse_face_end_row
6579 || hpos
< dpyinfo
->mouse_face_end_col
6580 || dpyinfo
->mouse_face_past_end
)))
6582 /* Clear the display of the old active region, if any. */
6583 clear_mouse_face (dpyinfo
);
6585 /* Find the highest priority overlay that has a mouse-face prop. */
6587 for (i
= noverlays
- 1; i
>= 0; --i
)
6589 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6590 if (!NILP (mouse_face
))
6592 overlay
= overlay_vec
[i
];
6597 /* If no overlay applies, get a text property. */
6599 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6601 /* Handle the overlay case. */
6602 if (! NILP (overlay
))
6604 /* Find the range of text around this char that
6605 should be active. */
6606 Lisp_Object before
, after
;
6609 before
= Foverlay_start (overlay
);
6610 after
= Foverlay_end (overlay
);
6611 /* Record this as the current active region. */
6612 fast_find_position (w
, XFASTINT (before
),
6613 &dpyinfo
->mouse_face_beg_col
,
6614 &dpyinfo
->mouse_face_beg_row
,
6615 &dpyinfo
->mouse_face_beg_x
,
6616 &dpyinfo
->mouse_face_beg_y
);
6617 dpyinfo
->mouse_face_past_end
6618 = !fast_find_position (w
, XFASTINT (after
),
6619 &dpyinfo
->mouse_face_end_col
,
6620 &dpyinfo
->mouse_face_end_row
,
6621 &dpyinfo
->mouse_face_end_x
,
6622 &dpyinfo
->mouse_face_end_y
);
6623 dpyinfo
->mouse_face_window
= window
;
6624 dpyinfo
->mouse_face_face_id
6625 = face_at_buffer_position (w
, pos
, 0, 0,
6626 &ignore
, pos
+ 1, 1);
6628 /* Display it as active. */
6629 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6631 /* Handle the text property case. */
6632 else if (! NILP (mouse_face
))
6634 /* Find the range of text around this char that
6635 should be active. */
6636 Lisp_Object before
, after
, beginning
, end
;
6639 beginning
= Fmarker_position (w
->start
);
6640 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6641 - XFASTINT (w
->window_end_pos
)));
6643 = Fprevious_single_property_change (make_number (pos
+ 1),
6645 w
->buffer
, beginning
);
6647 = Fnext_single_property_change (position
, Qmouse_face
,
6649 /* Record this as the current active region. */
6650 fast_find_position (w
, XFASTINT (before
),
6651 &dpyinfo
->mouse_face_beg_col
,
6652 &dpyinfo
->mouse_face_beg_row
,
6653 &dpyinfo
->mouse_face_beg_x
,
6654 &dpyinfo
->mouse_face_beg_y
);
6655 dpyinfo
->mouse_face_past_end
6656 = !fast_find_position (w
, XFASTINT (after
),
6657 &dpyinfo
->mouse_face_end_col
,
6658 &dpyinfo
->mouse_face_end_row
,
6659 &dpyinfo
->mouse_face_end_x
,
6660 &dpyinfo
->mouse_face_end_y
);
6661 dpyinfo
->mouse_face_window
= window
;
6662 dpyinfo
->mouse_face_face_id
6663 = face_at_buffer_position (w
, pos
, 0, 0,
6664 &ignore
, pos
+ 1, 1);
6666 /* Display it as active. */
6667 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6671 /* Look for a `help-echo' property. */
6673 Lisp_Object help
, overlay
;
6675 /* Check overlays first. */
6676 help
= overlay
= Qnil
;
6677 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6679 overlay
= overlay_vec
[i
];
6680 help
= Foverlay_get (overlay
, Qhelp_echo
);
6686 help_echo_window
= window
;
6687 help_echo_object
= overlay
;
6688 help_echo_pos
= pos
;
6692 /* Try text properties. */
6693 if ((STRINGP (glyph
->object
)
6694 && glyph
->charpos
>= 0
6695 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6696 || (BUFFERP (glyph
->object
)
6697 && glyph
->charpos
>= BEGV
6698 && glyph
->charpos
< ZV
))
6699 help
= Fget_text_property (make_number (glyph
->charpos
),
6700 Qhelp_echo
, glyph
->object
);
6705 help_echo_window
= window
;
6706 help_echo_object
= glyph
->object
;
6707 help_echo_pos
= glyph
->charpos
;
6714 current_buffer
= obuf
;
6720 redo_mouse_highlight ()
6722 if (!NILP (last_mouse_motion_frame
)
6723 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6724 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6725 last_mouse_motion_event
.x
,
6726 last_mouse_motion_event
.y
);
6731 /***********************************************************************
6733 ***********************************************************************/
6735 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6736 struct glyph
**, int *, int *, int *));
6738 /* Tool-bar item index of the item on which a mouse button was pressed
6741 static int last_tool_bar_item
;
6744 /* Get information about the tool-bar item at position X/Y on frame F.
6745 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6746 the current matrix of the tool-bar window of F, or NULL if not
6747 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6748 item in F->current_tool_bar_items. Value is
6750 -1 if X/Y is not on a tool-bar item
6751 0 if X/Y is on the same item that was highlighted before.
6755 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6758 struct glyph
**glyph
;
6759 int *hpos
, *vpos
, *prop_idx
;
6761 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6762 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6765 /* Find the glyph under X/Y. */
6766 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6770 /* Get the start of this tool-bar item's properties in
6771 f->current_tool_bar_items. */
6772 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6775 /* Is mouse on the highlighted item? */
6776 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6777 && *vpos
>= dpyinfo
->mouse_face_beg_row
6778 && *vpos
<= dpyinfo
->mouse_face_end_row
6779 && (*vpos
> dpyinfo
->mouse_face_beg_row
6780 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6781 && (*vpos
< dpyinfo
->mouse_face_end_row
6782 || *hpos
< dpyinfo
->mouse_face_end_col
6783 || dpyinfo
->mouse_face_past_end
))
6790 /* Handle mouse button event on the tool-bar of frame F, at
6791 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6795 x_handle_tool_bar_click (f
, button_event
)
6797 XButtonEvent
*button_event
;
6799 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6800 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6801 int hpos
, vpos
, prop_idx
;
6802 struct glyph
*glyph
;
6803 Lisp_Object enabled_p
;
6804 int x
= button_event
->x
;
6805 int y
= button_event
->y
;
6807 /* If not on the highlighted tool-bar item, return. */
6808 frame_to_window_pixel_xy (w
, &x
, &y
);
6809 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6812 /* If item is disabled, do nothing. */
6813 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6814 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6815 if (NILP (enabled_p
))
6818 if (button_event
->type
== ButtonPress
)
6820 /* Show item in pressed state. */
6821 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6822 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6823 last_tool_bar_item
= prop_idx
;
6827 Lisp_Object key
, frame
;
6828 struct input_event event
;
6830 /* Show item in released state. */
6831 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6832 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6834 key
= (XVECTOR (f
->current_tool_bar_items
)
6835 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6837 XSETFRAME (frame
, f
);
6838 event
.kind
= TOOL_BAR_EVENT
;
6839 event
.frame_or_window
= frame
;
6841 kbd_buffer_store_event (&event
);
6843 event
.kind
= TOOL_BAR_EVENT
;
6844 event
.frame_or_window
= frame
;
6846 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6847 button_event
->state
);
6848 kbd_buffer_store_event (&event
);
6849 last_tool_bar_item
= -1;
6854 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6855 tool-bar window-relative coordinates X/Y. Called from
6856 note_mouse_highlight. */
6859 note_tool_bar_highlight (f
, x
, y
)
6863 Lisp_Object window
= f
->tool_bar_window
;
6864 struct window
*w
= XWINDOW (window
);
6865 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6867 struct glyph
*glyph
;
6868 struct glyph_row
*row
;
6870 Lisp_Object enabled_p
;
6872 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6873 int mouse_down_p
, rc
;
6875 /* Function note_mouse_highlight is called with negative x(y
6876 values when mouse moves outside of the frame. */
6877 if (x
<= 0 || y
<= 0)
6879 clear_mouse_face (dpyinfo
);
6883 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6886 /* Not on tool-bar item. */
6887 clear_mouse_face (dpyinfo
);
6891 /* On same tool-bar item as before. */
6894 clear_mouse_face (dpyinfo
);
6896 /* Mouse is down, but on different tool-bar item? */
6897 mouse_down_p
= (dpyinfo
->grabbed
6898 && f
== last_mouse_frame
6899 && FRAME_LIVE_P (f
));
6901 && last_tool_bar_item
!= prop_idx
)
6904 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6905 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6907 /* If tool-bar item is not enabled, don't highlight it. */
6908 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6909 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6910 if (!NILP (enabled_p
))
6912 /* Compute the x-position of the glyph. In front and past the
6913 image is a space. We include this is the highlighted area. */
6914 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6915 for (i
= x
= 0; i
< hpos
; ++i
)
6916 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6918 /* Record this as the current active region. */
6919 dpyinfo
->mouse_face_beg_col
= hpos
;
6920 dpyinfo
->mouse_face_beg_row
= vpos
;
6921 dpyinfo
->mouse_face_beg_x
= x
;
6922 dpyinfo
->mouse_face_beg_y
= row
->y
;
6923 dpyinfo
->mouse_face_past_end
= 0;
6925 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6926 dpyinfo
->mouse_face_end_row
= vpos
;
6927 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6928 dpyinfo
->mouse_face_end_y
= row
->y
;
6929 dpyinfo
->mouse_face_window
= window
;
6930 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6932 /* Display it as active. */
6933 show_mouse_face (dpyinfo
, draw
);
6934 dpyinfo
->mouse_face_image_state
= draw
;
6939 /* Set help_echo to a help string.to display for this tool-bar item.
6940 XTread_socket does the rest. */
6941 help_echo_object
= help_echo_window
= Qnil
;
6943 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6944 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6945 if (NILP (help_echo
))
6946 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6947 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6952 /* Find the glyph matrix position of buffer position POS in window W.
6953 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6954 current glyphs must be up to date. If POS is above window start
6955 return (0, 0, 0, 0). If POS is after end of W, return end of
6959 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6962 int *hpos
, *vpos
, *x
, *y
;
6966 int maybe_next_line_p
= 0;
6967 int line_start_position
;
6968 int yb
= window_text_bottom_y (w
);
6969 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6970 struct glyph_row
*best_row
= row
;
6971 int row_vpos
= 0, best_row_vpos
= 0;
6976 if (row
->used
[TEXT_AREA
])
6977 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6979 line_start_position
= 0;
6981 if (line_start_position
> pos
)
6983 /* If the position sought is the end of the buffer,
6984 don't include the blank lines at the bottom of the window. */
6985 else if (line_start_position
== pos
6986 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6988 maybe_next_line_p
= 1;
6991 else if (line_start_position
> 0)
6994 best_row_vpos
= row_vpos
;
6997 if (row
->y
+ row
->height
>= yb
)
7004 /* Find the right column within BEST_ROW. */
7006 current_x
= best_row
->x
;
7007 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7009 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7012 charpos
= glyph
->charpos
;
7016 *vpos
= best_row_vpos
;
7021 else if (charpos
> pos
)
7023 else if (charpos
> 0)
7026 current_x
+= glyph
->pixel_width
;
7029 /* If we're looking for the end of the buffer,
7030 and we didn't find it in the line we scanned,
7031 use the start of the following line. */
7032 if (maybe_next_line_p
)
7037 current_x
= best_row
->x
;
7040 *vpos
= best_row_vpos
;
7041 *hpos
= lastcol
+ 1;
7048 /* Display the active region described by mouse_face_*
7049 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7052 show_mouse_face (dpyinfo
, draw
)
7053 struct x_display_info
*dpyinfo
;
7054 enum draw_glyphs_face draw
;
7056 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7057 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7059 int cursor_off_p
= 0;
7060 struct cursor_pos saved_cursor
;
7062 saved_cursor
= output_cursor
;
7064 /* If window is in the process of being destroyed, don't bother
7066 if (w
->current_matrix
== NULL
)
7069 /* Recognize when we are called to operate on rows that don't exist
7070 anymore. This can happen when a window is split. */
7071 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7074 set_output_cursor (&w
->phys_cursor
);
7076 /* Note that mouse_face_beg_row etc. are window relative. */
7077 for (i
= dpyinfo
->mouse_face_beg_row
;
7078 i
<= dpyinfo
->mouse_face_end_row
;
7081 int start_hpos
, end_hpos
, start_x
;
7082 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7084 /* Don't do anything if row doesn't have valid contents. */
7085 if (!row
->enabled_p
)
7088 /* For all but the first row, the highlight starts at column 0. */
7089 if (i
== dpyinfo
->mouse_face_beg_row
)
7091 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7092 start_x
= dpyinfo
->mouse_face_beg_x
;
7100 if (i
== dpyinfo
->mouse_face_end_row
)
7101 end_hpos
= dpyinfo
->mouse_face_end_col
;
7103 end_hpos
= row
->used
[TEXT_AREA
];
7105 /* If the cursor's in the text we are about to rewrite, turn the
7107 if (!w
->pseudo_window_p
7108 && i
== output_cursor
.vpos
7109 && output_cursor
.hpos
>= start_hpos
- 1
7110 && output_cursor
.hpos
<= end_hpos
)
7112 x_update_window_cursor (w
, 0);
7116 if (end_hpos
> start_hpos
)
7118 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7119 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7120 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7124 /* If we turned the cursor off, turn it back on. */
7126 x_display_cursor (w
, 1,
7127 output_cursor
.hpos
, output_cursor
.vpos
,
7128 output_cursor
.x
, output_cursor
.y
);
7130 output_cursor
= saved_cursor
;
7134 /* Change the mouse cursor. */
7135 if (draw
== DRAW_NORMAL_TEXT
)
7136 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7137 f
->output_data
.x
->text_cursor
);
7138 else if (draw
== DRAW_MOUSE_FACE
)
7139 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7140 f
->output_data
.x
->cross_cursor
);
7142 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7143 f
->output_data
.x
->nontext_cursor
);
7146 /* Clear out the mouse-highlighted active region.
7147 Redraw it un-highlighted first. */
7150 clear_mouse_face (dpyinfo
)
7151 struct x_display_info
*dpyinfo
;
7156 if (! NILP (dpyinfo
->mouse_face_window
))
7157 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7159 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7160 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7161 dpyinfo
->mouse_face_window
= Qnil
;
7165 /* Clear any mouse-face on window W. This function is part of the
7166 redisplay interface, and is called from try_window_id and similar
7167 functions to ensure the mouse-highlight is off. */
7170 x_clear_mouse_face (w
)
7173 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7177 XSETWINDOW (window
, w
);
7178 if (EQ (window
, dpyinfo
->mouse_face_window
))
7179 clear_mouse_face (dpyinfo
);
7184 /* Just discard the mouse face information for frame F, if any.
7185 This is used when the size of F is changed. */
7188 cancel_mouse_face (f
)
7192 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7194 window
= dpyinfo
->mouse_face_window
;
7195 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7197 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7198 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7199 dpyinfo
->mouse_face_window
= Qnil
;
7203 static struct scroll_bar
*x_window_to_scroll_bar ();
7204 static void x_scroll_bar_report_motion ();
7206 /* Return the current position of the mouse.
7207 *fp should be a frame which indicates which display to ask about.
7209 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7210 and *part to the frame, window, and scroll bar part that the mouse
7211 is over. Set *x and *y to the portion and whole of the mouse's
7212 position on the scroll bar.
7214 If the mouse movement started elsewhere, set *fp to the frame the
7215 mouse is on, *bar_window to nil, and *x and *y to the character cell
7218 Set *time to the server time-stamp for the time at which the mouse
7219 was at this position.
7221 Don't store anything if we don't have a valid set of values to report.
7223 This clears the mouse_moved flag, so we can wait for the next mouse
7227 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7230 Lisp_Object
*bar_window
;
7231 enum scroll_bar_part
*part
;
7233 unsigned long *time
;
7239 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7240 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7246 Window dummy_window
;
7249 Lisp_Object frame
, tail
;
7251 /* Clear the mouse-moved flag for every frame on this display. */
7252 FOR_EACH_FRAME (tail
, frame
)
7253 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7254 XFRAME (frame
)->mouse_moved
= 0;
7256 last_mouse_scroll_bar
= Qnil
;
7258 /* Figure out which root window we're on. */
7259 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7260 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7262 /* The root window which contains the pointer. */
7265 /* Trash which we can't trust if the pointer is on
7266 a different screen. */
7269 /* The position on that root window. */
7272 /* More trash we can't trust. */
7275 /* Modifier keys and pointer buttons, about which
7277 (unsigned int *) &dummy
);
7279 /* Now we have a position on the root; find the innermost window
7280 containing the pointer. */
7284 int parent_x
= 0, parent_y
= 0;
7289 /* XTranslateCoordinates can get errors if the window
7290 structure is changing at the same time this function
7291 is running. So at least we must not crash from them. */
7293 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7295 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7296 && FRAME_LIVE_P (last_mouse_frame
))
7298 /* If mouse was grabbed on a frame, give coords for that frame
7299 even if the mouse is now outside it. */
7300 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7302 /* From-window, to-window. */
7303 root
, FRAME_X_WINDOW (last_mouse_frame
),
7305 /* From-position, to-position. */
7306 root_x
, root_y
, &win_x
, &win_y
,
7310 f1
= last_mouse_frame
;
7316 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7318 /* From-window, to-window. */
7321 /* From-position, to-position. */
7322 root_x
, root_y
, &win_x
, &win_y
,
7327 if (child
== None
|| child
== win
)
7335 /* Now we know that:
7336 win is the innermost window containing the pointer
7337 (XTC says it has no child containing the pointer),
7338 win_x and win_y are the pointer's position in it
7339 (XTC did this the last time through), and
7340 parent_x and parent_y are the pointer's position in win's parent.
7341 (They are what win_x and win_y were when win was child.
7342 If win is the root window, it has no parent, and
7343 parent_{x,y} are invalid, but that's okay, because we'll
7344 never use them in that case.) */
7346 /* Is win one of our frames? */
7347 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7350 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7353 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7355 /* If not, is it one of our scroll bars? */
7358 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7362 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7368 if (f1
== 0 && insist
> 0)
7369 f1
= SELECTED_FRAME ();
7373 /* Ok, we found a frame. Store all the values.
7374 last_mouse_glyph is a rectangle used to reduce the
7375 generation of mouse events. To not miss any motion
7376 events, we must divide the frame into rectangles of the
7377 size of the smallest character that could be displayed
7378 on it, i.e. into the same rectangles that matrices on
7379 the frame are divided into. */
7381 #if OLD_REDISPLAY_CODE
7382 int ignore1
, ignore2
;
7383 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7385 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7389 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7390 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7394 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7395 round down even for negative values. */
7401 last_mouse_glyph
.width
= width
;
7402 last_mouse_glyph
.height
= height
;
7403 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7404 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7411 XSETINT (*x
, win_x
);
7412 XSETINT (*y
, win_y
);
7413 *time
= last_mouse_movement_time
;
7422 #ifdef USE_X_TOOLKIT
7424 /* Atimer callback function for TIMER. Called every 0.1s to process
7425 Xt timeouts, if needed. We must avoid calling XtAppPending as
7426 much as possible because that function does an implicit XFlush
7427 that slows us down. */
7430 x_process_timeouts (timer
)
7431 struct atimer
*timer
;
7433 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7436 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7437 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7442 #endif /* USE_X_TOOLKIT */
7445 /* Scroll bar support. */
7447 /* Given an X window ID, find the struct scroll_bar which manages it.
7448 This can be called in GC, so we have to make sure to strip off mark
7451 static struct scroll_bar
*
7452 x_window_to_scroll_bar (window_id
)
7457 for (tail
= Vframe_list
;
7458 XGCTYPE (tail
) == Lisp_Cons
;
7461 Lisp_Object frame
, bar
, condemned
;
7463 frame
= XCAR (tail
);
7464 /* All elements of Vframe_list should be frames. */
7465 if (! GC_FRAMEP (frame
))
7468 /* Scan this frame's scroll bar list for a scroll bar with the
7470 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7471 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7472 /* This trick allows us to search both the ordinary and
7473 condemned scroll bar lists with one loop. */
7474 ! GC_NILP (bar
) || (bar
= condemned
,
7477 bar
= XSCROLL_BAR (bar
)->next
)
7478 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7479 return XSCROLL_BAR (bar
);
7487 /************************************************************************
7489 ************************************************************************/
7491 #if USE_TOOLKIT_SCROLL_BARS
7493 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7494 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7495 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7496 struct scroll_bar
*));
7497 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7501 /* Id of action hook installed for scroll bars. */
7503 static XtActionHookId action_hook_id
;
7505 /* Lisp window being scrolled. Set when starting to interact with
7506 a toolkit scroll bar, reset to nil when ending the interaction. */
7508 static Lisp_Object window_being_scrolled
;
7510 /* Last scroll bar part sent in xm_scroll_callback. */
7512 static int last_scroll_bar_part
;
7514 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7515 that movements of 1/20 of the screen size are mapped to up/down. */
7517 static Boolean xaw3d_arrow_scroll
;
7519 /* Whether the drag scrolling maintains the mouse at the top of the
7520 thumb. If not, resizing the thumb needs to be done more carefully
7521 to avoid jerkyness. */
7523 static Boolean xaw3d_pick_top
;
7526 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7527 bars are used.. The hook is responsible for detecting when
7528 the user ends an interaction with the scroll bar, and generates
7529 a `end-scroll' scroll_bar_click' event if so. */
7532 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7535 XtPointer client_data
;
7539 Cardinal
*num_params
;
7545 scroll_bar_p
= XmIsScrollBar (widget
);
7546 end_action
= "Release";
7547 #else /* !USE_MOTIF i.e. use Xaw */
7548 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7549 end_action
= "EndScroll";
7550 #endif /* USE_MOTIF */
7553 && strcmp (action_name
, end_action
) == 0
7554 && WINDOWP (window_being_scrolled
))
7558 x_send_scroll_bar_event (window_being_scrolled
,
7559 scroll_bar_end_scroll
, 0, 0);
7560 w
= XWINDOW (window_being_scrolled
);
7561 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7562 window_being_scrolled
= Qnil
;
7563 last_scroll_bar_part
= -1;
7565 /* Xt timeouts no longer needed. */
7566 toolkit_scroll_bar_interaction
= 0;
7571 /* Send a client message with message type Xatom_Scrollbar for a
7572 scroll action to the frame of WINDOW. PART is a value identifying
7573 the part of the scroll bar that was clicked on. PORTION is the
7574 amount to scroll of a whole of WHOLE. */
7577 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7579 int part
, portion
, whole
;
7582 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7583 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7585 /* Construct a ClientMessage event to send to the frame. */
7586 ev
->type
= ClientMessage
;
7587 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7588 ev
->display
= FRAME_X_DISPLAY (f
);
7589 ev
->window
= FRAME_X_WINDOW (f
);
7591 ev
->data
.l
[0] = (long) XFASTINT (window
);
7592 ev
->data
.l
[1] = (long) part
;
7593 ev
->data
.l
[2] = (long) 0;
7594 ev
->data
.l
[3] = (long) portion
;
7595 ev
->data
.l
[4] = (long) whole
;
7597 /* Make Xt timeouts work while the scroll bar is active. */
7598 toolkit_scroll_bar_interaction
= 1;
7600 /* Setting the event mask to zero means that the message will
7601 be sent to the client that created the window, and if that
7602 window no longer exists, no event will be sent. */
7604 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7609 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7613 x_scroll_bar_to_input_event (event
, ievent
)
7615 struct input_event
*ievent
;
7617 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7621 XSETFASTINT (window
, ev
->data
.l
[0]);
7622 f
= XFRAME (XWINDOW (window
)->frame
);
7624 ievent
->kind
= scroll_bar_click
;
7625 ievent
->frame_or_window
= window
;
7627 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7628 ievent
->part
= ev
->data
.l
[1];
7629 ievent
->code
= ev
->data
.l
[2];
7630 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7631 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7632 ievent
->modifiers
= 0;
7638 /* Minimum and maximum values used for Motif scroll bars. */
7641 #define XM_SB_MAX 10000000
7642 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7645 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7646 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7647 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7650 xm_scroll_callback (widget
, client_data
, call_data
)
7652 XtPointer client_data
, call_data
;
7654 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7655 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7657 int part
= -1, whole
= 0, portion
= 0;
7661 case XmCR_DECREMENT
:
7662 bar
->dragging
= Qnil
;
7663 part
= scroll_bar_up_arrow
;
7666 case XmCR_INCREMENT
:
7667 bar
->dragging
= Qnil
;
7668 part
= scroll_bar_down_arrow
;
7671 case XmCR_PAGE_DECREMENT
:
7672 bar
->dragging
= Qnil
;
7673 part
= scroll_bar_above_handle
;
7676 case XmCR_PAGE_INCREMENT
:
7677 bar
->dragging
= Qnil
;
7678 part
= scroll_bar_below_handle
;
7682 bar
->dragging
= Qnil
;
7683 part
= scroll_bar_to_top
;
7686 case XmCR_TO_BOTTOM
:
7687 bar
->dragging
= Qnil
;
7688 part
= scroll_bar_to_bottom
;
7694 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7695 && XINT (bar
->dragging
) <= cs
->value
);
7697 /* Get the slider size. */
7699 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7702 /* At the max position of the scroll bar, do a line-wise
7703 movement. Without doing anything, the LessTif scroll bar
7704 calls us with the same cs->value again and again. If we
7705 want to make sure that we can reach the end of the buffer,
7706 we have to do something.
7708 Implementation note: setting bar->dragging always to
7709 cs->value gives a smoother movement at the max position.
7710 Setting it to nil when doing line-wise movement gives
7711 a better slider behavior. */
7713 if (cs
->value
+ slider_size
== XM_SB_MAX
7715 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7717 part
= scroll_bar_down_arrow
;
7718 bar
->dragging
= Qnil
;
7722 whole
= XM_SB_RANGE
;
7723 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7724 part
= scroll_bar_handle
;
7725 bar
->dragging
= make_number (cs
->value
);
7730 case XmCR_VALUE_CHANGED
:
7736 window_being_scrolled
= bar
->window
;
7737 last_scroll_bar_part
= part
;
7738 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7743 #else /* !USE_MOTIF, i.e. Xaw. */
7746 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7747 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7748 scroll bar struct. CALL_DATA is a pointer to a float saying where
7752 xaw_jump_callback (widget
, client_data
, call_data
)
7754 XtPointer client_data
, call_data
;
7756 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7757 float top
= *(float *) call_data
;
7759 int whole
, portion
, height
;
7762 /* Get the size of the thumb, a value between 0 and 1. */
7764 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7768 portion
= shown
< 1 ? top
* whole
: 0;
7770 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7771 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7772 the bottom, so we force the scrolling whenever we see that we're
7773 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7774 we try to ensure that we always stay two pixels away from the
7776 part
= scroll_bar_down_arrow
;
7778 part
= scroll_bar_handle
;
7780 window_being_scrolled
= bar
->window
;
7781 bar
->dragging
= make_number (portion
);
7782 last_scroll_bar_part
= part
;
7783 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7787 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7788 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7789 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7790 the scroll bar. CALL_DATA is an integer specifying the action that
7791 has taken place. It's magnitude is in the range 0..height of the
7792 scroll bar. Negative values mean scroll towards buffer start.
7793 Values < height of scroll bar mean line-wise movement. */
7796 xaw_scroll_callback (widget
, client_data
, call_data
)
7798 XtPointer client_data
, call_data
;
7800 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7801 int position
= (int) call_data
;
7805 /* Get the height of the scroll bar. */
7807 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7810 if (abs (position
) >= height
)
7811 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
7813 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
7814 it maps line-movement to call_data = max(5, height/20). */
7815 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
7816 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
7818 part
= scroll_bar_move_ratio
;
7820 window_being_scrolled
= bar
->window
;
7821 bar
->dragging
= Qnil
;
7822 last_scroll_bar_part
= part
;
7823 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
7827 #endif /* not USE_MOTIF */
7830 /* Create the widget for scroll bar BAR on frame F. Record the widget
7831 and X window of the scroll bar in BAR. */
7834 x_create_toolkit_scroll_bar (f
, bar
)
7836 struct scroll_bar
*bar
;
7842 char *scroll_bar_name
= "verticalScrollBar";
7843 unsigned long pixel
;
7848 /* LessTif 0.85, problems:
7850 1. When the mouse if over the scroll bar, the scroll bar will
7851 get keyboard events. I didn't find a way to turn this off.
7853 2. Do we have to explicitly set the cursor to get an arrow
7854 cursor (see below)? */
7856 /* Set resources. Create the widget. */
7857 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7858 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7859 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7860 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7861 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7862 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7863 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7865 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7868 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7872 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7875 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7879 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7880 scroll_bar_name
, av
, ac
);
7882 /* Add one callback for everything that can happen. */
7883 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7885 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7887 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7889 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7891 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7893 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7895 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7898 /* Realize the widget. Only after that is the X window created. */
7899 XtRealizeWidget (widget
);
7901 /* Set the cursor to an arrow. I didn't find a resource to do that.
7902 And I'm wondering why it hasn't an arrow cursor by default. */
7903 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7904 f
->output_data
.x
->nontext_cursor
);
7906 #else /* !USE_MOTIF i.e. use Xaw */
7908 /* Set resources. Create the widget. The background of the
7909 Xaw3d scroll bar widget is a little bit light for my taste.
7910 We don't alter it here to let users change it according
7911 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7912 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7913 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7914 /* For smoother scrolling with Xaw3d -sm */
7915 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
7916 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
7918 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7921 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7925 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7928 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7932 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7933 f
->output_data
.x
->edit_widget
, av
, ac
);
7937 char *val
= initial
;
7938 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
7939 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
7941 { /* ARROW_SCROLL */
7942 xaw3d_arrow_scroll
= True
;
7943 /* Isn't that just a personal preference ? -sm */
7944 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
7948 /* Define callbacks. */
7949 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
7950 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
7953 /* Realize the widget. Only after that is the X window created. */
7954 XtRealizeWidget (widget
);
7956 #endif /* !USE_MOTIF */
7958 /* Install an action hook that let's us detect when the user
7959 finishes interacting with a scroll bar. */
7960 if (action_hook_id
== 0)
7961 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7963 /* Remember X window and widget in the scroll bar vector. */
7964 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7965 xwindow
= XtWindow (widget
);
7966 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7972 /* Set the thumb size and position of scroll bar BAR. We are currently
7973 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7976 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7977 struct scroll_bar
*bar
;
7978 int portion
, position
, whole
;
7981 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7987 top
= (float) position
/ whole
;
7988 shown
= (float) portion
/ whole
;
7996 Boolean arrow1_selected
, arrow2_selected
;
7997 unsigned char flags
;
7998 XmScrollBarWidget sb
;
8000 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8001 is the scroll bar's maximum and MIN is the scroll bar's minimum
8003 size
= shown
* XM_SB_RANGE
;
8004 size
= min (size
, XM_SB_RANGE
);
8005 size
= max (size
, 1);
8007 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8008 value
= top
* XM_SB_RANGE
;
8009 value
= min (value
, XM_SB_MAX
- size
);
8010 value
= max (value
, XM_SB_MIN
);
8012 /* LessTif: Calling XmScrollBarSetValues after an increment or
8013 decrement turns off auto-repeat LessTif-internally. This can
8014 be seen in ScrollBar.c which resets Arrow1Selected and
8015 Arrow2Selected. It also sets internal flags so that LessTif
8016 believes the mouse is in the slider. We either have to change
8017 our code, or work around that by accessing private data. */
8019 sb
= (XmScrollBarWidget
) widget
;
8020 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
8021 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
8022 flags
= sb
->scrollBar
.flags
;
8024 if (NILP (bar
->dragging
))
8025 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8026 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8027 /* This has the negative side effect that the slider value is
8028 not what it would be if we scrolled here using line-wise or
8029 page-wise movement. */
8030 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8033 /* If currently dragging, only update the slider size.
8034 This reduces flicker effects. */
8035 int old_value
, old_size
, increment
, page_increment
;
8037 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8038 &increment
, &page_increment
);
8039 XmScrollBarSetValues (widget
, old_value
,
8040 min (size
, XM_SB_RANGE
- old_value
),
8044 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
8045 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
8046 sb
->scrollBar
.flags
= flags
;
8048 #else /* !USE_MOTIF i.e. use Xaw */
8050 float old_top
, old_shown
;
8052 XtVaGetValues (widget
,
8053 XtNtopOfThumb
, &old_top
,
8054 XtNshown
, &old_shown
,
8058 /* Massage the top+shown values. */
8059 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8060 top
= max (0, min (1, top
));
8063 /* Keep two pixels available for moving the thumb down. */
8064 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8066 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8067 check that your system's configuration file contains a define
8068 for `NARROWPROTO'. See s/freebsd.h for an example. */
8069 if (top
!= old_top
|| shown
!= old_shown
)
8071 if (NILP (bar
->dragging
))
8072 XawScrollbarSetThumb (widget
, top
, shown
);
8076 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8077 int scroll_mode
= 0;
8079 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8080 if (xaw3d_arrow_scroll
)
8082 /* Xaw3d stupidly ignores resize requests while dragging
8083 so we have to make it believe it's not in dragging mode. */
8084 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8085 if (scroll_mode
== 2)
8086 sb
->scrollbar
.scroll_mode
= 0;
8089 /* Try to make the scrolling a tad smoother. */
8090 if (!xaw3d_pick_top
)
8091 shown
= min (shown
, old_shown
);
8093 XawScrollbarSetThumb (widget
, top
, shown
);
8096 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8097 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8102 #endif /* !USE_MOTIF */
8107 #endif /* USE_TOOLKIT_SCROLL_BARS */
8111 /************************************************************************
8112 Scroll bars, general
8113 ************************************************************************/
8115 /* Create a scroll bar and return the scroll bar vector for it. W is
8116 the Emacs window on which to create the scroll bar. TOP, LEFT,
8117 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8120 static struct scroll_bar
*
8121 x_scroll_bar_create (w
, top
, left
, width
, height
)
8123 int top
, left
, width
, height
;
8125 struct frame
*f
= XFRAME (w
->frame
);
8126 struct scroll_bar
*bar
8127 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8131 #if USE_TOOLKIT_SCROLL_BARS
8132 x_create_toolkit_scroll_bar (f
, bar
);
8133 #else /* not USE_TOOLKIT_SCROLL_BARS */
8135 XSetWindowAttributes a
;
8139 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8140 if (a
.background_pixel
== -1)
8141 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8143 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8144 | ButtonMotionMask
| PointerMotionHintMask
8146 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8148 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8150 /* Clear the area of W that will serve as a scroll bar. This is
8151 for the case that a window has been split horizontally. In
8152 this case, no clear_frame is generated to reduce flickering. */
8153 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8155 window_box_height (w
), False
);
8157 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8158 /* Position and size of scroll bar. */
8159 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8161 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8163 /* Border width, depth, class, and visual. */
8170 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8172 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8174 XSETWINDOW (bar
->window
, w
);
8175 XSETINT (bar
->top
, top
);
8176 XSETINT (bar
->left
, left
);
8177 XSETINT (bar
->width
, width
);
8178 XSETINT (bar
->height
, height
);
8179 XSETINT (bar
->start
, 0);
8180 XSETINT (bar
->end
, 0);
8181 bar
->dragging
= Qnil
;
8183 /* Add bar to its frame's list of scroll bars. */
8184 bar
->next
= FRAME_SCROLL_BARS (f
);
8186 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8187 if (!NILP (bar
->next
))
8188 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8190 /* Map the window/widget. */
8191 #if USE_TOOLKIT_SCROLL_BARS
8192 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
8193 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8194 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8196 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8198 #else /* not USE_TOOLKIT_SCROLL_BARS */
8199 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8200 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8207 /* Draw BAR's handle in the proper position.
8209 If the handle is already drawn from START to END, don't bother
8210 redrawing it, unless REBUILD is non-zero; in that case, always
8211 redraw it. (REBUILD is handy for drawing the handle after expose
8214 Normally, we want to constrain the start and end of the handle to
8215 fit inside its rectangle, but if the user is dragging the scroll
8216 bar handle, we want to let them drag it down all the way, so that
8217 the bar's top is as far down as it goes; otherwise, there's no way
8218 to move to the very end of the buffer. */
8220 #ifndef USE_TOOLKIT_SCROLL_BARS
8223 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8224 struct scroll_bar
*bar
;
8228 int dragging
= ! NILP (bar
->dragging
);
8229 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8230 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8231 GC gc
= f
->output_data
.x
->normal_gc
;
8233 /* If the display is already accurate, do nothing. */
8235 && start
== XINT (bar
->start
)
8236 && end
== XINT (bar
->end
))
8242 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8243 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8244 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8246 /* Make sure the values are reasonable, and try to preserve
8247 the distance between start and end. */
8249 int length
= end
- start
;
8253 else if (start
> top_range
)
8255 end
= start
+ length
;
8259 else if (end
> top_range
&& ! dragging
)
8263 /* Store the adjusted setting in the scroll bar. */
8264 XSETINT (bar
->start
, start
);
8265 XSETINT (bar
->end
, end
);
8267 /* Clip the end position, just for display. */
8268 if (end
> top_range
)
8271 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8272 below top positions, to make sure the handle is always at least
8273 that many pixels tall. */
8274 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8276 /* Draw the empty space above the handle. Note that we can't clear
8277 zero-height areas; that means "clear to end of window." */
8279 XClearArea (FRAME_X_DISPLAY (f
), w
,
8281 /* x, y, width, height, and exposures. */
8282 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8283 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8284 inside_width
, start
,
8287 /* Change to proper foreground color if one is specified. */
8288 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8289 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8290 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8292 /* Draw the handle itself. */
8293 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8295 /* x, y, width, height */
8296 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8297 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8298 inside_width
, end
- start
);
8300 /* Restore the foreground color of the GC if we changed it above. */
8301 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8302 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8303 f
->output_data
.x
->foreground_pixel
);
8305 /* Draw the empty space below the handle. Note that we can't
8306 clear zero-height areas; that means "clear to end of window." */
8307 if (end
< inside_height
)
8308 XClearArea (FRAME_X_DISPLAY (f
), w
,
8310 /* x, y, width, height, and exposures. */
8311 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8312 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8313 inside_width
, inside_height
- end
,
8321 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8323 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8327 x_scroll_bar_remove (bar
)
8328 struct scroll_bar
*bar
;
8332 #if USE_TOOLKIT_SCROLL_BARS
8333 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
8334 #else /* not USE_TOOLKIT_SCROLL_BARS */
8336 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8337 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8339 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8341 /* Disassociate this scroll bar from its window. */
8342 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8348 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8349 that we are displaying PORTION characters out of a total of WHOLE
8350 characters, starting at POSITION. If WINDOW has no scroll bar,
8354 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8356 int portion
, whole
, position
;
8358 struct frame
*f
= XFRAME (w
->frame
);
8359 struct scroll_bar
*bar
;
8360 int top
, height
, left
, sb_left
, width
, sb_width
;
8361 int window_x
, window_y
, window_width
, window_height
;
8363 /* Get window dimensions. */
8364 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8366 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8367 height
= window_height
;
8369 /* Compute the left edge of the scroll bar area. */
8370 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8371 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8373 left
= XFASTINT (w
->left
);
8374 left
*= CANON_X_UNIT (f
);
8375 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8377 /* Compute the width of the scroll bar which might be less than
8378 the width of the area reserved for the scroll bar. */
8379 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8380 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8384 /* Compute the left edge of the scroll bar. */
8385 #ifdef USE_TOOLKIT_SCROLL_BARS
8386 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8387 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8389 sb_left
= left
+ (width
- sb_width
) / 2;
8391 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8392 sb_left
= left
+ width
- sb_width
;
8397 /* Does the scroll bar exist yet? */
8398 if (NILP (w
->vertical_scroll_bar
))
8401 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8402 left
, top
, width
, height
, False
);
8404 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8408 /* It may just need to be moved and resized. */
8409 unsigned int mask
= 0;
8411 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8415 if (sb_left
!= XINT (bar
->left
))
8417 if (top
!= XINT (bar
->top
))
8419 if (sb_width
!= XINT (bar
->width
))
8421 if (height
!= XINT (bar
->height
))
8424 #ifdef USE_TOOLKIT_SCROLL_BARS
8426 /* Since toolkit scroll bars are smaller than the space reserved
8427 for them on the frame, we have to clear "under" them. */
8428 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8429 left
, top
, width
, height
, False
);
8431 /* Move/size the scroll bar widget. */
8433 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8434 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8436 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8439 #else /* not USE_TOOLKIT_SCROLL_BARS */
8441 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8443 /* Clear areas not covered by the scroll bar. This makes sure a
8444 previous mode line display is cleared after C-x 2 C-x 1, for
8445 example. Non-toolkit scroll bars are as wide as the area
8446 reserved for scroll bars - trim at both sides. */
8447 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8448 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8450 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8451 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8452 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8456 /* Move/size the scroll bar window. */
8461 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8463 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8465 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8469 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8471 /* Remember new settings. */
8472 XSETINT (bar
->left
, sb_left
);
8473 XSETINT (bar
->top
, top
);
8474 XSETINT (bar
->width
, sb_width
);
8475 XSETINT (bar
->height
, height
);
8480 #if USE_TOOLKIT_SCROLL_BARS
8481 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8482 #else /* not USE_TOOLKIT_SCROLL_BARS */
8483 /* Set the scroll bar's current state, unless we're currently being
8485 if (NILP (bar
->dragging
))
8487 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8490 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8493 int start
= ((double) position
* top_range
) / whole
;
8494 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8495 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8498 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8500 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8504 /* The following three hooks are used when we're doing a thorough
8505 redisplay of the frame. We don't explicitly know which scroll bars
8506 are going to be deleted, because keeping track of when windows go
8507 away is a real pain - "Can you say set-window-configuration, boys
8508 and girls?" Instead, we just assert at the beginning of redisplay
8509 that *all* scroll bars are to be removed, and then save a scroll bar
8510 from the fiery pit when we actually redisplay its window. */
8512 /* Arrange for all scroll bars on FRAME to be removed at the next call
8513 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8514 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8517 XTcondemn_scroll_bars (frame
)
8520 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8521 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8524 bar
= FRAME_SCROLL_BARS (frame
);
8525 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8526 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8527 XSCROLL_BAR (bar
)->prev
= Qnil
;
8528 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8529 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8530 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8534 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8535 Note that WINDOW isn't necessarily condemned at all. */
8537 XTredeem_scroll_bar (window
)
8538 struct window
*window
;
8540 struct scroll_bar
*bar
;
8542 /* We can't redeem this window's scroll bar if it doesn't have one. */
8543 if (NILP (window
->vertical_scroll_bar
))
8546 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8548 /* Unlink it from the condemned list. */
8550 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8552 if (NILP (bar
->prev
))
8554 /* If the prev pointer is nil, it must be the first in one of
8556 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8557 /* It's not condemned. Everything's fine. */
8559 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8560 window
->vertical_scroll_bar
))
8561 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8563 /* If its prev pointer is nil, it must be at the front of
8564 one or the other! */
8568 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8570 if (! NILP (bar
->next
))
8571 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8573 bar
->next
= FRAME_SCROLL_BARS (f
);
8575 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8576 if (! NILP (bar
->next
))
8577 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8581 /* Remove all scroll bars on FRAME that haven't been saved since the
8582 last call to `*condemn_scroll_bars_hook'. */
8585 XTjudge_scroll_bars (f
)
8588 Lisp_Object bar
, next
;
8590 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8592 /* Clear out the condemned list now so we won't try to process any
8593 more events on the hapless scroll bars. */
8594 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8596 for (; ! NILP (bar
); bar
= next
)
8598 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8600 x_scroll_bar_remove (b
);
8603 b
->next
= b
->prev
= Qnil
;
8606 /* Now there should be no references to the condemned scroll bars,
8607 and they should get garbage-collected. */
8611 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8612 is a no-op when using toolkit scroll bars.
8614 This may be called from a signal handler, so we have to ignore GC
8618 x_scroll_bar_expose (bar
, event
)
8619 struct scroll_bar
*bar
;
8622 #ifndef USE_TOOLKIT_SCROLL_BARS
8624 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8625 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8626 GC gc
= f
->output_data
.x
->normal_gc
;
8627 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8631 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8633 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8634 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8636 /* x, y, width, height */
8638 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8639 XINT (bar
->height
) - 1);
8643 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8646 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8647 is set to something other than no_event, it is enqueued.
8649 This may be called from a signal handler, so we have to ignore GC
8652 #ifndef USE_TOOLKIT_SCROLL_BARS
8655 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8656 struct scroll_bar
*bar
;
8658 struct input_event
*emacs_event
;
8660 if (! GC_WINDOWP (bar
->window
))
8663 emacs_event
->kind
= scroll_bar_click
;
8664 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8665 emacs_event
->modifiers
8666 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8667 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8668 event
->xbutton
.state
)
8669 | (event
->type
== ButtonRelease
8672 emacs_event
->frame_or_window
= bar
->window
;
8673 emacs_event
->arg
= Qnil
;
8674 emacs_event
->timestamp
= event
->xbutton
.time
;
8677 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8679 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8682 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8683 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8686 if (y
> top_range
) y
= top_range
;
8688 if (y
< XINT (bar
->start
))
8689 emacs_event
->part
= scroll_bar_above_handle
;
8690 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8691 emacs_event
->part
= scroll_bar_handle
;
8693 emacs_event
->part
= scroll_bar_below_handle
;
8695 /* Just because the user has clicked on the handle doesn't mean
8696 they want to drag it. Lisp code needs to be able to decide
8697 whether or not we're dragging. */
8699 /* If the user has just clicked on the handle, record where they're
8701 if (event
->type
== ButtonPress
8702 && emacs_event
->part
== scroll_bar_handle
)
8703 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8706 /* If the user has released the handle, set it to its final position. */
8707 if (event
->type
== ButtonRelease
8708 && ! NILP (bar
->dragging
))
8710 int new_start
= y
- XINT (bar
->dragging
);
8711 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8713 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8714 bar
->dragging
= Qnil
;
8717 /* Same deal here as the other #if 0. */
8719 /* Clicks on the handle are always reported as occurring at the top of
8721 if (emacs_event
->part
== scroll_bar_handle
)
8722 emacs_event
->x
= bar
->start
;
8724 XSETINT (emacs_event
->x
, y
);
8726 XSETINT (emacs_event
->x
, y
);
8729 XSETINT (emacs_event
->y
, top_range
);
8733 /* Handle some mouse motion while someone is dragging the scroll bar.
8735 This may be called from a signal handler, so we have to ignore GC
8739 x_scroll_bar_note_movement (bar
, event
)
8740 struct scroll_bar
*bar
;
8743 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8745 last_mouse_movement_time
= event
->xmotion
.time
;
8748 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8750 /* If we're dragging the bar, display it. */
8751 if (! GC_NILP (bar
->dragging
))
8753 /* Where should the handle be now? */
8754 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8756 if (new_start
!= XINT (bar
->start
))
8758 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8760 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8765 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8767 /* Return information to the user about the current position of the mouse
8768 on the scroll bar. */
8771 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8773 Lisp_Object
*bar_window
;
8774 enum scroll_bar_part
*part
;
8776 unsigned long *time
;
8778 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8779 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8780 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8782 Window dummy_window
;
8784 unsigned int dummy_mask
;
8788 /* Get the mouse's position relative to the scroll bar window, and
8790 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8792 /* Root, child, root x and root y. */
8793 &dummy_window
, &dummy_window
,
8794 &dummy_coord
, &dummy_coord
,
8796 /* Position relative to scroll bar. */
8799 /* Mouse buttons and modifier keys. */
8806 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8809 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8811 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8813 if (! NILP (bar
->dragging
))
8814 win_y
-= XINT (bar
->dragging
);
8818 if (win_y
> top_range
)
8822 *bar_window
= bar
->window
;
8824 if (! NILP (bar
->dragging
))
8825 *part
= scroll_bar_handle
;
8826 else if (win_y
< XINT (bar
->start
))
8827 *part
= scroll_bar_above_handle
;
8828 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8829 *part
= scroll_bar_handle
;
8831 *part
= scroll_bar_below_handle
;
8833 XSETINT (*x
, win_y
);
8834 XSETINT (*y
, top_range
);
8837 last_mouse_scroll_bar
= Qnil
;
8840 *time
= last_mouse_movement_time
;
8846 /* The screen has been cleared so we may have changed foreground or
8847 background colors, and the scroll bars may need to be redrawn.
8848 Clear out the scroll bars, and ask for expose events, so we can
8852 x_scroll_bar_clear (f
)
8855 #ifndef USE_TOOLKIT_SCROLL_BARS
8858 /* We can have scroll bars even if this is 0,
8859 if we just turned off scroll bar mode.
8860 But in that case we should not clear them. */
8861 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8862 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8863 bar
= XSCROLL_BAR (bar
)->next
)
8864 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8866 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8869 /* This processes Expose events from the menu-bar specific X event
8870 loop in xmenu.c. This allows to redisplay the frame if necessary
8871 when handling menu-bar or pop-up items. */
8874 process_expose_from_menu (event
)
8878 struct x_display_info
*dpyinfo
;
8879 int frame_exposed_p
= 0;
8883 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8884 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8887 if (f
->async_visible
== 0)
8889 f
->async_visible
= 1;
8890 f
->async_iconified
= 0;
8891 f
->output_data
.x
->has_been_visible
= 1;
8892 SET_FRAME_GARBAGED (f
);
8896 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8897 event
.xexpose
.x
, event
.xexpose
.y
,
8898 event
.xexpose
.width
, event
.xexpose
.height
);
8899 frame_exposed_p
= 1;
8904 struct scroll_bar
*bar
8905 = x_window_to_scroll_bar (event
.xexpose
.window
);
8908 x_scroll_bar_expose (bar
, &event
);
8912 return frame_exposed_p
;
8915 /* Define a queue to save up SelectionRequest events for later handling. */
8917 struct selection_event_queue
8920 struct selection_event_queue
*next
;
8923 static struct selection_event_queue
*queue
;
8925 /* Nonzero means queue up certain events--don't process them yet. */
8927 static int x_queue_selection_requests
;
8929 /* Queue up an X event *EVENT, to be processed later. */
8932 x_queue_event (f
, event
)
8936 struct selection_event_queue
*queue_tmp
8937 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8939 if (queue_tmp
!= NULL
)
8941 queue_tmp
->event
= *event
;
8942 queue_tmp
->next
= queue
;
8947 /* Take all the queued events and put them back
8948 so that they get processed afresh. */
8951 x_unqueue_events (display
)
8954 while (queue
!= NULL
)
8956 struct selection_event_queue
*queue_tmp
= queue
;
8957 XPutBackEvent (display
, &queue_tmp
->event
);
8958 queue
= queue_tmp
->next
;
8959 xfree ((char *)queue_tmp
);
8963 /* Start queuing SelectionRequest events. */
8966 x_start_queuing_selection_requests (display
)
8969 x_queue_selection_requests
++;
8972 /* Stop queuing SelectionRequest events. */
8975 x_stop_queuing_selection_requests (display
)
8978 x_queue_selection_requests
--;
8979 x_unqueue_events (display
);
8982 /* The main X event-reading loop - XTread_socket. */
8984 /* Time stamp of enter window event. This is only used by XTread_socket,
8985 but we have to put it out here, since static variables within functions
8986 sometimes don't work. */
8988 static Time enter_timestamp
;
8990 /* This holds the state XLookupString needs to implement dead keys
8991 and other tricks known as "compose processing". _X Window System_
8992 says that a portable program can't use this, but Stephen Gildea assures
8993 me that letting the compiler initialize it to zeros will work okay.
8995 This must be defined outside of XTread_socket, for the same reasons
8996 given for enter_time stamp, above. */
8998 static XComposeStatus compose_status
;
9000 /* Record the last 100 characters stored
9001 to help debug the loss-of-chars-during-GC problem. */
9003 static int temp_index
;
9004 static short temp_buffer
[100];
9006 /* Set this to nonzero to fake an "X I/O error"
9007 on a particular display. */
9009 struct x_display_info
*XTread_socket_fake_io_error
;
9011 /* When we find no input here, we occasionally do a no-op command
9012 to verify that the X server is still running and we can still talk with it.
9013 We try all the open displays, one by one.
9014 This variable is used for cycling thru the displays. */
9016 static struct x_display_info
*next_noop_dpyinfo
;
9018 #define SET_SAVED_MENU_EVENT(size) \
9021 if (f->output_data.x->saved_menu_event == 0) \
9022 f->output_data.x->saved_menu_event \
9023 = (XEvent *) xmalloc (sizeof (XEvent)); \
9024 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9025 if (numchars >= 1) \
9027 bufp->kind = menu_bar_activate_event; \
9028 XSETFRAME (bufp->frame_or_window, f); \
9037 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9038 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9040 /* Read events coming from the X server.
9041 This routine is called by the SIGIO handler.
9042 We return as soon as there are no more events to be read.
9044 Events representing keys are stored in buffer BUFP,
9045 which can hold up to NUMCHARS characters.
9046 We return the number of characters stored into the buffer,
9047 thus pretending to be `read'.
9049 EXPECTED is nonzero if the caller knows input is available. */
9052 XTread_socket (sd
, bufp
, numchars
, expected
)
9054 /* register */ struct input_event
*bufp
;
9055 /* register */ int numchars
;
9062 int event_found
= 0;
9063 struct x_display_info
*dpyinfo
;
9064 struct coding_system coding
;
9066 if (interrupt_input_blocked
)
9068 interrupt_input_pending
= 1;
9072 interrupt_input_pending
= 0;
9075 /* So people can tell when we have read the available input. */
9076 input_signal_count
++;
9079 abort (); /* Don't think this happens. */
9083 /* The input should be decoded if it is from XIM. Currently the
9084 locale of XIM is the same as that of the system. So, we can use
9085 Vlocale_coding_system which is initialized properly at Emacs
9087 setup_coding_system (Vlocale_coding_system
, &coding
);
9088 coding
.src_multibyte
= 0;
9089 coding
.dst_multibyte
= 1;
9090 /* The input is converted to events, thus we can't handle
9091 composition. Anyway, there's no XIM that gives us composition
9093 coding
.composing
= COMPOSITION_DISABLED
;
9095 /* Find the display we are supposed to read input for.
9096 It's the one communicating on descriptor SD. */
9097 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9099 #if 0 /* This ought to be unnecessary; let's verify it. */
9101 /* If available, Xlib uses FIOSNBIO to make the socket
9102 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9103 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9104 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9105 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9106 #endif /* ! defined (FIOSNBIO) */
9109 #if 0 /* This code can't be made to work, with multiple displays,
9110 and appears not to be used on any system any more.
9111 Also keyboard.c doesn't turn O_NDELAY on and off
9112 for X connections. */
9115 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9117 extern int read_alarm_should_throw
;
9118 read_alarm_should_throw
= 1;
9119 XPeekEvent (dpyinfo
->display
, &event
);
9120 read_alarm_should_throw
= 0;
9122 #endif /* HAVE_SELECT */
9126 /* For debugging, this gives a way to fake an I/O error. */
9127 if (dpyinfo
== XTread_socket_fake_io_error
)
9129 XTread_socket_fake_io_error
= 0;
9130 x_io_error_quitter (dpyinfo
->display
);
9133 while (XPending (dpyinfo
->display
))
9135 XNextEvent (dpyinfo
->display
, &event
);
9139 /* Filter events for the current X input method.
9140 XFilterEvent returns non-zero if the input method has
9141 consumed the event. We pass the frame's X window to
9142 XFilterEvent because that's the one for which the IC
9144 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9145 event
.xclient
.window
);
9146 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9156 if (event
.xclient
.message_type
9157 == dpyinfo
->Xatom_wm_protocols
9158 && event
.xclient
.format
== 32)
9160 if (event
.xclient
.data
.l
[0]
9161 == dpyinfo
->Xatom_wm_take_focus
)
9163 /* Use x_any_window_to_frame because this
9164 could be the shell widget window
9165 if the frame has no title bar. */
9166 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9168 /* Not quite sure this is needed -pd */
9169 if (f
&& FRAME_XIC (f
))
9170 XSetICFocus (FRAME_XIC (f
));
9172 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9173 instructs the WM to set the input focus automatically for
9174 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9175 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9176 it has set the focus. So, XSetInputFocus below is not
9179 The call to XSetInputFocus below has also caused trouble. In
9180 cases where the XSetInputFocus done by the WM and the one
9181 below are temporally close (on a fast machine), the call
9182 below can generate additional FocusIn events which confuse
9185 /* Since we set WM_TAKE_FOCUS, we must call
9186 XSetInputFocus explicitly. But not if f is null,
9187 since that might be an event for a deleted frame. */
9190 Display
*d
= event
.xclient
.display
;
9191 /* Catch and ignore errors, in case window has been
9192 iconified by a window manager such as GWM. */
9193 int count
= x_catch_errors (d
);
9194 XSetInputFocus (d
, event
.xclient
.window
,
9195 /* The ICCCM says this is
9196 the only valid choice. */
9198 event
.xclient
.data
.l
[1]);
9199 /* This is needed to detect the error
9200 if there is an error. */
9202 x_uncatch_errors (d
, count
);
9204 /* Not certain about handling scroll bars here */
9207 else if (event
.xclient
.data
.l
[0]
9208 == dpyinfo
->Xatom_wm_save_yourself
)
9210 /* Save state modify the WM_COMMAND property to
9211 something which can reinstate us. This notifies
9212 the session manager, who's looking for such a
9213 PropertyNotify. Can restart processing when
9214 a keyboard or mouse event arrives. */
9217 f
= x_top_window_to_frame (dpyinfo
,
9218 event
.xclient
.window
);
9220 /* This is just so we only give real data once
9221 for a single Emacs process. */
9222 if (f
== SELECTED_FRAME ())
9223 XSetCommand (FRAME_X_DISPLAY (f
),
9224 event
.xclient
.window
,
9225 initial_argv
, initial_argc
);
9227 XSetCommand (FRAME_X_DISPLAY (f
),
9228 event
.xclient
.window
,
9232 else if (event
.xclient
.data
.l
[0]
9233 == dpyinfo
->Xatom_wm_delete_window
)
9236 = x_any_window_to_frame (dpyinfo
,
9237 event
.xclient
.window
);
9244 bufp
->kind
= delete_window_event
;
9245 XSETFRAME (bufp
->frame_or_window
, f
);
9254 else if (event
.xclient
.message_type
9255 == dpyinfo
->Xatom_wm_configure_denied
)
9258 else if (event
.xclient
.message_type
9259 == dpyinfo
->Xatom_wm_window_moved
)
9263 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9265 new_x
= event
.xclient
.data
.s
[0];
9266 new_y
= event
.xclient
.data
.s
[1];
9270 f
->output_data
.x
->left_pos
= new_x
;
9271 f
->output_data
.x
->top_pos
= new_y
;
9275 else if (event
.xclient
.message_type
9276 == dpyinfo
->Xatom_editres
)
9279 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9280 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9283 #endif /* HACK_EDITRES */
9284 else if ((event
.xclient
.message_type
9285 == dpyinfo
->Xatom_DONE
)
9286 || (event
.xclient
.message_type
9287 == dpyinfo
->Xatom_PAGE
))
9289 /* Ghostview job completed. Kill it. We could
9290 reply with "Next" if we received "Page", but we
9291 currently never do because we are interested in
9292 images, only, which should have 1 page. */
9293 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9295 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9296 x_kill_gs_process (pixmap
, f
);
9297 expose_frame (f
, 0, 0, 0, 0);
9299 #ifdef USE_TOOLKIT_SCROLL_BARS
9300 /* Scroll bar callbacks send a ClientMessage from which
9301 we construct an input_event. */
9302 else if (event
.xclient
.message_type
9303 == dpyinfo
->Xatom_Scrollbar
)
9305 x_scroll_bar_to_input_event (&event
, bufp
);
9306 ++bufp
, ++count
, --numchars
;
9309 #endif /* USE_TOOLKIT_SCROLL_BARS */
9315 case SelectionNotify
:
9316 #ifdef USE_X_TOOLKIT
9317 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9319 #endif /* not USE_X_TOOLKIT */
9320 x_handle_selection_notify (&event
.xselection
);
9323 case SelectionClear
: /* Someone has grabbed ownership. */
9324 #ifdef USE_X_TOOLKIT
9325 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9327 #endif /* USE_X_TOOLKIT */
9329 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9334 bufp
->kind
= selection_clear_event
;
9335 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9336 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9337 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9338 bufp
->frame_or_window
= Qnil
;
9347 case SelectionRequest
: /* Someone wants our selection. */
9348 #ifdef USE_X_TOOLKIT
9349 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9351 #endif /* USE_X_TOOLKIT */
9352 if (x_queue_selection_requests
)
9353 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9357 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9362 bufp
->kind
= selection_request_event
;
9363 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9364 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9365 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9366 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9367 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9368 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9369 bufp
->frame_or_window
= Qnil
;
9378 case PropertyNotify
:
9379 #ifdef USE_X_TOOLKIT
9380 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9382 #endif /* not USE_X_TOOLKIT */
9383 x_handle_property_notify (&event
.xproperty
);
9386 case ReparentNotify
:
9387 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9391 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9392 x_real_positions (f
, &x
, &y
);
9393 f
->output_data
.x
->left_pos
= x
;
9394 f
->output_data
.x
->top_pos
= y
;
9399 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9402 if (f
->async_visible
== 0)
9404 f
->async_visible
= 1;
9405 f
->async_iconified
= 0;
9406 f
->output_data
.x
->has_been_visible
= 1;
9407 SET_FRAME_GARBAGED (f
);
9410 expose_frame (x_window_to_frame (dpyinfo
,
9411 event
.xexpose
.window
),
9412 event
.xexpose
.x
, event
.xexpose
.y
,
9413 event
.xexpose
.width
, event
.xexpose
.height
);
9417 #ifdef USE_TOOLKIT_SCROLL_BARS
9418 /* Dispatch event to the widget. */
9420 #else /* not USE_TOOLKIT_SCROLL_BARS */
9421 struct scroll_bar
*bar
9422 = x_window_to_scroll_bar (event
.xexpose
.window
);
9425 x_scroll_bar_expose (bar
, &event
);
9426 #ifdef USE_X_TOOLKIT
9429 #endif /* USE_X_TOOLKIT */
9430 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9434 case GraphicsExpose
: /* This occurs when an XCopyArea's
9435 source area was obscured or not
9437 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9441 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9442 event
.xgraphicsexpose
.width
,
9443 event
.xgraphicsexpose
.height
);
9445 #ifdef USE_X_TOOLKIT
9448 #endif /* USE_X_TOOLKIT */
9451 case NoExpose
: /* This occurs when an XCopyArea's
9452 source area was completely
9457 /* Redo the mouse-highlight after the tooltip has gone. */
9458 if (event
.xmap
.window
== tip_window
)
9461 redo_mouse_highlight ();
9464 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9465 if (f
) /* F may no longer exist if
9466 the frame was deleted. */
9468 /* While a frame is unmapped, display generation is
9469 disabled; you don't want to spend time updating a
9470 display that won't ever be seen. */
9471 f
->async_visible
= 0;
9472 /* We can't distinguish, from the event, whether the window
9473 has become iconified or invisible. So assume, if it
9474 was previously visible, than now it is iconified.
9475 But x_make_frame_invisible clears both
9476 the visible flag and the iconified flag;
9477 and that way, we know the window is not iconified now. */
9478 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9480 f
->async_iconified
= 1;
9482 bufp
->kind
= iconify_event
;
9483 XSETFRAME (bufp
->frame_or_window
, f
);
9493 if (event
.xmap
.window
== tip_window
)
9494 /* The tooltip has been drawn already. Avoid
9495 the SET_FRAME_GARBAGED below. */
9498 /* We use x_top_window_to_frame because map events can
9499 come for sub-windows and they don't mean that the
9500 frame is visible. */
9501 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9504 f
->async_visible
= 1;
9505 f
->async_iconified
= 0;
9506 f
->output_data
.x
->has_been_visible
= 1;
9508 /* wait_reading_process_input will notice this and update
9509 the frame's display structures. */
9510 SET_FRAME_GARBAGED (f
);
9514 bufp
->kind
= deiconify_event
;
9515 XSETFRAME (bufp
->frame_or_window
, f
);
9521 else if (! NILP (Vframe_list
)
9522 && ! NILP (XCDR (Vframe_list
)))
9523 /* Force a redisplay sooner or later
9524 to update the frame titles
9525 in case this is the second frame. */
9526 record_asynch_buffer_change ();
9531 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9534 /* I couldn't find a way to prevent LessTif scroll bars
9535 from consuming key events. */
9538 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9540 if (widget
&& XmIsScrollBar (widget
))
9542 widget
= XtParent (widget
);
9543 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9546 #endif /* USE_MOTIF */
9550 KeySym keysym
, orig_keysym
;
9551 /* al%imercury@uunet.uu.net says that making this 81
9552 instead of 80 fixed a bug whereby meta chars made
9555 It seems that some version of XmbLookupString has
9556 a bug of not returning XBufferOverflow in
9557 status_return even if the input is too long to
9558 fit in 81 bytes. So, we must prepare sufficient
9559 bytes for copy_buffer. 513 bytes (256 chars for
9560 two-byte character set) seems to be a faily good
9561 approximation. -- 2000.8.10 handa@etl.go.jp */
9562 unsigned char copy_buffer
[513];
9563 unsigned char *copy_bufptr
= copy_buffer
;
9564 int copy_bufsiz
= sizeof (copy_buffer
);
9568 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9569 extra_keyboard_modifiers
);
9570 modifiers
= event
.xkey
.state
;
9572 /* This will have to go some day... */
9574 /* make_lispy_event turns chars into control chars.
9575 Don't do it here because XLookupString is too eager. */
9576 event
.xkey
.state
&= ~ControlMask
;
9577 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9578 | dpyinfo
->super_mod_mask
9579 | dpyinfo
->hyper_mod_mask
9580 | dpyinfo
->alt_mod_mask
);
9582 /* In case Meta is ComposeCharacter,
9583 clear its status. According to Markus Ehrnsperger
9584 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9585 this enables ComposeCharacter to work whether or
9586 not it is combined with Meta. */
9587 if (modifiers
& dpyinfo
->meta_mod_mask
)
9588 bzero (&compose_status
, sizeof (compose_status
));
9593 Status status_return
;
9595 nbytes
= XmbLookupString (FRAME_XIC (f
),
9596 &event
.xkey
, copy_bufptr
,
9597 copy_bufsiz
, &keysym
,
9599 if (status_return
== XBufferOverflow
)
9601 copy_bufsiz
= nbytes
+ 1;
9602 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9603 nbytes
= XmbLookupString (FRAME_XIC (f
),
9604 &event
.xkey
, copy_bufptr
,
9605 copy_bufsiz
, &keysym
,
9609 if (status_return
== XLookupNone
)
9611 else if (status_return
== XLookupChars
)
9616 else if (status_return
!= XLookupKeySym
9617 && status_return
!= XLookupBoth
)
9621 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9622 copy_bufsiz
, &keysym
,
9625 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9626 copy_bufsiz
, &keysym
,
9630 orig_keysym
= keysym
;
9634 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9635 || keysym
== XK_Delete
9636 #ifdef XK_ISO_Left_Tab
9637 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9639 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9640 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9641 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9643 /* This recognizes the "extended function keys".
9644 It seems there's no cleaner way.
9645 Test IsModifierKey to avoid handling mode_switch
9647 || ((unsigned) (keysym
) >= XK_Select
9648 && (unsigned)(keysym
) < XK_KP_Space
)
9650 #ifdef XK_dead_circumflex
9651 || orig_keysym
== XK_dead_circumflex
9653 #ifdef XK_dead_grave
9654 || orig_keysym
== XK_dead_grave
9656 #ifdef XK_dead_tilde
9657 || orig_keysym
== XK_dead_tilde
9659 #ifdef XK_dead_diaeresis
9660 || orig_keysym
== XK_dead_diaeresis
9662 #ifdef XK_dead_macron
9663 || orig_keysym
== XK_dead_macron
9665 #ifdef XK_dead_degree
9666 || orig_keysym
== XK_dead_degree
9668 #ifdef XK_dead_acute
9669 || orig_keysym
== XK_dead_acute
9671 #ifdef XK_dead_cedilla
9672 || orig_keysym
== XK_dead_cedilla
9674 #ifdef XK_dead_breve
9675 || orig_keysym
== XK_dead_breve
9677 #ifdef XK_dead_ogonek
9678 || orig_keysym
== XK_dead_ogonek
9680 #ifdef XK_dead_caron
9681 || orig_keysym
== XK_dead_caron
9683 #ifdef XK_dead_doubleacute
9684 || orig_keysym
== XK_dead_doubleacute
9686 #ifdef XK_dead_abovedot
9687 || orig_keysym
== XK_dead_abovedot
9689 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9690 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9691 /* Any "vendor-specific" key is ok. */
9692 || (orig_keysym
& (1 << 28)))
9693 && ! (IsModifierKey (orig_keysym
)
9695 #ifdef XK_Mode_switch
9696 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9699 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9701 #endif /* not HAVE_X11R5 */
9704 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9706 temp_buffer
[temp_index
++] = keysym
;
9707 bufp
->kind
= non_ascii_keystroke
;
9708 bufp
->code
= keysym
;
9709 XSETFRAME (bufp
->frame_or_window
, f
);
9712 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9714 bufp
->timestamp
= event
.xkey
.time
;
9719 else if (numchars
> nbytes
)
9723 unsigned char *p
, *pend
;
9726 for (i
= 0; i
< nbytes
; i
++)
9728 if (temp_index
== (sizeof temp_buffer
9731 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
9734 if (/* If the event is not from XIM, */
9735 event
.xkey
.keycode
!= 0
9736 /* or the current locale doesn't request
9737 decoding of the intup data, ... */
9738 || coding
.type
== coding_type_raw_text
9739 || coding
.type
== coding_type_no_conversion
)
9741 /* ... we can use the input data as is. */
9746 /* We have to decode the input data. */
9750 require
= decoding_buffer_size (&coding
, nbytes
);
9751 p
= (unsigned char *) alloca (require
);
9752 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
9753 decode_coding (&coding
, copy_bufptr
, p
,
9755 nbytes
= coding
.produced
;
9756 nchars
= coding
.produced_char
;
9760 /* Convert the input data to a sequence of
9761 character events. */
9762 for (i
= 0; i
< nbytes
; i
+= len
)
9764 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
9766 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
9768 : multibyte_char_keystroke
);
9770 XSETFRAME (bufp
->frame_or_window
, f
);
9773 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9775 bufp
->timestamp
= event
.xkey
.time
;
9782 if (keysym
== NoSymbol
)
9792 /* Don't dispatch this event since XtDispatchEvent calls
9793 XFilterEvent, and two calls in a row may freeze the
9802 /* Don't dispatch this event since XtDispatchEvent calls
9803 XFilterEvent, and two calls in a row may freeze the
9810 /* Here's a possible interpretation of the whole
9811 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9812 you get a FocusIn event, you have to get a FocusOut
9813 event before you relinquish the focus. If you
9814 haven't received a FocusIn event, then a mere
9815 LeaveNotify is enough to free you. */
9819 int from_menu_bar_p
= 0;
9821 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9823 #ifdef LESSTIF_VERSION
9824 /* When clicking outside of a menu bar popup to close
9825 it, we get a FocusIn/ EnterNotify sequence of
9826 events. The flag event.xcrossing.focus is not set
9827 in the EnterNotify event of that sequence because
9828 the focus is in the menu bar,
9829 event.xcrossing.window is the frame's X window.
9830 Unconditionally setting the focus frame to null in
9831 this case is not the right thing, because no event
9832 follows that could set the focus frame to the right
9835 This could be a LessTif bug, but I wasn't able to
9836 reproduce the behavior in a simple test program.
9838 (gerd, LessTif 0.88.1). */
9840 if (!event
.xcrossing
.focus
9842 && f
->output_data
.x
->menubar_widget
)
9847 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9848 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9849 from_menu_bar_p
= 1;
9851 #endif /* LESSTIF_VERSION */
9853 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9855 /* Avoid nasty pop/raise loops. */
9856 if (f
&& (!(f
->auto_raise
)
9858 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9860 x_new_focus_frame (dpyinfo
, f
);
9861 enter_timestamp
= event
.xcrossing
.time
;
9864 else if (f
== dpyinfo
->x_focus_frame
)
9865 x_new_focus_frame (dpyinfo
, 0);
9867 /* EnterNotify counts as mouse movement,
9868 so update things that depend on mouse position. */
9869 if (f
&& !f
->output_data
.x
->busy_p
)
9870 note_mouse_movement (f
, &event
.xmotion
);
9875 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9876 if (event
.xfocus
.detail
!= NotifyPointer
)
9877 dpyinfo
->x_focus_event_frame
= f
;
9880 x_new_focus_frame (dpyinfo
, f
);
9882 /* Don't stop displaying the initial startup message
9883 for a switch-frame event we don't need. */
9884 if (GC_NILP (Vterminal_frame
)
9885 && GC_CONSP (Vframe_list
)
9886 && !GC_NILP (XCDR (Vframe_list
)))
9888 bufp
->kind
= FOCUS_IN_EVENT
;
9889 XSETFRAME (bufp
->frame_or_window
, f
);
9891 ++bufp
, ++count
, --numchars
;
9896 if (f
&& FRAME_XIC (f
))
9897 XSetICFocus (FRAME_XIC (f
));
9903 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9907 int from_menu_bar_p
= 0;
9909 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9911 /* If we move outside the frame, then we're
9912 certainly no longer on any text in the frame. */
9913 clear_mouse_face (dpyinfo
);
9914 dpyinfo
->mouse_face_mouse_frame
= 0;
9917 /* Generate a nil HELP_EVENT to cancel a help-echo.
9918 Do it only if there's something to cancel.
9919 Otherwise, the startup message is cleared when
9920 the mouse leaves the frame. */
9921 if (any_help_event_p
)
9926 XSETFRAME (frame
, f
);
9927 n
= gen_help_event (bufp
, numchars
,
9928 Qnil
, frame
, Qnil
, Qnil
, 0);
9929 bufp
+= n
, count
+= n
, numchars
-= n
;
9932 #ifdef LESSTIF_VERSION
9933 /* Please see the comment at the start of the
9934 EnterNotify case. */
9935 if (!event
.xcrossing
.focus
9936 && f
->output_data
.x
->menubar_widget
)
9940 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9941 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9942 from_menu_bar_p
= 1;
9944 #endif /* LESSTIF_VERSION */
9946 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9947 x_mouse_leave (dpyinfo
);
9950 if (f
== dpyinfo
->x_focus_event_frame
)
9951 dpyinfo
->x_focus_event_frame
= 0;
9952 if (f
== dpyinfo
->x_focus_frame
)
9953 x_new_focus_frame (dpyinfo
, 0);
9959 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9960 if (event
.xfocus
.detail
!= NotifyPointer
9961 && f
== dpyinfo
->x_focus_event_frame
)
9962 dpyinfo
->x_focus_event_frame
= 0;
9963 if (f
&& f
== dpyinfo
->x_focus_frame
)
9964 x_new_focus_frame (dpyinfo
, 0);
9967 if (f
&& FRAME_XIC (f
))
9968 XUnsetICFocus (FRAME_XIC (f
));
9975 previous_help_echo
= help_echo
;
9976 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
9979 if (dpyinfo
->grabbed
&& last_mouse_frame
9980 && FRAME_LIVE_P (last_mouse_frame
))
9981 f
= last_mouse_frame
;
9983 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9986 note_mouse_movement (f
, &event
.xmotion
);
9989 #ifndef USE_TOOLKIT_SCROLL_BARS
9990 struct scroll_bar
*bar
9991 = x_window_to_scroll_bar (event
.xmotion
.window
);
9994 x_scroll_bar_note_movement (bar
, &event
);
9995 #endif /* USE_TOOLKIT_SCROLL_BARS */
9997 /* If we move outside the frame, then we're
9998 certainly no longer on any text in the frame. */
9999 clear_mouse_face (dpyinfo
);
10002 /* If the contents of the global variable help_echo
10003 has changed, generate a HELP_EVENT. */
10004 if (!NILP (help_echo
)
10005 || !NILP (previous_help_echo
))
10011 XSETFRAME (frame
, f
);
10015 any_help_event_p
= 1;
10016 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10017 help_echo_window
, help_echo_object
,
10019 bufp
+= n
, count
+= n
, numchars
-= n
;
10025 case ConfigureNotify
:
10026 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10029 #ifndef USE_X_TOOLKIT
10030 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10031 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10033 /* In the toolkit version, change_frame_size
10034 is called by the code that handles resizing
10035 of the EmacsFrame widget. */
10037 /* Even if the number of character rows and columns has
10038 not changed, the font size may have changed, so we need
10039 to check the pixel dimensions as well. */
10040 if (columns
!= f
->width
10041 || rows
!= f
->height
10042 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10043 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10045 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10046 SET_FRAME_GARBAGED (f
);
10047 cancel_mouse_face (f
);
10051 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10052 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10054 /* What we have now is the position of Emacs's own window.
10055 Convert that to the position of the window manager window. */
10056 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10057 &f
->output_data
.x
->top_pos
);
10060 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10061 xic_set_statusarea (f
);
10064 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10066 /* Since the WM decorations come below top_pos now,
10067 we must put them below top_pos in the future. */
10068 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10069 x_wm_set_size_hint (f
, (long) 0, 0);
10072 /* Some window managers pass (0,0) as the location of
10073 the window, and the Motif event handler stores it
10074 in the emacs widget, which messes up Motif menus. */
10075 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10077 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10078 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10080 #endif /* USE_MOTIF */
10085 case ButtonRelease
:
10087 /* If we decide we want to generate an event to be seen
10088 by the rest of Emacs, we put it here. */
10089 struct input_event emacs_event
;
10090 int tool_bar_p
= 0;
10092 emacs_event
.kind
= no_event
;
10093 bzero (&compose_status
, sizeof (compose_status
));
10095 if (dpyinfo
->grabbed
10096 && last_mouse_frame
10097 && FRAME_LIVE_P (last_mouse_frame
))
10098 f
= last_mouse_frame
;
10100 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10104 /* Is this in the tool-bar? */
10105 if (WINDOWP (f
->tool_bar_window
)
10106 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10108 Lisp_Object window
;
10111 x
= event
.xbutton
.x
;
10112 y
= event
.xbutton
.y
;
10115 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10116 if (EQ (window
, f
->tool_bar_window
))
10118 x_handle_tool_bar_click (f
, &event
.xbutton
);
10124 if (!dpyinfo
->x_focus_frame
10125 || f
== dpyinfo
->x_focus_frame
)
10126 construct_mouse_click (&emacs_event
, &event
, f
);
10130 #ifndef USE_TOOLKIT_SCROLL_BARS
10131 struct scroll_bar
*bar
10132 = x_window_to_scroll_bar (event
.xbutton
.window
);
10135 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10136 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10139 if (event
.type
== ButtonPress
)
10141 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10142 last_mouse_frame
= f
;
10143 /* Ignore any mouse motion that happened
10144 before this event; any subsequent mouse-movement
10145 Emacs events should reflect only motion after
10146 the ButtonPress. */
10148 f
->mouse_moved
= 0;
10151 last_tool_bar_item
= -1;
10155 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10158 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10160 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10166 #ifdef USE_X_TOOLKIT
10167 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10168 /* For a down-event in the menu bar,
10169 don't pass it to Xt right now.
10170 Instead, save it away
10171 and we will pass it to Xt from kbd_buffer_get_event.
10172 That way, we can run some Lisp code first. */
10173 if (f
&& event
.type
== ButtonPress
10174 /* Verify the event is really within the menu bar
10175 and not just sent to it due to grabbing. */
10176 && event
.xbutton
.x
>= 0
10177 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10178 && event
.xbutton
.y
>= 0
10179 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10180 && event
.xbutton
.same_screen
)
10182 SET_SAVED_BUTTON_EVENT
;
10183 XSETFRAME (last_mouse_press_frame
, f
);
10185 else if (event
.type
== ButtonPress
)
10187 last_mouse_press_frame
= Qnil
;
10191 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10192 but I am trying to be cautious. */
10193 else if (event
.type
== ButtonRelease
)
10195 if (!NILP (last_mouse_press_frame
))
10197 f
= XFRAME (last_mouse_press_frame
);
10198 if (f
->output_data
.x
)
10199 SET_SAVED_BUTTON_EVENT
;
10204 #endif /* USE_MOTIF */
10207 #endif /* USE_X_TOOLKIT */
10211 case CirculateNotify
:
10214 case CirculateRequest
:
10217 case VisibilityNotify
:
10220 case MappingNotify
:
10221 /* Someone has changed the keyboard mapping - update the
10223 switch (event
.xmapping
.request
)
10225 case MappingModifier
:
10226 x_find_modifier_meanings (dpyinfo
);
10227 /* This is meant to fall through. */
10228 case MappingKeyboard
:
10229 XRefreshKeyboardMapping (&event
.xmapping
);
10235 #ifdef USE_X_TOOLKIT
10237 XtDispatchEvent (&event
);
10239 #endif /* USE_X_TOOLKIT */
10247 /* On some systems, an X bug causes Emacs to get no more events
10248 when the window is destroyed. Detect that. (1994.) */
10251 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10252 One XNOOP in 100 loops will make Emacs terminate.
10253 B. Bretthauer, 1994 */
10255 if (x_noop_count
>= 100)
10259 if (next_noop_dpyinfo
== 0)
10260 next_noop_dpyinfo
= x_display_list
;
10262 XNoOp (next_noop_dpyinfo
->display
);
10264 /* Each time we get here, cycle through the displays now open. */
10265 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10269 /* If the focus was just given to an auto-raising frame,
10271 /* ??? This ought to be able to handle more than one such frame. */
10272 if (pending_autoraise_frame
)
10274 x_raise_frame (pending_autoraise_frame
);
10275 pending_autoraise_frame
= 0;
10286 /***********************************************************************
10288 ***********************************************************************/
10290 /* Note if the text cursor of window W has been overwritten by a
10291 drawing operation that outputs N glyphs starting at HPOS in the
10292 line given by output_cursor.vpos. N < 0 means all the rest of the
10293 line after HPOS has been written. */
10296 note_overwritten_text_cursor (w
, hpos
, n
)
10300 if (updated_area
== TEXT_AREA
10301 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10302 && hpos
<= w
->phys_cursor
.hpos
10304 || hpos
+ n
> w
->phys_cursor
.hpos
))
10305 w
->phys_cursor_on_p
= 0;
10309 /* Set clipping for output in glyph row ROW. W is the window in which
10310 we operate. GC is the graphics context to set clipping in.
10311 WHOLE_LINE_P non-zero means include the areas used for truncation
10312 mark display and alike in the clipping rectangle.
10314 ROW may be a text row or, e.g., a mode line. Text rows must be
10315 clipped to the interior of the window dedicated to text display,
10316 mode lines must be clipped to the whole window. */
10319 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10321 struct glyph_row
*row
;
10325 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10326 XRectangle clip_rect
;
10327 int window_x
, window_y
, window_width
, window_height
;
10329 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10331 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10332 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10333 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10334 clip_rect
.width
= window_width
;
10335 clip_rect
.height
= row
->visible_height
;
10337 /* If clipping to the whole line, including trunc marks, extend
10338 the rectangle to the left and increase its width. */
10341 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10342 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10345 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10349 /* Draw a hollow box cursor on window W in glyph row ROW. */
10352 x_draw_hollow_cursor (w
, row
)
10354 struct glyph_row
*row
;
10356 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10357 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10358 Display
*dpy
= FRAME_X_DISPLAY (f
);
10361 struct glyph
*cursor_glyph
;
10364 /* Compute frame-relative coordinates from window-relative
10366 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10367 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10368 + row
->ascent
- w
->phys_cursor_ascent
);
10369 h
= row
->height
- 1;
10371 /* Get the glyph the cursor is on. If we can't tell because
10372 the current matrix is invalid or such, give up. */
10373 cursor_glyph
= get_phys_cursor_glyph (w
);
10374 if (cursor_glyph
== NULL
)
10377 /* Compute the width of the rectangle to draw. If on a stretch
10378 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10379 rectangle as wide as the glyph, but use a canonical character
10381 wd
= cursor_glyph
->pixel_width
- 1;
10382 if (cursor_glyph
->type
== STRETCH_GLYPH
10383 && !x_stretch_cursor_p
)
10384 wd
= min (CANON_X_UNIT (f
), wd
);
10386 /* The foreground of cursor_gc is typically the same as the normal
10387 background color, which can cause the cursor box to be invisible. */
10388 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10389 if (dpyinfo
->scratch_cursor_gc
)
10390 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10392 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10393 GCForeground
, &xgcv
);
10394 gc
= dpyinfo
->scratch_cursor_gc
;
10396 /* Set clipping, draw the rectangle, and reset clipping again. */
10397 x_clip_to_row (w
, row
, gc
, 0);
10398 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10399 XSetClipMask (dpy
, gc
, None
);
10403 /* Draw a bar cursor on window W in glyph row ROW.
10405 Implementation note: One would like to draw a bar cursor with an
10406 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10407 Unfortunately, I didn't find a font yet that has this property set.
10411 x_draw_bar_cursor (w
, row
, width
)
10413 struct glyph_row
*row
;
10416 struct frame
*f
= XFRAME (w
->frame
);
10417 struct glyph
*cursor_glyph
;
10420 unsigned long mask
;
10425 /* If cursor is out of bounds, don't draw garbage. This can happen
10426 in mini-buffer windows when switching between echo area glyphs
10427 and mini-buffer. */
10428 cursor_glyph
= get_phys_cursor_glyph (w
);
10429 if (cursor_glyph
== NULL
)
10432 /* If on an image, draw like a normal cursor. That's usually better
10433 visible than drawing a bar, esp. if the image is large so that
10434 the bar might not be in the window. */
10435 if (cursor_glyph
->type
== IMAGE_GLYPH
)
10437 struct glyph_row
*row
;
10438 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
10439 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
10443 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10444 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10445 xgcv
.graphics_exposures
= 0;
10446 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10447 dpy
= FRAME_X_DISPLAY (f
);
10448 window
= FRAME_X_WINDOW (f
);
10449 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10452 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10455 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10456 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10460 width
= f
->output_data
.x
->cursor_width
;
10462 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10463 x_clip_to_row (w
, row
, gc
, 0);
10464 XFillRectangle (dpy
, window
, gc
,
10466 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10467 min (cursor_glyph
->pixel_width
, width
),
10469 XSetClipMask (dpy
, gc
, None
);
10474 /* Clear the cursor of window W to background color, and mark the
10475 cursor as not shown. This is used when the text where the cursor
10476 is is about to be rewritten. */
10482 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10483 x_update_window_cursor (w
, 0);
10487 /* Draw the cursor glyph of window W in glyph row ROW. See the
10488 comment of x_draw_glyphs for the meaning of HL. */
10491 x_draw_phys_cursor_glyph (w
, row
, hl
)
10493 struct glyph_row
*row
;
10494 enum draw_glyphs_face hl
;
10496 /* If cursor hpos is out of bounds, don't draw garbage. This can
10497 happen in mini-buffer windows when switching between echo area
10498 glyphs and mini-buffer. */
10499 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10501 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10502 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10505 /* When we erase the cursor, and ROW is overlapped by other
10506 rows, make sure that these overlapping parts of other rows
10508 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10510 if (row
> w
->current_matrix
->rows
10511 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10512 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10514 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10515 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10516 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10522 /* Erase the image of a cursor of window W from the screen. */
10525 x_erase_phys_cursor (w
)
10528 struct frame
*f
= XFRAME (w
->frame
);
10529 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10530 int hpos
= w
->phys_cursor
.hpos
;
10531 int vpos
= w
->phys_cursor
.vpos
;
10532 int mouse_face_here_p
= 0;
10533 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10534 struct glyph_row
*cursor_row
;
10535 struct glyph
*cursor_glyph
;
10536 enum draw_glyphs_face hl
;
10538 /* No cursor displayed or row invalidated => nothing to do on the
10540 if (w
->phys_cursor_type
== NO_CURSOR
)
10541 goto mark_cursor_off
;
10543 /* VPOS >= active_glyphs->nrows means that window has been resized.
10544 Don't bother to erase the cursor. */
10545 if (vpos
>= active_glyphs
->nrows
)
10546 goto mark_cursor_off
;
10548 /* If row containing cursor is marked invalid, there is nothing we
10550 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10551 if (!cursor_row
->enabled_p
)
10552 goto mark_cursor_off
;
10554 /* This can happen when the new row is shorter than the old one.
10555 In this case, either x_draw_glyphs or clear_end_of_line
10556 should have cleared the cursor. Note that we wouldn't be
10557 able to erase the cursor in this case because we don't have a
10558 cursor glyph at hand. */
10559 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10560 goto mark_cursor_off
;
10562 /* If the cursor is in the mouse face area, redisplay that when
10563 we clear the cursor. */
10564 if (! NILP (dpyinfo
->mouse_face_window
)
10565 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10566 && (vpos
> dpyinfo
->mouse_face_beg_row
10567 || (vpos
== dpyinfo
->mouse_face_beg_row
10568 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10569 && (vpos
< dpyinfo
->mouse_face_end_row
10570 || (vpos
== dpyinfo
->mouse_face_end_row
10571 && hpos
< dpyinfo
->mouse_face_end_col
))
10572 /* Don't redraw the cursor's spot in mouse face if it is at the
10573 end of a line (on a newline). The cursor appears there, but
10574 mouse highlighting does not. */
10575 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10576 mouse_face_here_p
= 1;
10578 /* Maybe clear the display under the cursor. */
10579 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10582 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10584 cursor_glyph
= get_phys_cursor_glyph (w
);
10585 if (cursor_glyph
== NULL
)
10586 goto mark_cursor_off
;
10588 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10590 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10592 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10594 cursor_glyph
->pixel_width
,
10595 cursor_row
->visible_height
,
10599 /* Erase the cursor by redrawing the character underneath it. */
10600 if (mouse_face_here_p
)
10601 hl
= DRAW_MOUSE_FACE
;
10602 else if (cursor_row
->inverse_p
)
10603 hl
= DRAW_INVERSE_VIDEO
;
10605 hl
= DRAW_NORMAL_TEXT
;
10606 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10609 w
->phys_cursor_on_p
= 0;
10610 w
->phys_cursor_type
= NO_CURSOR
;
10614 /* Display or clear cursor of window W. If ON is zero, clear the
10615 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10616 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10619 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10621 int on
, hpos
, vpos
, x
, y
;
10623 struct frame
*f
= XFRAME (w
->frame
);
10624 int new_cursor_type
;
10625 int new_cursor_width
;
10626 struct glyph_matrix
*current_glyphs
;
10627 struct glyph_row
*glyph_row
;
10628 struct glyph
*glyph
;
10630 /* This is pointless on invisible frames, and dangerous on garbaged
10631 windows and frames; in the latter case, the frame or window may
10632 be in the midst of changing its size, and x and y may be off the
10634 if (! FRAME_VISIBLE_P (f
)
10635 || FRAME_GARBAGED_P (f
)
10636 || vpos
>= w
->current_matrix
->nrows
10637 || hpos
>= w
->current_matrix
->matrix_w
)
10640 /* If cursor is off and we want it off, return quickly. */
10641 if (!on
&& !w
->phys_cursor_on_p
)
10644 current_glyphs
= w
->current_matrix
;
10645 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10646 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10648 /* If cursor row is not enabled, we don't really know where to
10649 display the cursor. */
10650 if (!glyph_row
->enabled_p
)
10652 w
->phys_cursor_on_p
= 0;
10656 xassert (interrupt_input_blocked
);
10658 /* Set new_cursor_type to the cursor we want to be displayed. In a
10659 mini-buffer window, we want the cursor only to appear if we are
10660 reading input from this window. For the selected window, we want
10661 the cursor type given by the frame parameter. If explicitly
10662 marked off, draw no cursor. In all other cases, we want a hollow
10664 new_cursor_width
= -1;
10665 if (cursor_in_echo_area
10666 && FRAME_HAS_MINIBUF_P (f
)
10667 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10669 if (w
== XWINDOW (echo_area_window
))
10670 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10672 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10676 if (w
!= XWINDOW (selected_window
)
10677 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10679 extern int cursor_in_non_selected_windows
;
10681 if (MINI_WINDOW_P (w
)
10682 || !cursor_in_non_selected_windows
10683 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
10684 new_cursor_type
= NO_CURSOR
;
10686 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10688 else if (w
->cursor_off_p
)
10689 new_cursor_type
= NO_CURSOR
;
10692 struct buffer
*b
= XBUFFER (w
->buffer
);
10694 if (EQ (b
->cursor_type
, Qt
))
10695 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10697 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10698 &new_cursor_width
);
10702 /* If cursor is currently being shown and we don't want it to be or
10703 it is in the wrong place, or the cursor type is not what we want,
10705 if (w
->phys_cursor_on_p
10707 || w
->phys_cursor
.x
!= x
10708 || w
->phys_cursor
.y
!= y
10709 || new_cursor_type
!= w
->phys_cursor_type
))
10710 x_erase_phys_cursor (w
);
10712 /* If the cursor is now invisible and we want it to be visible,
10714 if (on
&& !w
->phys_cursor_on_p
)
10716 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10717 w
->phys_cursor_height
= glyph_row
->height
;
10719 /* Set phys_cursor_.* before x_draw_.* is called because some
10720 of them may need the information. */
10721 w
->phys_cursor
.x
= x
;
10722 w
->phys_cursor
.y
= glyph_row
->y
;
10723 w
->phys_cursor
.hpos
= hpos
;
10724 w
->phys_cursor
.vpos
= vpos
;
10725 w
->phys_cursor_type
= new_cursor_type
;
10726 w
->phys_cursor_on_p
= 1;
10728 switch (new_cursor_type
)
10730 case HOLLOW_BOX_CURSOR
:
10731 x_draw_hollow_cursor (w
, glyph_row
);
10734 case FILLED_BOX_CURSOR
:
10735 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10739 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10750 if (w
== XWINDOW (f
->selected_window
))
10751 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10752 xic_set_preeditarea (w
, x
, y
);
10757 if (updating_frame
!= f
)
10758 XFlush (FRAME_X_DISPLAY (f
));
10763 /* Display the cursor on window W, or clear it. X and Y are window
10764 relative pixel coordinates. HPOS and VPOS are glyph matrix
10765 positions. If W is not the selected window, display a hollow
10766 cursor. ON non-zero means display the cursor at X, Y which
10767 correspond to HPOS, VPOS, otherwise it is cleared. */
10770 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10772 int on
, hpos
, vpos
, x
, y
;
10775 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10780 /* Display the cursor on window W, or clear it, according to ON_P.
10781 Don't change the cursor's position. */
10784 x_update_cursor (f
, on_p
)
10787 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10791 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10792 in the window tree rooted at W. */
10795 x_update_cursor_in_window_tree (w
, on_p
)
10801 if (!NILP (w
->hchild
))
10802 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10803 else if (!NILP (w
->vchild
))
10804 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10806 x_update_window_cursor (w
, on_p
);
10808 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10813 /* Switch the display of W's cursor on or off, according to the value
10817 x_update_window_cursor (w
, on
)
10821 /* Don't update cursor in windows whose frame is in the process
10822 of being deleted. */
10823 if (w
->current_matrix
)
10826 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10827 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10837 /* Refresh bitmap kitchen sink icon for frame F
10838 when we get an expose event for it. */
10844 /* Normally, the window manager handles this function. */
10847 /* Make the x-window of frame F use the gnu icon bitmap. */
10850 x_bitmap_icon (f
, file
)
10856 if (FRAME_X_WINDOW (f
) == 0)
10859 /* Free up our existing icon bitmap if any. */
10860 if (f
->output_data
.x
->icon_bitmap
> 0)
10861 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10862 f
->output_data
.x
->icon_bitmap
= 0;
10864 if (STRINGP (file
))
10865 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10868 /* Create the GNU bitmap if necessary. */
10869 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10870 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10871 = x_create_bitmap_from_data (f
, gnu_bits
,
10872 gnu_width
, gnu_height
);
10874 /* The first time we create the GNU bitmap,
10875 this increments the ref-count one extra time.
10876 As a result, the GNU bitmap is never freed.
10877 That way, we don't have to worry about allocating it again. */
10878 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10880 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10883 x_wm_set_icon_pixmap (f
, bitmap_id
);
10884 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10890 /* Make the x-window of frame F use a rectangle with text.
10891 Use ICON_NAME as the text. */
10894 x_text_icon (f
, icon_name
)
10898 if (FRAME_X_WINDOW (f
) == 0)
10903 XTextProperty text
;
10904 text
.value
= (unsigned char *) icon_name
;
10905 text
.encoding
= XA_STRING
;
10907 text
.nitems
= strlen (icon_name
);
10908 #ifdef USE_X_TOOLKIT
10909 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10911 #else /* not USE_X_TOOLKIT */
10912 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10913 #endif /* not USE_X_TOOLKIT */
10915 #else /* not HAVE_X11R4 */
10916 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10917 #endif /* not HAVE_X11R4 */
10919 if (f
->output_data
.x
->icon_bitmap
> 0)
10920 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10921 f
->output_data
.x
->icon_bitmap
= 0;
10922 x_wm_set_icon_pixmap (f
, 0);
10927 #define X_ERROR_MESSAGE_SIZE 200
10929 /* If non-nil, this should be a string.
10930 It means catch X errors and store the error message in this string. */
10932 static Lisp_Object x_error_message_string
;
10934 /* An X error handler which stores the error message in
10935 x_error_message_string. This is called from x_error_handler if
10936 x_catch_errors is in effect. */
10939 x_error_catcher (display
, error
)
10941 XErrorEvent
*error
;
10943 XGetErrorText (display
, error
->error_code
,
10944 XSTRING (x_error_message_string
)->data
,
10945 X_ERROR_MESSAGE_SIZE
);
10948 /* Begin trapping X errors for display DPY. Actually we trap X errors
10949 for all displays, but DPY should be the display you are actually
10952 After calling this function, X protocol errors no longer cause
10953 Emacs to exit; instead, they are recorded in the string
10954 stored in x_error_message_string.
10956 Calling x_check_errors signals an Emacs error if an X error has
10957 occurred since the last call to x_catch_errors or x_check_errors.
10959 Calling x_uncatch_errors resumes the normal error handling. */
10961 void x_check_errors ();
10962 static Lisp_Object
x_catch_errors_unwind ();
10965 x_catch_errors (dpy
)
10968 int count
= specpdl_ptr
- specpdl
;
10970 /* Make sure any errors from previous requests have been dealt with. */
10971 XSync (dpy
, False
);
10973 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10975 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10976 XSTRING (x_error_message_string
)->data
[0] = 0;
10981 /* Unbind the binding that we made to check for X errors. */
10984 x_catch_errors_unwind (old_val
)
10985 Lisp_Object old_val
;
10987 x_error_message_string
= old_val
;
10991 /* If any X protocol errors have arrived since the last call to
10992 x_catch_errors or x_check_errors, signal an Emacs error using
10993 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10996 x_check_errors (dpy
, format
)
11000 /* Make sure to catch any errors incurred so far. */
11001 XSync (dpy
, False
);
11003 if (XSTRING (x_error_message_string
)->data
[0])
11004 error (format
, XSTRING (x_error_message_string
)->data
);
11007 /* Nonzero if we had any X protocol errors
11008 since we did x_catch_errors on DPY. */
11011 x_had_errors_p (dpy
)
11014 /* Make sure to catch any errors incurred so far. */
11015 XSync (dpy
, False
);
11017 return XSTRING (x_error_message_string
)->data
[0] != 0;
11020 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11023 x_clear_errors (dpy
)
11026 XSTRING (x_error_message_string
)->data
[0] = 0;
11029 /* Stop catching X protocol errors and let them make Emacs die.
11030 DPY should be the display that was passed to x_catch_errors.
11031 COUNT should be the value that was returned by
11032 the corresponding call to x_catch_errors. */
11035 x_uncatch_errors (dpy
, count
)
11039 unbind_to (count
, Qnil
);
11043 static unsigned int x_wire_count
;
11046 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11051 /* Handle SIGPIPE, which can happen when the connection to a server
11052 simply goes away. SIGPIPE is handled by x_connection_signal.
11053 Don't need to do anything, because the write which caused the
11054 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11055 which will do the appropriate cleanup for us. */
11058 x_connection_signal (signalnum
) /* If we don't have an argument, */
11059 int signalnum
; /* some compilers complain in signal calls. */
11062 /* USG systems forget handlers when they are used;
11063 must reestablish each time */
11064 signal (signalnum
, x_connection_signal
);
11068 /* Handling X errors. */
11070 /* Handle the loss of connection to display DISPLAY. */
11073 x_connection_closed (display
, error_message
)
11075 char *error_message
;
11077 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
11078 Lisp_Object frame
, tail
;
11080 /* Indicate that this display is dead. */
11082 #if 0 /* Closing the display caused a bus error on OpenWindows. */
11083 #ifdef USE_X_TOOLKIT
11084 XtCloseDisplay (display
);
11089 dpyinfo
->display
= 0;
11091 /* First delete frames whose mini-buffers are on frames
11092 that are on the dead display. */
11093 FOR_EACH_FRAME (tail
, frame
)
11095 Lisp_Object minibuf_frame
;
11097 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11098 if (FRAME_X_P (XFRAME (frame
))
11099 && FRAME_X_P (XFRAME (minibuf_frame
))
11100 && ! EQ (frame
, minibuf_frame
)
11101 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11102 Fdelete_frame (frame
, Qt
);
11105 /* Now delete all remaining frames on the dead display.
11106 We are now sure none of these is used as the mini-buffer
11107 for another frame that we need to delete. */
11108 FOR_EACH_FRAME (tail
, frame
)
11109 if (FRAME_X_P (XFRAME (frame
))
11110 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11112 /* Set this to t so that Fdelete_frame won't get confused
11113 trying to find a replacement. */
11114 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11115 Fdelete_frame (frame
, Qt
);
11119 x_delete_display (dpyinfo
);
11121 if (x_display_list
== 0)
11123 fprintf (stderr
, "%s\n", error_message
);
11124 shut_down_emacs (0, 0, Qnil
);
11128 /* Ordinary stack unwind doesn't deal with these. */
11130 sigunblock (sigmask (SIGIO
));
11132 sigunblock (sigmask (SIGALRM
));
11133 TOTALLY_UNBLOCK_INPUT
;
11135 clear_waiting_for_input ();
11136 error ("%s", error_message
);
11139 /* This is the usual handler for X protocol errors.
11140 It kills all frames on the display that we got the error for.
11141 If that was the only one, it prints an error message and kills Emacs. */
11144 x_error_quitter (display
, error
)
11146 XErrorEvent
*error
;
11148 char buf
[256], buf1
[356];
11150 /* Note that there is no real way portable across R3/R4 to get the
11151 original error handler. */
11153 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11154 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11155 buf
, error
->request_code
);
11156 x_connection_closed (display
, buf1
);
11159 /* This is the first-level handler for X protocol errors.
11160 It calls x_error_quitter or x_error_catcher. */
11163 x_error_handler (display
, error
)
11165 XErrorEvent
*error
;
11167 if (! NILP (x_error_message_string
))
11168 x_error_catcher (display
, error
);
11170 x_error_quitter (display
, error
);
11174 /* This is the handler for X IO errors, always.
11175 It kills all frames on the display that we lost touch with.
11176 If that was the only one, it prints an error message and kills Emacs. */
11179 x_io_error_quitter (display
)
11184 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11185 x_connection_closed (display
, buf
);
11189 /* Changing the font of the frame. */
11191 /* Give frame F the font named FONTNAME as its default font, and
11192 return the full name of that font. FONTNAME may be a wildcard
11193 pattern; in that case, we choose some font that fits the pattern.
11194 The return value shows which font we chose. */
11197 x_new_font (f
, fontname
)
11199 register char *fontname
;
11201 struct font_info
*fontp
11202 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11207 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11208 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11209 f
->output_data
.x
->fontset
= -1;
11211 /* Compute the scroll bar width in character columns. */
11212 if (f
->scroll_bar_pixel_width
> 0)
11214 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11215 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11219 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11220 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11223 /* Now make the frame display the given font. */
11224 if (FRAME_X_WINDOW (f
) != 0)
11226 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11227 f
->output_data
.x
->font
->fid
);
11228 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11229 f
->output_data
.x
->font
->fid
);
11230 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11231 f
->output_data
.x
->font
->fid
);
11233 frame_update_line_height (f
);
11234 x_set_window_size (f
, 0, f
->width
, f
->height
);
11237 /* If we are setting a new frame's font for the first time,
11238 there are no faces yet, so this font's height is the line height. */
11239 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11241 return build_string (fontp
->full_name
);
11244 /* Give frame F the fontset named FONTSETNAME as its default font, and
11245 return the full name of that fontset. FONTSETNAME may be a wildcard
11246 pattern; in that case, we choose some fontset that fits the pattern.
11247 The return value shows which fontset we chose. */
11250 x_new_fontset (f
, fontsetname
)
11254 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11255 Lisp_Object result
;
11260 if (f
->output_data
.x
->fontset
== fontset
)
11261 /* This fontset is already set in frame F. There's nothing more
11263 return fontset_name (fontset
);
11265 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11267 if (!STRINGP (result
))
11268 /* Can't load ASCII font. */
11271 /* Since x_new_font doesn't update any fontset information, do it now. */
11272 f
->output_data
.x
->fontset
= fontset
;
11276 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11277 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11280 return build_string (fontsetname
);
11284 /***********************************************************************
11286 ***********************************************************************/
11292 /* XIM destroy callback function, which is called whenever the
11293 connection to input method XIM dies. CLIENT_DATA contains a
11294 pointer to the x_display_info structure corresponding to XIM. */
11297 xim_destroy_callback (xim
, client_data
, call_data
)
11299 XPointer client_data
;
11300 XPointer call_data
;
11302 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11303 Lisp_Object frame
, tail
;
11307 /* No need to call XDestroyIC.. */
11308 FOR_EACH_FRAME (tail
, frame
)
11310 struct frame
*f
= XFRAME (frame
);
11311 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11313 FRAME_XIC (f
) = NULL
;
11314 if (FRAME_XIC_FONTSET (f
))
11316 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11317 FRAME_XIC_FONTSET (f
) = NULL
;
11322 /* No need to call XCloseIM. */
11323 dpyinfo
->xim
= NULL
;
11324 XFree (dpyinfo
->xim_styles
);
11328 #endif /* HAVE_X11R6 */
11330 /* Open the connection to the XIM server on display DPYINFO.
11331 RESOURCE_NAME is the resource name Emacs uses. */
11334 xim_open_dpy (dpyinfo
, resource_name
)
11335 struct x_display_info
*dpyinfo
;
11336 char *resource_name
;
11341 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11342 dpyinfo
->xim
= xim
;
11347 XIMCallback destroy
;
11350 /* Get supported styles and XIM values. */
11351 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11354 destroy
.callback
= xim_destroy_callback
;
11355 destroy
.client_data
= (XPointer
)dpyinfo
;
11356 /* This isn't prptotyped in OSF 5.0. */
11357 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11361 #else /* not USE_XIM */
11362 dpyinfo
->xim
= NULL
;
11363 #endif /* not USE_XIM */
11367 #ifdef HAVE_X11R6_XIM
11371 struct x_display_info
*dpyinfo
;
11372 char *resource_name
;
11375 /* XIM instantiate callback function, which is called whenever an XIM
11376 server is available. DISPLAY is teh display of the XIM.
11377 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11378 when the callback was registered. */
11381 xim_instantiate_callback (display
, client_data
, call_data
)
11383 XPointer client_data
;
11384 XPointer call_data
;
11386 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11387 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11389 /* We don't support multiple XIM connections. */
11393 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11395 /* Create XIC for the existing frames on the same display, as long
11396 as they have no XIC. */
11397 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11399 Lisp_Object tail
, frame
;
11402 FOR_EACH_FRAME (tail
, frame
)
11404 struct frame
*f
= XFRAME (frame
);
11406 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11407 if (FRAME_XIC (f
) == NULL
)
11409 create_frame_xic (f
);
11410 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11411 xic_set_statusarea (f
);
11412 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11414 struct window
*w
= XWINDOW (f
->selected_window
);
11415 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11424 #endif /* HAVE_X11R6_XIM */
11427 /* Open a connection to the XIM server on display DPYINFO.
11428 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11429 connection only at the first time. On X11R6, open the connection
11430 in the XIM instantiate callback function. */
11433 xim_initialize (dpyinfo
, resource_name
)
11434 struct x_display_info
*dpyinfo
;
11435 char *resource_name
;
11438 #ifdef HAVE_X11R6_XIM
11439 struct xim_inst_t
*xim_inst
;
11442 dpyinfo
->xim
= NULL
;
11443 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11444 xim_inst
->dpyinfo
= dpyinfo
;
11445 len
= strlen (resource_name
);
11446 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11447 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11448 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11449 resource_name
, EMACS_CLASS
,
11450 xim_instantiate_callback
,
11451 /* Fixme: This is XPointer in
11452 XFree86 but (XPointer *) on
11453 Tru64, at least. */
11454 (XPointer
) xim_inst
);
11455 #else /* not HAVE_X11R6_XIM */
11456 dpyinfo
->xim
= NULL
;
11457 xim_open_dpy (dpyinfo
, resource_name
);
11458 #endif /* not HAVE_X11R6_XIM */
11460 #else /* not USE_XIM */
11461 dpyinfo
->xim
= NULL
;
11462 #endif /* not USE_XIM */
11466 /* Close the connection to the XIM server on display DPYINFO. */
11469 xim_close_dpy (dpyinfo
)
11470 struct x_display_info
*dpyinfo
;
11473 #ifdef HAVE_X11R6_XIM
11474 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11476 xim_instantiate_callback
, NULL
);
11477 #endif /* not HAVE_X11R6_XIM */
11478 XCloseIM (dpyinfo
->xim
);
11479 dpyinfo
->xim
= NULL
;
11480 XFree (dpyinfo
->xim_styles
);
11481 #endif /* USE_XIM */
11484 #endif /* not HAVE_X11R6_XIM */
11488 /* Calculate the absolute position in frame F
11489 from its current recorded position values and gravity. */
11492 x_calc_absolute_position (f
)
11496 int win_x
= 0, win_y
= 0;
11497 int flags
= f
->output_data
.x
->size_hint_flags
;
11500 /* We have nothing to do if the current position
11501 is already for the top-left corner. */
11502 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11505 #ifdef USE_X_TOOLKIT
11506 this_window
= XtWindow (f
->output_data
.x
->widget
);
11508 this_window
= FRAME_X_WINDOW (f
);
11511 /* Find the position of the outside upper-left corner of
11512 the inner window, with respect to the outer window.
11513 But do this only if we will need the results. */
11514 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11519 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11522 x_clear_errors (FRAME_X_DISPLAY (f
));
11523 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11525 /* From-window, to-window. */
11527 f
->output_data
.x
->parent_desc
,
11529 /* From-position, to-position. */
11530 0, 0, &win_x
, &win_y
,
11532 /* Child of win. */
11534 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11536 Window newroot
, newparent
= 0xdeadbeef;
11537 Window
*newchildren
;
11538 unsigned int nchildren
;
11540 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11541 &newparent
, &newchildren
, &nchildren
))
11544 XFree ((char *) newchildren
);
11546 f
->output_data
.x
->parent_desc
= newparent
;
11552 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11556 /* Treat negative positions as relative to the leftmost bottommost
11557 position that fits on the screen. */
11558 if (flags
& XNegative
)
11559 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11560 - 2 * f
->output_data
.x
->border_width
- win_x
11562 + f
->output_data
.x
->left_pos
);
11564 if (flags
& YNegative
)
11566 int menubar_height
= 0;
11568 #ifdef USE_X_TOOLKIT
11569 if (f
->output_data
.x
->menubar_widget
)
11571 = (f
->output_data
.x
->menubar_widget
->core
.height
11572 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
11575 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11576 - 2 * f
->output_data
.x
->border_width
11580 + f
->output_data
.x
->top_pos
);
11583 /* The left_pos and top_pos
11584 are now relative to the top and left screen edges,
11585 so the flags should correspond. */
11586 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11589 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11590 to really change the position, and 0 when calling from
11591 x_make_frame_visible (in that case, XOFF and YOFF are the current
11592 position values). It is -1 when calling from x_set_frame_parameters,
11593 which means, do adjust for borders but don't change the gravity. */
11596 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11598 register int xoff
, yoff
;
11599 int change_gravity
;
11601 int modified_top
, modified_left
;
11603 if (change_gravity
> 0)
11605 f
->output_data
.x
->top_pos
= yoff
;
11606 f
->output_data
.x
->left_pos
= xoff
;
11607 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11609 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11611 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11612 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11614 x_calc_absolute_position (f
);
11617 x_wm_set_size_hint (f
, (long) 0, 0);
11619 modified_left
= f
->output_data
.x
->left_pos
;
11620 modified_top
= f
->output_data
.x
->top_pos
;
11621 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11622 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11623 /* It is a mystery why we need to add the border_width here
11624 when the frame is already visible, but experiment says we do. */
11625 if (change_gravity
!= 0)
11627 modified_left
+= f
->output_data
.x
->border_width
;
11628 modified_top
+= f
->output_data
.x
->border_width
;
11632 #ifdef USE_X_TOOLKIT
11633 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11634 modified_left
, modified_top
);
11635 #else /* not USE_X_TOOLKIT */
11636 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11637 modified_left
, modified_top
);
11638 #endif /* not USE_X_TOOLKIT */
11642 /* Call this to change the size of frame F's x-window.
11643 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11644 for this size change and subsequent size changes.
11645 Otherwise we leave the window gravity unchanged. */
11648 x_set_window_size (f
, change_gravity
, cols
, rows
)
11650 int change_gravity
;
11653 #ifndef USE_X_TOOLKIT
11654 int pixelwidth
, pixelheight
;
11659 #ifdef USE_X_TOOLKIT
11661 /* The x and y position of the widget is clobbered by the
11662 call to XtSetValues within EmacsFrameSetCharSize.
11663 This is a real kludge, but I don't understand Xt so I can't
11664 figure out a correct fix. Can anyone else tell me? -- rms. */
11665 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11666 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11667 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11668 f
->output_data
.x
->widget
->core
.x
= xpos
;
11669 f
->output_data
.x
->widget
->core
.y
= ypos
;
11672 #else /* not USE_X_TOOLKIT */
11674 check_frame_size (f
, &rows
, &cols
);
11675 f
->output_data
.x
->vertical_scroll_bar_extra
11676 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11678 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11679 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11680 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11681 f
->output_data
.x
->flags_areas_extra
11682 = FRAME_FLAGS_AREA_WIDTH (f
);
11683 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11684 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11686 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11687 x_wm_set_size_hint (f
, (long) 0, 0);
11689 XSync (FRAME_X_DISPLAY (f
), False
);
11690 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11691 pixelwidth
, pixelheight
);
11693 /* Now, strictly speaking, we can't be sure that this is accurate,
11694 but the window manager will get around to dealing with the size
11695 change request eventually, and we'll hear how it went when the
11696 ConfigureNotify event gets here.
11698 We could just not bother storing any of this information here,
11699 and let the ConfigureNotify event set everything up, but that
11700 might be kind of confusing to the Lisp code, since size changes
11701 wouldn't be reported in the frame parameters until some random
11702 point in the future when the ConfigureNotify event arrives.
11704 We pass 1 for DELAY since we can't run Lisp code inside of
11706 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11707 PIXEL_WIDTH (f
) = pixelwidth
;
11708 PIXEL_HEIGHT (f
) = pixelheight
;
11710 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11711 receive in the ConfigureNotify event; if we get what we asked
11712 for, then the event won't cause the screen to become garbaged, so
11713 we have to make sure to do it here. */
11714 SET_FRAME_GARBAGED (f
);
11716 XFlush (FRAME_X_DISPLAY (f
));
11718 #endif /* not USE_X_TOOLKIT */
11720 /* If cursor was outside the new size, mark it as off. */
11721 mark_window_cursors_off (XWINDOW (f
->root_window
));
11723 /* Clear out any recollection of where the mouse highlighting was,
11724 since it might be in a place that's outside the new frame size.
11725 Actually checking whether it is outside is a pain in the neck,
11726 so don't try--just let the highlighting be done afresh with new size. */
11727 cancel_mouse_face (f
);
11732 /* Mouse warping. */
11735 x_set_mouse_position (f
, x
, y
)
11741 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11742 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11744 if (pix_x
< 0) pix_x
= 0;
11745 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11747 if (pix_y
< 0) pix_y
= 0;
11748 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11752 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11753 0, 0, 0, 0, pix_x
, pix_y
);
11757 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11760 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11766 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11767 0, 0, 0, 0, pix_x
, pix_y
);
11771 /* focus shifting, raising and lowering. */
11774 x_focus_on_frame (f
)
11777 #if 0 /* This proves to be unpleasant. */
11781 /* I don't think that the ICCCM allows programs to do things like this
11782 without the interaction of the window manager. Whatever you end up
11783 doing with this code, do it to x_unfocus_frame too. */
11784 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11785 RevertToPointerRoot
, CurrentTime
);
11790 x_unfocus_frame (f
)
11794 /* Look at the remarks in x_focus_on_frame. */
11795 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11796 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11797 RevertToPointerRoot
, CurrentTime
);
11801 /* Raise frame F. */
11807 if (f
->async_visible
)
11810 #ifdef USE_X_TOOLKIT
11811 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11812 #else /* not USE_X_TOOLKIT */
11813 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11814 #endif /* not USE_X_TOOLKIT */
11815 XFlush (FRAME_X_DISPLAY (f
));
11820 /* Lower frame F. */
11826 if (f
->async_visible
)
11829 #ifdef USE_X_TOOLKIT
11830 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11831 #else /* not USE_X_TOOLKIT */
11832 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11833 #endif /* not USE_X_TOOLKIT */
11834 XFlush (FRAME_X_DISPLAY (f
));
11840 XTframe_raise_lower (f
, raise_flag
)
11850 /* Change of visibility. */
11852 /* This tries to wait until the frame is really visible.
11853 However, if the window manager asks the user where to position
11854 the frame, this will return before the user finishes doing that.
11855 The frame will not actually be visible at that time,
11856 but it will become visible later when the window manager
11857 finishes with it. */
11860 x_make_frame_visible (f
)
11864 int original_top
, original_left
;
11865 int retry_count
= 2;
11871 type
= x_icon_type (f
);
11873 x_bitmap_icon (f
, type
);
11875 if (! FRAME_VISIBLE_P (f
))
11877 /* We test FRAME_GARBAGED_P here to make sure we don't
11878 call x_set_offset a second time
11879 if we get to x_make_frame_visible a second time
11880 before the window gets really visible. */
11881 if (! FRAME_ICONIFIED_P (f
)
11882 && ! f
->output_data
.x
->asked_for_visible
)
11883 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11885 f
->output_data
.x
->asked_for_visible
= 1;
11887 if (! EQ (Vx_no_window_manager
, Qt
))
11888 x_wm_set_window_state (f
, NormalState
);
11889 #ifdef USE_X_TOOLKIT
11890 /* This was XtPopup, but that did nothing for an iconified frame. */
11891 XtMapWidget (f
->output_data
.x
->widget
);
11892 #else /* not USE_X_TOOLKIT */
11893 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11894 #endif /* not USE_X_TOOLKIT */
11895 #if 0 /* This seems to bring back scroll bars in the wrong places
11896 if the window configuration has changed. They seem
11897 to come back ok without this. */
11898 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11899 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11903 XFlush (FRAME_X_DISPLAY (f
));
11905 /* Synchronize to ensure Emacs knows the frame is visible
11906 before we do anything else. We do this loop with input not blocked
11907 so that incoming events are handled. */
11911 /* This must be before UNBLOCK_INPUT
11912 since events that arrive in response to the actions above
11913 will set it when they are handled. */
11914 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11916 original_left
= f
->output_data
.x
->left_pos
;
11917 original_top
= f
->output_data
.x
->top_pos
;
11919 /* This must come after we set COUNT. */
11922 /* We unblock here so that arriving X events are processed. */
11924 /* Now move the window back to where it was "supposed to be".
11925 But don't do it if the gravity is negative.
11926 When the gravity is negative, this uses a position
11927 that is 3 pixels too low. Perhaps that's really the border width.
11929 Don't do this if the window has never been visible before,
11930 because the window manager may choose the position
11931 and we don't want to override it. */
11933 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11934 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11935 && previously_visible
)
11939 unsigned int width
, height
, border
, depth
;
11943 /* On some window managers (such as FVWM) moving an existing
11944 window, even to the same place, causes the window manager
11945 to introduce an offset. This can cause the window to move
11946 to an unexpected location. Check the geometry (a little
11947 slow here) and then verify that the window is in the right
11948 place. If the window is not in the right place, move it
11949 there, and take the potential window manager hit. */
11950 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11951 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11953 if (original_left
!= x
|| original_top
!= y
)
11954 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11955 original_left
, original_top
);
11960 XSETFRAME (frame
, f
);
11962 /* Wait until the frame is visible. Process X events until a
11963 MapNotify event has been seen, or until we think we won't get a
11964 MapNotify at all.. */
11965 for (count
= input_signal_count
+ 10;
11966 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
11968 /* Force processing of queued events. */
11971 /* Machines that do polling rather than SIGIO have been
11972 observed to go into a busy-wait here. So we'll fake an
11973 alarm signal to let the handler know that there's something
11974 to be read. We used to raise a real alarm, but it seems
11975 that the handler isn't always enabled here. This is
11977 if (input_polling_used ())
11979 /* It could be confusing if a real alarm arrives while
11980 processing the fake one. Turn it off and let the
11981 handler reset it. */
11982 extern void poll_for_input_1
P_ ((void));
11983 int old_poll_suppress_count
= poll_suppress_count
;
11984 poll_suppress_count
= 1;
11985 poll_for_input_1 ();
11986 poll_suppress_count
= old_poll_suppress_count
;
11989 /* See if a MapNotify event has been processed. */
11990 FRAME_SAMPLE_VISIBILITY (f
);
11995 (let ((f (selected-frame)))
11999 the frame is not raised with various window managers on
12000 FreeBSD, Linux and Solaris. It turns out that, for some
12001 unknown reason, the call to XtMapWidget is completely ignored.
12002 Mapping the widget a second time works. */
12004 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
12009 /* Change from mapped state to withdrawn state. */
12011 /* Make the frame visible (mapped and not iconified). */
12014 x_make_frame_invisible (f
)
12019 #ifdef USE_X_TOOLKIT
12020 /* Use the frame's outermost window, not the one we normally draw on. */
12021 window
= XtWindow (f
->output_data
.x
->widget
);
12022 #else /* not USE_X_TOOLKIT */
12023 window
= FRAME_X_WINDOW (f
);
12024 #endif /* not USE_X_TOOLKIT */
12026 /* Don't keep the highlight on an invisible frame. */
12027 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12028 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12030 #if 0/* This might add unreliability; I don't trust it -- rms. */
12031 if (! f
->async_visible
&& ! f
->async_iconified
)
12037 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12038 that the current position of the window is user-specified, rather than
12039 program-specified, so that when the window is mapped again, it will be
12040 placed at the same location, without forcing the user to position it
12041 by hand again (they have already done that once for this window.) */
12042 x_wm_set_size_hint (f
, (long) 0, 1);
12046 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12047 DefaultScreen (FRAME_X_DISPLAY (f
))))
12049 UNBLOCK_INPUT_RESIGNAL
;
12050 error ("Can't notify window manager of window withdrawal");
12052 #else /* ! defined (HAVE_X11R4) */
12054 /* Tell the window manager what we're going to do. */
12055 if (! EQ (Vx_no_window_manager
, Qt
))
12059 unmap
.xunmap
.type
= UnmapNotify
;
12060 unmap
.xunmap
.window
= window
;
12061 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12062 unmap
.xunmap
.from_configure
= False
;
12063 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12064 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12066 SubstructureRedirectMaskSubstructureNotifyMask
,
12069 UNBLOCK_INPUT_RESIGNAL
;
12070 error ("Can't notify window manager of withdrawal");
12074 /* Unmap the window ourselves. Cheeky! */
12075 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12076 #endif /* ! defined (HAVE_X11R4) */
12078 /* We can't distinguish this from iconification
12079 just by the event that we get from the server.
12080 So we can't win using the usual strategy of letting
12081 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12082 and synchronize with the server to make sure we agree. */
12084 FRAME_ICONIFIED_P (f
) = 0;
12085 f
->async_visible
= 0;
12086 f
->async_iconified
= 0;
12093 /* Change window state from mapped to iconified. */
12096 x_iconify_frame (f
)
12102 /* Don't keep the highlight on an invisible frame. */
12103 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12104 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12106 if (f
->async_iconified
)
12111 FRAME_SAMPLE_VISIBILITY (f
);
12113 type
= x_icon_type (f
);
12115 x_bitmap_icon (f
, type
);
12117 #ifdef USE_X_TOOLKIT
12119 if (! FRAME_VISIBLE_P (f
))
12121 if (! EQ (Vx_no_window_manager
, Qt
))
12122 x_wm_set_window_state (f
, IconicState
);
12123 /* This was XtPopup, but that did nothing for an iconified frame. */
12124 XtMapWidget (f
->output_data
.x
->widget
);
12125 /* The server won't give us any event to indicate
12126 that an invisible frame was changed to an icon,
12127 so we have to record it here. */
12130 f
->async_iconified
= 1;
12131 f
->async_visible
= 0;
12136 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12137 XtWindow (f
->output_data
.x
->widget
),
12138 DefaultScreen (FRAME_X_DISPLAY (f
)));
12142 error ("Can't notify window manager of iconification");
12144 f
->async_iconified
= 1;
12145 f
->async_visible
= 0;
12149 XFlush (FRAME_X_DISPLAY (f
));
12151 #else /* not USE_X_TOOLKIT */
12153 /* Make sure the X server knows where the window should be positioned,
12154 in case the user deiconifies with the window manager. */
12155 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12156 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12158 /* Since we don't know which revision of X we're running, we'll use both
12159 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12161 /* X11R4: send a ClientMessage to the window manager using the
12162 WM_CHANGE_STATE type. */
12166 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12167 message
.xclient
.type
= ClientMessage
;
12168 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12169 message
.xclient
.format
= 32;
12170 message
.xclient
.data
.l
[0] = IconicState
;
12172 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12173 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12175 SubstructureRedirectMask
| SubstructureNotifyMask
,
12178 UNBLOCK_INPUT_RESIGNAL
;
12179 error ("Can't notify window manager of iconification");
12183 /* X11R3: set the initial_state field of the window manager hints to
12185 x_wm_set_window_state (f
, IconicState
);
12187 if (!FRAME_VISIBLE_P (f
))
12189 /* If the frame was withdrawn, before, we must map it. */
12190 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12193 f
->async_iconified
= 1;
12194 f
->async_visible
= 0;
12196 XFlush (FRAME_X_DISPLAY (f
));
12198 #endif /* not USE_X_TOOLKIT */
12201 /* Destroy the X window of frame F. */
12204 x_destroy_window (f
)
12207 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12211 /* If a display connection is dead, don't try sending more
12212 commands to the X server. */
12213 if (dpyinfo
->display
!= 0)
12215 if (f
->output_data
.x
->icon_desc
!= 0)
12216 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12219 free_frame_xic (f
);
12221 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
12222 #ifdef USE_X_TOOLKIT
12223 if (f
->output_data
.x
->widget
)
12224 XtDestroyWidget (f
->output_data
.x
->widget
);
12225 free_frame_menubar (f
);
12226 #endif /* USE_X_TOOLKIT */
12228 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12229 unload_color (f
, f
->output_data
.x
->background_pixel
);
12230 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12231 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12232 unload_color (f
, f
->output_data
.x
->border_pixel
);
12233 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12234 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12235 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12236 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12237 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12238 if (f
->output_data
.x
->white_relief
.allocated_p
)
12239 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12240 if (f
->output_data
.x
->black_relief
.allocated_p
)
12241 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12243 free_frame_faces (f
);
12244 XFlush (FRAME_X_DISPLAY (f
));
12247 if (f
->output_data
.x
->saved_menu_event
)
12248 xfree (f
->output_data
.x
->saved_menu_event
);
12250 xfree (f
->output_data
.x
);
12251 f
->output_data
.x
= 0;
12252 if (f
== dpyinfo
->x_focus_frame
)
12253 dpyinfo
->x_focus_frame
= 0;
12254 if (f
== dpyinfo
->x_focus_event_frame
)
12255 dpyinfo
->x_focus_event_frame
= 0;
12256 if (f
== dpyinfo
->x_highlight_frame
)
12257 dpyinfo
->x_highlight_frame
= 0;
12259 dpyinfo
->reference_count
--;
12261 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12263 dpyinfo
->mouse_face_beg_row
12264 = dpyinfo
->mouse_face_beg_col
= -1;
12265 dpyinfo
->mouse_face_end_row
12266 = dpyinfo
->mouse_face_end_col
= -1;
12267 dpyinfo
->mouse_face_window
= Qnil
;
12268 dpyinfo
->mouse_face_deferred_gc
= 0;
12269 dpyinfo
->mouse_face_mouse_frame
= 0;
12275 /* Setting window manager hints. */
12277 /* Set the normal size hints for the window manager, for frame F.
12278 FLAGS is the flags word to use--or 0 meaning preserve the flags
12279 that the window now has.
12280 If USER_POSITION is nonzero, we set the USPosition
12281 flag (this is useful when FLAGS is 0). */
12284 x_wm_set_size_hint (f
, flags
, user_position
)
12289 XSizeHints size_hints
;
12291 #ifdef USE_X_TOOLKIT
12294 Dimension widget_width
, widget_height
;
12295 Window window
= XtWindow (f
->output_data
.x
->widget
);
12296 #else /* not USE_X_TOOLKIT */
12297 Window window
= FRAME_X_WINDOW (f
);
12298 #endif /* not USE_X_TOOLKIT */
12300 /* Setting PMaxSize caused various problems. */
12301 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12303 size_hints
.x
= f
->output_data
.x
->left_pos
;
12304 size_hints
.y
= f
->output_data
.x
->top_pos
;
12306 #ifdef USE_X_TOOLKIT
12307 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12308 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12309 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12310 size_hints
.height
= widget_height
;
12311 size_hints
.width
= widget_width
;
12312 #else /* not USE_X_TOOLKIT */
12313 size_hints
.height
= PIXEL_HEIGHT (f
);
12314 size_hints
.width
= PIXEL_WIDTH (f
);
12315 #endif /* not USE_X_TOOLKIT */
12317 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12318 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12319 size_hints
.max_width
12320 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12321 size_hints
.max_height
12322 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12324 /* Calculate the base and minimum sizes.
12326 (When we use the X toolkit, we don't do it here.
12327 Instead we copy the values that the widgets are using, below.) */
12328 #ifndef USE_X_TOOLKIT
12330 int base_width
, base_height
;
12331 int min_rows
= 0, min_cols
= 0;
12333 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12334 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12336 check_frame_size (f
, &min_rows
, &min_cols
);
12338 /* The window manager uses the base width hints to calculate the
12339 current number of rows and columns in the frame while
12340 resizing; min_width and min_height aren't useful for this
12341 purpose, since they might not give the dimensions for a
12342 zero-row, zero-column frame.
12344 We use the base_width and base_height members if we have
12345 them; otherwise, we set the min_width and min_height members
12346 to the size for a zero x zero frame. */
12349 size_hints
.flags
|= PBaseSize
;
12350 size_hints
.base_width
= base_width
;
12351 size_hints
.base_height
= base_height
;
12352 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12353 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12355 size_hints
.min_width
= base_width
;
12356 size_hints
.min_height
= base_height
;
12360 /* If we don't need the old flags, we don't need the old hint at all. */
12363 size_hints
.flags
|= flags
;
12366 #endif /* not USE_X_TOOLKIT */
12369 XSizeHints hints
; /* Sometimes I hate X Windows... */
12370 long supplied_return
;
12374 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12377 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12380 #ifdef USE_X_TOOLKIT
12381 size_hints
.base_height
= hints
.base_height
;
12382 size_hints
.base_width
= hints
.base_width
;
12383 size_hints
.min_height
= hints
.min_height
;
12384 size_hints
.min_width
= hints
.min_width
;
12388 size_hints
.flags
|= flags
;
12393 if (hints
.flags
& PSize
)
12394 size_hints
.flags
|= PSize
;
12395 if (hints
.flags
& PPosition
)
12396 size_hints
.flags
|= PPosition
;
12397 if (hints
.flags
& USPosition
)
12398 size_hints
.flags
|= USPosition
;
12399 if (hints
.flags
& USSize
)
12400 size_hints
.flags
|= USSize
;
12404 #ifndef USE_X_TOOLKIT
12409 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12410 size_hints
.flags
|= PWinGravity
;
12414 size_hints
.flags
&= ~ PPosition
;
12415 size_hints
.flags
|= USPosition
;
12417 #endif /* PWinGravity */
12420 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12422 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12426 /* Used for IconicState or NormalState */
12429 x_wm_set_window_state (f
, state
)
12433 #ifdef USE_X_TOOLKIT
12436 XtSetArg (al
[0], XtNinitialState
, state
);
12437 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12438 #else /* not USE_X_TOOLKIT */
12439 Window window
= FRAME_X_WINDOW (f
);
12441 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12442 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12444 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12445 #endif /* not USE_X_TOOLKIT */
12449 x_wm_set_icon_pixmap (f
, pixmap_id
)
12453 Pixmap icon_pixmap
;
12455 #ifndef USE_X_TOOLKIT
12456 Window window
= FRAME_X_WINDOW (f
);
12461 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12462 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12466 /* It seems there is no way to turn off use of an icon pixmap.
12467 The following line does it, only if no icon has yet been created,
12468 for some window managers. But with mwm it crashes.
12469 Some people say it should clear the IconPixmapHint bit in this case,
12470 but that doesn't work, and the X consortium said it isn't the
12471 right thing at all. Since there is no way to win,
12472 best to explicitly give up. */
12474 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12480 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12484 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12485 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12488 #else /* not USE_X_TOOLKIT */
12490 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12491 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12493 #endif /* not USE_X_TOOLKIT */
12497 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12499 int icon_x
, icon_y
;
12501 #ifdef USE_X_TOOLKIT
12502 Window window
= XtWindow (f
->output_data
.x
->widget
);
12504 Window window
= FRAME_X_WINDOW (f
);
12507 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12508 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12509 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12511 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12515 /***********************************************************************
12517 ***********************************************************************/
12519 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12522 x_get_font_info (f
, font_idx
)
12526 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12530 /* Return a list of names of available fonts matching PATTERN on frame
12531 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
12532 to be listed. Frame F NULL means we have not yet created any
12533 frame on X, and consult the first display in x_display_list.
12534 MAXNAMES sets a limit on how many fonts to match. */
12537 x_list_fonts (f
, pattern
, size
, maxnames
)
12539 Lisp_Object pattern
;
12543 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12544 Lisp_Object tem
, second_best
;
12545 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
12546 int try_XLoadQueryFont
= 0;
12549 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12550 if (NILP (patterns
))
12551 patterns
= Fcons (pattern
, Qnil
);
12553 if (maxnames
== 1 && !size
)
12554 /* We can return any single font matching PATTERN. */
12555 try_XLoadQueryFont
= 1;
12557 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12560 char **names
= NULL
;
12562 pattern
= XCAR (patterns
);
12563 /* See if we cached the result for this particular query.
12564 The cache is an alist of the form:
12565 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
12567 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
12568 key
= Fcons (pattern
, make_number (maxnames
)),
12569 !NILP (list
= Fassoc (key
, tem
))))
12571 list
= Fcdr_safe (list
);
12572 /* We have a cashed list. Don't have to get the list again. */
12576 /* At first, put PATTERN in the cache. */
12579 count
= x_catch_errors (dpy
);
12581 if (try_XLoadQueryFont
)
12584 unsigned long value
;
12586 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12587 if (x_had_errors_p (dpy
))
12589 /* This error is perhaps due to insufficient memory on X
12590 server. Let's just ignore it. */
12592 x_clear_errors (dpy
);
12596 && XGetFontProperty (font
, XA_FONT
, &value
))
12598 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12599 int len
= strlen (name
);
12602 /* If DXPC (a Differential X Protocol Compressor)
12603 Ver.3.7 is running, XGetAtomName will return null
12604 string. We must avoid such a name. */
12606 try_XLoadQueryFont
= 0;
12610 names
= (char **) alloca (sizeof (char *));
12611 /* Some systems only allow alloca assigned to a
12613 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12614 bcopy (name
, names
[0], len
+ 1);
12619 try_XLoadQueryFont
= 0;
12622 XFreeFont (dpy
, font
);
12625 if (!try_XLoadQueryFont
)
12627 /* We try at least 10 fonts because XListFonts will return
12628 auto-scaled fonts at the head. */
12629 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12631 if (x_had_errors_p (dpy
))
12633 /* This error is perhaps due to insufficient memory on X
12634 server. Let's just ignore it. */
12636 x_clear_errors (dpy
);
12640 x_uncatch_errors (dpy
, count
);
12647 /* Make a list of all the fonts we got back.
12648 Store that in the font cache for the display. */
12649 for (i
= 0; i
< num_fonts
; i
++)
12652 char *p
= names
[i
];
12653 int average_width
= -1, dashes
= 0;
12655 /* Count the number of dashes in NAMES[I]. If there are
12656 14 dashes, and the field value following 12th dash
12657 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12658 is usually too ugly to be used for editing. Let's
12664 if (dashes
== 7) /* PIXEL_SIZE field */
12666 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12667 average_width
= atoi (p
);
12669 if (dashes
< 14 || average_width
!= 0)
12671 tem
= build_string (names
[i
]);
12672 if (NILP (Fassoc (tem
, list
)))
12674 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12675 && ((fast_c_string_match_ignore_case
12676 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12678 /* We can set the value of PIXEL_SIZE to the
12679 width of this font. */
12680 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12682 /* For the moment, width is not known. */
12683 list
= Fcons (Fcons (tem
, Qnil
), list
);
12687 if (!try_XLoadQueryFont
)
12688 XFreeFontNames (names
);
12691 /* Now store the result in the cache. */
12693 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
12694 = Fcons (Fcons (key
, list
),
12695 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
12698 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12700 newlist
= second_best
= Qnil
;
12701 /* Make a list of the fonts that have the right width. */
12702 for (; CONSP (list
); list
= XCDR (list
))
12708 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12712 newlist
= Fcons (XCAR (tem
), newlist
);
12716 if (!INTEGERP (XCDR (tem
)))
12718 /* Since we have not yet known the size of this font, we
12719 must try slow function call XLoadQueryFont. */
12720 XFontStruct
*thisinfo
;
12723 count
= x_catch_errors (dpy
);
12724 thisinfo
= XLoadQueryFont (dpy
,
12725 XSTRING (XCAR (tem
))->data
);
12726 if (x_had_errors_p (dpy
))
12728 /* This error is perhaps due to insufficient memory on X
12729 server. Let's just ignore it. */
12731 x_clear_errors (dpy
);
12733 x_uncatch_errors (dpy
, count
);
12739 = (thisinfo
->min_bounds
.width
== 0
12741 : make_number (thisinfo
->max_bounds
.width
));
12742 XFreeFont (dpy
, thisinfo
);
12745 /* For unknown reason, the previous call of XListFont had
12746 returned a font which can't be opened. Record the size
12747 as 0 not to try to open it again. */
12748 XCDR (tem
) = make_number (0);
12751 found_size
= XINT (XCDR (tem
));
12752 if (found_size
== size
)
12753 newlist
= Fcons (XCAR (tem
), newlist
);
12754 else if (found_size
> 0)
12756 if (NILP (second_best
))
12758 else if (found_size
< size
)
12760 if (XINT (XCDR (second_best
)) > size
12761 || XINT (XCDR (second_best
)) < found_size
)
12766 if (XINT (XCDR (second_best
)) > size
12767 && XINT (XCDR (second_best
)) > found_size
)
12772 if (!NILP (newlist
))
12774 else if (!NILP (second_best
))
12776 newlist
= Fcons (XCAR (second_best
), Qnil
);
12787 /* Check that FONT is valid on frame F. It is if it can be found in F's
12791 x_check_font (f
, font
)
12796 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12798 xassert (font
!= NULL
);
12800 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12801 if (dpyinfo
->font_table
[i
].name
12802 && font
== dpyinfo
->font_table
[i
].font
)
12805 xassert (i
< dpyinfo
->n_fonts
);
12808 #endif /* GLYPH_DEBUG != 0 */
12810 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12811 Note: There are (broken) X fonts out there with invalid XFontStruct
12812 min_bounds contents. For example, handa@etl.go.jp reports that
12813 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
12814 have font->min_bounds.width == 0. */
12817 x_font_min_bounds (font
, w
, h
)
12821 *h
= FONT_HEIGHT (font
);
12822 *w
= font
->min_bounds
.width
;
12824 /* Try to handle the case where FONT->min_bounds has invalid
12825 contents. Since the only font known to have invalid min_bounds
12826 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12828 *w
= font
->max_bounds
.width
;
12832 /* Compute the smallest character width and smallest font height over
12833 all fonts available on frame F. Set the members smallest_char_width
12834 and smallest_font_height in F's x_display_info structure to
12835 the values computed. Value is non-zero if smallest_font_height or
12836 smallest_char_width become smaller than they were before. */
12839 x_compute_min_glyph_bounds (f
)
12843 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12845 int old_width
= dpyinfo
->smallest_char_width
;
12846 int old_height
= dpyinfo
->smallest_font_height
;
12848 dpyinfo
->smallest_font_height
= 100000;
12849 dpyinfo
->smallest_char_width
= 100000;
12851 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12852 if (dpyinfo
->font_table
[i
].name
)
12854 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12857 font
= (XFontStruct
*) fontp
->font
;
12858 xassert (font
!= (XFontStruct
*) ~0);
12859 x_font_min_bounds (font
, &w
, &h
);
12861 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12862 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12865 xassert (dpyinfo
->smallest_char_width
> 0
12866 && dpyinfo
->smallest_font_height
> 0);
12868 return (dpyinfo
->n_fonts
== 1
12869 || dpyinfo
->smallest_char_width
< old_width
12870 || dpyinfo
->smallest_font_height
< old_height
);
12874 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12875 pointer to the structure font_info while allocating it dynamically.
12876 If SIZE is 0, load any size of font.
12877 If loading is failed, return NULL. */
12880 x_load_font (f
, fontname
, size
)
12882 register char *fontname
;
12885 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12886 Lisp_Object font_names
;
12889 /* Get a list of all the fonts that match this name. Once we
12890 have a list of matching fonts, we compare them against the fonts
12891 we already have by comparing names. */
12892 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12894 if (!NILP (font_names
))
12899 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12900 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12901 if (dpyinfo
->font_table
[i
].name
12902 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12903 XSTRING (XCAR (tail
))->data
)
12904 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12905 XSTRING (XCAR (tail
))->data
)))
12906 return (dpyinfo
->font_table
+ i
);
12909 /* Load the font and add it to the table. */
12913 struct font_info
*fontp
;
12914 unsigned long value
;
12917 /* If we have found fonts by x_list_font, load one of them. If
12918 not, we still try to load a font by the name given as FONTNAME
12919 because XListFonts (called in x_list_font) of some X server has
12920 a bug of not finding a font even if the font surely exists and
12921 is loadable by XLoadQueryFont. */
12922 if (size
> 0 && !NILP (font_names
))
12923 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12926 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12927 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12928 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12930 /* This error is perhaps due to insufficient memory on X
12931 server. Let's just ignore it. */
12933 x_clear_errors (FRAME_X_DISPLAY (f
));
12935 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12940 /* Find a free slot in the font table. */
12941 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12942 if (dpyinfo
->font_table
[i
].name
== NULL
)
12945 /* If no free slot found, maybe enlarge the font table. */
12946 if (i
== dpyinfo
->n_fonts
12947 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12950 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12951 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12952 dpyinfo
->font_table
12953 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12956 fontp
= dpyinfo
->font_table
+ i
;
12957 if (i
== dpyinfo
->n_fonts
)
12958 ++dpyinfo
->n_fonts
;
12960 /* Now fill in the slots of *FONTP. */
12962 fontp
->font
= font
;
12963 fontp
->font_idx
= i
;
12964 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12965 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12967 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12969 if (XGetFontProperty (font
, XA_FONT
, &value
))
12971 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12975 /* Count the number of dashes in the "full name".
12976 If it is too few, this isn't really the font's full name,
12978 In X11R4, the fonts did not come with their canonical names
12989 full_name
= (char *) xmalloc (p
- name
+ 1);
12990 bcopy (name
, full_name
, p
- name
+ 1);
12996 if (full_name
!= 0)
12997 fontp
->full_name
= full_name
;
12999 fontp
->full_name
= fontp
->name
;
13001 fontp
->size
= font
->max_bounds
.width
;
13002 fontp
->height
= FONT_HEIGHT (font
);
13004 /* For some font, ascent and descent in max_bounds field is
13005 larger than the above value. */
13006 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
13007 if (max_height
> fontp
->height
)
13008 fontp
->height
= max_height
;
13011 if (NILP (font_names
))
13013 /* We come here because of a bug of XListFonts mentioned at
13014 the head of this block. Let's store this information in
13015 the cache for x_list_fonts. */
13016 Lisp_Object lispy_name
= build_string (fontname
);
13017 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13019 XCDR (dpyinfo
->name_list_element
)
13020 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
13021 Fcons (Fcons (lispy_full_name
,
13022 make_number (fontp
->size
)),
13024 XCDR (dpyinfo
->name_list_element
));
13026 XCDR (dpyinfo
->name_list_element
)
13027 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
13028 Fcons (Fcons (lispy_full_name
,
13029 make_number (fontp
->size
)),
13031 XCDR (dpyinfo
->name_list_element
));
13034 /* The slot `encoding' specifies how to map a character
13035 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13036 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13037 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13038 2:0xA020..0xFF7F). For the moment, we don't know which charset
13039 uses this font. So, we set information in fontp->encoding[1]
13040 which is never used by any charset. If mapping can't be
13041 decided, set FONT_ENCODING_NOT_DECIDED. */
13043 = (font
->max_byte1
== 0
13045 ? (font
->min_char_or_byte2
< 0x80
13046 ? (font
->max_char_or_byte2
< 0x80
13047 ? 0 /* 0x20..0x7F */
13048 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13049 : 1) /* 0xA0..0xFF */
13051 : (font
->min_byte1
< 0x80
13052 ? (font
->max_byte1
< 0x80
13053 ? (font
->min_char_or_byte2
< 0x80
13054 ? (font
->max_char_or_byte2
< 0x80
13055 ? 0 /* 0x2020..0x7F7F */
13056 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13057 : 3) /* 0x20A0..0x7FFF */
13058 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13059 : (font
->min_char_or_byte2
< 0x80
13060 ? (font
->max_char_or_byte2
< 0x80
13061 ? 2 /* 0xA020..0xFF7F */
13062 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13063 : 1))); /* 0xA0A0..0xFFFF */
13065 fontp
->baseline_offset
13066 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13067 ? (long) value
: 0);
13068 fontp
->relative_compose
13069 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13070 ? (long) value
: 0);
13071 fontp
->default_ascent
13072 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13073 ? (long) value
: 0);
13075 /* Set global flag fonts_changed_p to non-zero if the font loaded
13076 has a character with a smaller width than any other character
13077 before, or if the font loaded has a smalle>r height than any
13078 other font loaded before. If this happens, it will make a
13079 glyph matrix reallocation necessary. */
13080 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13087 /* Return a pointer to struct font_info of a font named FONTNAME for
13088 frame F. If no such font is loaded, return NULL. */
13091 x_query_font (f
, fontname
)
13093 register char *fontname
;
13095 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13098 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13099 if (dpyinfo
->font_table
[i
].name
13100 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13101 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13102 return (dpyinfo
->font_table
+ i
);
13107 /* Find a CCL program for a font specified by FONTP, and set the member
13108 `encoder' of the structure. */
13111 x_find_ccl_program (fontp
)
13112 struct font_info
*fontp
;
13114 Lisp_Object list
, elt
;
13117 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13121 && STRINGP (XCAR (elt
))
13122 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13129 struct ccl_program
*ccl
13130 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13132 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13135 fontp
->font_encoder
= ccl
;
13141 /***********************************************************************
13143 ***********************************************************************/
13145 #ifdef USE_X_TOOLKIT
13146 static XrmOptionDescRec emacs_options
[] = {
13147 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13148 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13150 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13151 XrmoptionSepArg
, NULL
},
13152 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13154 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13155 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13156 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13157 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13158 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13159 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13160 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13162 #endif /* USE_X_TOOLKIT */
13164 static int x_initialized
;
13166 #ifdef MULTI_KBOARD
13167 /* Test whether two display-name strings agree up to the dot that separates
13168 the screen number from the server number. */
13170 same_x_server (name1
, name2
)
13171 char *name1
, *name2
;
13173 int seen_colon
= 0;
13174 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13175 int system_name_length
= strlen (system_name
);
13176 int length_until_period
= 0;
13178 while (system_name
[length_until_period
] != 0
13179 && system_name
[length_until_period
] != '.')
13180 length_until_period
++;
13182 /* Treat `unix' like an empty host name. */
13183 if (! strncmp (name1
, "unix:", 5))
13185 if (! strncmp (name2
, "unix:", 5))
13187 /* Treat this host's name like an empty host name. */
13188 if (! strncmp (name1
, system_name
, system_name_length
)
13189 && name1
[system_name_length
] == ':')
13190 name1
+= system_name_length
;
13191 if (! strncmp (name2
, system_name
, system_name_length
)
13192 && name2
[system_name_length
] == ':')
13193 name2
+= system_name_length
;
13194 /* Treat this host's domainless name like an empty host name. */
13195 if (! strncmp (name1
, system_name
, length_until_period
)
13196 && name1
[length_until_period
] == ':')
13197 name1
+= length_until_period
;
13198 if (! strncmp (name2
, system_name
, length_until_period
)
13199 && name2
[length_until_period
] == ':')
13200 name2
+= length_until_period
;
13202 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13206 if (seen_colon
&& *name1
== '.')
13210 && (*name1
== '.' || *name1
== '\0')
13211 && (*name2
== '.' || *name2
== '\0'));
13215 struct x_display_info
*
13216 x_term_init (display_name
, xrm_option
, resource_name
)
13217 Lisp_Object display_name
;
13219 char *resource_name
;
13223 struct x_display_info
*dpyinfo
;
13228 if (!x_initialized
)
13234 #ifdef USE_X_TOOLKIT
13235 /* weiner@footloose.sps.mot.com reports that this causes
13237 X protocol error: BadAtom (invalid Atom parameter)
13238 on protocol request 18skiloaf.
13239 So let's not use it until R6. */
13240 #ifdef HAVE_X11XTR6
13241 XtSetLanguageProc (NULL
, NULL
, NULL
);
13252 argv
[argc
++] = "-xrm";
13253 argv
[argc
++] = xrm_option
;
13255 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13256 resource_name
, EMACS_CLASS
,
13257 emacs_options
, XtNumber (emacs_options
),
13260 #ifdef HAVE_X11XTR6
13261 /* I think this is to compensate for XtSetLanguageProc. */
13266 #else /* not USE_X_TOOLKIT */
13268 XSetLocaleModifiers ("");
13270 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13271 #endif /* not USE_X_TOOLKIT */
13273 /* Detect failure. */
13280 /* We have definitely succeeded. Record the new connection. */
13282 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13284 #ifdef MULTI_KBOARD
13286 struct x_display_info
*share
;
13289 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13290 share
= share
->next
, tail
= XCDR (tail
))
13291 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13292 XSTRING (display_name
)->data
))
13295 dpyinfo
->kboard
= share
->kboard
;
13298 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13299 init_kboard (dpyinfo
->kboard
);
13300 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13302 char *vendor
= ServerVendor (dpy
);
13304 dpyinfo
->kboard
->Vsystem_key_alist
13305 = call1 (Qvendor_specific_keysyms
,
13306 build_string (vendor
? vendor
: ""));
13310 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13311 all_kboards
= dpyinfo
->kboard
;
13312 /* Don't let the initial kboard remain current longer than necessary.
13313 That would cause problems if a file loaded on startup tries to
13314 prompt in the mini-buffer. */
13315 if (current_kboard
== initial_kboard
)
13316 current_kboard
= dpyinfo
->kboard
;
13318 dpyinfo
->kboard
->reference_count
++;
13322 /* Put this display on the chain. */
13323 dpyinfo
->next
= x_display_list
;
13324 x_display_list
= dpyinfo
;
13326 /* Put it on x_display_name_list as well, to keep them parallel. */
13327 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13328 x_display_name_list
);
13329 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13331 dpyinfo
->display
= dpy
;
13334 XSetAfterFunction (x_current_display
, x_trace_wire
);
13338 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13339 + STRING_BYTES (XSTRING (Vsystem_name
))
13341 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13342 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13344 /* Figure out which modifier bits mean what. */
13345 x_find_modifier_meanings (dpyinfo
);
13347 /* Get the scroll bar cursor. */
13348 dpyinfo
->vertical_scroll_bar_cursor
13349 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13351 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13352 resource_name
, EMACS_CLASS
);
13353 #ifdef HAVE_XRMSETDATABASE
13354 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13356 dpyinfo
->display
->db
= xrdb
;
13358 /* Put the rdb where we can find it in a way that works on
13360 dpyinfo
->xrdb
= xrdb
;
13362 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13363 DefaultScreen (dpyinfo
->display
));
13364 select_visual (dpyinfo
);
13365 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13366 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13367 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13368 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13369 dpyinfo
->grabbed
= 0;
13370 dpyinfo
->reference_count
= 0;
13371 dpyinfo
->icon_bitmap_id
= -1;
13372 dpyinfo
->font_table
= NULL
;
13373 dpyinfo
->n_fonts
= 0;
13374 dpyinfo
->font_table_size
= 0;
13375 dpyinfo
->bitmaps
= 0;
13376 dpyinfo
->bitmaps_size
= 0;
13377 dpyinfo
->bitmaps_last
= 0;
13378 dpyinfo
->scratch_cursor_gc
= 0;
13379 dpyinfo
->mouse_face_mouse_frame
= 0;
13380 dpyinfo
->mouse_face_deferred_gc
= 0;
13381 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13382 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13383 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13384 dpyinfo
->mouse_face_window
= Qnil
;
13385 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13386 dpyinfo
->mouse_face_defer
= 0;
13387 dpyinfo
->x_focus_frame
= 0;
13388 dpyinfo
->x_focus_event_frame
= 0;
13389 dpyinfo
->x_highlight_frame
= 0;
13390 dpyinfo
->image_cache
= make_image_cache ();
13392 /* See if a private colormap is requested. */
13393 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13395 if (dpyinfo
->visual
->class == PseudoColor
)
13398 value
= display_x_get_resource (dpyinfo
,
13399 build_string ("privateColormap"),
13400 build_string ("PrivateColormap"),
13402 if (STRINGP (value
)
13403 && (!strcmp (XSTRING (value
)->data
, "true")
13404 || !strcmp (XSTRING (value
)->data
, "on")))
13405 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13409 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13410 dpyinfo
->visual
, AllocNone
);
13413 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13414 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13415 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13416 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13417 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13418 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13419 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13422 dpyinfo
->Xatom_wm_protocols
13423 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13424 dpyinfo
->Xatom_wm_take_focus
13425 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13426 dpyinfo
->Xatom_wm_save_yourself
13427 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13428 dpyinfo
->Xatom_wm_delete_window
13429 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13430 dpyinfo
->Xatom_wm_change_state
13431 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13432 dpyinfo
->Xatom_wm_configure_denied
13433 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13434 dpyinfo
->Xatom_wm_window_moved
13435 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13436 dpyinfo
->Xatom_editres
13437 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13438 dpyinfo
->Xatom_CLIPBOARD
13439 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13440 dpyinfo
->Xatom_TIMESTAMP
13441 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13442 dpyinfo
->Xatom_TEXT
13443 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13444 dpyinfo
->Xatom_COMPOUND_TEXT
13445 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13446 dpyinfo
->Xatom_DELETE
13447 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13448 dpyinfo
->Xatom_MULTIPLE
13449 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13450 dpyinfo
->Xatom_INCR
13451 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13452 dpyinfo
->Xatom_EMACS_TMP
13453 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13454 dpyinfo
->Xatom_TARGETS
13455 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13456 dpyinfo
->Xatom_NULL
13457 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13458 dpyinfo
->Xatom_ATOM_PAIR
13459 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13460 /* For properties of font. */
13461 dpyinfo
->Xatom_PIXEL_SIZE
13462 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13463 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13464 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13465 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13466 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13467 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13468 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13470 /* Ghostscript support. */
13471 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13472 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13474 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13477 dpyinfo
->cut_buffers_initialized
= 0;
13479 connection
= ConnectionNumber (dpyinfo
->display
);
13480 dpyinfo
->connection
= connection
;
13485 null_bits
[0] = 0x00;
13487 dpyinfo
->null_pixel
13488 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13489 null_bits
, 1, 1, (long) 0, (long) 0,
13494 extern int gray_bitmap_width
, gray_bitmap_height
;
13495 extern unsigned char *gray_bitmap_bits
;
13497 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13499 gray_bitmap_width
, gray_bitmap_height
,
13500 (unsigned long) 1, (unsigned long) 0, 1);
13504 xim_initialize (dpyinfo
, resource_name
);
13507 #ifdef subprocesses
13508 /* This is only needed for distinguishing keyboard and process input. */
13509 if (connection
!= 0)
13510 add_keyboard_wait_descriptor (connection
);
13513 #ifndef F_SETOWN_BUG
13515 #ifdef F_SETOWN_SOCK_NEG
13516 /* stdin is a socket here */
13517 fcntl (connection
, F_SETOWN
, -getpid ());
13518 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13519 fcntl (connection
, F_SETOWN
, getpid ());
13520 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13521 #endif /* ! defined (F_SETOWN) */
13522 #endif /* F_SETOWN_BUG */
13525 if (interrupt_input
)
13526 init_sigio (connection
);
13527 #endif /* ! defined (SIGIO) */
13530 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13531 /* Make sure that we have a valid font for dialog boxes
13532 so that Xt does not crash. */
13534 Display
*dpy
= dpyinfo
->display
;
13535 XrmValue d
, fr
, to
;
13539 d
.addr
= (XPointer
)&dpy
;
13540 d
.size
= sizeof (Display
*);
13541 fr
.addr
= XtDefaultFont
;
13542 fr
.size
= sizeof (XtDefaultFont
);
13543 to
.size
= sizeof (Font
*);
13544 to
.addr
= (XPointer
)&font
;
13545 count
= x_catch_errors (dpy
);
13546 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13548 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13549 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13550 x_uncatch_errors (dpy
, count
);
13555 /* See if we should run in synchronous mode. This is useful
13556 for debugging X code. */
13559 value
= display_x_get_resource (dpyinfo
,
13560 build_string ("synchronous"),
13561 build_string ("Synchronous"),
13563 if (STRINGP (value
)
13564 && (!strcmp (XSTRING (value
)->data
, "true")
13565 || !strcmp (XSTRING (value
)->data
, "on")))
13566 XSynchronize (dpyinfo
->display
, True
);
13574 /* Get rid of display DPYINFO, assuming all frames are already gone,
13575 and without sending any more commands to the X server. */
13578 x_delete_display (dpyinfo
)
13579 struct x_display_info
*dpyinfo
;
13581 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13583 /* Discard this display from x_display_name_list and x_display_list.
13584 We can't use Fdelq because that can quit. */
13585 if (! NILP (x_display_name_list
)
13586 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13587 x_display_name_list
= XCDR (x_display_name_list
);
13592 tail
= x_display_name_list
;
13593 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13595 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13597 XCDR (tail
) = XCDR (XCDR (tail
));
13600 tail
= XCDR (tail
);
13604 if (next_noop_dpyinfo
== dpyinfo
)
13605 next_noop_dpyinfo
= dpyinfo
->next
;
13607 if (x_display_list
== dpyinfo
)
13608 x_display_list
= dpyinfo
->next
;
13611 struct x_display_info
*tail
;
13613 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13614 if (tail
->next
== dpyinfo
)
13615 tail
->next
= tail
->next
->next
;
13618 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13619 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13620 XrmDestroyDatabase (dpyinfo
->xrdb
);
13623 #ifdef MULTI_KBOARD
13624 if (--dpyinfo
->kboard
->reference_count
== 0)
13625 delete_kboard (dpyinfo
->kboard
);
13629 xim_close_dpy (dpyinfo
);
13632 xfree (dpyinfo
->font_table
);
13633 xfree (dpyinfo
->x_id_name
);
13637 /* Set up use of X before we make the first connection. */
13639 static struct redisplay_interface x_redisplay_interface
=
13644 x_clear_end_of_line
,
13646 x_after_update_window_line
,
13647 x_update_window_begin
,
13648 x_update_window_end
,
13651 x_clear_mouse_face
,
13652 x_get_glyph_overhangs
,
13653 x_fix_overlapping_area
13659 rif
= &x_redisplay_interface
;
13661 clear_frame_hook
= x_clear_frame
;
13662 ins_del_lines_hook
= x_ins_del_lines
;
13663 change_line_highlight_hook
= x_change_line_highlight
;
13664 delete_glyphs_hook
= x_delete_glyphs
;
13665 ring_bell_hook
= XTring_bell
;
13666 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13667 set_terminal_modes_hook
= XTset_terminal_modes
;
13668 update_begin_hook
= x_update_begin
;
13669 update_end_hook
= x_update_end
;
13670 set_terminal_window_hook
= XTset_terminal_window
;
13671 read_socket_hook
= XTread_socket
;
13672 frame_up_to_date_hook
= XTframe_up_to_date
;
13673 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13674 mouse_position_hook
= XTmouse_position
;
13675 frame_rehighlight_hook
= XTframe_rehighlight
;
13676 frame_raise_lower_hook
= XTframe_raise_lower
;
13677 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13678 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13679 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13680 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13681 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13683 scroll_region_ok
= 1; /* we'll scroll partial frames */
13684 char_ins_del_ok
= 0; /* just as fast to write the line */
13685 line_ins_del_ok
= 1; /* we'll just blt 'em */
13686 fast_clear_end_of_line
= 1; /* X does this well */
13687 memory_below_frame
= 0; /* we don't remember what scrolls
13692 last_tool_bar_item
= -1;
13693 any_help_event_p
= 0;
13695 /* Try to use interrupt input; if we can't, then start polling. */
13696 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13698 #ifdef USE_X_TOOLKIT
13699 XtToolkitInitialize ();
13700 Xt_app_con
= XtCreateApplicationContext ();
13701 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13703 /* Install an asynchronous timer that processes Xt timeout events
13704 every 0.1s. This is necessary because some widget sets use
13705 timeouts internally, for example the LessTif menu bar, or the
13706 Xaw3d scroll bar. When Xt timouts aren't processed, these
13707 widgets don't behave normally. */
13709 EMACS_TIME interval
;
13710 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13711 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13715 #if USE_TOOLKIT_SCROLL_BARS
13716 xaw3d_arrow_scroll
= False
;
13717 xaw3d_pick_top
= True
;
13720 /* Note that there is no real way portable across R3/R4 to get the
13721 original error handler. */
13722 XSetErrorHandler (x_error_handler
);
13723 XSetIOErrorHandler (x_io_error_quitter
);
13725 /* Disable Window Change signals; they are handled by X events. */
13727 signal (SIGWINCH
, SIG_DFL
);
13728 #endif /* ! defined (SIGWINCH) */
13730 signal (SIGPIPE
, x_connection_signal
);
13737 staticpro (&x_error_message_string
);
13738 x_error_message_string
= Qnil
;
13740 staticpro (&x_display_name_list
);
13741 x_display_name_list
= Qnil
;
13743 staticpro (&last_mouse_scroll_bar
);
13744 last_mouse_scroll_bar
= Qnil
;
13746 staticpro (&Qvendor_specific_keysyms
);
13747 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13749 staticpro (&last_mouse_press_frame
);
13750 last_mouse_press_frame
= Qnil
;
13753 staticpro (&help_echo
);
13754 help_echo_object
= Qnil
;
13755 staticpro (&help_echo_object
);
13756 help_echo_window
= Qnil
;
13757 staticpro (&help_echo_window
);
13758 previous_help_echo
= Qnil
;
13759 staticpro (&previous_help_echo
);
13760 help_echo_pos
= -1;
13762 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13763 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
13764 For example, if a block cursor is over a tab, it will be drawn as\n\
13765 wide as that tab on the display.");
13766 x_stretch_cursor_p
= 0;
13768 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
13769 "If not nil, Emacs uses toolkit scroll bars.");
13770 #if USE_TOOLKIT_SCROLL_BARS
13771 x_toolkit_scroll_bars_p
= 1;
13773 x_toolkit_scroll_bars_p
= 0;
13776 staticpro (&last_mouse_motion_frame
);
13777 last_mouse_motion_frame
= Qnil
;
13780 #endif /* not HAVE_X_WINDOWS */