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 /* memmove will be defined as a macro in Xfuncs.h unless
154 <string.h> is included beforehand. The declaration for memmove in
155 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
160 #define min(a,b) ((a) < (b) ? (a) : (b))
163 #define max(a,b) ((a) > (b) ? (a) : (b))
166 #define abs(x) ((x) < 0 ? -(x) : (x))
168 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
171 /* Bitmaps for truncated lines. */
176 LEFT_TRUNCATION_BITMAP
,
177 RIGHT_TRUNCATION_BITMAP
,
178 OVERLAY_ARROW_BITMAP
,
179 CONTINUED_LINE_BITMAP
,
180 CONTINUATION_LINE_BITMAP
,
184 /* Bitmap drawn to indicate lines not displaying text if
185 `indicate-empty-lines' is non-nil. */
189 static unsigned char zv_bits
[] = {
190 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
192 /* An arrow like this: `<-'. */
195 #define left_height 8
196 static unsigned char left_bits
[] = {
197 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
199 /* Right truncation arrow bitmap `->'. */
201 #define right_width 8
202 #define right_height 8
203 static unsigned char right_bits
[] = {
204 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
206 /* Marker for continued lines. */
208 #define continued_width 8
209 #define continued_height 8
210 static unsigned char continued_bits
[] = {
211 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
213 /* Marker for continuation lines. */
215 #define continuation_width 8
216 #define continuation_height 8
217 static unsigned char continuation_bits
[] = {
218 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
220 /* Overlay arrow bitmap. */
226 static unsigned char ov_bits
[] = {
227 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
229 /* A triangular arrow. */
232 static unsigned char ov_bits
[] = {
233 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
237 extern Lisp_Object Qhelp_echo
;
240 /* Non-zero means Emacs uses toolkit scroll bars. */
242 int x_toolkit_scroll_bars_p
;
244 /* If a string, XTread_socket generates an event to display that string.
245 (The display is done in read_char.) */
247 static Lisp_Object help_echo
;
248 static Lisp_Object help_echo_window
;
249 static Lisp_Object help_echo_object
;
250 static int help_echo_pos
;
252 /* Temporary variable for XTread_socket. */
254 static Lisp_Object previous_help_echo
;
256 /* Non-zero means that a HELP_EVENT has been generated since Emacs
259 static int any_help_event_p
;
261 /* Non-zero means draw block and hollow cursor as wide as the glyph
262 under it. For example, if a block cursor is over a tab, it will be
263 drawn as wide as that tab on the display. */
265 int x_stretch_cursor_p
;
267 /* This is a chain of structures for all the X displays currently in
270 struct x_display_info
*x_display_list
;
272 /* This is a list of cons cells, each of the form (NAME
273 . FONT-LIST-CACHE), one for each element of x_display_list and in
274 the same order. NAME is the name of the frame. FONT-LIST-CACHE
275 records previous values returned by x-list-fonts. */
277 Lisp_Object x_display_name_list
;
279 /* Frame being updated by update_frame. This is declared in term.c.
280 This is set by update_begin and looked at by all the XT functions.
281 It is zero while not inside an update. In that case, the XT
282 functions assume that `selected_frame' is the frame to apply to. */
284 extern struct frame
*updating_frame
;
286 extern int waiting_for_input
;
288 /* This is a frame waiting to be auto-raised, within XTread_socket. */
290 struct frame
*pending_autoraise_frame
;
293 /* The application context for Xt use. */
294 XtAppContext Xt_app_con
;
295 static String Xt_default_resources
[] = {0};
296 #endif /* USE_X_TOOLKIT */
298 /* Nominal cursor position -- where to draw output.
299 HPOS and VPOS are window relative glyph matrix coordinates.
300 X and Y are window relative pixel coordinates. */
302 struct cursor_pos output_cursor
;
304 /* Non-zero means user is interacting with a toolkit scroll bar. */
306 static int toolkit_scroll_bar_interaction
;
310 Formerly, we used PointerMotionHintMask (in standard_event_mask)
311 so that we would have to call XQueryPointer after each MotionNotify
312 event to ask for another such event. However, this made mouse tracking
313 slow, and there was a bug that made it eventually stop.
315 Simply asking for MotionNotify all the time seems to work better.
317 In order to avoid asking for motion events and then throwing most
318 of them away or busy-polling the server for mouse positions, we ask
319 the server for pointer motion hints. This means that we get only
320 one event per group of mouse movements. "Groups" are delimited by
321 other kinds of events (focus changes and button clicks, for
322 example), or by XQueryPointer calls; when one of these happens, we
323 get another MotionNotify event the next time the mouse moves. This
324 is at least as efficient as getting motion events when mouse
325 tracking is on, and I suspect only negligibly worse when tracking
328 /* Where the mouse was last time we reported a mouse event. */
330 FRAME_PTR last_mouse_frame
;
331 static XRectangle last_mouse_glyph
;
332 static Lisp_Object last_mouse_press_frame
;
334 /* The scroll bar in which the last X motion event occurred.
336 If the last X motion event occurred in a scroll bar, we set this so
337 XTmouse_position can know whether to report a scroll bar motion or
340 If the last X motion event didn't occur in a scroll bar, we set
341 this to Qnil, to tell XTmouse_position to return an ordinary motion
344 static Lisp_Object last_mouse_scroll_bar
;
346 /* This is a hack. We would really prefer that XTmouse_position would
347 return the time associated with the position it returns, but there
348 doesn't seem to be any way to wrest the time-stamp from the server
349 along with the position query. So, we just keep track of the time
350 of the last movement we received, and return that in hopes that
351 it's somewhat accurate. */
353 static Time last_mouse_movement_time
;
355 /* Incremented by XTread_socket whenever it really tries to read
359 static int volatile input_signal_count
;
361 static int input_signal_count
;
364 /* Used locally within XTread_socket. */
366 static int x_noop_count
;
368 /* Initial values of argv and argc. */
370 extern char **initial_argv
;
371 extern int initial_argc
;
373 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
375 /* Tells if a window manager is present or not. */
377 extern Lisp_Object Vx_no_window_manager
;
379 extern Lisp_Object Qface
, Qmouse_face
;
383 /* A mask of extra modifier bits to put into every keyboard char. */
385 extern int extra_keyboard_modifiers
;
387 static Lisp_Object Qvendor_specific_keysyms
;
389 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
390 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
393 /* Enumeration for overriding/changing the face to use for drawing
394 glyphs in x_draw_glyphs. */
396 enum draw_glyphs_face
406 static void x_update_window_end
P_ ((struct window
*, int, int));
407 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
408 void x_delete_display
P_ ((struct x_display_info
*));
409 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
411 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
413 static void set_output_cursor
P_ ((struct cursor_pos
*));
414 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
415 int *, int *, int *));
416 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
417 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
418 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
419 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
420 static void show_mouse_face
P_ ((struct x_display_info
*,
421 enum draw_glyphs_face
));
422 static int x_io_error_quitter
P_ ((Display
*));
423 int x_catch_errors
P_ ((Display
*));
424 void x_uncatch_errors
P_ ((Display
*, int));
425 void x_lower_frame
P_ ((struct frame
*));
426 void x_scroll_bar_clear
P_ ((struct frame
*));
427 int x_had_errors_p
P_ ((Display
*));
428 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
429 void x_raise_frame
P_ ((struct frame
*));
430 void x_set_window_size
P_ ((struct frame
*, int, int, int));
431 void x_wm_set_window_state
P_ ((struct frame
*, int));
432 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
433 void x_initialize
P_ ((void));
434 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
435 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
436 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
438 enum draw_glyphs_face
));
439 static void x_update_end
P_ ((struct frame
*));
440 static void XTframe_up_to_date
P_ ((struct frame
*));
441 static void XTreassert_line_highlight
P_ ((int, int));
442 static void x_change_line_highlight
P_ ((int, int, int, int));
443 static void XTset_terminal_modes
P_ ((void));
444 static void XTreset_terminal_modes
P_ ((void));
445 static void XTcursor_to
P_ ((int, int, int, int));
446 static void x_write_glyphs
P_ ((struct glyph
*, int));
447 static void x_clear_end_of_line
P_ ((int));
448 static void x_clear_frame
P_ ((void));
449 static void x_clear_cursor
P_ ((struct window
*));
450 static void frame_highlight
P_ ((struct frame
*));
451 static void frame_unhighlight
P_ ((struct frame
*));
452 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
453 static void XTframe_rehighlight
P_ ((struct frame
*));
454 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
455 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
456 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
457 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
459 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
460 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
461 static void expose_window
P_ ((struct window
*, XRectangle
*));
462 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
463 XRectangle
*, enum glyph_row_area
));
464 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
466 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
467 static void x_update_window_cursor
P_ ((struct window
*, int));
468 static void x_erase_phys_cursor
P_ ((struct window
*));
469 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
470 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
473 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
475 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
476 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
477 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
478 static void x_flush
P_ ((struct frame
*f
));
479 static void x_update_begin
P_ ((struct frame
*));
480 static void x_update_window_begin
P_ ((struct window
*));
481 static void x_draw_vertical_border
P_ ((struct window
*));
482 static void x_after_update_window_line
P_ ((struct glyph_row
*));
483 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
484 static void x_produce_stretch_glyph
P_ ((struct it
*));
487 /* Flush display of frame F, or of all frames if F is null. */
496 Lisp_Object rest
, frame
;
497 FOR_EACH_FRAME (rest
, frame
)
498 x_flush (XFRAME (frame
));
500 else if (FRAME_X_P (f
))
501 XFlush (FRAME_X_DISPLAY (f
));
506 /* Remove calls to XFlush by defining XFlush to an empty replacement.
507 Calls to XFlush should be unnecessary because the X output buffer
508 is flushed automatically as needed by calls to XPending,
509 XNextEvent, or XWindowEvent according to the XFlush man page.
510 XTread_socket calls XPending. Removing XFlush improves
513 #define XFlush(DISPLAY) (void) 0
516 /***********************************************************************
518 ***********************************************************************/
522 /* This is a function useful for recording debugging information about
523 the sequence of occurrences in this file. */
531 struct record event_record
[100];
533 int event_record_index
;
535 record_event (locus
, type
)
539 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
540 event_record_index
= 0;
542 event_record
[event_record_index
].locus
= locus
;
543 event_record
[event_record_index
].type
= type
;
544 event_record_index
++;
551 /* Return the struct x_display_info corresponding to DPY. */
553 struct x_display_info
*
554 x_display_info_for_display (dpy
)
557 struct x_display_info
*dpyinfo
;
559 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
560 if (dpyinfo
->display
== dpy
)
568 /***********************************************************************
569 Starting and ending an update
570 ***********************************************************************/
572 /* Start an update of frame F. This function is installed as a hook
573 for update_begin, i.e. it is called when update_begin is called.
574 This function is called prior to calls to x_update_window_begin for
575 each window being updated. Currently, there is nothing to do here
576 because all interesting stuff is done on a window basis. */
586 /* Start update of window W. Set the global variable updated_window
587 to the window being updated and set output_cursor to the cursor
591 x_update_window_begin (w
)
594 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
595 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
598 set_output_cursor (&w
->cursor
);
602 if (f
== display_info
->mouse_face_mouse_frame
)
604 /* Don't do highlighting for mouse motion during the update. */
605 display_info
->mouse_face_defer
= 1;
607 /* If F needs to be redrawn, simply forget about any prior mouse
609 if (FRAME_GARBAGED_P (f
))
610 display_info
->mouse_face_window
= Qnil
;
612 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
613 their mouse_face_p flag set, which means that they are always
614 unequal to rows in a desired matrix which never have that
615 flag set. So, rows containing mouse-face glyphs are never
616 scrolled, and we don't have to switch the mouse highlight off
617 here to prevent it from being scrolled. */
619 /* Can we tell that this update does not affect the window
620 where the mouse highlight is? If so, no need to turn off.
621 Likewise, don't do anything if the frame is garbaged;
622 in that case, the frame's current matrix that we would use
623 is all wrong, and we will redisplay that line anyway. */
624 if (!NILP (display_info
->mouse_face_window
)
625 && w
== XWINDOW (display_info
->mouse_face_window
))
629 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
630 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
633 if (i
< w
->desired_matrix
->nrows
)
634 clear_mouse_face (display_info
);
643 /* Draw a vertical window border to the right of window W if W doesn't
644 have vertical scroll bars. */
647 x_draw_vertical_border (w
)
650 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
652 /* Redraw borders between horizontally adjacent windows. Don't
653 do it for frames with vertical scroll bars because either the
654 right scroll bar of a window, or the left scroll bar of its
655 neighbor will suffice as a border. */
656 if (!WINDOW_RIGHTMOST_P (w
)
657 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
661 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
662 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
665 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
666 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
671 /* End update of window W (which is equal to updated_window).
673 Draw vertical borders between horizontally adjacent windows, and
674 display W's cursor if CURSOR_ON_P is non-zero.
676 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
677 glyphs in mouse-face were overwritten. In that case we have to
678 make sure that the mouse-highlight is properly redrawn.
680 W may be a menu bar pseudo-window in case we don't have X toolkit
681 support. Such windows don't have a cursor, so don't display it
685 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
687 int cursor_on_p
, mouse_face_overwritten_p
;
689 if (!w
->pseudo_window_p
)
691 struct x_display_info
*dpyinfo
692 = FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
696 /* If a row with mouse-face was overwritten, arrange for
697 XTframe_up_to_date to redisplay the mouse highlight. */
698 if (mouse_face_overwritten_p
)
700 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
701 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
702 dpyinfo
->mouse_face_window
= Qnil
;
706 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
708 output_cursor
.x
, output_cursor
.y
);
710 x_draw_vertical_border (w
);
714 updated_window
= NULL
;
718 /* End update of frame F. This function is installed as a hook in
725 /* Mouse highlight may be displayed again. */
726 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
729 XFlush (FRAME_X_DISPLAY (f
));
734 /* This function is called from various places in xdisp.c whenever a
735 complete update has been performed. The global variable
736 updated_window is not available here. */
739 XTframe_up_to_date (f
)
744 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
746 if (dpyinfo
->mouse_face_deferred_gc
747 || f
== dpyinfo
->mouse_face_mouse_frame
)
750 if (dpyinfo
->mouse_face_mouse_frame
)
751 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
752 dpyinfo
->mouse_face_mouse_x
,
753 dpyinfo
->mouse_face_mouse_y
);
754 dpyinfo
->mouse_face_deferred_gc
= 0;
761 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
762 arrow bitmaps, or clear the areas where they would be displayed
763 before DESIRED_ROW is made current. The window being updated is
764 found in updated_window. This function It is called from
765 update_window_line only if it is known that there are differences
766 between bitmaps to be drawn between current row and DESIRED_ROW. */
769 x_after_update_window_line (desired_row
)
770 struct glyph_row
*desired_row
;
772 struct window
*w
= updated_window
;
776 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
779 x_draw_row_bitmaps (w
, desired_row
);
781 /* When a window has disappeared, make sure that no rest of
782 full-width rows stays visible in the internal border. */
783 if (windows_or_buffers_changed
)
785 struct frame
*f
= XFRAME (w
->frame
);
786 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
787 int height
= desired_row
->visible_height
;
788 int x
= (window_box_right (w
, -1)
789 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
790 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
792 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
793 x
, y
, width
, height
, False
);
801 /* Draw the bitmap WHICH in one of the areas to the left or right of
802 window W. ROW is the glyph row for which to display the bitmap; it
803 determines the vertical position at which the bitmap has to be
807 x_draw_bitmap (w
, row
, which
)
809 struct glyph_row
*row
;
810 enum bitmap_type which
;
812 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
813 Display
*display
= FRAME_X_DISPLAY (f
);
814 Window window
= FRAME_X_WINDOW (f
);
818 GC gc
= f
->output_data
.x
->normal_gc
;
820 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
822 /* Must clip because of partially visible lines. */
823 x_clip_to_row (w
, row
, gc
, 1);
827 case LEFT_TRUNCATION_BITMAP
:
831 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
833 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
836 case OVERLAY_ARROW_BITMAP
:
840 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
842 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
845 case RIGHT_TRUNCATION_BITMAP
:
849 x
= window_box_right (w
, -1);
850 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
853 case CONTINUED_LINE_BITMAP
:
856 bits
= continued_bits
;
857 x
= window_box_right (w
, -1);
858 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
861 case CONTINUATION_LINE_BITMAP
:
862 wd
= continuation_width
;
863 h
= continuation_height
;
864 bits
= continuation_bits
;
865 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
867 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
874 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
876 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
883 /* Convert to frame coordinates. Set dy to the offset in the row to
884 start drawing the bitmap. */
885 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
886 dy
= (row
->height
- h
) / 2;
888 /* Draw the bitmap. I believe these small pixmaps can be cached
890 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
891 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
893 face
->background
, depth
);
894 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
895 XFreePixmap (display
, pixmap
);
896 XSetClipMask (display
, gc
, None
);
900 /* Draw flags bitmaps for glyph row ROW on window W. Call this
901 function with input blocked. */
904 x_draw_row_bitmaps (w
, row
)
906 struct glyph_row
*row
;
908 struct frame
*f
= XFRAME (w
->frame
);
909 enum bitmap_type bitmap
;
911 int header_line_height
= -1;
913 xassert (interrupt_input_blocked
);
915 /* If row is completely invisible, because of vscrolling, we
916 don't have to draw anything. */
917 if (row
->visible_height
<= 0)
920 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
921 PREPARE_FACE_FOR_DISPLAY (f
, face
);
923 /* Decide which bitmap to draw at the left side. */
924 if (row
->overlay_arrow_p
)
925 bitmap
= OVERLAY_ARROW_BITMAP
;
926 else if (row
->truncated_on_left_p
)
927 bitmap
= LEFT_TRUNCATION_BITMAP
;
928 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
929 bitmap
= CONTINUATION_LINE_BITMAP
;
930 else if (row
->indicate_empty_line_p
)
931 bitmap
= ZV_LINE_BITMAP
;
935 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
937 if (bitmap
== NO_BITMAP
938 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
939 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
941 /* If W has a vertical border to its left, don't draw over it. */
942 int border
= ((XFASTINT (w
->left
) > 0
943 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
945 int left
= window_box_left (w
, -1);
947 if (header_line_height
< 0)
948 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
950 /* In case the same realized face is used for bitmap areas and
951 for something displayed in the text (e.g. face `region' on
952 mono-displays, the fill style may have been changed to
953 FillSolid in x_draw_glyph_string_background. */
955 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
957 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
959 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
962 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
964 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
966 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
967 row
->visible_height
);
969 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
972 /* Draw the left bitmap. */
973 if (bitmap
!= NO_BITMAP
)
974 x_draw_bitmap (w
, row
, bitmap
);
976 /* Decide which bitmap to draw at the right side. */
977 if (row
->truncated_on_right_p
)
978 bitmap
= RIGHT_TRUNCATION_BITMAP
;
979 else if (row
->continued_p
)
980 bitmap
= CONTINUED_LINE_BITMAP
;
984 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
986 if (bitmap
== NO_BITMAP
987 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
988 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
990 int right
= window_box_right (w
, -1);
992 if (header_line_height
< 0)
993 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
995 /* In case the same realized face is used for bitmap areas and
996 for something displayed in the text (e.g. face `region' on
997 mono-displays, the fill style may have been changed to
998 FillSolid in x_draw_glyph_string_background. */
1000 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1002 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1003 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1006 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1008 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
1009 row
->visible_height
);
1011 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1014 /* Draw the right bitmap. */
1015 if (bitmap
!= NO_BITMAP
)
1016 x_draw_bitmap (w
, row
, bitmap
);
1020 /***********************************************************************
1022 ***********************************************************************/
1024 /* External interface to control of standout mode. Not used for X
1025 frames. Aborts when called. */
1028 XTreassert_line_highlight (new, vpos
)
1035 /* Call this when about to modify line at position VPOS and change
1036 whether it is highlighted. Not used for X frames. Aborts when
1040 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1041 int new_highlight
, vpos
, y
, first_unused_hpos
;
1047 /* This is called when starting Emacs and when restarting after
1048 suspend. When starting Emacs, no X window is mapped. And nothing
1049 must be done to Emacs's own window if it is suspended (though that
1053 XTset_terminal_modes ()
1057 /* This is called when exiting or suspending Emacs. Exiting will make
1058 the X-windows go away, and suspending requires no action. */
1061 XTreset_terminal_modes ()
1067 /***********************************************************************
1069 ***********************************************************************/
1071 /* Set the global variable output_cursor to CURSOR. All cursor
1072 positions are relative to updated_window. */
1075 set_output_cursor (cursor
)
1076 struct cursor_pos
*cursor
;
1078 output_cursor
.hpos
= cursor
->hpos
;
1079 output_cursor
.vpos
= cursor
->vpos
;
1080 output_cursor
.x
= cursor
->x
;
1081 output_cursor
.y
= cursor
->y
;
1085 /* Set a nominal cursor position.
1087 HPOS and VPOS are column/row positions in a window glyph matrix. X
1088 and Y are window text area relative pixel positions.
1090 If this is done during an update, updated_window will contain the
1091 window that is being updated and the position is the future output
1092 cursor position for that window. If updated_window is null, use
1093 selected_window and display the cursor at the given position. */
1096 XTcursor_to (vpos
, hpos
, y
, x
)
1097 int vpos
, hpos
, y
, x
;
1101 /* If updated_window is not set, work on selected_window. */
1105 w
= XWINDOW (selected_window
);
1107 /* Set the output cursor. */
1108 output_cursor
.hpos
= hpos
;
1109 output_cursor
.vpos
= vpos
;
1110 output_cursor
.x
= x
;
1111 output_cursor
.y
= y
;
1113 /* If not called as part of an update, really display the cursor.
1114 This will also set the cursor position of W. */
1115 if (updated_window
== NULL
)
1118 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1119 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1126 /***********************************************************************
1128 ***********************************************************************/
1130 /* Function prototypes of this page. */
1132 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1136 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1137 int, XChar2b
*, int));
1138 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1139 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1140 static void x_append_glyph
P_ ((struct it
*));
1141 static void x_append_composite_glyph
P_ ((struct it
*));
1142 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1144 static void x_produce_glyphs
P_ ((struct it
*));
1145 static void x_produce_image_glyph
P_ ((struct it
*it
));
1148 /* Return a pointer to per-char metric information in FONT of a
1149 character pointed by B which is a pointer to an XChar2b. */
1151 #define PER_CHAR_METRIC(font, b) \
1153 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1154 + (((font)->min_byte1 || (font)->max_byte1) \
1155 ? (((b)->byte1 - (font)->min_byte1) \
1156 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1158 : &((font)->max_bounds))
1161 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1162 is not contained in the font. */
1164 static INLINE XCharStruct
*
1165 x_per_char_metric (font
, char2b
)
1169 /* The result metric information. */
1170 XCharStruct
*pcm
= NULL
;
1172 xassert (font
&& char2b
);
1174 if (font
->per_char
!= NULL
)
1176 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1178 /* min_char_or_byte2 specifies the linear character index
1179 corresponding to the first element of the per_char array,
1180 max_char_or_byte2 is the index of the last character. A
1181 character with non-zero CHAR2B->byte1 is not in the font.
1182 A character with byte2 less than min_char_or_byte2 or
1183 greater max_char_or_byte2 is not in the font. */
1184 if (char2b
->byte1
== 0
1185 && char2b
->byte2
>= font
->min_char_or_byte2
1186 && char2b
->byte2
<= font
->max_char_or_byte2
)
1187 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1191 /* If either min_byte1 or max_byte1 are nonzero, both
1192 min_char_or_byte2 and max_char_or_byte2 are less than
1193 256, and the 2-byte character index values corresponding
1194 to the per_char array element N (counting from 0) are:
1196 byte1 = N/D + min_byte1
1197 byte2 = N\D + min_char_or_byte2
1201 D = max_char_or_byte2 - min_char_or_byte2 + 1
1202 / = integer division
1203 \ = integer modulus */
1204 if (char2b
->byte1
>= font
->min_byte1
1205 && char2b
->byte1
<= font
->max_byte1
1206 && char2b
->byte2
>= font
->min_char_or_byte2
1207 && char2b
->byte2
<= font
->max_char_or_byte2
)
1209 pcm
= (font
->per_char
1210 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1211 * (char2b
->byte1
- font
->min_byte1
))
1212 + (char2b
->byte2
- font
->min_char_or_byte2
));
1218 /* If the per_char pointer is null, all glyphs between the first
1219 and last character indexes inclusive have the same
1220 information, as given by both min_bounds and max_bounds. */
1221 if (char2b
->byte2
>= font
->min_char_or_byte2
1222 && char2b
->byte2
<= font
->max_char_or_byte2
)
1223 pcm
= &font
->max_bounds
;
1226 return ((pcm
== NULL
1227 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1232 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1233 the two-byte form of C. Encoding is returned in *CHAR2B. */
1236 x_encode_char (c
, char2b
, font_info
)
1239 struct font_info
*font_info
;
1241 int charset
= CHAR_CHARSET (c
);
1242 XFontStruct
*font
= font_info
->font
;
1244 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1245 This may be either a program in a special encoder language or a
1247 if (font_info
->font_encoder
)
1249 /* It's a program. */
1250 struct ccl_program
*ccl
= font_info
->font_encoder
;
1252 if (CHARSET_DIMENSION (charset
) == 1)
1254 ccl
->reg
[0] = charset
;
1255 ccl
->reg
[1] = char2b
->byte2
;
1259 ccl
->reg
[0] = charset
;
1260 ccl
->reg
[1] = char2b
->byte1
;
1261 ccl
->reg
[2] = char2b
->byte2
;
1264 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1266 /* We assume that MSBs are appropriately set/reset by CCL
1268 if (font
->max_byte1
== 0) /* 1-byte font */
1269 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1271 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1273 else if (font_info
->encoding
[charset
])
1275 /* Fixed encoding scheme. See fontset.h for the meaning of the
1276 encoding numbers. */
1277 int enc
= font_info
->encoding
[charset
];
1279 if ((enc
== 1 || enc
== 2)
1280 && CHARSET_DIMENSION (charset
) == 2)
1281 char2b
->byte1
|= 0x80;
1283 if (enc
== 1 || enc
== 3)
1284 char2b
->byte2
|= 0x80;
1289 /* Get face and two-byte form of character C in face FACE_ID on frame
1290 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1291 means we want to display multibyte text. Value is a pointer to a
1292 realized face that is ready for display. */
1294 static INLINE
struct face
*
1295 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1301 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1305 /* Unibyte case. We don't have to encode, but we have to make
1306 sure to use a face suitable for unibyte. */
1309 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1310 face
= FACE_FROM_ID (f
, face_id
);
1312 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1314 /* Case of ASCII in a face known to fit ASCII. */
1320 int c1
, c2
, charset
;
1322 /* Split characters into bytes. If c2 is -1 afterwards, C is
1323 really a one-byte character so that byte1 is zero. */
1324 SPLIT_CHAR (c
, charset
, c1
, c2
);
1326 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1328 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1330 /* Maybe encode the character in *CHAR2B. */
1331 if (face
->font
!= NULL
)
1333 struct font_info
*font_info
1334 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1336 x_encode_char (c
, char2b
, font_info
);
1340 /* Make sure X resources of the face are allocated. */
1341 xassert (face
!= NULL
);
1342 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1348 /* Get face and two-byte form of character glyph GLYPH on frame F.
1349 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1350 a pointer to a realized face that is ready for display. */
1352 static INLINE
struct face
*
1353 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1355 struct glyph
*glyph
;
1361 xassert (glyph
->type
== CHAR_GLYPH
);
1362 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1367 if (!glyph
->multibyte_p
)
1369 /* Unibyte case. We don't have to encode, but we have to make
1370 sure to use a face suitable for unibyte. */
1372 char2b
->byte2
= glyph
->u
.ch
;
1374 else if (glyph
->u
.ch
< 128
1375 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1377 /* Case of ASCII in a face known to fit ASCII. */
1379 char2b
->byte2
= glyph
->u
.ch
;
1383 int c1
, c2
, charset
;
1385 /* Split characters into bytes. If c2 is -1 afterwards, C is
1386 really a one-byte character so that byte1 is zero. */
1387 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1389 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1391 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1393 /* Maybe encode the character in *CHAR2B. */
1394 if (charset
!= CHARSET_ASCII
)
1396 struct font_info
*font_info
1397 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1400 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1403 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1408 /* Make sure X resources of the face are allocated. */
1409 xassert (face
!= NULL
);
1410 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1415 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1416 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1422 struct glyph
*glyph
;
1423 enum glyph_row_area area
= it
->area
;
1425 xassert (it
->glyph_row
);
1426 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1428 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1429 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1431 glyph
->charpos
= CHARPOS (it
->position
);
1432 glyph
->object
= it
->object
;
1433 glyph
->pixel_width
= it
->pixel_width
;
1434 glyph
->voffset
= it
->voffset
;
1435 glyph
->type
= CHAR_GLYPH
;
1436 glyph
->multibyte_p
= it
->multibyte_p
;
1437 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1438 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1439 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1440 || it
->phys_descent
> it
->descent
);
1441 glyph
->padding_p
= 0;
1442 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1443 glyph
->face_id
= it
->face_id
;
1444 glyph
->u
.ch
= it
->char_to_display
;
1445 ++it
->glyph_row
->used
[area
];
1449 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1450 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1453 x_append_composite_glyph (it
)
1456 struct glyph
*glyph
;
1457 enum glyph_row_area area
= it
->area
;
1459 xassert (it
->glyph_row
);
1461 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1462 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1464 glyph
->charpos
= CHARPOS (it
->position
);
1465 glyph
->object
= it
->object
;
1466 glyph
->pixel_width
= it
->pixel_width
;
1467 glyph
->voffset
= it
->voffset
;
1468 glyph
->type
= COMPOSITE_GLYPH
;
1469 glyph
->multibyte_p
= it
->multibyte_p
;
1470 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1471 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1472 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1473 || it
->phys_descent
> it
->descent
);
1474 glyph
->padding_p
= 0;
1475 glyph
->glyph_not_available_p
= 0;
1476 glyph
->face_id
= it
->face_id
;
1477 glyph
->u
.cmp_id
= it
->cmp_id
;
1478 ++it
->glyph_row
->used
[area
];
1483 /* Change IT->ascent and IT->height according to the setting of
1487 take_vertical_position_into_account (it
)
1492 if (it
->voffset
< 0)
1493 /* Increase the ascent so that we can display the text higher
1495 it
->ascent
+= abs (it
->voffset
);
1497 /* Increase the descent so that we can display the text lower
1499 it
->descent
+= it
->voffset
;
1504 /* Produce glyphs/get display metrics for the image IT is loaded with.
1505 See the description of struct display_iterator in dispextern.h for
1506 an overview of struct display_iterator. */
1509 x_produce_image_glyph (it
)
1515 xassert (it
->what
== IT_IMAGE
);
1517 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1518 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1521 /* Make sure X resources of the face and image are loaded. */
1522 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1523 prepare_image_for_display (it
->f
, img
);
1525 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1526 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->margin
- it
->ascent
;
1527 it
->pixel_width
= img
->width
+ 2 * img
->margin
;
1531 if (face
->box
!= FACE_NO_BOX
)
1533 it
->ascent
+= face
->box_line_width
;
1534 it
->descent
+= face
->box_line_width
;
1536 if (it
->start_of_box_run_p
)
1537 it
->pixel_width
+= face
->box_line_width
;
1538 if (it
->end_of_box_run_p
)
1539 it
->pixel_width
+= face
->box_line_width
;
1542 take_vertical_position_into_account (it
);
1546 struct glyph
*glyph
;
1547 enum glyph_row_area area
= it
->area
;
1549 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1550 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1552 glyph
->charpos
= CHARPOS (it
->position
);
1553 glyph
->object
= it
->object
;
1554 glyph
->pixel_width
= it
->pixel_width
;
1555 glyph
->voffset
= it
->voffset
;
1556 glyph
->type
= IMAGE_GLYPH
;
1557 glyph
->multibyte_p
= it
->multibyte_p
;
1558 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1559 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1560 glyph
->overlaps_vertically_p
= 0;
1561 glyph
->padding_p
= 0;
1562 glyph
->glyph_not_available_p
= 0;
1563 glyph
->face_id
= it
->face_id
;
1564 glyph
->u
.img_id
= img
->id
;
1565 ++it
->glyph_row
->used
[area
];
1571 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1572 of the glyph, WIDTH and HEIGHT are the width and height of the
1573 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1574 ascent of the glyph (0 <= ASCENT <= 1). */
1577 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1583 struct glyph
*glyph
;
1584 enum glyph_row_area area
= it
->area
;
1586 xassert (ascent
>= 0 && ascent
<= 1);
1588 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1589 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1591 glyph
->charpos
= CHARPOS (it
->position
);
1592 glyph
->object
= object
;
1593 glyph
->pixel_width
= width
;
1594 glyph
->voffset
= it
->voffset
;
1595 glyph
->type
= STRETCH_GLYPH
;
1596 glyph
->multibyte_p
= it
->multibyte_p
;
1597 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1598 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1599 glyph
->overlaps_vertically_p
= 0;
1600 glyph
->padding_p
= 0;
1601 glyph
->glyph_not_available_p
= 0;
1602 glyph
->face_id
= it
->face_id
;
1603 glyph
->u
.stretch
.ascent
= height
* ascent
;
1604 glyph
->u
.stretch
.height
= height
;
1605 ++it
->glyph_row
->used
[area
];
1610 /* Produce a stretch glyph for iterator IT. IT->object is the value
1611 of the glyph property displayed. The value must be a list
1612 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1615 1. `:width WIDTH' specifies that the space should be WIDTH *
1616 canonical char width wide. WIDTH may be an integer or floating
1619 2. `:relative-width FACTOR' specifies that the width of the stretch
1620 should be computed from the width of the first character having the
1621 `glyph' property, and should be FACTOR times that width.
1623 3. `:align-to HPOS' specifies that the space should be wide enough
1624 to reach HPOS, a value in canonical character units.
1626 Exactly one of the above pairs must be present.
1628 4. `:height HEIGHT' specifies that the height of the stretch produced
1629 should be HEIGHT, measured in canonical character units.
1631 5. `:relative-height FACTOR' specifies that the height of the the
1632 stretch should be FACTOR times the height of the characters having
1635 Either none or exactly one of 4 or 5 must be present.
1637 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1638 of the stretch should be used for the ascent of the stretch.
1639 ASCENT must be in the range 0 <= ASCENT <= 100. */
1642 ((INTEGERP (X) || FLOATP (X)) \
1648 x_produce_stretch_glyph (it
)
1651 /* (space :width WIDTH :height HEIGHT. */
1653 extern Lisp_Object Qspace
;
1655 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1656 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1657 extern Lisp_Object QCalign_to
;
1658 Lisp_Object prop
, plist
;
1659 double width
= 0, height
= 0, ascent
= 0;
1660 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1661 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1663 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1665 /* List should start with `space'. */
1666 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1667 plist
= XCDR (it
->object
);
1669 /* Compute the width of the stretch. */
1670 if (prop
= Fplist_get (plist
, QCwidth
),
1672 /* Absolute width `:width WIDTH' specified and valid. */
1673 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1674 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1677 /* Relative width `:relative-width FACTOR' specified and valid.
1678 Compute the width of the characters having the `glyph'
1681 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1684 if (it
->multibyte_p
)
1686 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1687 - IT_BYTEPOS (*it
));
1688 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1691 it2
.c
= *p
, it2
.len
= 1;
1693 it2
.glyph_row
= NULL
;
1694 it2
.what
= IT_CHARACTER
;
1695 x_produce_glyphs (&it2
);
1696 width
= NUMVAL (prop
) * it2
.pixel_width
;
1698 else if (prop
= Fplist_get (plist
, QCalign_to
),
1700 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1702 /* Nothing specified -> width defaults to canonical char width. */
1703 width
= CANON_X_UNIT (it
->f
);
1705 /* Compute height. */
1706 if (prop
= Fplist_get (plist
, QCheight
),
1708 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1709 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1711 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1713 height
= FONT_HEIGHT (font
);
1715 /* Compute percentage of height used for ascent. If
1716 `:ascent ASCENT' is present and valid, use that. Otherwise,
1717 derive the ascent from the font in use. */
1718 if (prop
= Fplist_get (plist
, QCascent
),
1719 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1720 ascent
= NUMVAL (prop
) / 100.0;
1722 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1731 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1732 if (!STRINGP (object
))
1733 object
= it
->w
->buffer
;
1734 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1737 it
->pixel_width
= width
;
1738 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1739 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1742 if (face
->box
!= FACE_NO_BOX
)
1744 it
->ascent
+= face
->box_line_width
;
1745 it
->descent
+= face
->box_line_width
;
1747 if (it
->start_of_box_run_p
)
1748 it
->pixel_width
+= face
->box_line_width
;
1749 if (it
->end_of_box_run_p
)
1750 it
->pixel_width
+= face
->box_line_width
;
1753 take_vertical_position_into_account (it
);
1756 /* Return proper value to be used as baseline offset of font that has
1757 ASCENT and DESCENT to draw characters by the font at the vertical
1758 center of the line of frame F.
1760 Here, out task is to find the value of BOFF in the following figure;
1762 -------------------------+-----------+-
1763 -+-+---------+-+ | |
1765 | | | | F_ASCENT F_HEIGHT
1768 | | |-|-+------+-----------|------- baseline
1770 | |---------|-+-+ | |
1772 -+-+---------+-+ F_DESCENT |
1773 -------------------------+-----------+-
1775 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1776 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1777 DESCENT = FONT->descent
1778 HEIGHT = FONT_HEIGHT (FONT)
1779 F_DESCENT = (F->output_data.x->font->descent
1780 - F->output_data.x->baseline_offset)
1781 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1784 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1786 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT))) / 2 \
1787 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1789 /* Produce glyphs/get display metrics for the display element IT is
1790 loaded with. See the description of struct display_iterator in
1791 dispextern.h for an overview of struct display_iterator. */
1794 x_produce_glyphs (it
)
1797 it
->glyph_not_available_p
= 0;
1799 if (it
->what
== IT_CHARACTER
)
1803 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1805 int font_not_found_p
;
1806 struct font_info
*font_info
;
1807 int boff
; /* baseline offset */
1809 /* Maybe translate single-byte characters to multibyte, or the
1811 it
->char_to_display
= it
->c
;
1812 if (!ASCII_BYTE_P (it
->c
))
1814 if (unibyte_display_via_language_environment
1815 && SINGLE_BYTE_CHAR_P (it
->c
)
1817 || !NILP (Vnonascii_translation_table
)))
1819 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1820 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1821 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1823 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1824 && !it
->multibyte_p
)
1826 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1827 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1828 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1832 /* Get font to use. Encode IT->char_to_display. */
1833 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1834 it
->face_id
, &char2b
,
1838 /* When no suitable font found, use the default font. */
1839 font_not_found_p
= font
== NULL
;
1840 if (font_not_found_p
)
1842 font
= FRAME_FONT (it
->f
);
1843 boff
= it
->f
->output_data
.x
->baseline_offset
;
1848 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1849 boff
= font_info
->baseline_offset
;
1850 if (font_info
->vertical_centering
)
1851 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1854 if (it
->char_to_display
>= ' '
1855 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1857 /* Either unibyte or ASCII. */
1862 pcm
= x_per_char_metric (font
, &char2b
);
1863 it
->ascent
= font
->ascent
+ boff
;
1864 it
->descent
= font
->descent
- boff
;
1868 it
->phys_ascent
= pcm
->ascent
+ boff
;
1869 it
->phys_descent
= pcm
->descent
- boff
;
1870 it
->pixel_width
= pcm
->width
;
1874 it
->glyph_not_available_p
= 1;
1875 it
->phys_ascent
= font
->ascent
+ boff
;
1876 it
->phys_descent
= font
->descent
- boff
;
1877 it
->pixel_width
= FONT_WIDTH (font
);
1880 /* If this is a space inside a region of text with
1881 `space-width' property, change its width. */
1882 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1884 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1886 /* If face has a box, add the box thickness to the character
1887 height. If character has a box line to the left and/or
1888 right, add the box line width to the character's width. */
1889 if (face
->box
!= FACE_NO_BOX
)
1891 int thick
= face
->box_line_width
;
1893 it
->ascent
+= thick
;
1894 it
->descent
+= thick
;
1896 if (it
->start_of_box_run_p
)
1897 it
->pixel_width
+= thick
;
1898 if (it
->end_of_box_run_p
)
1899 it
->pixel_width
+= thick
;
1902 /* If face has an overline, add the height of the overline
1903 (1 pixel) and a 1 pixel margin to the character height. */
1904 if (face
->overline_p
)
1907 take_vertical_position_into_account (it
);
1909 /* If we have to actually produce glyphs, do it. */
1914 /* Translate a space with a `space-width' property
1915 into a stretch glyph. */
1916 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1917 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1918 it
->ascent
+ it
->descent
, ascent
);
1921 x_append_glyph (it
);
1923 /* If characters with lbearing or rbearing are displayed
1924 in this line, record that fact in a flag of the
1925 glyph row. This is used to optimize X output code. */
1926 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1927 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1930 else if (it
->char_to_display
== '\n')
1932 /* A newline has no width but we need the height of the line. */
1933 it
->pixel_width
= 0;
1935 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1936 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1938 if (face
->box
!= FACE_NO_BOX
)
1940 int thick
= face
->box_line_width
;
1941 it
->ascent
+= thick
;
1942 it
->descent
+= thick
;
1945 else if (it
->char_to_display
== '\t')
1947 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1948 int x
= it
->current_x
+ it
->continuation_lines_width
;
1949 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1951 it
->pixel_width
= next_tab_x
- x
;
1953 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1954 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1958 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1959 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1960 it
->ascent
+ it
->descent
, ascent
);
1965 /* A multi-byte character. Assume that the display width of the
1966 character is the width of the character multiplied by the
1967 width of the font. */
1969 /* If we found a font, this font should give us the right
1970 metrics. If we didn't find a font, use the frame's
1971 default font and calculate the width of the character
1972 from the charset width; this is what old redisplay code
1974 pcm
= x_per_char_metric (font
, &char2b
);
1975 if (font_not_found_p
|| !pcm
)
1977 int charset
= CHAR_CHARSET (it
->char_to_display
);
1979 it
->glyph_not_available_p
= 1;
1980 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1981 * CHARSET_WIDTH (charset
));
1982 it
->phys_ascent
= font
->ascent
+ boff
;
1983 it
->phys_descent
= font
->descent
- boff
;
1987 it
->pixel_width
= pcm
->width
;
1988 it
->phys_ascent
= pcm
->ascent
+ boff
;
1989 it
->phys_descent
= pcm
->descent
- boff
;
1991 && (pcm
->lbearing
< 0
1992 || pcm
->rbearing
> pcm
->width
))
1993 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1996 it
->ascent
= font
->ascent
+ boff
;
1997 it
->descent
= font
->descent
- boff
;
1998 if (face
->box
!= FACE_NO_BOX
)
2000 int thick
= face
->box_line_width
;
2001 it
->ascent
+= thick
;
2002 it
->descent
+= thick
;
2004 if (it
->start_of_box_run_p
)
2005 it
->pixel_width
+= thick
;
2006 if (it
->end_of_box_run_p
)
2007 it
->pixel_width
+= thick
;
2010 /* If face has an overline, add the height of the overline
2011 (1 pixel) and a 1 pixel margin to the character height. */
2012 if (face
->overline_p
)
2015 take_vertical_position_into_account (it
);
2018 x_append_glyph (it
);
2021 else if (it
->what
== IT_COMPOSITION
)
2023 /* Note: A composition is represented as one glyph in the
2024 glyph matrix. There are no padding glyphs. */
2027 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2029 int font_not_found_p
;
2030 struct font_info
*font_info
;
2031 int boff
; /* baseline offset */
2032 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2034 /* Maybe translate single-byte characters to multibyte. */
2035 it
->char_to_display
= it
->c
;
2036 if (unibyte_display_via_language_environment
2037 && SINGLE_BYTE_CHAR_P (it
->c
)
2040 && !NILP (Vnonascii_translation_table
))))
2042 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2045 /* Get face and font to use. Encode IT->char_to_display. */
2046 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2047 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2048 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2049 it
->face_id
, &char2b
, it
->multibyte_p
);
2052 /* When no suitable font found, use the default font. */
2053 font_not_found_p
= font
== NULL
;
2054 if (font_not_found_p
)
2056 font
= FRAME_FONT (it
->f
);
2057 boff
= it
->f
->output_data
.x
->baseline_offset
;
2062 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2063 boff
= font_info
->baseline_offset
;
2064 if (font_info
->vertical_centering
)
2065 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2068 /* There are no padding glyphs, so there is only one glyph to
2069 produce for the composition. Important is that pixel_width,
2070 ascent and descent are the values of what is drawn by
2071 draw_glyphs (i.e. the values of the overall glyphs composed). */
2074 /* If we have not yet calculated pixel size data of glyphs of
2075 the composition for the current face font, calculate them
2076 now. Theoretically, we have to check all fonts for the
2077 glyphs, but that requires much time and memory space. So,
2078 here we check only the font of the first glyph. This leads
2079 to incorrect display very rarely, and C-l (recenter) can
2080 correct the display anyway. */
2081 if (cmp
->font
!= (void *) font
)
2083 /* Ascent and descent of the font of the first character of
2084 this composition (adjusted by baseline offset). Ascent
2085 and descent of overall glyphs should not be less than
2086 them respectively. */
2087 int font_ascent
= font
->ascent
+ boff
;
2088 int font_descent
= font
->descent
- boff
;
2089 /* Bounding box of the overall glyphs. */
2090 int leftmost
, rightmost
, lowest
, highest
;
2091 int i
, width
, ascent
, descent
;
2093 cmp
->font
= (void *) font
;
2095 /* Initialize the bounding box. */
2096 pcm
= x_per_char_metric (font
, &char2b
);
2100 ascent
= pcm
->ascent
;
2101 descent
= pcm
->descent
;
2105 width
= FONT_WIDTH (font
);
2106 ascent
= font
->ascent
;
2107 descent
= font
->descent
;
2111 lowest
= - descent
+ boff
;
2112 highest
= ascent
+ boff
;
2116 && font_info
->default_ascent
2117 && CHAR_TABLE_P (Vuse_default_ascent
)
2118 && !NILP (Faref (Vuse_default_ascent
,
2119 make_number (it
->char_to_display
))))
2120 highest
= font_info
->default_ascent
+ boff
;
2122 /* Draw the first glyph at the normal position. It may be
2123 shifted to right later if some other glyphs are drawn at
2125 cmp
->offsets
[0] = 0;
2126 cmp
->offsets
[1] = boff
;
2128 /* Set cmp->offsets for the remaining glyphs. */
2129 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2131 int left
, right
, btm
, top
;
2132 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2133 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2135 face
= FACE_FROM_ID (it
->f
, face_id
);
2136 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2141 font
= FRAME_FONT (it
->f
);
2142 boff
= it
->f
->output_data
.x
->baseline_offset
;
2148 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2149 boff
= font_info
->baseline_offset
;
2150 if (font_info
->vertical_centering
)
2151 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2154 pcm
= x_per_char_metric (font
, &char2b
);
2158 ascent
= pcm
->ascent
;
2159 descent
= pcm
->descent
;
2163 width
= FONT_WIDTH (font
);
2164 ascent
= font
->ascent
;
2165 descent
= font
->descent
;
2168 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2170 /* Relative composition with or without
2172 left
= (leftmost
+ rightmost
- width
) / 2;
2173 btm
= - descent
+ boff
;
2174 if (font_info
&& font_info
->relative_compose
2175 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2176 || NILP (Faref (Vignore_relative_composition
,
2177 make_number (ch
)))))
2180 if (- descent
>= font_info
->relative_compose
)
2181 /* One extra pixel between two glyphs. */
2183 else if (ascent
<= 0)
2184 /* One extra pixel between two glyphs. */
2185 btm
= lowest
- 1 - ascent
- descent
;
2190 /* A composition rule is specified by an integer
2191 value that encodes global and new reference
2192 points (GREF and NREF). GREF and NREF are
2193 specified by numbers as below:
2201 ---3---4---5--- baseline
2203 6---7---8 -- descent
2205 int rule
= COMPOSITION_RULE (cmp
, i
);
2206 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2208 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2209 grefx
= gref
% 3, nrefx
= nref
% 3;
2210 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2213 + grefx
* (rightmost
- leftmost
) / 2
2214 - nrefx
* width
/ 2);
2215 btm
= ((grefy
== 0 ? highest
2217 : grefy
== 2 ? lowest
2218 : (highest
+ lowest
) / 2)
2219 - (nrefy
== 0 ? ascent
+ descent
2220 : nrefy
== 1 ? descent
- boff
2222 : (ascent
+ descent
) / 2));
2225 cmp
->offsets
[i
* 2] = left
;
2226 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2228 /* Update the bounding box of the overall glyphs. */
2229 right
= left
+ width
;
2230 top
= btm
+ descent
+ ascent
;
2231 if (left
< leftmost
)
2233 if (right
> rightmost
)
2241 /* If there are glyphs whose x-offsets are negative,
2242 shift all glyphs to the right and make all x-offsets
2246 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2247 cmp
->offsets
[i
* 2] -= leftmost
;
2248 rightmost
-= leftmost
;
2251 cmp
->pixel_width
= rightmost
;
2252 cmp
->ascent
= highest
;
2253 cmp
->descent
= - lowest
;
2254 if (cmp
->ascent
< font_ascent
)
2255 cmp
->ascent
= font_ascent
;
2256 if (cmp
->descent
< font_descent
)
2257 cmp
->descent
= font_descent
;
2260 it
->pixel_width
= cmp
->pixel_width
;
2261 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2262 it
->descent
= it
->phys_descent
= cmp
->descent
;
2264 if (face
->box
!= FACE_NO_BOX
)
2266 int thick
= face
->box_line_width
;
2267 it
->ascent
+= thick
;
2268 it
->descent
+= thick
;
2270 if (it
->start_of_box_run_p
)
2271 it
->pixel_width
+= thick
;
2272 if (it
->end_of_box_run_p
)
2273 it
->pixel_width
+= thick
;
2276 /* If face has an overline, add the height of the overline
2277 (1 pixel) and a 1 pixel margin to the character height. */
2278 if (face
->overline_p
)
2281 take_vertical_position_into_account (it
);
2284 x_append_composite_glyph (it
);
2286 else if (it
->what
== IT_IMAGE
)
2287 x_produce_image_glyph (it
);
2288 else if (it
->what
== IT_STRETCH
)
2289 x_produce_stretch_glyph (it
);
2291 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2292 because this isn't true for images with `:ascent 100'. */
2293 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2294 if (it
->area
== TEXT_AREA
)
2295 it
->current_x
+= it
->pixel_width
;
2297 it
->descent
+= it
->extra_line_spacing
;
2299 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2300 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2301 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2302 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2306 /* Estimate the pixel height of the mode or top line on frame F.
2307 FACE_ID specifies what line's height to estimate. */
2310 x_estimate_mode_line_height (f
, face_id
)
2312 enum face_id face_id
;
2316 /* This function is called so early when Emacs starts that the face
2317 cache and mode line face are not yet initialized. */
2318 if (FRAME_FACE_CACHE (f
))
2320 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2322 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
2329 /***********************************************************************
2331 ***********************************************************************/
2333 /* A sequence of glyphs to be drawn in the same face.
2335 This data structure is not really completely X specific, so it
2336 could possibly, at least partially, be useful for other systems. It
2337 is currently not part of the external redisplay interface because
2338 it's not clear what other systems will need. */
2342 /* X-origin of the string. */
2345 /* Y-origin and y-position of the base line of this string. */
2348 /* The width of the string, not including a face extension. */
2351 /* The width of the string, including a face extension. */
2352 int background_width
;
2354 /* The height of this string. This is the height of the line this
2355 string is drawn in, and can be different from the height of the
2356 font the string is drawn in. */
2359 /* Number of pixels this string overwrites in front of its x-origin.
2360 This number is zero if the string has an lbearing >= 0; it is
2361 -lbearing, if the string has an lbearing < 0. */
2364 /* Number of pixels this string overwrites past its right-most
2365 nominal x-position, i.e. x + width. Zero if the string's
2366 rbearing is <= its nominal width, rbearing - width otherwise. */
2369 /* The frame on which the glyph string is drawn. */
2372 /* The window on which the glyph string is drawn. */
2375 /* X display and window for convenience. */
2379 /* The glyph row for which this string was built. It determines the
2380 y-origin and height of the string. */
2381 struct glyph_row
*row
;
2383 /* The area within row. */
2384 enum glyph_row_area area
;
2386 /* Characters to be drawn, and number of characters. */
2390 /* A face-override for drawing cursors, mouse face and similar. */
2391 enum draw_glyphs_face hl
;
2393 /* Face in which this string is to be drawn. */
2396 /* Font in which this string is to be drawn. */
2399 /* Font info for this string. */
2400 struct font_info
*font_info
;
2402 /* Non-null means this string describes (part of) a composition.
2403 All characters from char2b are drawn composed. */
2404 struct composition
*cmp
;
2406 /* Index of this glyph string's first character in the glyph
2407 definition of CMP. If this is zero, this glyph string describes
2408 the first character of a composition. */
2411 /* 1 means this glyph strings face has to be drawn to the right end
2412 of the window's drawing area. */
2413 unsigned extends_to_end_of_line_p
: 1;
2415 /* 1 means the background of this string has been drawn. */
2416 unsigned background_filled_p
: 1;
2418 /* 1 means glyph string must be drawn with 16-bit functions. */
2419 unsigned two_byte_p
: 1;
2421 /* 1 means that the original font determined for drawing this glyph
2422 string could not be loaded. The member `font' has been set to
2423 the frame's default font in this case. */
2424 unsigned font_not_found_p
: 1;
2426 /* 1 means that the face in which this glyph string is drawn has a
2428 unsigned stippled_p
: 1;
2430 /* 1 means only the foreground of this glyph string must be drawn,
2431 and we should use the physical height of the line this glyph
2432 string appears in as clip rect. */
2433 unsigned for_overlaps_p
: 1;
2435 /* The GC to use for drawing this glyph string. */
2438 /* A pointer to the first glyph in the string. This glyph
2439 corresponds to char2b[0]. Needed to draw rectangles if
2440 font_not_found_p is 1. */
2441 struct glyph
*first_glyph
;
2443 /* Image, if any. */
2446 struct glyph_string
*next
, *prev
;
2453 x_dump_glyph_string (s
)
2454 struct glyph_string
*s
;
2456 fprintf (stderr
, "glyph string\n");
2457 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2458 s
->x
, s
->y
, s
->width
, s
->height
);
2459 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2460 fprintf (stderr
, " hl = %d\n", s
->hl
);
2461 fprintf (stderr
, " left overhang = %d, right = %d\n",
2462 s
->left_overhang
, s
->right_overhang
);
2463 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2464 fprintf (stderr
, " extends to end of line = %d\n",
2465 s
->extends_to_end_of_line_p
);
2466 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2467 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2470 #endif /* GLYPH_DEBUG */
2474 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2475 struct glyph_string
**,
2476 struct glyph_string
*,
2477 struct glyph_string
*));
2478 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2479 struct glyph_string
**,
2480 struct glyph_string
*,
2481 struct glyph_string
*));
2482 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2483 struct glyph_string
**,
2484 struct glyph_string
*));
2485 static int x_left_overwritten
P_ ((struct glyph_string
*));
2486 static int x_left_overwriting
P_ ((struct glyph_string
*));
2487 static int x_right_overwritten
P_ ((struct glyph_string
*));
2488 static int x_right_overwriting
P_ ((struct glyph_string
*));
2489 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2491 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2492 XChar2b
*, struct window
*,
2494 enum glyph_row_area
, int,
2495 enum draw_glyphs_face
));
2496 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2497 enum glyph_row_area
, int, int,
2498 enum draw_glyphs_face
, int *, int *, int));
2499 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2500 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2501 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2503 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2504 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2505 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2506 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2507 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2508 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2509 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2510 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2511 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2513 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2514 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2515 unsigned long *, double, int));
2516 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2517 double, int, unsigned long));
2518 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2519 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2520 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2521 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2522 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2523 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2524 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2526 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2527 int, int, int, int, XRectangle
*));
2528 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2529 int, int, int, XRectangle
*));
2530 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2531 enum glyph_row_area
));
2532 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2534 enum glyph_row_area
, int, int));
2537 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2541 /* Append the list of glyph strings with head H and tail T to the list
2542 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2545 x_append_glyph_string_lists (head
, tail
, h
, t
)
2546 struct glyph_string
**head
, **tail
;
2547 struct glyph_string
*h
, *t
;
2561 /* Prepend the list of glyph strings with head H and tail T to the
2562 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2566 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2567 struct glyph_string
**head
, **tail
;
2568 struct glyph_string
*h
, *t
;
2582 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2583 Set *HEAD and *TAIL to the resulting list. */
2586 x_append_glyph_string (head
, tail
, s
)
2587 struct glyph_string
**head
, **tail
;
2588 struct glyph_string
*s
;
2590 s
->next
= s
->prev
= NULL
;
2591 x_append_glyph_string_lists (head
, tail
, s
, s
);
2595 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2600 struct glyph_string
*s
;
2602 if (s
->font
== FRAME_FONT (s
->f
)
2603 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2604 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2606 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2609 /* Cursor on non-default face: must merge. */
2613 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2614 xgcv
.foreground
= s
->face
->background
;
2616 /* If the glyph would be invisible, try a different foreground. */
2617 if (xgcv
.foreground
== xgcv
.background
)
2618 xgcv
.foreground
= s
->face
->foreground
;
2619 if (xgcv
.foreground
== xgcv
.background
)
2620 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2621 if (xgcv
.foreground
== xgcv
.background
)
2622 xgcv
.foreground
= s
->face
->foreground
;
2624 /* Make sure the cursor is distinct from text in this face. */
2625 if (xgcv
.background
== s
->face
->background
2626 && xgcv
.foreground
== s
->face
->foreground
)
2628 xgcv
.background
= s
->face
->foreground
;
2629 xgcv
.foreground
= s
->face
->background
;
2632 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2633 xgcv
.font
= s
->font
->fid
;
2634 xgcv
.graphics_exposures
= False
;
2635 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2637 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2638 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2641 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2642 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2644 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2649 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2652 x_set_mouse_face_gc (s
)
2653 struct glyph_string
*s
;
2658 /* What face has to be used for the mouse face? */
2659 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2660 face
= FACE_FROM_ID (s
->f
, face_id
);
2661 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2662 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2664 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2665 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2666 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2668 /* If font in this face is same as S->font, use it. */
2669 if (s
->font
== s
->face
->font
)
2670 s
->gc
= s
->face
->gc
;
2673 /* Otherwise construct scratch_cursor_gc with values from FACE
2678 xgcv
.background
= s
->face
->background
;
2679 xgcv
.foreground
= s
->face
->foreground
;
2680 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2681 xgcv
.font
= s
->font
->fid
;
2682 xgcv
.graphics_exposures
= False
;
2683 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2685 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2686 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2689 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2690 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2692 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2695 xassert (s
->gc
!= 0);
2699 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2700 Faces to use in the mode line have already been computed when the
2701 matrix was built, so there isn't much to do, here. */
2704 x_set_mode_line_face_gc (s
)
2705 struct glyph_string
*s
;
2707 s
->gc
= s
->face
->gc
;
2711 /* Set S->gc of glyph string S for drawing that glyph string. Set
2712 S->stippled_p to a non-zero value if the face of S has a stipple
2716 x_set_glyph_string_gc (s
)
2717 struct glyph_string
*s
;
2719 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2721 if (s
->hl
== DRAW_NORMAL_TEXT
)
2723 s
->gc
= s
->face
->gc
;
2724 s
->stippled_p
= s
->face
->stipple
!= 0;
2726 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2728 x_set_mode_line_face_gc (s
);
2729 s
->stippled_p
= s
->face
->stipple
!= 0;
2731 else if (s
->hl
== DRAW_CURSOR
)
2733 x_set_cursor_gc (s
);
2736 else if (s
->hl
== DRAW_MOUSE_FACE
)
2738 x_set_mouse_face_gc (s
);
2739 s
->stippled_p
= s
->face
->stipple
!= 0;
2741 else if (s
->hl
== DRAW_IMAGE_RAISED
2742 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2744 s
->gc
= s
->face
->gc
;
2745 s
->stippled_p
= s
->face
->stipple
!= 0;
2749 s
->gc
= s
->face
->gc
;
2750 s
->stippled_p
= s
->face
->stipple
!= 0;
2753 /* GC must have been set. */
2754 xassert (s
->gc
!= 0);
2758 /* Return in *R the clipping rectangle for glyph string S. */
2761 x_get_glyph_string_clip_rect (s
, r
)
2762 struct glyph_string
*s
;
2765 if (s
->row
->full_width_p
)
2767 /* Draw full-width. X coordinates are relative to S->w->left. */
2768 int canon_x
= CANON_X_UNIT (s
->f
);
2770 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2771 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2773 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2775 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2776 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2780 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2782 /* Unless displaying a mode or menu bar line, which are always
2783 fully visible, clip to the visible part of the row. */
2784 if (s
->w
->pseudo_window_p
)
2785 r
->height
= s
->row
->visible_height
;
2787 r
->height
= s
->height
;
2791 /* This is a text line that may be partially visible. */
2792 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2793 r
->width
= window_box_width (s
->w
, s
->area
);
2794 r
->height
= s
->row
->visible_height
;
2797 /* Don't use S->y for clipping because it doesn't take partially
2798 visible lines into account. For example, it can be negative for
2799 partially visible lines at the top of a window. */
2800 if (!s
->row
->full_width_p
2801 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2802 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2804 r
->y
= max (0, s
->row
->y
);
2806 /* If drawing a tool-bar window, draw it over the internal border
2807 at the top of the window. */
2808 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2809 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2811 /* If S draws overlapping rows, it's sufficient to use the top and
2812 bottom of the window for clipping because this glyph string
2813 intentionally draws over other lines. */
2814 if (s
->for_overlaps_p
)
2816 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2817 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2820 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2824 /* Set clipping for output of glyph string S. S may be part of a mode
2825 line or menu if we don't have X toolkit support. */
2828 x_set_glyph_string_clipping (s
)
2829 struct glyph_string
*s
;
2832 x_get_glyph_string_clip_rect (s
, &r
);
2833 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2837 /* Compute left and right overhang of glyph string S. If S is a glyph
2838 string for a composition, assume overhangs don't exist. */
2841 x_compute_glyph_string_overhangs (s
)
2842 struct glyph_string
*s
;
2845 && s
->first_glyph
->type
== CHAR_GLYPH
)
2848 int direction
, font_ascent
, font_descent
;
2849 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2850 &font_ascent
, &font_descent
, &cs
);
2851 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2852 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2857 /* Compute overhangs and x-positions for glyph string S and its
2858 predecessors, or successors. X is the starting x-position for S.
2859 BACKWARD_P non-zero means process predecessors. */
2862 x_compute_overhangs_and_x (s
, x
, backward_p
)
2863 struct glyph_string
*s
;
2871 x_compute_glyph_string_overhangs (s
);
2881 x_compute_glyph_string_overhangs (s
);
2890 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2891 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2892 assumed to be zero. */
2895 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2896 struct glyph
*glyph
;
2902 if (glyph
->type
== CHAR_GLYPH
)
2906 struct font_info
*font_info
;
2910 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2912 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2914 && (pcm
= x_per_char_metric (font
, &char2b
)))
2916 if (pcm
->rbearing
> pcm
->width
)
2917 *right
= pcm
->rbearing
- pcm
->width
;
2918 if (pcm
->lbearing
< 0)
2919 *left
= -pcm
->lbearing
;
2925 /* Return the index of the first glyph preceding glyph string S that
2926 is overwritten by S because of S's left overhang. Value is -1
2927 if no glyphs are overwritten. */
2930 x_left_overwritten (s
)
2931 struct glyph_string
*s
;
2935 if (s
->left_overhang
)
2938 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2939 int first
= s
->first_glyph
- glyphs
;
2941 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2942 x
-= glyphs
[i
].pixel_width
;
2953 /* Return the index of the first glyph preceding glyph string S that
2954 is overwriting S because of its right overhang. Value is -1 if no
2955 glyph in front of S overwrites S. */
2958 x_left_overwriting (s
)
2959 struct glyph_string
*s
;
2962 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2963 int first
= s
->first_glyph
- glyphs
;
2967 for (i
= first
- 1; i
>= 0; --i
)
2970 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2973 x
-= glyphs
[i
].pixel_width
;
2980 /* Return the index of the last glyph following glyph string S that is
2981 not overwritten by S because of S's right overhang. Value is -1 if
2982 no such glyph is found. */
2985 x_right_overwritten (s
)
2986 struct glyph_string
*s
;
2990 if (s
->right_overhang
)
2993 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2994 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2995 int end
= s
->row
->used
[s
->area
];
2997 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
2998 x
+= glyphs
[i
].pixel_width
;
3007 /* Return the index of the last glyph following glyph string S that
3008 overwrites S because of its left overhang. Value is negative
3009 if no such glyph is found. */
3012 x_right_overwriting (s
)
3013 struct glyph_string
*s
;
3016 int end
= s
->row
->used
[s
->area
];
3017 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3018 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3022 for (i
= first
; i
< end
; ++i
)
3025 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3028 x
+= glyphs
[i
].pixel_width
;
3035 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3038 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3039 struct glyph_string
*s
;
3043 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3044 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3045 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3046 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3050 /* Draw the background of glyph_string S. If S->background_filled_p
3051 is non-zero don't draw it. FORCE_P non-zero means draw the
3052 background even if it wouldn't be drawn normally. This is used
3053 when a string preceding S draws into the background of S, or S
3054 contains the first component of a composition. */
3057 x_draw_glyph_string_background (s
, force_p
)
3058 struct glyph_string
*s
;
3061 /* Nothing to do if background has already been drawn or if it
3062 shouldn't be drawn in the first place. */
3063 if (!s
->background_filled_p
)
3067 /* Fill background with a stipple pattern. */
3068 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3069 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3070 s
->y
+ s
->face
->box_line_width
,
3071 s
->background_width
,
3072 s
->height
- 2 * s
->face
->box_line_width
);
3073 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3074 s
->background_filled_p
= 1;
3076 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
3077 || s
->font_not_found_p
3078 || s
->extends_to_end_of_line_p
3081 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
3082 s
->background_width
,
3083 s
->height
- 2 * s
->face
->box_line_width
);
3084 s
->background_filled_p
= 1;
3090 /* Draw the foreground of glyph string S. */
3093 x_draw_glyph_string_foreground (s
)
3094 struct glyph_string
*s
;
3098 /* If first glyph of S has a left box line, start drawing the text
3099 of S to the right of that box line. */
3100 if (s
->face
->box
!= FACE_NO_BOX
3101 && s
->first_glyph
->left_box_line_p
)
3102 x
= s
->x
+ s
->face
->box_line_width
;
3106 /* Draw characters of S as rectangles if S's font could not be
3108 if (s
->font_not_found_p
)
3110 for (i
= 0; i
< s
->nchars
; ++i
)
3112 struct glyph
*g
= s
->first_glyph
+ i
;
3113 XDrawRectangle (s
->display
, s
->window
,
3114 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3116 x
+= g
->pixel_width
;
3121 char *char1b
= (char *) s
->char2b
;
3122 int boff
= s
->font_info
->baseline_offset
;
3124 if (s
->font_info
->vertical_centering
)
3125 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3127 /* If we can use 8-bit functions, condense S->char2b. */
3129 for (i
= 0; i
< s
->nchars
; ++i
)
3130 char1b
[i
] = s
->char2b
[i
].byte2
;
3132 /* Draw text with XDrawString if background has already been
3133 filled. Otherwise, use XDrawImageString. (Note that
3134 XDrawImageString is usually faster than XDrawString.) Always
3135 use XDrawImageString when drawing the cursor so that there is
3136 no chance that characters under a box cursor are invisible. */
3137 if (s
->for_overlaps_p
3138 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3140 /* Draw characters with 16-bit or 8-bit functions. */
3142 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3143 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3145 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3146 s
->ybase
- boff
, char1b
, s
->nchars
);
3151 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3152 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3154 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3155 s
->ybase
- boff
, char1b
, s
->nchars
);
3160 /* Draw the foreground of composite glyph string S. */
3163 x_draw_composite_glyph_string_foreground (s
)
3164 struct glyph_string
*s
;
3168 /* If first glyph of S has a left box line, start drawing the text
3169 of S to the right of that box line. */
3170 if (s
->face
->box
!= FACE_NO_BOX
3171 && s
->first_glyph
->left_box_line_p
)
3172 x
= s
->x
+ s
->face
->box_line_width
;
3176 /* S is a glyph string for a composition. S->gidx is the index of
3177 the first character drawn for glyphs of this composition.
3178 S->gidx == 0 means we are drawing the very first character of
3179 this composition. */
3181 /* Draw a rectangle for the composition if the font for the very
3182 first character of the composition could not be loaded. */
3183 if (s
->font_not_found_p
)
3186 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3187 s
->width
- 1, s
->height
- 1);
3191 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3192 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3193 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3194 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3200 #ifdef USE_X_TOOLKIT
3202 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3205 /* Return the frame on which widget WIDGET is used.. Abort if frame
3206 cannot be determined. */
3208 static struct frame
*
3209 x_frame_of_widget (widget
)
3212 struct x_display_info
*dpyinfo
;
3216 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3218 /* Find the top-level shell of the widget. Note that this function
3219 can be called when the widget is not yet realized, so XtWindow
3220 (widget) == 0. That's the reason we can't simply use
3221 x_any_window_to_frame. */
3222 while (!XtIsTopLevelShell (widget
))
3223 widget
= XtParent (widget
);
3225 /* Look for a frame with that top-level widget. Allocate the color
3226 on that frame to get the right gamma correction value. */
3227 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3228 if (GC_FRAMEP (XCAR (tail
))
3229 && (f
= XFRAME (XCAR (tail
)),
3230 (f
->output_data
.nothing
!= 1
3231 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3232 && f
->output_data
.x
->widget
== widget
)
3239 /* Allocate the color COLOR->pixel on the screen and display of
3240 widget WIDGET in colormap CMAP. If an exact match cannot be
3241 allocated, try the nearest color available. Value is non-zero
3242 if successful. This is called from lwlib. */
3245 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3250 struct frame
*f
= x_frame_of_widget (widget
);
3251 return x_alloc_nearest_color (f
, cmap
, color
);
3255 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3256 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3257 If this produces the same color as PIXEL, try a color where all RGB
3258 values have DELTA added. Return the allocated color in *PIXEL.
3259 DISPLAY is the X display, CMAP is the colormap to operate on.
3260 Value is non-zero if successful. */
3263 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3267 unsigned long *pixel
;
3271 struct frame
*f
= x_frame_of_widget (widget
);
3272 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3276 #endif /* USE_X_TOOLKIT */
3279 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3280 CMAP. If an exact match can't be allocated, try the nearest color
3281 available. Value is non-zero if successful. Set *COLOR to the
3285 x_alloc_nearest_color (f
, cmap
, color
)
3290 Display
*display
= FRAME_X_DISPLAY (f
);
3291 Screen
*screen
= FRAME_X_SCREEN (f
);
3294 gamma_correct (f
, color
);
3295 rc
= XAllocColor (display
, cmap
, color
);
3298 /* If we got to this point, the colormap is full, so we're going
3299 to try to get the next closest color. The algorithm used is
3300 a least-squares matching, which is what X uses for closest
3301 color matching with StaticColor visuals. */
3303 unsigned long nearest_delta
= ~0;
3304 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3305 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3307 for (i
= 0; i
< ncells
; ++i
)
3309 XQueryColors (display
, cmap
, cells
, ncells
);
3311 for (nearest
= i
= 0; i
< ncells
; ++i
)
3313 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3314 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3315 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3316 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3318 if (delta
< nearest_delta
)
3321 nearest_delta
= delta
;
3325 color
->red
= cells
[nearest
].red
;
3326 color
->green
= cells
[nearest
].green
;
3327 color
->blue
= cells
[nearest
].blue
;
3328 rc
= XAllocColor (display
, cmap
, color
);
3331 #ifdef DEBUG_X_COLORS
3333 register_color (color
->pixel
);
3334 #endif /* DEBUG_X_COLORS */
3340 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3341 It's necessary to do this instead of just using PIXEL directly to
3342 get color reference counts right. */
3345 x_copy_color (f
, pixel
)
3347 unsigned long pixel
;
3351 color
.pixel
= pixel
;
3353 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3354 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3356 #ifdef DEBUG_X_COLORS
3357 register_color (pixel
);
3363 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3364 It's necessary to do this instead of just using PIXEL directly to
3365 get color reference counts right. */
3368 x_copy_dpy_color (dpy
, cmap
, pixel
)
3371 unsigned long pixel
;
3375 color
.pixel
= pixel
;
3377 XQueryColor (dpy
, cmap
, &color
);
3378 XAllocColor (dpy
, cmap
, &color
);
3380 #ifdef DEBUG_X_COLORS
3381 register_color (pixel
);
3387 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3388 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3389 If this produces the same color as PIXEL, try a color where all RGB
3390 values have DELTA added. Return the allocated color in *PIXEL.
3391 DISPLAY is the X display, CMAP is the colormap to operate on.
3392 Value is non-zero if successful. */
3395 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3399 unsigned long *pixel
;
3406 /* Get RGB color values. */
3407 color
.pixel
= *pixel
;
3408 XQueryColor (display
, cmap
, &color
);
3410 /* Change RGB values by specified FACTOR. Avoid overflow! */
3411 xassert (factor
>= 0);
3412 new.red
= min (0xffff, factor
* color
.red
);
3413 new.green
= min (0xffff, factor
* color
.green
);
3414 new.blue
= min (0xffff, factor
* color
.blue
);
3416 /* Try to allocate the color. */
3417 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3420 if (new.pixel
== *pixel
)
3422 /* If we end up with the same color as before, try adding
3423 delta to the RGB values. */
3424 x_free_colors (f
, &new.pixel
, 1);
3426 new.red
= min (0xffff, delta
+ color
.red
);
3427 new.green
= min (0xffff, delta
+ color
.green
);
3428 new.blue
= min (0xffff, delta
+ color
.blue
);
3429 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3440 /* Set up the foreground color for drawing relief lines of glyph
3441 string S. RELIEF is a pointer to a struct relief containing the GC
3442 with which lines will be drawn. Use a color that is FACTOR or
3443 DELTA lighter or darker than the relief's background which is found
3444 in S->f->output_data.x->relief_background. If such a color cannot
3445 be allocated, use DEFAULT_PIXEL, instead. */
3448 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3450 struct relief
*relief
;
3453 unsigned long default_pixel
;
3456 struct x_output
*di
= f
->output_data
.x
;
3457 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3458 unsigned long pixel
;
3459 unsigned long background
= di
->relief_background
;
3460 Colormap cmap
= FRAME_X_COLORMAP (f
);
3461 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3462 Display
*dpy
= FRAME_X_DISPLAY (f
);
3464 xgcv
.graphics_exposures
= False
;
3465 xgcv
.line_width
= 1;
3467 /* Free previously allocated color. The color cell will be reused
3468 when it has been freed as many times as it was allocated, so this
3469 doesn't affect faces using the same colors. */
3471 && relief
->allocated_p
)
3473 x_free_colors (f
, &relief
->pixel
, 1);
3474 relief
->allocated_p
= 0;
3477 /* Allocate new color. */
3478 xgcv
.foreground
= default_pixel
;
3480 if (dpyinfo
->n_planes
!= 1
3481 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3483 relief
->allocated_p
= 1;
3484 xgcv
.foreground
= relief
->pixel
= pixel
;
3487 if (relief
->gc
== 0)
3489 xgcv
.stipple
= dpyinfo
->gray
;
3491 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3494 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3498 /* Set up colors for the relief lines around glyph string S. */
3501 x_setup_relief_colors (s
)
3502 struct glyph_string
*s
;
3504 struct x_output
*di
= s
->f
->output_data
.x
;
3505 unsigned long color
;
3507 if (s
->face
->use_box_color_for_shadows_p
)
3508 color
= s
->face
->box_color
;
3513 /* Get the background color of the face. */
3514 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3515 color
= xgcv
.background
;
3518 if (di
->white_relief
.gc
== 0
3519 || color
!= di
->relief_background
)
3521 di
->relief_background
= color
;
3522 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3523 WHITE_PIX_DEFAULT (s
->f
));
3524 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3525 BLACK_PIX_DEFAULT (s
->f
));
3530 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3531 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3532 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3533 relief. LEFT_P non-zero means draw a relief on the left side of
3534 the rectangle. RIGHT_P non-zero means draw a relief on the right
3535 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3539 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3540 raised_p
, left_p
, right_p
, clip_rect
)
3542 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3543 XRectangle
*clip_rect
;
3549 gc
= f
->output_data
.x
->white_relief
.gc
;
3551 gc
= f
->output_data
.x
->black_relief
.gc
;
3552 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3555 for (i
= 0; i
< width
; ++i
)
3556 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3557 left_x
+ i
* left_p
, top_y
+ i
,
3558 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3562 for (i
= 0; i
< width
; ++i
)
3563 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3564 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3566 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3568 gc
= f
->output_data
.x
->black_relief
.gc
;
3570 gc
= f
->output_data
.x
->white_relief
.gc
;
3571 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3574 for (i
= 0; i
< width
; ++i
)
3575 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3576 left_x
+ i
* left_p
, bottom_y
- i
,
3577 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3581 for (i
= 0; i
< width
; ++i
)
3582 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3583 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3585 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3589 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3590 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3591 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3592 left side of the rectangle. RIGHT_P non-zero means draw a line
3593 on the right side of the rectangle. CLIP_RECT is the clipping
3594 rectangle to use when drawing. */
3597 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3598 left_p
, right_p
, clip_rect
)
3599 struct glyph_string
*s
;
3600 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3601 XRectangle
*clip_rect
;
3605 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3606 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3607 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3610 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3611 left_x
, top_y
, right_x
- left_x
, width
);
3615 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3616 left_x
, top_y
, width
, bottom_y
- top_y
);
3619 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3620 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3624 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3625 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3627 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3628 XSetClipMask (s
->display
, s
->gc
, None
);
3632 /* Draw a box around glyph string S. */
3635 x_draw_glyph_string_box (s
)
3636 struct glyph_string
*s
;
3638 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3639 int left_p
, right_p
;
3640 struct glyph
*last_glyph
;
3641 XRectangle clip_rect
;
3643 last_x
= window_box_right (s
->w
, s
->area
);
3644 if (s
->row
->full_width_p
3645 && !s
->w
->pseudo_window_p
)
3647 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3648 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3649 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3652 /* The glyph that may have a right box line. */
3653 last_glyph
= (s
->cmp
|| s
->img
3655 : s
->first_glyph
+ s
->nchars
- 1);
3657 width
= s
->face
->box_line_width
;
3658 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3660 right_x
= ((s
->row
->full_width_p
3662 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3664 bottom_y
= top_y
+ s
->height
- 1;
3666 left_p
= (s
->first_glyph
->left_box_line_p
3667 || (s
->hl
== DRAW_MOUSE_FACE
3669 || s
->prev
->hl
!= s
->hl
)));
3670 right_p
= (last_glyph
->right_box_line_p
3671 || (s
->hl
== DRAW_MOUSE_FACE
3673 || s
->next
->hl
!= s
->hl
)));
3675 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3677 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3678 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3679 left_p
, right_p
, &clip_rect
);
3682 x_setup_relief_colors (s
);
3683 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3684 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3689 /* Draw foreground of image glyph string S. */
3692 x_draw_image_foreground (s
)
3693 struct glyph_string
*s
;
3696 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3698 /* If first glyph of S has a left box line, start drawing it to the
3699 right of that line. */
3700 if (s
->face
->box
!= FACE_NO_BOX
3701 && s
->first_glyph
->left_box_line_p
)
3702 x
= s
->x
+ s
->face
->box_line_width
;
3706 /* If there is a margin around the image, adjust x- and y-position
3710 x
+= s
->img
->margin
;
3711 y
+= s
->img
->margin
;
3718 /* We can't set both a clip mask and use XSetClipRectangles
3719 because the latter also sets a clip mask. We also can't
3720 trust on the shape extension to be available
3721 (XShapeCombineRegion). So, compute the rectangle to draw
3723 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3726 XRectangle clip_rect
, image_rect
, r
;
3728 xgcv
.clip_mask
= s
->img
->mask
;
3729 xgcv
.clip_x_origin
= x
;
3730 xgcv
.clip_y_origin
= y
;
3731 xgcv
.function
= GXcopy
;
3732 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3734 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3737 image_rect
.width
= s
->img
->width
;
3738 image_rect
.height
= s
->img
->height
;
3739 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3740 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3741 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3745 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
3747 XRectangle clip_rect
, image_rect
, r
;
3749 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3752 image_rect
.width
= s
->img
->width
;
3753 image_rect
.height
= s
->img
->height
;
3754 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3755 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3756 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3758 /* When the image has a mask, we can expect that at
3759 least part of a mouse highlight or a block cursor will
3760 be visible. If the image doesn't have a mask, make
3761 a block cursor visible by drawing a rectangle around
3762 the image. I believe it's looking better if we do
3763 nothing here for mouse-face. */
3764 if (s
->hl
== DRAW_CURSOR
)
3765 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3766 s
->img
->width
- 1, s
->img
->height
- 1);
3770 /* Draw a rectangle if image could not be loaded. */
3771 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3772 s
->img
->width
- 1, s
->img
->height
- 1);
3776 /* Draw a relief around the image glyph string S. */
3779 x_draw_image_relief (s
)
3780 struct glyph_string
*s
;
3782 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3785 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3787 /* If first glyph of S has a left box line, start drawing it to the
3788 right of that line. */
3789 if (s
->face
->box
!= FACE_NO_BOX
3790 && s
->first_glyph
->left_box_line_p
)
3791 x
= s
->x
+ s
->face
->box_line_width
;
3795 /* If there is a margin around the image, adjust x- and y-position
3799 x
+= s
->img
->margin
;
3800 y
+= s
->img
->margin
;
3803 if (s
->hl
== DRAW_IMAGE_SUNKEN
3804 || s
->hl
== DRAW_IMAGE_RAISED
)
3806 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3807 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3811 thick
= abs (s
->img
->relief
);
3812 raised_p
= s
->img
->relief
> 0;
3817 x1
= x
+ s
->img
->width
+ thick
- 1;
3818 y1
= y
+ s
->img
->height
+ thick
- 1;
3820 x_setup_relief_colors (s
);
3821 x_get_glyph_string_clip_rect (s
, &r
);
3822 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3826 /* Draw the foreground of image glyph string S to PIXMAP. */
3829 x_draw_image_foreground_1 (s
, pixmap
)
3830 struct glyph_string
*s
;
3834 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3836 /* If first glyph of S has a left box line, start drawing it to the
3837 right of that line. */
3838 if (s
->face
->box
!= FACE_NO_BOX
3839 && s
->first_glyph
->left_box_line_p
)
3840 x
= s
->face
->box_line_width
;
3844 /* If there is a margin around the image, adjust x- and y-position
3848 x
+= s
->img
->margin
;
3849 y
+= s
->img
->margin
;
3856 /* We can't set both a clip mask and use XSetClipRectangles
3857 because the latter also sets a clip mask. We also can't
3858 trust on the shape extension to be available
3859 (XShapeCombineRegion). So, compute the rectangle to draw
3861 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3865 xgcv
.clip_mask
= s
->img
->mask
;
3866 xgcv
.clip_x_origin
= x
;
3867 xgcv
.clip_y_origin
= y
;
3868 xgcv
.function
= GXcopy
;
3869 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3871 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3872 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3873 XSetClipMask (s
->display
, s
->gc
, None
);
3877 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3878 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3880 /* When the image has a mask, we can expect that at
3881 least part of a mouse highlight or a block cursor will
3882 be visible. If the image doesn't have a mask, make
3883 a block cursor visible by drawing a rectangle around
3884 the image. I believe it's looking better if we do
3885 nothing here for mouse-face. */
3886 if (s
->hl
== DRAW_CURSOR
)
3887 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3888 s
->img
->width
- 1, s
->img
->height
- 1);
3892 /* Draw a rectangle if image could not be loaded. */
3893 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3894 s
->img
->width
- 1, s
->img
->height
- 1);
3898 /* Draw part of the background of glyph string S. X, Y, W, and H
3899 give the rectangle to draw. */
3902 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3903 struct glyph_string
*s
;
3908 /* Fill background with a stipple pattern. */
3909 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3910 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3911 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3914 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3918 /* Draw image glyph string S.
3921 s->x +-------------------------
3924 | +-------------------------
3927 | | +-------------------
3933 x_draw_image_glyph_string (s
)
3934 struct glyph_string
*s
;
3937 int box_line_width
= s
->face
->box_line_width
;
3938 int margin
= s
->img
->margin
;
3940 Pixmap pixmap
= None
;
3942 height
= s
->height
- 2 * box_line_width
;
3944 /* Fill background with face under the image. Do it only if row is
3945 taller than image or if image has a clip mask to reduce
3947 s
->stippled_p
= s
->face
->stipple
!= 0;
3948 if (height
> s
->img
->height
3951 || s
->img
->pixmap
== 0
3952 || s
->width
!= s
->background_width
)
3954 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3955 x
= s
->x
+ box_line_width
;
3959 y
= s
->y
+ box_line_width
;
3963 /* Create a pixmap as large as the glyph string Fill it with
3964 the background color. Copy the image to it, using its
3965 mask. Copy the temporary pixmap to the display. */
3966 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3967 int depth
= DefaultDepthOfScreen (screen
);
3969 /* Create a pixmap as large as the glyph string. */
3970 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3971 s
->background_width
,
3974 /* Don't clip in the following because we're working on the
3976 XSetClipMask (s
->display
, s
->gc
, None
);
3978 /* Fill the pixmap with the background color/stipple. */
3981 /* Fill background with a stipple pattern. */
3982 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3983 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3984 0, 0, s
->background_width
, s
->height
);
3985 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3990 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3992 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3993 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3994 0, 0, s
->background_width
, s
->height
);
3995 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3999 /* Implementation idea: Is it possible to construct a mask?
4000 We could look at the color at the margins of the image, and
4001 say that this color is probably the background color of the
4003 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4005 s
->background_filled_p
= 1;
4008 /* Draw the foreground. */
4011 x_draw_image_foreground_1 (s
, pixmap
);
4012 x_set_glyph_string_clipping (s
);
4013 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4014 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4015 XFreePixmap (s
->display
, pixmap
);
4018 x_draw_image_foreground (s
);
4020 /* If we must draw a relief around the image, do it. */
4022 || s
->hl
== DRAW_IMAGE_RAISED
4023 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4024 x_draw_image_relief (s
);
4028 /* Draw stretch glyph string S. */
4031 x_draw_stretch_glyph_string (s
)
4032 struct glyph_string
*s
;
4034 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4035 s
->stippled_p
= s
->face
->stipple
!= 0;
4037 if (s
->hl
== DRAW_CURSOR
4038 && !x_stretch_cursor_p
)
4040 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4041 as wide as the stretch glyph. */
4042 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4045 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4047 /* Clear rest using the GC of the original non-cursor face. */
4048 if (width
< s
->background_width
)
4050 GC gc
= s
->face
->gc
;
4051 int x
= s
->x
+ width
, y
= s
->y
;
4052 int w
= s
->background_width
- width
, h
= s
->height
;
4055 x_get_glyph_string_clip_rect (s
, &r
);
4056 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4058 if (s
->face
->stipple
)
4060 /* Fill background with a stipple pattern. */
4061 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4062 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4063 XSetFillStyle (s
->display
, gc
, FillSolid
);
4068 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4069 XSetForeground (s
->display
, gc
, xgcv
.background
);
4070 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4071 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4076 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4079 s
->background_filled_p
= 1;
4083 /* Draw glyph string S. */
4086 x_draw_glyph_string (s
)
4087 struct glyph_string
*s
;
4089 /* If S draws into the background of its successor, draw the
4090 background of the successor first so that S can draw into it.
4091 This makes S->next use XDrawString instead of XDrawImageString. */
4092 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4094 xassert (s
->next
->img
== NULL
);
4095 x_set_glyph_string_gc (s
->next
);
4096 x_set_glyph_string_clipping (s
->next
);
4097 x_draw_glyph_string_background (s
->next
, 1);
4100 /* Set up S->gc, set clipping and draw S. */
4101 x_set_glyph_string_gc (s
);
4102 x_set_glyph_string_clipping (s
);
4104 switch (s
->first_glyph
->type
)
4107 x_draw_image_glyph_string (s
);
4111 x_draw_stretch_glyph_string (s
);
4115 if (s
->for_overlaps_p
)
4116 s
->background_filled_p
= 1;
4118 x_draw_glyph_string_background (s
, 0);
4119 x_draw_glyph_string_foreground (s
);
4122 case COMPOSITE_GLYPH
:
4123 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4124 s
->background_filled_p
= 1;
4126 x_draw_glyph_string_background (s
, 1);
4127 x_draw_composite_glyph_string_foreground (s
);
4134 if (!s
->for_overlaps_p
)
4136 /* Draw underline. */
4137 if (s
->face
->underline_p
)
4139 unsigned long dy
, h
;
4141 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4143 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
4146 if (s
->face
->underline_defaulted_p
)
4147 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4152 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4153 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4154 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4156 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4160 /* Draw overline. */
4161 if (s
->face
->overline_p
)
4163 unsigned long dy
= 0, h
= 1;
4165 if (s
->face
->overline_color_defaulted_p
)
4166 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4171 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4172 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4173 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4175 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4179 /* Draw strike-through. */
4180 if (s
->face
->strike_through_p
)
4182 unsigned long h
= 1;
4183 unsigned long dy
= (s
->height
- h
) / 2;
4185 if (s
->face
->strike_through_color_defaulted_p
)
4186 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4191 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4192 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4193 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4195 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4200 if (s
->face
->box
!= FACE_NO_BOX
)
4201 x_draw_glyph_string_box (s
);
4204 /* Reset clipping. */
4205 XSetClipMask (s
->display
, s
->gc
, None
);
4209 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4210 struct face
**, int));
4213 /* Fill glyph string S with composition components specified by S->cmp.
4215 FACES is an array of faces for all components of this composition.
4216 S->gidx is the index of the first component for S.
4217 OVERLAPS_P non-zero means S should draw the foreground only, and
4218 use its physical height for clipping.
4220 Value is the index of a component not in S. */
4223 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4224 struct glyph_string
*s
;
4225 struct face
**faces
;
4232 s
->for_overlaps_p
= overlaps_p
;
4234 s
->face
= faces
[s
->gidx
];
4235 s
->font
= s
->face
->font
;
4236 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4238 /* For all glyphs of this composition, starting at the offset
4239 S->gidx, until we reach the end of the definition or encounter a
4240 glyph that requires the different face, add it to S. */
4242 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4245 /* All glyph strings for the same composition has the same width,
4246 i.e. the width set for the first component of the composition. */
4248 s
->width
= s
->first_glyph
->pixel_width
;
4250 /* If the specified font could not be loaded, use the frame's
4251 default font, but record the fact that we couldn't load it in
4252 the glyph string so that we can draw rectangles for the
4253 characters of the glyph string. */
4254 if (s
->font
== NULL
)
4256 s
->font_not_found_p
= 1;
4257 s
->font
= FRAME_FONT (s
->f
);
4260 /* Adjust base line for subscript/superscript text. */
4261 s
->ybase
+= s
->first_glyph
->voffset
;
4263 xassert (s
->face
&& s
->face
->gc
);
4265 /* This glyph string must always be drawn with 16-bit functions. */
4268 return s
->gidx
+ s
->nchars
;
4272 /* Fill glyph string S from a sequence of character glyphs.
4274 FACE_ID is the face id of the string. START is the index of the
4275 first glyph to consider, END is the index of the last + 1.
4276 OVERLAPS_P non-zero means S should draw the foreground only, and
4277 use its physical height for clipping.
4279 Value is the index of the first glyph not in S. */
4282 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4283 struct glyph_string
*s
;
4285 int start
, end
, overlaps_p
;
4287 struct glyph
*glyph
, *last
;
4289 int glyph_not_available_p
;
4291 xassert (s
->f
== XFRAME (s
->w
->frame
));
4292 xassert (s
->nchars
== 0);
4293 xassert (start
>= 0 && end
> start
);
4295 s
->for_overlaps_p
= overlaps_p
,
4296 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4297 last
= s
->row
->glyphs
[s
->area
] + end
;
4298 voffset
= glyph
->voffset
;
4300 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4303 && glyph
->type
== CHAR_GLYPH
4304 && glyph
->voffset
== voffset
4305 /* Same face id implies same font, nowadays. */
4306 && glyph
->face_id
== face_id
4307 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4311 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4312 s
->char2b
+ s
->nchars
,
4314 s
->two_byte_p
= two_byte_p
;
4316 xassert (s
->nchars
<= end
- start
);
4317 s
->width
+= glyph
->pixel_width
;
4321 s
->font
= s
->face
->font
;
4322 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4324 /* If the specified font could not be loaded, use the frame's font,
4325 but record the fact that we couldn't load it in
4326 S->font_not_found_p so that we can draw rectangles for the
4327 characters of the glyph string. */
4328 if (s
->font
== NULL
|| glyph_not_available_p
)
4330 s
->font_not_found_p
= 1;
4331 s
->font
= FRAME_FONT (s
->f
);
4334 /* Adjust base line for subscript/superscript text. */
4335 s
->ybase
+= voffset
;
4337 xassert (s
->face
&& s
->face
->gc
);
4338 return glyph
- s
->row
->glyphs
[s
->area
];
4342 /* Fill glyph string S from image glyph S->first_glyph. */
4345 x_fill_image_glyph_string (s
)
4346 struct glyph_string
*s
;
4348 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4349 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4351 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4352 s
->font
= s
->face
->font
;
4353 s
->width
= s
->first_glyph
->pixel_width
;
4355 /* Adjust base line for subscript/superscript text. */
4356 s
->ybase
+= s
->first_glyph
->voffset
;
4360 /* Fill glyph string S from a sequence of stretch glyphs.
4362 ROW is the glyph row in which the glyphs are found, AREA is the
4363 area within the row. START is the index of the first glyph to
4364 consider, END is the index of the last + 1.
4366 Value is the index of the first glyph not in S. */
4369 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4370 struct glyph_string
*s
;
4371 struct glyph_row
*row
;
4372 enum glyph_row_area area
;
4375 struct glyph
*glyph
, *last
;
4376 int voffset
, face_id
;
4378 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4380 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4381 last
= s
->row
->glyphs
[s
->area
] + end
;
4382 face_id
= glyph
->face_id
;
4383 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4384 s
->font
= s
->face
->font
;
4385 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4386 s
->width
= glyph
->pixel_width
;
4387 voffset
= glyph
->voffset
;
4391 && glyph
->type
== STRETCH_GLYPH
4392 && glyph
->voffset
== voffset
4393 && glyph
->face_id
== face_id
);
4395 s
->width
+= glyph
->pixel_width
;
4397 /* Adjust base line for subscript/superscript text. */
4398 s
->ybase
+= voffset
;
4400 xassert (s
->face
&& s
->face
->gc
);
4401 return glyph
- s
->row
->glyphs
[s
->area
];
4405 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4406 of XChar2b structures for S; it can't be allocated in
4407 x_init_glyph_string because it must be allocated via `alloca'. W
4408 is the window on which S is drawn. ROW and AREA are the glyph row
4409 and area within the row from which S is constructed. START is the
4410 index of the first glyph structure covered by S. HL is a
4411 face-override for drawing S. */
4414 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4415 struct glyph_string
*s
;
4418 struct glyph_row
*row
;
4419 enum glyph_row_area area
;
4421 enum draw_glyphs_face hl
;
4423 bzero (s
, sizeof *s
);
4425 s
->f
= XFRAME (w
->frame
);
4426 s
->display
= FRAME_X_DISPLAY (s
->f
);
4427 s
->window
= FRAME_X_WINDOW (s
->f
);
4432 s
->first_glyph
= row
->glyphs
[area
] + start
;
4433 s
->height
= row
->height
;
4434 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4436 /* Display the internal border below the tool-bar window. */
4437 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4438 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4440 s
->ybase
= s
->y
+ row
->ascent
;
4444 /* Set background width of glyph string S. START is the index of the
4445 first glyph following S. LAST_X is the right-most x-position + 1
4446 in the drawing area. */
4449 x_set_glyph_string_background_width (s
, start
, last_x
)
4450 struct glyph_string
*s
;
4454 /* If the face of this glyph string has to be drawn to the end of
4455 the drawing area, set S->extends_to_end_of_line_p. */
4456 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4458 if (start
== s
->row
->used
[s
->area
]
4459 && s
->hl
== DRAW_NORMAL_TEXT
4460 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4461 || s
->face
->background
!= default_face
->background
4462 || s
->face
->stipple
!= default_face
->stipple
))
4463 s
->extends_to_end_of_line_p
= 1;
4465 /* If S extends its face to the end of the line, set its
4466 background_width to the distance to the right edge of the drawing
4468 if (s
->extends_to_end_of_line_p
)
4469 s
->background_width
= last_x
- s
->x
+ 1;
4471 s
->background_width
= s
->width
;
4475 /* Add a glyph string for a stretch glyph to the list of strings
4476 between HEAD and TAIL. START is the index of the stretch glyph in
4477 row area AREA of glyph row ROW. END is the index of the last glyph
4478 in that glyph row area. X is the current output position assigned
4479 to the new glyph string constructed. HL overrides that face of the
4480 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4481 is the right-most x-position of the drawing area. */
4483 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4484 and below -- keep them on one line. */
4485 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4488 s = (struct glyph_string *) alloca (sizeof *s); \
4489 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4490 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4491 x_append_glyph_string (&HEAD, &TAIL, s); \
4497 /* Add a glyph string for an image glyph to the list of strings
4498 between HEAD and TAIL. START is the index of the image glyph in
4499 row area AREA of glyph row ROW. END is the index of the last glyph
4500 in that glyph row area. X is the current output position assigned
4501 to the new glyph string constructed. HL overrides that face of the
4502 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4503 is the right-most x-position of the drawing area. */
4505 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4508 s = (struct glyph_string *) alloca (sizeof *s); \
4509 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4510 x_fill_image_glyph_string (s); \
4511 x_append_glyph_string (&HEAD, &TAIL, s); \
4518 /* Add a glyph string for a sequence of character glyphs to the list
4519 of strings between HEAD and TAIL. START is the index of the first
4520 glyph in row area AREA of glyph row ROW that is part of the new
4521 glyph string. END is the index of the last glyph in that glyph row
4522 area. X is the current output position assigned to the new glyph
4523 string constructed. HL overrides that face of the glyph; e.g. it
4524 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4525 right-most x-position of the drawing area. */
4527 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4533 c = (ROW)->glyphs[AREA][START].u.ch; \
4534 face_id = (ROW)->glyphs[AREA][START].face_id; \
4536 s = (struct glyph_string *) alloca (sizeof *s); \
4537 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4538 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4539 x_append_glyph_string (&HEAD, &TAIL, s); \
4541 START = x_fill_glyph_string (s, face_id, START, END, \
4547 /* Add a glyph string for a composite sequence to the list of strings
4548 between HEAD and TAIL. START is the index of the first glyph in
4549 row area AREA of glyph row ROW that is part of the new glyph
4550 string. END is the index of the last glyph in that glyph row area.
4551 X is the current output position assigned to the new glyph string
4552 constructed. HL overrides that face of the glyph; e.g. it is
4553 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4554 x-position of the drawing area. */
4556 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4558 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4559 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4560 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4561 struct composition *cmp = composition_table[cmp_id]; \
4562 int glyph_len = cmp->glyph_len; \
4564 struct face **faces; \
4565 struct glyph_string *first_s = NULL; \
4568 base_face = base_face->ascii_face; \
4569 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4570 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4571 /* At first, fill in `char2b' and `faces'. */ \
4572 for (n = 0; n < glyph_len; n++) \
4574 int c = COMPOSITION_GLYPH (cmp, n); \
4575 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4576 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4577 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4578 this_face_id, char2b + n, 1); \
4581 /* Make glyph_strings for each glyph sequence that is drawable by \
4582 the same face, and append them to HEAD/TAIL. */ \
4583 for (n = 0; n < cmp->glyph_len;) \
4585 s = (struct glyph_string *) alloca (sizeof *s); \
4586 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4587 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4595 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4603 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4604 of AREA of glyph row ROW on window W between indices START and END.
4605 HL overrides the face for drawing glyph strings, e.g. it is
4606 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4607 x-positions of the drawing area.
4609 This is an ugly monster macro construct because we must use alloca
4610 to allocate glyph strings (because x_draw_glyphs can be called
4613 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4616 HEAD = TAIL = NULL; \
4617 while (START < END) \
4619 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4620 switch (first_glyph->type) \
4623 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4624 TAIL, HL, X, LAST_X, \
4628 case COMPOSITE_GLYPH: \
4629 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4630 HEAD, TAIL, HL, X, LAST_X,\
4634 case STRETCH_GLYPH: \
4635 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4636 HEAD, TAIL, HL, X, LAST_X); \
4640 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4641 TAIL, HL, X, LAST_X); \
4648 x_set_glyph_string_background_width (s, START, LAST_X); \
4655 /* Draw glyphs between START and END in AREA of ROW on window W,
4656 starting at x-position X. X is relative to AREA in W. HL is a
4657 face-override with the following meaning:
4659 DRAW_NORMAL_TEXT draw normally
4660 DRAW_CURSOR draw in cursor face
4661 DRAW_MOUSE_FACE draw in mouse face.
4662 DRAW_INVERSE_VIDEO draw in mode line face
4663 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4664 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4666 If REAL_START is non-null, return in *REAL_START the real starting
4667 position for display. This can be different from START in case
4668 overlapping glyphs must be displayed. If REAL_END is non-null,
4669 return in *REAL_END the real end position for display. This can be
4670 different from END in case overlapping glyphs must be displayed.
4672 If OVERLAPS_P is non-zero, draw only the foreground of characters
4673 and clip to the physical height of ROW.
4675 Value is the x-position reached, relative to AREA of W. */
4678 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4682 struct glyph_row
*row
;
4683 enum glyph_row_area area
;
4685 enum draw_glyphs_face hl
;
4686 int *real_start
, *real_end
;
4689 struct glyph_string
*head
, *tail
;
4690 struct glyph_string
*s
;
4691 int last_x
, area_width
;
4695 /* Let's rather be paranoid than getting a SEGV. */
4696 start
= max (0, start
);
4697 end
= min (end
, row
->used
[area
]);
4699 *real_start
= start
;
4703 /* Translate X to frame coordinates. Set last_x to the right
4704 end of the drawing area. */
4705 if (row
->full_width_p
)
4707 /* X is relative to the left edge of W, without scroll bars
4709 struct frame
*f
= XFRAME (w
->frame
);
4710 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4711 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4714 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4715 last_x
= window_left_x
+ area_width
;
4717 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4719 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4720 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4726 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4727 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4731 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4732 area_width
= window_box_width (w
, area
);
4733 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4736 /* Build a doubly-linked list of glyph_string structures between
4737 head and tail from what we have to draw. Note that the macro
4738 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4739 the reason we use a separate variable `i'. */
4741 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4744 x_reached
= tail
->x
+ tail
->background_width
;
4748 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4749 the row, redraw some glyphs in front or following the glyph
4750 strings built above. */
4751 if (!overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4754 struct glyph_string
*h
, *t
;
4756 /* Compute overhangs for all glyph strings. */
4757 for (s
= head
; s
; s
= s
->next
)
4758 x_compute_glyph_string_overhangs (s
);
4760 /* Prepend glyph strings for glyphs in front of the first glyph
4761 string that are overwritten because of the first glyph
4762 string's left overhang. The background of all strings
4763 prepended must be drawn because the first glyph string
4765 i
= x_left_overwritten (head
);
4769 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4770 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4774 *real_start
= start
;
4775 x_compute_overhangs_and_x (t
, head
->x
, 1);
4776 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4779 /* Prepend glyph strings for glyphs in front of the first glyph
4780 string that overwrite that glyph string because of their
4781 right overhang. For these strings, only the foreground must
4782 be drawn, because it draws over the glyph string at `head'.
4783 The background must not be drawn because this would overwrite
4784 right overhangs of preceding glyphs for which no glyph
4786 i
= x_left_overwriting (head
);
4789 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4790 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4792 for (s
= h
; s
; s
= s
->next
)
4793 s
->background_filled_p
= 1;
4796 x_compute_overhangs_and_x (t
, head
->x
, 1);
4797 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4800 /* Append glyphs strings for glyphs following the last glyph
4801 string tail that are overwritten by tail. The background of
4802 these strings has to be drawn because tail's foreground draws
4804 i
= x_right_overwritten (tail
);
4807 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4808 DRAW_NORMAL_TEXT
, x
, last_x
,
4810 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4811 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4816 /* Append glyph strings for glyphs following the last glyph
4817 string tail that overwrite tail. The foreground of such
4818 glyphs has to be drawn because it writes into the background
4819 of tail. The background must not be drawn because it could
4820 paint over the foreground of following glyphs. */
4821 i
= x_right_overwriting (tail
);
4824 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4825 DRAW_NORMAL_TEXT
, x
, last_x
,
4827 for (s
= h
; s
; s
= s
->next
)
4828 s
->background_filled_p
= 1;
4829 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4830 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4836 /* Draw all strings. */
4837 for (s
= head
; s
; s
= s
->next
)
4838 x_draw_glyph_string (s
);
4840 /* Value is the x-position up to which drawn, relative to AREA of W.
4841 This doesn't include parts drawn because of overhangs. */
4842 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4843 if (!row
->full_width_p
)
4845 if (area
> LEFT_MARGIN_AREA
)
4846 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4847 if (area
> TEXT_AREA
)
4848 x_reached
-= window_box_width (w
, TEXT_AREA
);
4854 /* Fix the display of area AREA of overlapping row ROW in window W. */
4857 x_fix_overlapping_area (w
, row
, area
)
4859 struct glyph_row
*row
;
4860 enum glyph_row_area area
;
4866 if (area
== LEFT_MARGIN_AREA
)
4868 else if (area
== TEXT_AREA
)
4869 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4871 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4872 + window_box_width (w
, TEXT_AREA
));
4874 for (i
= 0; i
< row
->used
[area
];)
4876 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4878 int start
= i
, start_x
= x
;
4882 x
+= row
->glyphs
[area
][i
].pixel_width
;
4885 while (i
< row
->used
[area
]
4886 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4888 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4890 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4895 x
+= row
->glyphs
[area
][i
].pixel_width
;
4904 /* Output LEN glyphs starting at START at the nominal cursor position.
4905 Advance the nominal cursor over the text. The global variable
4906 updated_window contains the window being updated, updated_row is
4907 the glyph row being updated, and updated_area is the area of that
4908 row being updated. */
4911 x_write_glyphs (start
, len
)
4912 struct glyph
*start
;
4915 int x
, hpos
, real_start
, real_end
;
4917 xassert (updated_window
&& updated_row
);
4922 hpos
= start
- updated_row
->glyphs
[updated_area
];
4923 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4924 updated_row
, updated_area
,
4926 (updated_row
->inverse_p
4927 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4928 &real_start
, &real_end
, 0);
4930 /* If we drew over the cursor, note that it is not visible any more. */
4931 note_overwritten_text_cursor (updated_window
, real_start
,
4932 real_end
- real_start
);
4936 /* Advance the output cursor. */
4937 output_cursor
.hpos
+= len
;
4938 output_cursor
.x
= x
;
4942 /* Insert LEN glyphs from START at the nominal cursor position. */
4945 x_insert_glyphs (start
, len
)
4946 struct glyph
*start
;
4951 int line_height
, shift_by_width
, shifted_region_width
;
4952 struct glyph_row
*row
;
4953 struct glyph
*glyph
;
4954 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4956 xassert (updated_window
&& updated_row
);
4959 f
= XFRAME (WINDOW_FRAME (w
));
4961 /* Get the height of the line we are in. */
4963 line_height
= row
->height
;
4965 /* Get the width of the glyphs to insert. */
4967 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4968 shift_by_width
+= glyph
->pixel_width
;
4970 /* Get the width of the region to shift right. */
4971 shifted_region_width
= (window_box_width (w
, updated_area
)
4976 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4977 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4978 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4979 f
->output_data
.x
->normal_gc
,
4981 shifted_region_width
, line_height
,
4982 frame_x
+ shift_by_width
, frame_y
);
4984 /* Write the glyphs. */
4985 hpos
= start
- row
->glyphs
[updated_area
];
4986 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4987 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4988 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4990 /* Advance the output cursor. */
4991 output_cursor
.hpos
+= len
;
4992 output_cursor
.x
+= shift_by_width
;
4997 /* Delete N glyphs at the nominal cursor position. Not implemented
5008 /* Erase the current text line from the nominal cursor position
5009 (inclusive) to pixel column TO_X (exclusive). The idea is that
5010 everything from TO_X onward is already erased.
5012 TO_X is a pixel position relative to updated_area of
5013 updated_window. TO_X == -1 means clear to the end of this area. */
5016 x_clear_end_of_line (to_x
)
5020 struct window
*w
= updated_window
;
5021 int max_x
, min_y
, max_y
;
5022 int from_x
, from_y
, to_y
;
5024 xassert (updated_window
&& updated_row
);
5025 f
= XFRAME (w
->frame
);
5027 if (updated_row
->full_width_p
)
5029 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5030 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5031 && !w
->pseudo_window_p
)
5032 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5035 max_x
= window_box_width (w
, updated_area
);
5036 max_y
= window_text_bottom_y (w
);
5038 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5039 of window. For TO_X > 0, truncate to end of drawing area. */
5045 to_x
= min (to_x
, max_x
);
5047 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5049 /* Notice if the cursor will be cleared by this operation. */
5050 if (!updated_row
->full_width_p
)
5051 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5053 from_x
= output_cursor
.x
;
5055 /* Translate to frame coordinates. */
5056 if (updated_row
->full_width_p
)
5058 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5059 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5063 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5064 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5067 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5068 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5069 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5071 /* Prevent inadvertently clearing to end of the X window. */
5072 if (to_x
> from_x
&& to_y
> from_y
)
5075 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5076 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5083 /* Clear entire frame. If updating_frame is non-null, clear that
5084 frame. Otherwise clear the selected frame. */
5094 f
= SELECTED_FRAME ();
5096 /* Clearing the frame will erase any cursor, so mark them all as no
5098 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5099 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5100 output_cursor
.x
= -1;
5102 /* We don't set the output cursor here because there will always
5103 follow an explicit cursor_to. */
5105 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5107 /* We have to clear the scroll bars, too. If we have changed
5108 colors or something like that, then they should be notified. */
5109 x_scroll_bar_clear (f
);
5111 XFlush (FRAME_X_DISPLAY (f
));
5117 /* Invert the middle quarter of the frame for .15 sec. */
5119 /* We use the select system call to do the waiting, so we have to make
5120 sure it's available. If it isn't, we just won't do visual bells. */
5122 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5125 /* Subtract the `struct timeval' values X and Y, storing the result in
5126 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5129 timeval_subtract (result
, x
, y
)
5130 struct timeval
*result
, x
, y
;
5132 /* Perform the carry for the later subtraction by updating y. This
5133 is safer because on some systems the tv_sec member is unsigned. */
5134 if (x
.tv_usec
< y
.tv_usec
)
5136 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5137 y
.tv_usec
-= 1000000 * nsec
;
5141 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5143 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5144 y
.tv_usec
+= 1000000 * nsec
;
5148 /* Compute the time remaining to wait. tv_usec is certainly
5150 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5151 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5153 /* Return indication of whether the result should be considered
5155 return x
.tv_sec
< y
.tv_sec
;
5167 /* Create a GC that will use the GXxor function to flip foreground
5168 pixels into background pixels. */
5172 values
.function
= GXxor
;
5173 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5174 ^ f
->output_data
.x
->background_pixel
);
5176 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5177 GCFunction
| GCForeground
, &values
);
5181 /* Get the height not including a menu bar widget. */
5182 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5183 /* Height of each line to flash. */
5184 int flash_height
= FRAME_LINE_HEIGHT (f
);
5185 /* These will be the left and right margins of the rectangles. */
5186 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5187 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5191 /* Don't flash the area between a scroll bar and the frame
5192 edge it is next to. */
5193 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5195 case vertical_scroll_bar_left
:
5196 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5199 case vertical_scroll_bar_right
:
5200 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5207 width
= flash_right
- flash_left
;
5209 /* If window is tall, flash top and bottom line. */
5210 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5212 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5214 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5215 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5216 width
, flash_height
);
5217 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5219 (height
- flash_height
5220 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5221 width
, flash_height
);
5224 /* If it is short, flash it all. */
5225 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5226 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5227 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5232 struct timeval wakeup
;
5234 EMACS_GET_TIME (wakeup
);
5236 /* Compute time to wait until, propagating carry from usecs. */
5237 wakeup
.tv_usec
+= 150000;
5238 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5239 wakeup
.tv_usec
%= 1000000;
5241 /* Keep waiting until past the time wakeup. */
5244 struct timeval timeout
;
5246 EMACS_GET_TIME (timeout
);
5248 /* In effect, timeout = wakeup - timeout.
5249 Break if result would be negative. */
5250 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5253 /* Try to wait that long--but we might wake up sooner. */
5254 select (0, NULL
, NULL
, NULL
, &timeout
);
5258 /* If window is tall, flash top and bottom line. */
5259 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5261 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5263 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5264 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5265 width
, flash_height
);
5266 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5268 (height
- flash_height
5269 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5270 width
, flash_height
);
5273 /* If it is short, flash it all. */
5274 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5275 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5276 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5278 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5286 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5289 /* Make audible bell. */
5294 struct frame
*f
= SELECTED_FRAME ();
5296 if (FRAME_X_DISPLAY (f
))
5298 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5305 XBell (FRAME_X_DISPLAY (f
), 0);
5306 XFlush (FRAME_X_DISPLAY (f
));
5313 /* Specify how many text lines, from the top of the window,
5314 should be affected by insert-lines and delete-lines operations.
5315 This, and those operations, are used only within an update
5316 that is bounded by calls to x_update_begin and x_update_end. */
5319 XTset_terminal_window (n
)
5322 /* This function intentionally left blank. */
5327 /***********************************************************************
5329 ***********************************************************************/
5331 /* Perform an insert-lines or delete-lines operation, inserting N
5332 lines or deleting -N lines at vertical position VPOS. */
5335 x_ins_del_lines (vpos
, n
)
5342 /* Scroll part of the display as described by RUN. */
5345 x_scroll_run (w
, run
)
5349 struct frame
*f
= XFRAME (w
->frame
);
5350 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5352 /* Get frame-relative bounding box of the text display area of W,
5353 without mode lines. Include in this box the flags areas to the
5354 left and right of W. */
5355 window_box (w
, -1, &x
, &y
, &width
, &height
);
5356 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5357 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5359 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5360 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5361 bottom_y
= y
+ height
;
5365 /* Scrolling up. Make sure we don't copy part of the mode
5366 line at the bottom. */
5367 if (from_y
+ run
->height
> bottom_y
)
5368 height
= bottom_y
- from_y
;
5370 height
= run
->height
;
5374 /* Scolling down. Make sure we don't copy over the mode line.
5376 if (to_y
+ run
->height
> bottom_y
)
5377 height
= bottom_y
- to_y
;
5379 height
= run
->height
;
5384 /* Cursor off. Will be switched on again in x_update_window_end. */
5388 XCopyArea (FRAME_X_DISPLAY (f
),
5389 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5390 f
->output_data
.x
->normal_gc
,
5400 /***********************************************************************
5402 ***********************************************************************/
5404 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5405 corner of the exposed rectangle. W and H are width and height of
5406 the exposed area. All are pixel values. W or H zero means redraw
5407 the entire frame. */
5410 expose_frame (f
, x
, y
, w
, h
)
5416 TRACE ((stderr
, "expose_frame "));
5418 /* No need to redraw if frame will be redrawn soon. */
5419 if (FRAME_GARBAGED_P (f
))
5421 TRACE ((stderr
, " garbaged\n"));
5425 /* If basic faces haven't been realized yet, there is no point in
5426 trying to redraw anything. This can happen when we get an expose
5427 event while Emacs is starting, e.g. by moving another window. */
5428 if (FRAME_FACE_CACHE (f
) == NULL
5429 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5431 TRACE ((stderr
, " no faces\n"));
5435 if (w
== 0 || h
== 0)
5438 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5439 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5449 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5450 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5452 if (WINDOWP (f
->tool_bar_window
))
5454 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5455 XRectangle window_rect
;
5456 XRectangle intersection_rect
;
5457 int window_x
, window_y
, window_width
, window_height
;
5460 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5461 window_rect
.x
= window_x
;
5462 window_rect
.y
= window_y
;
5463 window_rect
.width
= window_width
;
5464 window_rect
.height
= window_height
;
5466 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5467 expose_window (w
, &intersection_rect
);
5470 #ifndef USE_X_TOOLKIT
5471 if (WINDOWP (f
->menu_bar_window
))
5473 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5474 XRectangle window_rect
;
5475 XRectangle intersection_rect
;
5476 int window_x
, window_y
, window_width
, window_height
;
5479 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5480 window_rect
.x
= window_x
;
5481 window_rect
.y
= window_y
;
5482 window_rect
.width
= window_width
;
5483 window_rect
.height
= window_height
;
5485 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5486 expose_window (w
, &intersection_rect
);
5488 #endif /* not USE_X_TOOLKIT */
5492 /* Redraw (parts) of all windows in the window tree rooted at W that
5493 intersect R. R contains frame pixel coordinates. */
5496 expose_window_tree (w
, r
)
5502 if (!NILP (w
->hchild
))
5503 expose_window_tree (XWINDOW (w
->hchild
), r
);
5504 else if (!NILP (w
->vchild
))
5505 expose_window_tree (XWINDOW (w
->vchild
), r
);
5508 XRectangle window_rect
;
5509 XRectangle intersection_rect
;
5510 struct frame
*f
= XFRAME (w
->frame
);
5511 int window_x
, window_y
, window_width
, window_height
;
5513 /* Frame-relative pixel rectangle of W. */
5514 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5518 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5519 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5520 window_rect
.y
= window_y
;
5523 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5524 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5526 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5528 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5529 expose_window (w
, &intersection_rect
);
5532 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5537 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5538 which intersects rectangle R. R is in window-relative coordinates. */
5541 expose_area (w
, row
, r
, area
)
5543 struct glyph_row
*row
;
5545 enum glyph_row_area area
;
5548 struct glyph
*first
= row
->glyphs
[area
];
5549 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5553 /* Set x to the window-relative start position for drawing glyphs of
5554 AREA. The first glyph of the text area can be partially visible.
5555 The first glyphs of other areas cannot. */
5556 if (area
== LEFT_MARGIN_AREA
)
5558 else if (area
== TEXT_AREA
)
5559 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5561 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5562 + window_box_width (w
, TEXT_AREA
));
5564 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5565 /* If row extends face to end of line write the whole line. */
5566 x_draw_glyphs (w
, x
, row
, area
,
5568 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5572 /* Find the first glyph that must be redrawn. */
5574 && x
+ first
->pixel_width
< r
->x
)
5576 x
+= first
->pixel_width
;
5580 /* Find the last one. */
5584 && x
< r
->x
+ r
->width
)
5586 x
+= last
->pixel_width
;
5592 x_draw_glyphs (w
, first_x
, row
, area
,
5593 first
- row
->glyphs
[area
],
5594 last
- row
->glyphs
[area
],
5595 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5601 /* Redraw the parts of the glyph row ROW on window W intersecting
5602 rectangle R. R is in window-relative coordinates. */
5605 expose_line (w
, row
, r
)
5607 struct glyph_row
*row
;
5610 xassert (row
->enabled_p
);
5612 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5613 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5614 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5618 if (row
->used
[LEFT_MARGIN_AREA
])
5619 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5620 if (row
->used
[TEXT_AREA
])
5621 expose_area (w
, row
, r
, TEXT_AREA
);
5622 if (row
->used
[RIGHT_MARGIN_AREA
])
5623 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5624 x_draw_row_bitmaps (w
, row
);
5629 /* Return non-zero if W's cursor intersects rectangle R. */
5632 x_phys_cursor_in_rect_p (w
, r
)
5636 XRectangle cr
, result
;
5637 struct glyph
*cursor_glyph
;
5639 cursor_glyph
= get_phys_cursor_glyph (w
);
5642 cr
.x
= w
->phys_cursor
.x
;
5643 cr
.y
= w
->phys_cursor
.y
;
5644 cr
.width
= cursor_glyph
->pixel_width
;
5645 cr
.height
= w
->phys_cursor_height
;
5646 return x_intersect_rectangles (&cr
, r
, &result
);
5653 /* Redraw a rectangle of window W. R is a rectangle in window
5654 relative coordinates. Call this function with input blocked. */
5657 expose_window (w
, r
)
5661 struct glyph_row
*row
;
5663 int yb
= window_text_bottom_y (w
);
5664 int cursor_cleared_p
;
5666 /* If window is not yet fully initialized, do nothing. This can
5667 happen when toolkit scroll bars are used and a window is split.
5668 Reconfiguring the scroll bar will generate an expose for a newly
5670 if (w
->current_matrix
== NULL
)
5673 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5674 r
->x
, r
->y
, r
->width
, r
->height
));
5676 /* Convert to window coordinates. */
5677 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5678 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5680 /* Turn off the cursor. */
5681 if (!w
->pseudo_window_p
5682 && x_phys_cursor_in_rect_p (w
, r
))
5685 cursor_cleared_p
= 1;
5688 cursor_cleared_p
= 0;
5690 /* Find the first row intersecting the rectangle R. */
5691 row
= w
->current_matrix
->rows
;
5693 while (row
->enabled_p
5695 && y
+ row
->height
< r
->y
)
5701 /* Display the text in the rectangle, one text line at a time. */
5702 while (row
->enabled_p
5704 && y
< r
->y
+ r
->height
)
5706 expose_line (w
, row
, r
);
5711 /* Display the mode line if there is one. */
5712 if (WINDOW_WANTS_MODELINE_P (w
)
5713 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5715 && row
->y
< r
->y
+ r
->height
)
5716 expose_line (w
, row
, r
);
5718 if (!w
->pseudo_window_p
)
5720 /* Draw border between windows. */
5721 x_draw_vertical_border (w
);
5723 /* Turn the cursor on again. */
5724 if (cursor_cleared_p
)
5725 x_update_window_cursor (w
, 1);
5730 /* Determine the intersection of two rectangles R1 and R2. Return
5731 the intersection in *RESULT. Value is non-zero if RESULT is not
5735 x_intersect_rectangles (r1
, r2
, result
)
5736 XRectangle
*r1
, *r2
, *result
;
5738 XRectangle
*left
, *right
;
5739 XRectangle
*upper
, *lower
;
5740 int intersection_p
= 0;
5742 /* Rearrange so that R1 is the left-most rectangle. */
5744 left
= r1
, right
= r2
;
5746 left
= r2
, right
= r1
;
5748 /* X0 of the intersection is right.x0, if this is inside R1,
5749 otherwise there is no intersection. */
5750 if (right
->x
<= left
->x
+ left
->width
)
5752 result
->x
= right
->x
;
5754 /* The right end of the intersection is the minimum of the
5755 the right ends of left and right. */
5756 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5759 /* Same game for Y. */
5761 upper
= r1
, lower
= r2
;
5763 upper
= r2
, lower
= r1
;
5765 /* The upper end of the intersection is lower.y0, if this is inside
5766 of upper. Otherwise, there is no intersection. */
5767 if (lower
->y
<= upper
->y
+ upper
->height
)
5769 result
->y
= lower
->y
;
5771 /* The lower end of the intersection is the minimum of the lower
5772 ends of upper and lower. */
5773 result
->height
= (min (lower
->y
+ lower
->height
,
5774 upper
->y
+ upper
->height
)
5780 return intersection_p
;
5791 /* We used to only do this if Vx_no_window_manager was non-nil, but
5792 the ICCCM (section 4.1.6) says that the window's border pixmap
5793 and border pixel are window attributes which are "private to the
5794 client", so we can always change it to whatever we want. */
5796 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5797 f
->output_data
.x
->border_pixel
);
5799 x_update_cursor (f
, 1);
5803 frame_unhighlight (f
)
5806 /* We used to only do this if Vx_no_window_manager was non-nil, but
5807 the ICCCM (section 4.1.6) says that the window's border pixmap
5808 and border pixel are window attributes which are "private to the
5809 client", so we can always change it to whatever we want. */
5811 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5812 f
->output_data
.x
->border_tile
);
5814 x_update_cursor (f
, 1);
5817 /* The focus has changed. Update the frames as necessary to reflect
5818 the new situation. Note that we can't change the selected frame
5819 here, because the Lisp code we are interrupting might become confused.
5820 Each event gets marked with the frame in which it occurred, so the
5821 Lisp code can tell when the switch took place by examining the events. */
5824 x_new_focus_frame (dpyinfo
, frame
)
5825 struct x_display_info
*dpyinfo
;
5826 struct frame
*frame
;
5828 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5830 if (frame
!= dpyinfo
->x_focus_frame
)
5832 /* Set this before calling other routines, so that they see
5833 the correct value of x_focus_frame. */
5834 dpyinfo
->x_focus_frame
= frame
;
5836 if (old_focus
&& old_focus
->auto_lower
)
5837 x_lower_frame (old_focus
);
5840 selected_frame
= frame
;
5841 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5843 Fselect_window (selected_frame
->selected_window
);
5844 choose_minibuf_frame ();
5847 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5848 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5850 pending_autoraise_frame
= 0;
5853 x_frame_rehighlight (dpyinfo
);
5856 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5859 x_mouse_leave (dpyinfo
)
5860 struct x_display_info
*dpyinfo
;
5862 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5865 /* The focus has changed, or we have redirected a frame's focus to
5866 another frame (this happens when a frame uses a surrogate
5867 mini-buffer frame). Shift the highlight as appropriate.
5869 The FRAME argument doesn't necessarily have anything to do with which
5870 frame is being highlighted or un-highlighted; we only use it to find
5871 the appropriate X display info. */
5874 XTframe_rehighlight (frame
)
5875 struct frame
*frame
;
5877 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5881 x_frame_rehighlight (dpyinfo
)
5882 struct x_display_info
*dpyinfo
;
5884 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5886 if (dpyinfo
->x_focus_frame
)
5888 dpyinfo
->x_highlight_frame
5889 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5890 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5891 : dpyinfo
->x_focus_frame
);
5892 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5894 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5895 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5899 dpyinfo
->x_highlight_frame
= 0;
5901 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5904 frame_unhighlight (old_highlight
);
5905 if (dpyinfo
->x_highlight_frame
)
5906 frame_highlight (dpyinfo
->x_highlight_frame
);
5912 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5914 /* Initialize mode_switch_bit and modifier_meaning. */
5916 x_find_modifier_meanings (dpyinfo
)
5917 struct x_display_info
*dpyinfo
;
5919 int min_code
, max_code
;
5922 XModifierKeymap
*mods
;
5924 dpyinfo
->meta_mod_mask
= 0;
5925 dpyinfo
->shift_lock_mask
= 0;
5926 dpyinfo
->alt_mod_mask
= 0;
5927 dpyinfo
->super_mod_mask
= 0;
5928 dpyinfo
->hyper_mod_mask
= 0;
5931 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5933 min_code
= dpyinfo
->display
->min_keycode
;
5934 max_code
= dpyinfo
->display
->max_keycode
;
5937 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5938 min_code
, max_code
- min_code
+ 1,
5940 mods
= XGetModifierMapping (dpyinfo
->display
);
5942 /* Scan the modifier table to see which modifier bits the Meta and
5943 Alt keysyms are on. */
5945 int row
, col
; /* The row and column in the modifier table. */
5947 for (row
= 3; row
< 8; row
++)
5948 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5951 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5953 /* Zeroes are used for filler. Skip them. */
5957 /* Are any of this keycode's keysyms a meta key? */
5961 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5963 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5969 dpyinfo
->meta_mod_mask
|= (1 << row
);
5974 dpyinfo
->alt_mod_mask
|= (1 << row
);
5979 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5984 dpyinfo
->super_mod_mask
|= (1 << row
);
5988 /* Ignore this if it's not on the lock modifier. */
5989 if ((1 << row
) == LockMask
)
5990 dpyinfo
->shift_lock_mask
= LockMask
;
5998 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5999 if (! dpyinfo
->meta_mod_mask
)
6001 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6002 dpyinfo
->alt_mod_mask
= 0;
6005 /* If some keys are both alt and meta,
6006 make them just meta, not alt. */
6007 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6009 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6012 XFree ((char *) syms
);
6013 XFreeModifiermap (mods
);
6016 /* Convert between the modifier bits X uses and the modifier bits
6020 x_x_to_emacs_modifiers (dpyinfo
, state
)
6021 struct x_display_info
*dpyinfo
;
6024 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6025 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6026 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6027 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6028 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6029 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6033 x_emacs_to_x_modifiers (dpyinfo
, state
)
6034 struct x_display_info
*dpyinfo
;
6037 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6038 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6039 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6040 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6041 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6042 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6045 /* Convert a keysym to its name. */
6048 x_get_keysym_name (keysym
)
6054 value
= XKeysymToString (keysym
);
6062 /* Mouse clicks and mouse movement. Rah. */
6064 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6065 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6066 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6067 not force the value into range. */
6070 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6072 register int pix_x
, pix_y
;
6073 register int *x
, *y
;
6077 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6078 even for negative values. */
6080 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6082 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6084 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6085 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6089 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6090 bounds
->height
= f
->output_data
.x
->line_height
;
6091 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6092 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6099 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6100 pix_x
= FRAME_WINDOW_WIDTH (f
);
6104 else if (pix_y
> f
->height
)
6113 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6114 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6115 can't tell the positions because W's display is not up to date,
6119 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6122 int *frame_x
, *frame_y
;
6126 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6127 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6129 if (display_completed
)
6131 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6132 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6133 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6139 *frame_x
+= glyph
->pixel_width
;
6147 *frame_y
= *frame_x
= 0;
6151 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6152 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6157 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6159 If the event is a button press, then note that we have grabbed
6163 construct_mouse_click (result
, event
, f
)
6164 struct input_event
*result
;
6165 XButtonEvent
*event
;
6168 /* Make the event type no_event; we'll change that when we decide
6170 result
->kind
= mouse_click
;
6171 result
->code
= event
->button
- Button1
;
6172 result
->timestamp
= event
->time
;
6173 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6175 | (event
->type
== ButtonRelease
6179 XSETINT (result
->x
, event
->x
);
6180 XSETINT (result
->y
, event
->y
);
6181 XSETFRAME (result
->frame_or_window
, f
);
6187 /* Function to report a mouse movement to the mainstream Emacs code.
6188 The input handler calls this.
6190 We have received a mouse movement event, which is given in *event.
6191 If the mouse is over a different glyph than it was last time, tell
6192 the mainstream emacs code by setting mouse_moved. If not, ask for
6193 another motion event, so we can check again the next time it moves. */
6195 static XMotionEvent last_mouse_motion_event
;
6196 static Lisp_Object last_mouse_motion_frame
;
6199 note_mouse_movement (frame
, event
)
6201 XMotionEvent
*event
;
6203 last_mouse_movement_time
= event
->time
;
6204 last_mouse_motion_event
= *event
;
6205 XSETFRAME (last_mouse_motion_frame
, frame
);
6207 if (event
->window
!= FRAME_X_WINDOW (frame
))
6209 frame
->mouse_moved
= 1;
6210 last_mouse_scroll_bar
= Qnil
;
6211 note_mouse_highlight (frame
, -1, -1);
6214 /* Has the mouse moved off the glyph it was on at the last sighting? */
6215 else if (event
->x
< last_mouse_glyph
.x
6216 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6217 || event
->y
< last_mouse_glyph
.y
6218 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6220 frame
->mouse_moved
= 1;
6221 last_mouse_scroll_bar
= Qnil
;
6222 note_mouse_highlight (frame
, event
->x
, event
->y
);
6226 /* This is used for debugging, to turn off note_mouse_highlight. */
6228 int disable_mouse_highlight
;
6232 /************************************************************************
6234 ************************************************************************/
6236 /* Find the glyph under window-relative coordinates X/Y in window W.
6237 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6238 strings. Return in *HPOS and *VPOS the row and column number of
6239 the glyph found. Return in *AREA the glyph area containing X.
6240 Value is a pointer to the glyph found or null if X/Y is not on
6241 text, or we can't tell because W's current matrix is not up to
6244 static struct glyph
*
6245 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6248 int *hpos
, *vpos
, *area
;
6250 struct glyph
*glyph
, *end
;
6251 struct glyph_row
*row
= NULL
;
6252 int x0
, i
, left_area_width
;
6254 /* Find row containing Y. Give up if some row is not enabled. */
6255 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6257 row
= MATRIX_ROW (w
->current_matrix
, i
);
6258 if (!row
->enabled_p
)
6260 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6267 /* Give up if Y is not in the window. */
6268 if (i
== w
->current_matrix
->nrows
)
6271 /* Get the glyph area containing X. */
6272 if (w
->pseudo_window_p
)
6279 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6280 if (x
< left_area_width
)
6282 *area
= LEFT_MARGIN_AREA
;
6285 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6288 x0
= row
->x
+ left_area_width
;
6292 *area
= RIGHT_MARGIN_AREA
;
6293 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6297 /* Find glyph containing X. */
6298 glyph
= row
->glyphs
[*area
];
6299 end
= glyph
+ row
->used
[*area
];
6302 if (x
< x0
+ glyph
->pixel_width
)
6304 if (w
->pseudo_window_p
)
6306 else if (BUFFERP (glyph
->object
))
6310 x0
+= glyph
->pixel_width
;
6317 *hpos
= glyph
- row
->glyphs
[*area
];
6322 /* Convert frame-relative x/y to coordinates relative to window W.
6323 Takes pseudo-windows into account. */
6326 frame_to_window_pixel_xy (w
, x
, y
)
6330 if (w
->pseudo_window_p
)
6332 /* A pseudo-window is always full-width, and starts at the
6333 left edge of the frame, plus a frame border. */
6334 struct frame
*f
= XFRAME (w
->frame
);
6335 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6336 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6340 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6341 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6346 /* Take proper action when mouse has moved to the mode or top line of
6347 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6348 mode line. X is relative to the start of the text display area of
6349 W, so the width of bitmap areas and scroll bars must be subtracted
6350 to get a position relative to the start of the mode line. */
6353 note_mode_line_highlight (w
, x
, mode_line_p
)
6357 struct frame
*f
= XFRAME (w
->frame
);
6358 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6359 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6360 struct glyph_row
*row
;
6363 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6365 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6369 struct glyph
*glyph
, *end
;
6370 Lisp_Object help
, map
;
6373 /* Find the glyph under X. */
6374 glyph
= row
->glyphs
[TEXT_AREA
];
6375 end
= glyph
+ row
->used
[TEXT_AREA
];
6376 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6377 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6379 && x
>= x0
+ glyph
->pixel_width
)
6381 x0
+= glyph
->pixel_width
;
6386 && STRINGP (glyph
->object
)
6387 && XSTRING (glyph
->object
)->intervals
6388 && glyph
->charpos
>= 0
6389 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6391 /* If we're on a string with `help-echo' text property,
6392 arrange for the help to be displayed. This is done by
6393 setting the global variable help_echo to the help string. */
6394 help
= Fget_text_property (make_number (glyph
->charpos
),
6395 Qhelp_echo
, glyph
->object
);
6399 XSETWINDOW (help_echo_window
, w
);
6400 help_echo_object
= glyph
->object
;
6401 help_echo_pos
= glyph
->charpos
;
6404 /* Change the mouse pointer according to what is under X/Y. */
6405 map
= Fget_text_property (make_number (glyph
->charpos
),
6406 Qlocal_map
, glyph
->object
);
6407 if (!NILP (Fkeymapp (map
)))
6408 cursor
= f
->output_data
.x
->nontext_cursor
;
6411 map
= Fget_text_property (make_number (glyph
->charpos
),
6412 Qkeymap
, glyph
->object
);
6413 if (!NILP (Fkeymapp (map
)))
6414 cursor
= f
->output_data
.x
->nontext_cursor
;
6419 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6423 /* Take proper action when the mouse has moved to position X, Y on
6424 frame F as regards highlighting characters that have mouse-face
6425 properties. Also de-highlighting chars where the mouse was before.
6426 X and Y can be negative or out of range. */
6429 note_mouse_highlight (f
, x
, y
)
6433 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6438 /* When a menu is active, don't highlight because this looks odd. */
6439 #ifdef USE_X_TOOLKIT
6440 if (popup_activated ())
6444 if (disable_mouse_highlight
6445 || !f
->glyphs_initialized_p
)
6448 dpyinfo
->mouse_face_mouse_x
= x
;
6449 dpyinfo
->mouse_face_mouse_y
= y
;
6450 dpyinfo
->mouse_face_mouse_frame
= f
;
6452 if (dpyinfo
->mouse_face_defer
)
6457 dpyinfo
->mouse_face_deferred_gc
= 1;
6461 /* Which window is that in? */
6462 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6464 /* If we were displaying active text in another window, clear that. */
6465 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6466 clear_mouse_face (dpyinfo
);
6468 /* Not on a window -> return. */
6469 if (!WINDOWP (window
))
6472 /* Convert to window-relative pixel coordinates. */
6473 w
= XWINDOW (window
);
6474 frame_to_window_pixel_xy (w
, &x
, &y
);
6476 /* Handle tool-bar window differently since it doesn't display a
6478 if (EQ (window
, f
->tool_bar_window
))
6480 note_tool_bar_highlight (f
, x
, y
);
6484 if (portion
== 1 || portion
== 3)
6486 /* Mouse is on the mode or top line. */
6487 note_mode_line_highlight (w
, x
, portion
== 1);
6491 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6492 f
->output_data
.x
->text_cursor
);
6494 /* Are we in a window whose display is up to date?
6495 And verify the buffer's text has not changed. */
6496 if (/* Within text portion of the window. */
6498 && EQ (w
->window_end_valid
, w
->buffer
)
6499 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6500 && (XFASTINT (w
->last_overlay_modified
)
6501 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6503 int hpos
, vpos
, pos
, i
, area
;
6504 struct glyph
*glyph
;
6506 /* Find the glyph under X/Y. */
6507 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6509 /* Clear mouse face if X/Y not over text. */
6511 || area
!= TEXT_AREA
6512 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6514 clear_mouse_face (dpyinfo
);
6518 pos
= glyph
->charpos
;
6519 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6521 /* Check for mouse-face and help-echo. */
6523 Lisp_Object mouse_face
, overlay
, position
;
6524 Lisp_Object
*overlay_vec
;
6526 struct buffer
*obuf
;
6529 /* If we get an out-of-range value, return now; avoid an error. */
6530 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6533 /* Make the window's buffer temporarily current for
6534 overlays_at and compute_char_face. */
6535 obuf
= current_buffer
;
6536 current_buffer
= XBUFFER (w
->buffer
);
6542 /* Is this char mouse-active or does it have help-echo? */
6543 XSETINT (position
, pos
);
6545 /* Put all the overlays we want in a vector in overlay_vec.
6546 Store the length in len. If there are more than 10, make
6547 enough space for all, and try again. */
6549 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6550 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6551 if (noverlays
> len
)
6554 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6555 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6558 /* Sort overlays into increasing priority order. */
6559 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6561 /* Check mouse-face highlighting. */
6562 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6563 && vpos
>= dpyinfo
->mouse_face_beg_row
6564 && vpos
<= dpyinfo
->mouse_face_end_row
6565 && (vpos
> dpyinfo
->mouse_face_beg_row
6566 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6567 && (vpos
< dpyinfo
->mouse_face_end_row
6568 || hpos
< dpyinfo
->mouse_face_end_col
6569 || dpyinfo
->mouse_face_past_end
)))
6571 /* Clear the display of the old active region, if any. */
6572 clear_mouse_face (dpyinfo
);
6574 /* Find the highest priority overlay that has a mouse-face prop. */
6576 for (i
= noverlays
- 1; i
>= 0; --i
)
6578 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6579 if (!NILP (mouse_face
))
6581 overlay
= overlay_vec
[i
];
6586 /* If no overlay applies, get a text property. */
6588 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6590 /* Handle the overlay case. */
6591 if (! NILP (overlay
))
6593 /* Find the range of text around this char that
6594 should be active. */
6595 Lisp_Object before
, after
;
6598 before
= Foverlay_start (overlay
);
6599 after
= Foverlay_end (overlay
);
6600 /* Record this as the current active region. */
6601 fast_find_position (w
, XFASTINT (before
),
6602 &dpyinfo
->mouse_face_beg_col
,
6603 &dpyinfo
->mouse_face_beg_row
,
6604 &dpyinfo
->mouse_face_beg_x
,
6605 &dpyinfo
->mouse_face_beg_y
);
6606 dpyinfo
->mouse_face_past_end
6607 = !fast_find_position (w
, XFASTINT (after
),
6608 &dpyinfo
->mouse_face_end_col
,
6609 &dpyinfo
->mouse_face_end_row
,
6610 &dpyinfo
->mouse_face_end_x
,
6611 &dpyinfo
->mouse_face_end_y
);
6612 dpyinfo
->mouse_face_window
= window
;
6613 dpyinfo
->mouse_face_face_id
6614 = face_at_buffer_position (w
, pos
, 0, 0,
6615 &ignore
, pos
+ 1, 1);
6617 /* Display it as active. */
6618 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6620 /* Handle the text property case. */
6621 else if (! NILP (mouse_face
))
6623 /* Find the range of text around this char that
6624 should be active. */
6625 Lisp_Object before
, after
, beginning
, end
;
6628 beginning
= Fmarker_position (w
->start
);
6629 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6630 - XFASTINT (w
->window_end_pos
)));
6632 = Fprevious_single_property_change (make_number (pos
+ 1),
6634 w
->buffer
, beginning
);
6636 = Fnext_single_property_change (position
, Qmouse_face
,
6638 /* Record this as the current active region. */
6639 fast_find_position (w
, XFASTINT (before
),
6640 &dpyinfo
->mouse_face_beg_col
,
6641 &dpyinfo
->mouse_face_beg_row
,
6642 &dpyinfo
->mouse_face_beg_x
,
6643 &dpyinfo
->mouse_face_beg_y
);
6644 dpyinfo
->mouse_face_past_end
6645 = !fast_find_position (w
, XFASTINT (after
),
6646 &dpyinfo
->mouse_face_end_col
,
6647 &dpyinfo
->mouse_face_end_row
,
6648 &dpyinfo
->mouse_face_end_x
,
6649 &dpyinfo
->mouse_face_end_y
);
6650 dpyinfo
->mouse_face_window
= window
;
6651 dpyinfo
->mouse_face_face_id
6652 = face_at_buffer_position (w
, pos
, 0, 0,
6653 &ignore
, pos
+ 1, 1);
6655 /* Display it as active. */
6656 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6660 /* Look for a `help-echo' property. */
6662 Lisp_Object help
, overlay
;
6664 /* Check overlays first. */
6666 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6668 overlay
= overlay_vec
[i
];
6669 help
= Foverlay_get (overlay
, Qhelp_echo
);
6675 help_echo_window
= window
;
6676 help_echo_object
= overlay
;
6677 help_echo_pos
= pos
;
6681 /* Try text properties. */
6682 if ((STRINGP (glyph
->object
)
6683 && glyph
->charpos
>= 0
6684 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6685 || (BUFFERP (glyph
->object
)
6686 && glyph
->charpos
>= BEGV
6687 && glyph
->charpos
< ZV
))
6688 help
= Fget_text_property (make_number (glyph
->charpos
),
6689 Qhelp_echo
, glyph
->object
);
6694 help_echo_window
= window
;
6695 help_echo_object
= glyph
->object
;
6696 help_echo_pos
= glyph
->charpos
;
6703 current_buffer
= obuf
;
6709 redo_mouse_highlight ()
6711 if (!NILP (last_mouse_motion_frame
)
6712 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6713 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6714 last_mouse_motion_event
.x
,
6715 last_mouse_motion_event
.y
);
6720 /***********************************************************************
6722 ***********************************************************************/
6724 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6725 struct glyph
**, int *, int *, int *));
6727 /* Tool-bar item index of the item on which a mouse button was pressed
6730 static int last_tool_bar_item
;
6733 /* Get information about the tool-bar item at position X/Y on frame F.
6734 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6735 the current matrix of the tool-bar window of F, or NULL if not
6736 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6737 item in F->current_tool_bar_items. Value is
6739 -1 if X/Y is not on a tool-bar item
6740 0 if X/Y is on the same item that was highlighted before.
6744 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6747 struct glyph
**glyph
;
6748 int *hpos
, *vpos
, *prop_idx
;
6750 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6751 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6754 /* Find the glyph under X/Y. */
6755 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6759 /* Get the start of this tool-bar item's properties in
6760 f->current_tool_bar_items. */
6761 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6764 /* Is mouse on the highlighted item? */
6765 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6766 && *vpos
>= dpyinfo
->mouse_face_beg_row
6767 && *vpos
<= dpyinfo
->mouse_face_end_row
6768 && (*vpos
> dpyinfo
->mouse_face_beg_row
6769 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6770 && (*vpos
< dpyinfo
->mouse_face_end_row
6771 || *hpos
< dpyinfo
->mouse_face_end_col
6772 || dpyinfo
->mouse_face_past_end
))
6779 /* Handle mouse button event on the tool-bar of frame F, at
6780 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6784 x_handle_tool_bar_click (f
, button_event
)
6786 XButtonEvent
*button_event
;
6788 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6789 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6790 int hpos
, vpos
, prop_idx
;
6791 struct glyph
*glyph
;
6792 Lisp_Object enabled_p
;
6793 int x
= button_event
->x
;
6794 int y
= button_event
->y
;
6796 /* If not on the highlighted tool-bar item, return. */
6797 frame_to_window_pixel_xy (w
, &x
, &y
);
6798 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6801 /* If item is disabled, do nothing. */
6802 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6803 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6804 if (NILP (enabled_p
))
6807 if (button_event
->type
== ButtonPress
)
6809 /* Show item in pressed state. */
6810 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6811 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6812 last_tool_bar_item
= prop_idx
;
6816 Lisp_Object key
, frame
;
6817 struct input_event event
;
6819 /* Show item in released state. */
6820 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6821 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6823 key
= (XVECTOR (f
->current_tool_bar_items
)
6824 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6826 XSETFRAME (frame
, f
);
6827 event
.kind
= TOOL_BAR_EVENT
;
6828 event
.frame_or_window
= frame
;
6830 kbd_buffer_store_event (&event
);
6832 event
.kind
= TOOL_BAR_EVENT
;
6833 event
.frame_or_window
= frame
;
6835 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6836 button_event
->state
);
6837 kbd_buffer_store_event (&event
);
6838 last_tool_bar_item
= -1;
6843 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6844 tool-bar window-relative coordinates X/Y. Called from
6845 note_mouse_highlight. */
6848 note_tool_bar_highlight (f
, x
, y
)
6852 Lisp_Object window
= f
->tool_bar_window
;
6853 struct window
*w
= XWINDOW (window
);
6854 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6856 struct glyph
*glyph
;
6857 struct glyph_row
*row
;
6859 Lisp_Object enabled_p
;
6861 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6862 int mouse_down_p
, rc
;
6864 /* Function note_mouse_highlight is called with negative x(y
6865 values when mouse moves outside of the frame. */
6866 if (x
<= 0 || y
<= 0)
6868 clear_mouse_face (dpyinfo
);
6872 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6875 /* Not on tool-bar item. */
6876 clear_mouse_face (dpyinfo
);
6880 /* On same tool-bar item as before. */
6883 clear_mouse_face (dpyinfo
);
6885 /* Mouse is down, but on different tool-bar item? */
6886 mouse_down_p
= (dpyinfo
->grabbed
6887 && f
== last_mouse_frame
6888 && FRAME_LIVE_P (f
));
6890 && last_tool_bar_item
!= prop_idx
)
6893 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6894 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6896 /* If tool-bar item is not enabled, don't highlight it. */
6897 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6898 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6899 if (!NILP (enabled_p
))
6901 /* Compute the x-position of the glyph. In front and past the
6902 image is a space. We include this is the highlighted area. */
6903 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6904 for (i
= x
= 0; i
< hpos
; ++i
)
6905 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6907 /* Record this as the current active region. */
6908 dpyinfo
->mouse_face_beg_col
= hpos
;
6909 dpyinfo
->mouse_face_beg_row
= vpos
;
6910 dpyinfo
->mouse_face_beg_x
= x
;
6911 dpyinfo
->mouse_face_beg_y
= row
->y
;
6912 dpyinfo
->mouse_face_past_end
= 0;
6914 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6915 dpyinfo
->mouse_face_end_row
= vpos
;
6916 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6917 dpyinfo
->mouse_face_end_y
= row
->y
;
6918 dpyinfo
->mouse_face_window
= window
;
6919 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6921 /* Display it as active. */
6922 show_mouse_face (dpyinfo
, draw
);
6923 dpyinfo
->mouse_face_image_state
= draw
;
6928 /* Set help_echo to a help string.to display for this tool-bar item.
6929 XTread_socket does the rest. */
6930 help_echo_object
= help_echo_window
= Qnil
;
6932 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6933 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6934 if (NILP (help_echo
))
6935 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6936 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6941 /* Find the glyph matrix position of buffer position POS in window W.
6942 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6943 current glyphs must be up to date. If POS is above window start
6944 return (0, 0, 0, 0). If POS is after end of W, return end of
6948 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6951 int *hpos
, *vpos
, *x
, *y
;
6955 int maybe_next_line_p
= 0;
6956 int line_start_position
;
6957 int yb
= window_text_bottom_y (w
);
6958 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6959 struct glyph_row
*best_row
= row
;
6960 int row_vpos
= 0, best_row_vpos
= 0;
6965 if (row
->used
[TEXT_AREA
])
6966 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6968 line_start_position
= 0;
6970 if (line_start_position
> pos
)
6972 /* If the position sought is the end of the buffer,
6973 don't include the blank lines at the bottom of the window. */
6974 else if (line_start_position
== pos
6975 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6977 maybe_next_line_p
= 1;
6980 else if (line_start_position
> 0)
6983 best_row_vpos
= row_vpos
;
6986 if (row
->y
+ row
->height
>= yb
)
6993 /* Find the right column within BEST_ROW. */
6995 current_x
= best_row
->x
;
6996 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6998 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7001 charpos
= glyph
->charpos
;
7005 *vpos
= best_row_vpos
;
7010 else if (charpos
> pos
)
7012 else if (charpos
> 0)
7015 current_x
+= glyph
->pixel_width
;
7018 /* If we're looking for the end of the buffer,
7019 and we didn't find it in the line we scanned,
7020 use the start of the following line. */
7021 if (maybe_next_line_p
)
7026 current_x
= best_row
->x
;
7029 *vpos
= best_row_vpos
;
7030 *hpos
= lastcol
+ 1;
7037 /* Display the active region described by mouse_face_*
7038 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7041 show_mouse_face (dpyinfo
, draw
)
7042 struct x_display_info
*dpyinfo
;
7043 enum draw_glyphs_face draw
;
7045 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7046 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7048 int cursor_off_p
= 0;
7049 struct cursor_pos saved_cursor
;
7051 saved_cursor
= output_cursor
;
7053 /* If window is in the process of being destroyed, don't bother
7055 if (w
->current_matrix
== NULL
)
7058 /* Recognize when we are called to operate on rows that don't exist
7059 anymore. This can happen when a window is split. */
7060 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7063 set_output_cursor (&w
->phys_cursor
);
7065 /* Note that mouse_face_beg_row etc. are window relative. */
7066 for (i
= dpyinfo
->mouse_face_beg_row
;
7067 i
<= dpyinfo
->mouse_face_end_row
;
7070 int start_hpos
, end_hpos
, start_x
;
7071 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7073 /* Don't do anything if row doesn't have valid contents. */
7074 if (!row
->enabled_p
)
7077 /* For all but the first row, the highlight starts at column 0. */
7078 if (i
== dpyinfo
->mouse_face_beg_row
)
7080 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7081 start_x
= dpyinfo
->mouse_face_beg_x
;
7089 if (i
== dpyinfo
->mouse_face_end_row
)
7090 end_hpos
= dpyinfo
->mouse_face_end_col
;
7092 end_hpos
= row
->used
[TEXT_AREA
];
7094 /* If the cursor's in the text we are about to rewrite, turn the
7096 if (!w
->pseudo_window_p
7097 && i
== output_cursor
.vpos
7098 && output_cursor
.hpos
>= start_hpos
- 1
7099 && output_cursor
.hpos
<= end_hpos
)
7101 x_update_window_cursor (w
, 0);
7105 if (end_hpos
> start_hpos
)
7107 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7108 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7109 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7113 /* If we turned the cursor off, turn it back on. */
7115 x_display_cursor (w
, 1,
7116 output_cursor
.hpos
, output_cursor
.vpos
,
7117 output_cursor
.x
, output_cursor
.y
);
7119 output_cursor
= saved_cursor
;
7123 /* Change the mouse cursor. */
7124 if (draw
== DRAW_NORMAL_TEXT
)
7125 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7126 f
->output_data
.x
->text_cursor
);
7127 else if (draw
== DRAW_MOUSE_FACE
)
7128 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7129 f
->output_data
.x
->cross_cursor
);
7131 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7132 f
->output_data
.x
->nontext_cursor
);
7135 /* Clear out the mouse-highlighted active region.
7136 Redraw it un-highlighted first. */
7139 clear_mouse_face (dpyinfo
)
7140 struct x_display_info
*dpyinfo
;
7145 if (! NILP (dpyinfo
->mouse_face_window
))
7146 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7148 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7149 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7150 dpyinfo
->mouse_face_window
= Qnil
;
7154 /* Clear any mouse-face on window W. This function is part of the
7155 redisplay interface, and is called from try_window_id and similar
7156 functions to ensure the mouse-highlight is off. */
7159 x_clear_mouse_face (w
)
7162 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7165 XSETWINDOW (window
, w
);
7166 if (EQ (window
, dpyinfo
->mouse_face_window
))
7167 clear_mouse_face (dpyinfo
);
7171 /* Just discard the mouse face information for frame F, if any.
7172 This is used when the size of F is changed. */
7175 cancel_mouse_face (f
)
7179 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7181 window
= dpyinfo
->mouse_face_window
;
7182 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7184 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7185 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7186 dpyinfo
->mouse_face_window
= Qnil
;
7190 static struct scroll_bar
*x_window_to_scroll_bar ();
7191 static void x_scroll_bar_report_motion ();
7193 /* Return the current position of the mouse.
7194 *fp should be a frame which indicates which display to ask about.
7196 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7197 and *part to the frame, window, and scroll bar part that the mouse
7198 is over. Set *x and *y to the portion and whole of the mouse's
7199 position on the scroll bar.
7201 If the mouse movement started elsewhere, set *fp to the frame the
7202 mouse is on, *bar_window to nil, and *x and *y to the character cell
7205 Set *time to the server time-stamp for the time at which the mouse
7206 was at this position.
7208 Don't store anything if we don't have a valid set of values to report.
7210 This clears the mouse_moved flag, so we can wait for the next mouse
7214 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7217 Lisp_Object
*bar_window
;
7218 enum scroll_bar_part
*part
;
7220 unsigned long *time
;
7226 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7227 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7233 Window dummy_window
;
7236 Lisp_Object frame
, tail
;
7238 /* Clear the mouse-moved flag for every frame on this display. */
7239 FOR_EACH_FRAME (tail
, frame
)
7240 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7241 XFRAME (frame
)->mouse_moved
= 0;
7243 last_mouse_scroll_bar
= Qnil
;
7245 /* Figure out which root window we're on. */
7246 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7247 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7249 /* The root window which contains the pointer. */
7252 /* Trash which we can't trust if the pointer is on
7253 a different screen. */
7256 /* The position on that root window. */
7259 /* More trash we can't trust. */
7262 /* Modifier keys and pointer buttons, about which
7264 (unsigned int *) &dummy
);
7266 /* Now we have a position on the root; find the innermost window
7267 containing the pointer. */
7271 int parent_x
= 0, parent_y
= 0;
7276 /* XTranslateCoordinates can get errors if the window
7277 structure is changing at the same time this function
7278 is running. So at least we must not crash from them. */
7280 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7282 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7283 && FRAME_LIVE_P (last_mouse_frame
))
7285 /* If mouse was grabbed on a frame, give coords for that frame
7286 even if the mouse is now outside it. */
7287 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7289 /* From-window, to-window. */
7290 root
, FRAME_X_WINDOW (last_mouse_frame
),
7292 /* From-position, to-position. */
7293 root_x
, root_y
, &win_x
, &win_y
,
7297 f1
= last_mouse_frame
;
7303 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7305 /* From-window, to-window. */
7308 /* From-position, to-position. */
7309 root_x
, root_y
, &win_x
, &win_y
,
7314 if (child
== None
|| child
== win
)
7322 /* Now we know that:
7323 win is the innermost window containing the pointer
7324 (XTC says it has no child containing the pointer),
7325 win_x and win_y are the pointer's position in it
7326 (XTC did this the last time through), and
7327 parent_x and parent_y are the pointer's position in win's parent.
7328 (They are what win_x and win_y were when win was child.
7329 If win is the root window, it has no parent, and
7330 parent_{x,y} are invalid, but that's okay, because we'll
7331 never use them in that case.) */
7333 /* Is win one of our frames? */
7334 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7337 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7340 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7342 /* If not, is it one of our scroll bars? */
7345 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7349 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7355 if (f1
== 0 && insist
> 0)
7356 f1
= SELECTED_FRAME ();
7360 /* Ok, we found a frame. Store all the values.
7361 last_mouse_glyph is a rectangle used to reduce the
7362 generation of mouse events. To not miss any motion
7363 events, we must divide the frame into rectangles of the
7364 size of the smallest character that could be displayed
7365 on it, i.e. into the same rectangles that matrices on
7366 the frame are divided into. */
7368 #if OLD_REDISPLAY_CODE
7369 int ignore1
, ignore2
;
7370 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7372 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7376 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7377 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7381 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7382 round down even for negative values. */
7388 last_mouse_glyph
.width
= width
;
7389 last_mouse_glyph
.height
= height
;
7390 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7391 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7398 XSETINT (*x
, win_x
);
7399 XSETINT (*y
, win_y
);
7400 *time
= last_mouse_movement_time
;
7409 #ifdef USE_X_TOOLKIT
7411 /* Atimer callback function for TIMER. Called every 0.1s to process
7412 Xt timeouts, if needed. We must avoid calling XtAppPending as
7413 much as possible because that function does an implicit XFlush
7414 that slows us down. */
7417 x_process_timeouts (timer
)
7418 struct atimer
*timer
;
7420 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7423 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7424 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7429 #endif /* USE_X_TOOLKIT */
7432 /* Scroll bar support. */
7434 /* Given an X window ID, find the struct scroll_bar which manages it.
7435 This can be called in GC, so we have to make sure to strip off mark
7438 static struct scroll_bar
*
7439 x_window_to_scroll_bar (window_id
)
7444 for (tail
= Vframe_list
;
7445 XGCTYPE (tail
) == Lisp_Cons
;
7448 Lisp_Object frame
, bar
, condemned
;
7450 frame
= XCAR (tail
);
7451 /* All elements of Vframe_list should be frames. */
7452 if (! GC_FRAMEP (frame
))
7455 /* Scan this frame's scroll bar list for a scroll bar with the
7457 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7458 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7459 /* This trick allows us to search both the ordinary and
7460 condemned scroll bar lists with one loop. */
7461 ! GC_NILP (bar
) || (bar
= condemned
,
7464 bar
= XSCROLL_BAR (bar
)->next
)
7465 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7466 return XSCROLL_BAR (bar
);
7474 /************************************************************************
7476 ************************************************************************/
7478 #if USE_TOOLKIT_SCROLL_BARS
7480 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7481 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7482 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7483 struct scroll_bar
*));
7484 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7488 /* Id of action hook installed for scroll bars. */
7490 static XtActionHookId action_hook_id
;
7492 /* Lisp window being scrolled. Set when starting to interact with
7493 a toolkit scroll bar, reset to nil when ending the interaction. */
7495 static Lisp_Object window_being_scrolled
;
7497 /* Last scroll bar part sent in xm_scroll_callback. */
7499 static int last_scroll_bar_part
;
7501 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7502 that movements of 1/20 of the screen size are mapped to up/down. */
7504 static Boolean xaw3d_arrow_scroll
;
7506 /* Whether the drag scrolling maintains the mouse at the top of the
7507 thumb. If not, resizing the thumb needs to be done more carefully
7508 to avoid jerkyness. */
7510 static Boolean xaw3d_pick_top
;
7513 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7514 bars are used.. The hook is responsible for detecting when
7515 the user ends an interaction with the scroll bar, and generates
7516 a `end-scroll' scroll_bar_click' event if so. */
7519 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7522 XtPointer client_data
;
7526 Cardinal
*num_params
;
7532 scroll_bar_p
= XmIsScrollBar (widget
);
7533 end_action
= "Release";
7534 #else /* !USE_MOTIF i.e. use Xaw */
7535 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7536 end_action
= "EndScroll";
7537 #endif /* USE_MOTIF */
7540 && strcmp (action_name
, end_action
) == 0
7541 && WINDOWP (window_being_scrolled
))
7545 x_send_scroll_bar_event (window_being_scrolled
,
7546 scroll_bar_end_scroll
, 0, 0);
7547 w
= XWINDOW (window_being_scrolled
);
7548 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7549 window_being_scrolled
= Qnil
;
7550 last_scroll_bar_part
= -1;
7552 /* Xt timeouts no longer needed. */
7553 toolkit_scroll_bar_interaction
= 0;
7558 /* Send a client message with message type Xatom_Scrollbar for a
7559 scroll action to the frame of WINDOW. PART is a value identifying
7560 the part of the scroll bar that was clicked on. PORTION is the
7561 amount to scroll of a whole of WHOLE. */
7564 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7566 int part
, portion
, whole
;
7569 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7570 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7572 /* Construct a ClientMessage event to send to the frame. */
7573 ev
->type
= ClientMessage
;
7574 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7575 ev
->display
= FRAME_X_DISPLAY (f
);
7576 ev
->window
= FRAME_X_WINDOW (f
);
7578 ev
->data
.l
[0] = (long) XFASTINT (window
);
7579 ev
->data
.l
[1] = (long) part
;
7580 ev
->data
.l
[2] = (long) 0;
7581 ev
->data
.l
[3] = (long) portion
;
7582 ev
->data
.l
[4] = (long) whole
;
7584 /* Make Xt timeouts work while the scroll bar is active. */
7585 toolkit_scroll_bar_interaction
= 1;
7587 /* Setting the event mask to zero means that the message will
7588 be sent to the client that created the window, and if that
7589 window no longer exists, no event will be sent. */
7591 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7596 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7600 x_scroll_bar_to_input_event (event
, ievent
)
7602 struct input_event
*ievent
;
7604 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7608 XSETFASTINT (window
, ev
->data
.l
[0]);
7609 f
= XFRAME (XWINDOW (window
)->frame
);
7611 ievent
->kind
= scroll_bar_click
;
7612 ievent
->frame_or_window
= window
;
7614 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7615 ievent
->part
= ev
->data
.l
[1];
7616 ievent
->code
= ev
->data
.l
[2];
7617 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7618 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7619 ievent
->modifiers
= 0;
7625 /* Minimum and maximum values used for Motif scroll bars. */
7628 #define XM_SB_MAX 10000000
7629 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7632 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7633 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7634 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7637 xm_scroll_callback (widget
, client_data
, call_data
)
7639 XtPointer client_data
, call_data
;
7641 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7642 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7644 int part
= -1, whole
= 0, portion
= 0;
7648 case XmCR_DECREMENT
:
7649 bar
->dragging
= Qnil
;
7650 part
= scroll_bar_up_arrow
;
7653 case XmCR_INCREMENT
:
7654 bar
->dragging
= Qnil
;
7655 part
= scroll_bar_down_arrow
;
7658 case XmCR_PAGE_DECREMENT
:
7659 bar
->dragging
= Qnil
;
7660 part
= scroll_bar_above_handle
;
7663 case XmCR_PAGE_INCREMENT
:
7664 bar
->dragging
= Qnil
;
7665 part
= scroll_bar_below_handle
;
7669 bar
->dragging
= Qnil
;
7670 part
= scroll_bar_to_top
;
7673 case XmCR_TO_BOTTOM
:
7674 bar
->dragging
= Qnil
;
7675 part
= scroll_bar_to_bottom
;
7681 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7682 && XINT (bar
->dragging
) <= cs
->value
);
7684 /* Get the slider size. */
7686 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7689 /* At the max position of the scroll bar, do a line-wise
7690 movement. Without doing anything, the LessTif scroll bar
7691 calls us with the same cs->value again and again. If we
7692 want to make sure that we can reach the end of the buffer,
7693 we have to do something.
7695 Implementation note: setting bar->dragging always to
7696 cs->value gives a smoother movement at the max position.
7697 Setting it to nil when doing line-wise movement gives
7698 a better slider behavior. */
7700 if (cs
->value
+ slider_size
== XM_SB_MAX
7702 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7704 part
= scroll_bar_down_arrow
;
7705 bar
->dragging
= Qnil
;
7709 whole
= XM_SB_RANGE
;
7710 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7711 part
= scroll_bar_handle
;
7712 bar
->dragging
= make_number (cs
->value
);
7717 case XmCR_VALUE_CHANGED
:
7723 window_being_scrolled
= bar
->window
;
7724 last_scroll_bar_part
= part
;
7725 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7730 #else /* !USE_MOTIF, i.e. Xaw. */
7733 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7734 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7735 scroll bar struct. CALL_DATA is a pointer to a float saying where
7739 xaw_jump_callback (widget
, client_data
, call_data
)
7741 XtPointer client_data
, call_data
;
7743 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7744 float top
= *(float *) call_data
;
7746 int whole
, portion
, height
;
7749 /* Get the size of the thumb, a value between 0 and 1. */
7751 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7755 portion
= shown
< 1 ? top
* whole
: 0;
7757 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7758 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7759 the bottom, so we force the scrolling whenever we see that we're
7760 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7761 we try to ensure that we always stay two pixels away from the
7763 part
= scroll_bar_down_arrow
;
7765 part
= scroll_bar_handle
;
7767 window_being_scrolled
= bar
->window
;
7768 bar
->dragging
= make_number (portion
);
7769 last_scroll_bar_part
= part
;
7770 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7774 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7775 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7776 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7777 the scroll bar. CALL_DATA is an integer specifying the action that
7778 has taken place. It's magnitude is in the range 0..height of the
7779 scroll bar. Negative values mean scroll towards buffer start.
7780 Values < height of scroll bar mean line-wise movement. */
7783 xaw_scroll_callback (widget
, client_data
, call_data
)
7785 XtPointer client_data
, call_data
;
7787 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7788 int position
= (int) call_data
;
7792 /* Get the height of the scroll bar. */
7794 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7797 if (abs (position
) >= height
)
7798 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
7800 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
7801 it maps line-movement to call_data = max(5, height/20). */
7802 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
7803 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
7805 part
= scroll_bar_move_ratio
;
7807 window_being_scrolled
= bar
->window
;
7808 bar
->dragging
= Qnil
;
7809 last_scroll_bar_part
= part
;
7810 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
7814 #endif /* not USE_MOTIF */
7817 /* Create the widget for scroll bar BAR on frame F. Record the widget
7818 and X window of the scroll bar in BAR. */
7821 x_create_toolkit_scroll_bar (f
, bar
)
7823 struct scroll_bar
*bar
;
7829 char *scroll_bar_name
= "verticalScrollBar";
7830 unsigned long pixel
;
7835 /* LessTif 0.85, problems:
7837 1. When the mouse if over the scroll bar, the scroll bar will
7838 get keyboard events. I didn't find a way to turn this off.
7840 2. Do we have to explicitly set the cursor to get an arrow
7841 cursor (see below)? */
7843 /* Set resources. Create the widget. */
7844 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7845 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7846 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7847 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7848 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7849 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7850 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7852 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7855 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7859 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7862 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7866 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7867 scroll_bar_name
, av
, ac
);
7869 /* Add one callback for everything that can happen. */
7870 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7872 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7874 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7876 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7878 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7880 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7882 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7885 /* Realize the widget. Only after that is the X window created. */
7886 XtRealizeWidget (widget
);
7888 /* Set the cursor to an arrow. I didn't find a resource to do that.
7889 And I'm wondering why it hasn't an arrow cursor by default. */
7890 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7891 f
->output_data
.x
->nontext_cursor
);
7893 #else /* !USE_MOTIF i.e. use Xaw */
7895 /* Set resources. Create the widget. The background of the
7896 Xaw3d scroll bar widget is a little bit light for my taste.
7897 We don't alter it here to let users change it according
7898 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7899 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7900 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7901 /* For smoother scrolling with Xaw3d -sm */
7902 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
7903 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
7905 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7908 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7912 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7915 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7919 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7920 f
->output_data
.x
->edit_widget
, av
, ac
);
7924 char *val
= initial
;
7925 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
7926 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
7928 { /* ARROW_SCROLL */
7929 xaw3d_arrow_scroll
= True
;
7930 /* Isn't that just a personal preference ? -sm */
7931 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
7935 /* Define callbacks. */
7936 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
7937 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
7940 /* Realize the widget. Only after that is the X window created. */
7941 XtRealizeWidget (widget
);
7943 #endif /* !USE_MOTIF */
7945 /* Install an action hook that let's us detect when the user
7946 finishes interacting with a scroll bar. */
7947 if (action_hook_id
== 0)
7948 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7950 /* Remember X window and widget in the scroll bar vector. */
7951 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7952 xwindow
= XtWindow (widget
);
7953 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7959 /* Set the thumb size and position of scroll bar BAR. We are currently
7960 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7963 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7964 struct scroll_bar
*bar
;
7965 int portion
, position
, whole
;
7968 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7974 top
= (float) position
/ whole
;
7975 shown
= (float) portion
/ whole
;
7983 Boolean arrow1_selected
, arrow2_selected
;
7984 unsigned char flags
;
7985 XmScrollBarWidget sb
;
7987 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
7988 is the scroll bar's maximum and MIN is the scroll bar's minimum
7990 size
= shown
* XM_SB_RANGE
;
7991 size
= min (size
, XM_SB_RANGE
);
7992 size
= max (size
, 1);
7994 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7995 value
= top
* XM_SB_RANGE
;
7996 value
= min (value
, XM_SB_MAX
- size
);
7997 value
= max (value
, XM_SB_MIN
);
7999 /* LessTif: Calling XmScrollBarSetValues after an increment or
8000 decrement turns off auto-repeat LessTif-internally. This can
8001 be seen in ScrollBar.c which resets Arrow1Selected and
8002 Arrow2Selected. It also sets internal flags so that LessTif
8003 believes the mouse is in the slider. We either have to change
8004 our code, or work around that by accessing private data. */
8006 sb
= (XmScrollBarWidget
) widget
;
8007 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
8008 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
8009 flags
= sb
->scrollBar
.flags
;
8011 if (NILP (bar
->dragging
))
8012 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8013 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8014 /* This has the negative side effect that the slider value is
8015 not what it would be if we scrolled here using line-wise or
8016 page-wise movement. */
8017 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8020 /* If currently dragging, only update the slider size.
8021 This reduces flicker effects. */
8022 int old_value
, old_size
, increment
, page_increment
;
8024 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8025 &increment
, &page_increment
);
8026 XmScrollBarSetValues (widget
, old_value
,
8027 min (size
, XM_SB_RANGE
- old_value
),
8031 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
8032 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
8033 sb
->scrollBar
.flags
= flags
;
8035 #else /* !USE_MOTIF i.e. use Xaw */
8037 float old_top
, old_shown
;
8039 XtVaGetValues (widget
,
8040 XtNtopOfThumb
, &old_top
,
8041 XtNshown
, &old_shown
,
8045 /* Massage the top+shown values. */
8046 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8047 top
= max (0, min (1, top
));
8050 /* Keep two pixels available for moving the thumb down. */
8051 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8053 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8054 check that your system's configuration file contains a define
8055 for `NARROWPROTO'. See s/freebsd.h for an example. */
8056 if (top
!= old_top
|| shown
!= old_shown
)
8058 if (NILP (bar
->dragging
))
8059 XawScrollbarSetThumb (widget
, top
, shown
);
8063 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8064 int scroll_mode
= 0;
8066 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8067 if (xaw3d_arrow_scroll
)
8069 /* Xaw3d stupidly ignores resize requests while dragging
8070 so we have to make it believe it's not in dragging mode. */
8071 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8072 if (scroll_mode
== 2)
8073 sb
->scrollbar
.scroll_mode
= 0;
8076 /* Try to make the scrolling a tad smoother. */
8077 if (!xaw3d_pick_top
)
8078 shown
= min (shown
, old_shown
);
8080 XawScrollbarSetThumb (widget
, top
, shown
);
8083 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8084 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8089 #endif /* !USE_MOTIF */
8094 #endif /* USE_TOOLKIT_SCROLL_BARS */
8098 /************************************************************************
8099 Scroll bars, general
8100 ************************************************************************/
8102 /* Create a scroll bar and return the scroll bar vector for it. W is
8103 the Emacs window on which to create the scroll bar. TOP, LEFT,
8104 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8107 static struct scroll_bar
*
8108 x_scroll_bar_create (w
, top
, left
, width
, height
)
8110 int top
, left
, width
, height
;
8112 struct frame
*f
= XFRAME (w
->frame
);
8113 struct scroll_bar
*bar
8114 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8118 #if USE_TOOLKIT_SCROLL_BARS
8119 x_create_toolkit_scroll_bar (f
, bar
);
8120 #else /* not USE_TOOLKIT_SCROLL_BARS */
8122 XSetWindowAttributes a
;
8126 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8127 if (a
.background_pixel
== -1)
8128 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8130 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8131 | ButtonMotionMask
| PointerMotionHintMask
8133 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8135 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8137 /* Clear the area of W that will serve as a scroll bar. This is
8138 for the case that a window has been split horizontally. In
8139 this case, no clear_frame is generated to reduce flickering. */
8140 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8142 window_box_height (w
), False
);
8144 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8145 /* Position and size of scroll bar. */
8146 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8148 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8150 /* Border width, depth, class, and visual. */
8157 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8159 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8161 XSETWINDOW (bar
->window
, w
);
8162 XSETINT (bar
->top
, top
);
8163 XSETINT (bar
->left
, left
);
8164 XSETINT (bar
->width
, width
);
8165 XSETINT (bar
->height
, height
);
8166 XSETINT (bar
->start
, 0);
8167 XSETINT (bar
->end
, 0);
8168 bar
->dragging
= Qnil
;
8170 /* Add bar to its frame's list of scroll bars. */
8171 bar
->next
= FRAME_SCROLL_BARS (f
);
8173 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8174 if (!NILP (bar
->next
))
8175 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8177 /* Map the window/widget. */
8178 #if USE_TOOLKIT_SCROLL_BARS
8179 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
8180 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8181 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8183 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8185 #else /* not USE_TOOLKIT_SCROLL_BARS */
8186 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8187 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8194 /* Draw BAR's handle in the proper position.
8196 If the handle is already drawn from START to END, don't bother
8197 redrawing it, unless REBUILD is non-zero; in that case, always
8198 redraw it. (REBUILD is handy for drawing the handle after expose
8201 Normally, we want to constrain the start and end of the handle to
8202 fit inside its rectangle, but if the user is dragging the scroll
8203 bar handle, we want to let them drag it down all the way, so that
8204 the bar's top is as far down as it goes; otherwise, there's no way
8205 to move to the very end of the buffer. */
8207 #ifndef USE_TOOLKIT_SCROLL_BARS
8210 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8211 struct scroll_bar
*bar
;
8215 int dragging
= ! NILP (bar
->dragging
);
8216 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8217 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8218 GC gc
= f
->output_data
.x
->normal_gc
;
8220 /* If the display is already accurate, do nothing. */
8222 && start
== XINT (bar
->start
)
8223 && end
== XINT (bar
->end
))
8229 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8230 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8231 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8233 /* Make sure the values are reasonable, and try to preserve
8234 the distance between start and end. */
8236 int length
= end
- start
;
8240 else if (start
> top_range
)
8242 end
= start
+ length
;
8246 else if (end
> top_range
&& ! dragging
)
8250 /* Store the adjusted setting in the scroll bar. */
8251 XSETINT (bar
->start
, start
);
8252 XSETINT (bar
->end
, end
);
8254 /* Clip the end position, just for display. */
8255 if (end
> top_range
)
8258 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8259 below top positions, to make sure the handle is always at least
8260 that many pixels tall. */
8261 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8263 /* Draw the empty space above the handle. Note that we can't clear
8264 zero-height areas; that means "clear to end of window." */
8266 XClearArea (FRAME_X_DISPLAY (f
), w
,
8268 /* x, y, width, height, and exposures. */
8269 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8270 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8271 inside_width
, start
,
8274 /* Change to proper foreground color if one is specified. */
8275 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8276 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8277 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8279 /* Draw the handle itself. */
8280 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8282 /* x, y, width, height */
8283 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8284 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8285 inside_width
, end
- start
);
8287 /* Restore the foreground color of the GC if we changed it above. */
8288 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8289 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8290 f
->output_data
.x
->foreground_pixel
);
8292 /* Draw the empty space below the handle. Note that we can't
8293 clear zero-height areas; that means "clear to end of window." */
8294 if (end
< inside_height
)
8295 XClearArea (FRAME_X_DISPLAY (f
), w
,
8297 /* x, y, width, height, and exposures. */
8298 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8299 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8300 inside_width
, inside_height
- end
,
8308 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8310 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8314 x_scroll_bar_remove (bar
)
8315 struct scroll_bar
*bar
;
8319 #if USE_TOOLKIT_SCROLL_BARS
8320 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
8321 #else /* not USE_TOOLKIT_SCROLL_BARS */
8323 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8324 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8326 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8328 /* Disassociate this scroll bar from its window. */
8329 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8335 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8336 that we are displaying PORTION characters out of a total of WHOLE
8337 characters, starting at POSITION. If WINDOW has no scroll bar,
8341 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8343 int portion
, whole
, position
;
8345 struct frame
*f
= XFRAME (w
->frame
);
8346 struct scroll_bar
*bar
;
8347 int top
, height
, left
, sb_left
, width
, sb_width
;
8348 int window_x
, window_y
, window_width
, window_height
;
8350 /* Get window dimensions. */
8351 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8353 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8354 height
= window_height
;
8356 /* Compute the left edge of the scroll bar area. */
8357 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8358 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8360 left
= XFASTINT (w
->left
);
8361 left
*= CANON_X_UNIT (f
);
8362 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8364 /* Compute the width of the scroll bar which might be less than
8365 the width of the area reserved for the scroll bar. */
8366 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8367 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8371 /* Compute the left edge of the scroll bar. */
8372 #ifdef USE_TOOLKIT_SCROLL_BARS
8373 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8374 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8376 sb_left
= left
+ (width
- sb_width
) / 2;
8378 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8379 sb_left
= left
+ width
- sb_width
;
8384 /* Does the scroll bar exist yet? */
8385 if (NILP (w
->vertical_scroll_bar
))
8388 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8389 left
, top
, width
, height
, False
);
8391 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8395 /* It may just need to be moved and resized. */
8396 unsigned int mask
= 0;
8398 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8402 if (sb_left
!= XINT (bar
->left
))
8404 if (top
!= XINT (bar
->top
))
8406 if (sb_width
!= XINT (bar
->width
))
8408 if (height
!= XINT (bar
->height
))
8411 #ifdef USE_TOOLKIT_SCROLL_BARS
8413 /* Since toolkit scroll bars are smaller than the space reserved
8414 for them on the frame, we have to clear "under" them. */
8415 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8416 left
, top
, width
, height
, False
);
8418 /* Move/size the scroll bar widget. */
8420 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8421 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8423 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8426 #else /* not USE_TOOLKIT_SCROLL_BARS */
8428 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8430 /* Clear areas not covered by the scroll bar. This makes sure a
8431 previous mode line display is cleared after C-x 2 C-x 1, for
8432 example. Non-toolkit scroll bars are as wide as the area
8433 reserved for scroll bars - trim at both sides. */
8434 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8435 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8437 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8438 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8439 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8443 /* Move/size the scroll bar window. */
8448 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8450 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8452 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8456 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8458 /* Remember new settings. */
8459 XSETINT (bar
->left
, sb_left
);
8460 XSETINT (bar
->top
, top
);
8461 XSETINT (bar
->width
, sb_width
);
8462 XSETINT (bar
->height
, height
);
8467 #if USE_TOOLKIT_SCROLL_BARS
8468 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8469 #else /* not USE_TOOLKIT_SCROLL_BARS */
8470 /* Set the scroll bar's current state, unless we're currently being
8472 if (NILP (bar
->dragging
))
8474 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8477 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8480 int start
= ((double) position
* top_range
) / whole
;
8481 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8482 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8485 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8487 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8491 /* The following three hooks are used when we're doing a thorough
8492 redisplay of the frame. We don't explicitly know which scroll bars
8493 are going to be deleted, because keeping track of when windows go
8494 away is a real pain - "Can you say set-window-configuration, boys
8495 and girls?" Instead, we just assert at the beginning of redisplay
8496 that *all* scroll bars are to be removed, and then save a scroll bar
8497 from the fiery pit when we actually redisplay its window. */
8499 /* Arrange for all scroll bars on FRAME to be removed at the next call
8500 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8501 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8504 XTcondemn_scroll_bars (frame
)
8507 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8508 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8511 bar
= FRAME_SCROLL_BARS (frame
);
8512 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8513 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8514 XSCROLL_BAR (bar
)->prev
= Qnil
;
8515 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8516 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8517 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8521 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8522 Note that WINDOW isn't necessarily condemned at all. */
8524 XTredeem_scroll_bar (window
)
8525 struct window
*window
;
8527 struct scroll_bar
*bar
;
8529 /* We can't redeem this window's scroll bar if it doesn't have one. */
8530 if (NILP (window
->vertical_scroll_bar
))
8533 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8535 /* Unlink it from the condemned list. */
8537 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8539 if (NILP (bar
->prev
))
8541 /* If the prev pointer is nil, it must be the first in one of
8543 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8544 /* It's not condemned. Everything's fine. */
8546 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8547 window
->vertical_scroll_bar
))
8548 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8550 /* If its prev pointer is nil, it must be at the front of
8551 one or the other! */
8555 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8557 if (! NILP (bar
->next
))
8558 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8560 bar
->next
= FRAME_SCROLL_BARS (f
);
8562 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8563 if (! NILP (bar
->next
))
8564 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8568 /* Remove all scroll bars on FRAME that haven't been saved since the
8569 last call to `*condemn_scroll_bars_hook'. */
8572 XTjudge_scroll_bars (f
)
8575 Lisp_Object bar
, next
;
8577 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8579 /* Clear out the condemned list now so we won't try to process any
8580 more events on the hapless scroll bars. */
8581 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8583 for (; ! NILP (bar
); bar
= next
)
8585 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8587 x_scroll_bar_remove (b
);
8590 b
->next
= b
->prev
= Qnil
;
8593 /* Now there should be no references to the condemned scroll bars,
8594 and they should get garbage-collected. */
8598 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8599 is a no-op when using toolkit scroll bars.
8601 This may be called from a signal handler, so we have to ignore GC
8605 x_scroll_bar_expose (bar
, event
)
8606 struct scroll_bar
*bar
;
8609 #ifndef USE_TOOLKIT_SCROLL_BARS
8611 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8612 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8613 GC gc
= f
->output_data
.x
->normal_gc
;
8614 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8618 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8620 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8621 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8623 /* x, y, width, height */
8625 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8626 XINT (bar
->height
) - 1);
8630 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8633 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8634 is set to something other than no_event, it is enqueued.
8636 This may be called from a signal handler, so we have to ignore GC
8639 #ifndef USE_TOOLKIT_SCROLL_BARS
8642 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8643 struct scroll_bar
*bar
;
8645 struct input_event
*emacs_event
;
8647 if (! GC_WINDOWP (bar
->window
))
8650 emacs_event
->kind
= scroll_bar_click
;
8651 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8652 emacs_event
->modifiers
8653 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8654 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8655 event
->xbutton
.state
)
8656 | (event
->type
== ButtonRelease
8659 emacs_event
->frame_or_window
= bar
->window
;
8660 emacs_event
->arg
= Qnil
;
8661 emacs_event
->timestamp
= event
->xbutton
.time
;
8664 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8666 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8669 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8670 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8673 if (y
> top_range
) y
= top_range
;
8675 if (y
< XINT (bar
->start
))
8676 emacs_event
->part
= scroll_bar_above_handle
;
8677 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8678 emacs_event
->part
= scroll_bar_handle
;
8680 emacs_event
->part
= scroll_bar_below_handle
;
8682 /* Just because the user has clicked on the handle doesn't mean
8683 they want to drag it. Lisp code needs to be able to decide
8684 whether or not we're dragging. */
8686 /* If the user has just clicked on the handle, record where they're
8688 if (event
->type
== ButtonPress
8689 && emacs_event
->part
== scroll_bar_handle
)
8690 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8693 /* If the user has released the handle, set it to its final position. */
8694 if (event
->type
== ButtonRelease
8695 && ! NILP (bar
->dragging
))
8697 int new_start
= y
- XINT (bar
->dragging
);
8698 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8700 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8701 bar
->dragging
= Qnil
;
8704 /* Same deal here as the other #if 0. */
8706 /* Clicks on the handle are always reported as occurring at the top of
8708 if (emacs_event
->part
== scroll_bar_handle
)
8709 emacs_event
->x
= bar
->start
;
8711 XSETINT (emacs_event
->x
, y
);
8713 XSETINT (emacs_event
->x
, y
);
8716 XSETINT (emacs_event
->y
, top_range
);
8720 /* Handle some mouse motion while someone is dragging the scroll bar.
8722 This may be called from a signal handler, so we have to ignore GC
8726 x_scroll_bar_note_movement (bar
, event
)
8727 struct scroll_bar
*bar
;
8730 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8732 last_mouse_movement_time
= event
->xmotion
.time
;
8735 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8737 /* If we're dragging the bar, display it. */
8738 if (! GC_NILP (bar
->dragging
))
8740 /* Where should the handle be now? */
8741 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8743 if (new_start
!= XINT (bar
->start
))
8745 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8747 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8752 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8754 /* Return information to the user about the current position of the mouse
8755 on the scroll bar. */
8758 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8760 Lisp_Object
*bar_window
;
8761 enum scroll_bar_part
*part
;
8763 unsigned long *time
;
8765 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8766 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8767 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8769 Window dummy_window
;
8771 unsigned int dummy_mask
;
8775 /* Get the mouse's position relative to the scroll bar window, and
8777 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8779 /* Root, child, root x and root y. */
8780 &dummy_window
, &dummy_window
,
8781 &dummy_coord
, &dummy_coord
,
8783 /* Position relative to scroll bar. */
8786 /* Mouse buttons and modifier keys. */
8793 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8796 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8798 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8800 if (! NILP (bar
->dragging
))
8801 win_y
-= XINT (bar
->dragging
);
8805 if (win_y
> top_range
)
8809 *bar_window
= bar
->window
;
8811 if (! NILP (bar
->dragging
))
8812 *part
= scroll_bar_handle
;
8813 else if (win_y
< XINT (bar
->start
))
8814 *part
= scroll_bar_above_handle
;
8815 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8816 *part
= scroll_bar_handle
;
8818 *part
= scroll_bar_below_handle
;
8820 XSETINT (*x
, win_y
);
8821 XSETINT (*y
, top_range
);
8824 last_mouse_scroll_bar
= Qnil
;
8827 *time
= last_mouse_movement_time
;
8833 /* The screen has been cleared so we may have changed foreground or
8834 background colors, and the scroll bars may need to be redrawn.
8835 Clear out the scroll bars, and ask for expose events, so we can
8839 x_scroll_bar_clear (f
)
8842 #ifndef USE_TOOLKIT_SCROLL_BARS
8845 /* We can have scroll bars even if this is 0,
8846 if we just turned off scroll bar mode.
8847 But in that case we should not clear them. */
8848 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8849 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8850 bar
= XSCROLL_BAR (bar
)->next
)
8851 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8853 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8856 /* This processes Expose events from the menu-bar specific X event
8857 loop in xmenu.c. This allows to redisplay the frame if necessary
8858 when handling menu-bar or pop-up items. */
8861 process_expose_from_menu (event
)
8865 struct x_display_info
*dpyinfo
;
8866 int frame_exposed_p
= 0;
8870 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8871 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8874 if (f
->async_visible
== 0)
8876 f
->async_visible
= 1;
8877 f
->async_iconified
= 0;
8878 f
->output_data
.x
->has_been_visible
= 1;
8879 SET_FRAME_GARBAGED (f
);
8883 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8884 event
.xexpose
.x
, event
.xexpose
.y
,
8885 event
.xexpose
.width
, event
.xexpose
.height
);
8886 frame_exposed_p
= 1;
8891 struct scroll_bar
*bar
8892 = x_window_to_scroll_bar (event
.xexpose
.window
);
8895 x_scroll_bar_expose (bar
, &event
);
8899 return frame_exposed_p
;
8902 /* Define a queue to save up SelectionRequest events for later handling. */
8904 struct selection_event_queue
8907 struct selection_event_queue
*next
;
8910 static struct selection_event_queue
*queue
;
8912 /* Nonzero means queue up certain events--don't process them yet. */
8914 static int x_queue_selection_requests
;
8916 /* Queue up an X event *EVENT, to be processed later. */
8919 x_queue_event (f
, event
)
8923 struct selection_event_queue
*queue_tmp
8924 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8926 if (queue_tmp
!= NULL
)
8928 queue_tmp
->event
= *event
;
8929 queue_tmp
->next
= queue
;
8934 /* Take all the queued events and put them back
8935 so that they get processed afresh. */
8938 x_unqueue_events (display
)
8941 while (queue
!= NULL
)
8943 struct selection_event_queue
*queue_tmp
= queue
;
8944 XPutBackEvent (display
, &queue_tmp
->event
);
8945 queue
= queue_tmp
->next
;
8946 xfree ((char *)queue_tmp
);
8950 /* Start queuing SelectionRequest events. */
8953 x_start_queuing_selection_requests (display
)
8956 x_queue_selection_requests
++;
8959 /* Stop queuing SelectionRequest events. */
8962 x_stop_queuing_selection_requests (display
)
8965 x_queue_selection_requests
--;
8966 x_unqueue_events (display
);
8969 /* The main X event-reading loop - XTread_socket. */
8971 /* Time stamp of enter window event. This is only used by XTread_socket,
8972 but we have to put it out here, since static variables within functions
8973 sometimes don't work. */
8975 static Time enter_timestamp
;
8977 /* This holds the state XLookupString needs to implement dead keys
8978 and other tricks known as "compose processing". _X Window System_
8979 says that a portable program can't use this, but Stephen Gildea assures
8980 me that letting the compiler initialize it to zeros will work okay.
8982 This must be defined outside of XTread_socket, for the same reasons
8983 given for enter_time stamp, above. */
8985 static XComposeStatus compose_status
;
8987 /* Record the last 100 characters stored
8988 to help debug the loss-of-chars-during-GC problem. */
8990 static int temp_index
;
8991 static short temp_buffer
[100];
8993 /* Set this to nonzero to fake an "X I/O error"
8994 on a particular display. */
8996 struct x_display_info
*XTread_socket_fake_io_error
;
8998 /* When we find no input here, we occasionally do a no-op command
8999 to verify that the X server is still running and we can still talk with it.
9000 We try all the open displays, one by one.
9001 This variable is used for cycling thru the displays. */
9003 static struct x_display_info
*next_noop_dpyinfo
;
9005 #define SET_SAVED_MENU_EVENT(size) \
9008 if (f->output_data.x->saved_menu_event == 0) \
9009 f->output_data.x->saved_menu_event \
9010 = (XEvent *) xmalloc (sizeof (XEvent)); \
9011 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9012 if (numchars >= 1) \
9014 bufp->kind = menu_bar_activate_event; \
9015 XSETFRAME (bufp->frame_or_window, f); \
9024 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9025 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9027 /* Read events coming from the X server.
9028 This routine is called by the SIGIO handler.
9029 We return as soon as there are no more events to be read.
9031 Events representing keys are stored in buffer BUFP,
9032 which can hold up to NUMCHARS characters.
9033 We return the number of characters stored into the buffer,
9034 thus pretending to be `read'.
9036 EXPECTED is nonzero if the caller knows input is available. */
9039 XTread_socket (sd
, bufp
, numchars
, expected
)
9041 /* register */ struct input_event
*bufp
;
9042 /* register */ int numchars
;
9049 int event_found
= 0;
9050 struct x_display_info
*dpyinfo
;
9051 struct coding_system coding
;
9053 if (interrupt_input_blocked
)
9055 interrupt_input_pending
= 1;
9059 interrupt_input_pending
= 0;
9062 /* So people can tell when we have read the available input. */
9063 input_signal_count
++;
9066 abort (); /* Don't think this happens. */
9070 /* The input should be decoded if it is from XIM. Currently the
9071 locale of XIM is the same as that of the system. So, we can use
9072 Vlocale_coding_system which is initialized properly at Emacs
9074 setup_coding_system (Vlocale_coding_system
, &coding
);
9075 coding
.src_multibyte
= 0;
9076 coding
.dst_multibyte
= 1;
9077 /* The input is converted to events, thus we can't handle
9078 composition. Anyway, there's no XIM that gives us composition
9080 coding
.composing
= COMPOSITION_DISABLED
;
9082 /* Find the display we are supposed to read input for.
9083 It's the one communicating on descriptor SD. */
9084 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9086 #if 0 /* This ought to be unnecessary; let's verify it. */
9088 /* If available, Xlib uses FIOSNBIO to make the socket
9089 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9090 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9091 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9092 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9093 #endif /* ! defined (FIOSNBIO) */
9096 #if 0 /* This code can't be made to work, with multiple displays,
9097 and appears not to be used on any system any more.
9098 Also keyboard.c doesn't turn O_NDELAY on and off
9099 for X connections. */
9102 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9104 extern int read_alarm_should_throw
;
9105 read_alarm_should_throw
= 1;
9106 XPeekEvent (dpyinfo
->display
, &event
);
9107 read_alarm_should_throw
= 0;
9109 #endif /* HAVE_SELECT */
9113 /* For debugging, this gives a way to fake an I/O error. */
9114 if (dpyinfo
== XTread_socket_fake_io_error
)
9116 XTread_socket_fake_io_error
= 0;
9117 x_io_error_quitter (dpyinfo
->display
);
9120 while (XPending (dpyinfo
->display
))
9122 XNextEvent (dpyinfo
->display
, &event
);
9126 /* Filter events for the current X input method.
9127 XFilterEvent returns non-zero if the input method has
9128 consumed the event. We pass the frame's X window to
9129 XFilterEvent because that's the one for which the IC
9131 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9132 event
.xclient
.window
);
9133 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9143 if (event
.xclient
.message_type
9144 == dpyinfo
->Xatom_wm_protocols
9145 && event
.xclient
.format
== 32)
9147 if (event
.xclient
.data
.l
[0]
9148 == dpyinfo
->Xatom_wm_take_focus
)
9150 /* Use x_any_window_to_frame because this
9151 could be the shell widget window
9152 if the frame has no title bar. */
9153 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9155 /* Not quite sure this is needed -pd */
9156 if (f
&& FRAME_XIC (f
))
9157 XSetICFocus (FRAME_XIC (f
));
9159 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9160 instructs the WM to set the input focus automatically for
9161 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9162 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9163 it has set the focus. So, XSetInputFocus below is not
9166 The call to XSetInputFocus below has also caused trouble. In
9167 cases where the XSetInputFocus done by the WM and the one
9168 below are temporally close (on a fast machine), the call
9169 below can generate additional FocusIn events which confuse
9172 /* Since we set WM_TAKE_FOCUS, we must call
9173 XSetInputFocus explicitly. But not if f is null,
9174 since that might be an event for a deleted frame. */
9177 Display
*d
= event
.xclient
.display
;
9178 /* Catch and ignore errors, in case window has been
9179 iconified by a window manager such as GWM. */
9180 int count
= x_catch_errors (d
);
9181 XSetInputFocus (d
, event
.xclient
.window
,
9182 /* The ICCCM says this is
9183 the only valid choice. */
9185 event
.xclient
.data
.l
[1]);
9186 /* This is needed to detect the error
9187 if there is an error. */
9189 x_uncatch_errors (d
, count
);
9191 /* Not certain about handling scroll bars here */
9194 else if (event
.xclient
.data
.l
[0]
9195 == dpyinfo
->Xatom_wm_save_yourself
)
9197 /* Save state modify the WM_COMMAND property to
9198 something which can reinstate us. This notifies
9199 the session manager, who's looking for such a
9200 PropertyNotify. Can restart processing when
9201 a keyboard or mouse event arrives. */
9204 f
= x_top_window_to_frame (dpyinfo
,
9205 event
.xclient
.window
);
9207 /* This is just so we only give real data once
9208 for a single Emacs process. */
9209 if (f
== SELECTED_FRAME ())
9210 XSetCommand (FRAME_X_DISPLAY (f
),
9211 event
.xclient
.window
,
9212 initial_argv
, initial_argc
);
9214 XSetCommand (FRAME_X_DISPLAY (f
),
9215 event
.xclient
.window
,
9219 else if (event
.xclient
.data
.l
[0]
9220 == dpyinfo
->Xatom_wm_delete_window
)
9223 = x_any_window_to_frame (dpyinfo
,
9224 event
.xclient
.window
);
9231 bufp
->kind
= delete_window_event
;
9232 XSETFRAME (bufp
->frame_or_window
, f
);
9241 else if (event
.xclient
.message_type
9242 == dpyinfo
->Xatom_wm_configure_denied
)
9245 else if (event
.xclient
.message_type
9246 == dpyinfo
->Xatom_wm_window_moved
)
9250 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9252 new_x
= event
.xclient
.data
.s
[0];
9253 new_y
= event
.xclient
.data
.s
[1];
9257 f
->output_data
.x
->left_pos
= new_x
;
9258 f
->output_data
.x
->top_pos
= new_y
;
9262 else if (event
.xclient
.message_type
9263 == dpyinfo
->Xatom_editres
)
9266 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9267 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9270 #endif /* HACK_EDITRES */
9271 else if ((event
.xclient
.message_type
9272 == dpyinfo
->Xatom_DONE
)
9273 || (event
.xclient
.message_type
9274 == dpyinfo
->Xatom_PAGE
))
9276 /* Ghostview job completed. Kill it. We could
9277 reply with "Next" if we received "Page", but we
9278 currently never do because we are interested in
9279 images, only, which should have 1 page. */
9280 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9282 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9283 x_kill_gs_process (pixmap
, f
);
9284 expose_frame (f
, 0, 0, 0, 0);
9286 #ifdef USE_TOOLKIT_SCROLL_BARS
9287 /* Scroll bar callbacks send a ClientMessage from which
9288 we construct an input_event. */
9289 else if (event
.xclient
.message_type
9290 == dpyinfo
->Xatom_Scrollbar
)
9292 x_scroll_bar_to_input_event (&event
, bufp
);
9293 ++bufp
, ++count
, --numchars
;
9296 #endif /* USE_TOOLKIT_SCROLL_BARS */
9302 case SelectionNotify
:
9303 #ifdef USE_X_TOOLKIT
9304 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9306 #endif /* not USE_X_TOOLKIT */
9307 x_handle_selection_notify (&event
.xselection
);
9310 case SelectionClear
: /* Someone has grabbed ownership. */
9311 #ifdef USE_X_TOOLKIT
9312 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9314 #endif /* USE_X_TOOLKIT */
9316 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9321 bufp
->kind
= selection_clear_event
;
9322 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9323 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9324 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9325 bufp
->frame_or_window
= Qnil
;
9334 case SelectionRequest
: /* Someone wants our selection. */
9335 #ifdef USE_X_TOOLKIT
9336 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9338 #endif /* USE_X_TOOLKIT */
9339 if (x_queue_selection_requests
)
9340 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9344 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9349 bufp
->kind
= selection_request_event
;
9350 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9351 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9352 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9353 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9354 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9355 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9356 bufp
->frame_or_window
= Qnil
;
9365 case PropertyNotify
:
9366 #ifdef USE_X_TOOLKIT
9367 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9369 #endif /* not USE_X_TOOLKIT */
9370 x_handle_property_notify (&event
.xproperty
);
9373 case ReparentNotify
:
9374 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9378 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9379 x_real_positions (f
, &x
, &y
);
9380 f
->output_data
.x
->left_pos
= x
;
9381 f
->output_data
.x
->top_pos
= y
;
9386 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9389 if (f
->async_visible
== 0)
9391 f
->async_visible
= 1;
9392 f
->async_iconified
= 0;
9393 f
->output_data
.x
->has_been_visible
= 1;
9394 SET_FRAME_GARBAGED (f
);
9397 expose_frame (x_window_to_frame (dpyinfo
,
9398 event
.xexpose
.window
),
9399 event
.xexpose
.x
, event
.xexpose
.y
,
9400 event
.xexpose
.width
, event
.xexpose
.height
);
9404 #ifdef USE_TOOLKIT_SCROLL_BARS
9405 /* Dispatch event to the widget. */
9407 #else /* not USE_TOOLKIT_SCROLL_BARS */
9408 struct scroll_bar
*bar
9409 = x_window_to_scroll_bar (event
.xexpose
.window
);
9412 x_scroll_bar_expose (bar
, &event
);
9413 #ifdef USE_X_TOOLKIT
9416 #endif /* USE_X_TOOLKIT */
9417 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9421 case GraphicsExpose
: /* This occurs when an XCopyArea's
9422 source area was obscured or not
9424 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9428 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9429 event
.xgraphicsexpose
.width
,
9430 event
.xgraphicsexpose
.height
);
9432 #ifdef USE_X_TOOLKIT
9435 #endif /* USE_X_TOOLKIT */
9438 case NoExpose
: /* This occurs when an XCopyArea's
9439 source area was completely
9444 /* Redo the mouse-highlight after the tooltip has gone. */
9445 if (event
.xmap
.window
== tip_window
)
9448 redo_mouse_highlight ();
9451 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9452 if (f
) /* F may no longer exist if
9453 the frame was deleted. */
9455 /* While a frame is unmapped, display generation is
9456 disabled; you don't want to spend time updating a
9457 display that won't ever be seen. */
9458 f
->async_visible
= 0;
9459 /* We can't distinguish, from the event, whether the window
9460 has become iconified or invisible. So assume, if it
9461 was previously visible, than now it is iconified.
9462 But x_make_frame_invisible clears both
9463 the visible flag and the iconified flag;
9464 and that way, we know the window is not iconified now. */
9465 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9467 f
->async_iconified
= 1;
9469 bufp
->kind
= iconify_event
;
9470 XSETFRAME (bufp
->frame_or_window
, f
);
9480 if (event
.xmap
.window
== tip_window
)
9481 /* The tooltip has been drawn already. Avoid
9482 the SET_FRAME_GARBAGED below. */
9485 /* We use x_top_window_to_frame because map events can
9486 come for sub-windows and they don't mean that the
9487 frame is visible. */
9488 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9491 f
->async_visible
= 1;
9492 f
->async_iconified
= 0;
9493 f
->output_data
.x
->has_been_visible
= 1;
9495 /* wait_reading_process_input will notice this and update
9496 the frame's display structures. */
9497 SET_FRAME_GARBAGED (f
);
9501 bufp
->kind
= deiconify_event
;
9502 XSETFRAME (bufp
->frame_or_window
, f
);
9508 else if (! NILP (Vframe_list
)
9509 && ! NILP (XCDR (Vframe_list
)))
9510 /* Force a redisplay sooner or later
9511 to update the frame titles
9512 in case this is the second frame. */
9513 record_asynch_buffer_change ();
9518 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9521 /* I couldn't find a way to prevent LessTif scroll bars
9522 from consuming key events. */
9525 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9527 if (widget
&& XmIsScrollBar (widget
))
9529 widget
= XtParent (widget
);
9530 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9533 #endif /* USE_MOTIF */
9537 KeySym keysym
, orig_keysym
;
9538 /* al%imercury@uunet.uu.net says that making this 81
9539 instead of 80 fixed a bug whereby meta chars made
9542 It seems that some version of XmbLookupString has
9543 a bug of not returning XBufferOverflow in
9544 status_return even if the input is too long to
9545 fit in 81 bytes. So, we must prepare sufficient
9546 bytes for copy_buffer. 513 bytes (256 chars for
9547 two-byte character set) seems to be a faily good
9548 approximation. -- 2000.8.10 handa@etl.go.jp */
9549 unsigned char copy_buffer
[513];
9550 unsigned char *copy_bufptr
= copy_buffer
;
9551 int copy_bufsiz
= sizeof (copy_buffer
);
9555 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9556 extra_keyboard_modifiers
);
9557 modifiers
= event
.xkey
.state
;
9559 /* This will have to go some day... */
9561 /* make_lispy_event turns chars into control chars.
9562 Don't do it here because XLookupString is too eager. */
9563 event
.xkey
.state
&= ~ControlMask
;
9564 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9565 | dpyinfo
->super_mod_mask
9566 | dpyinfo
->hyper_mod_mask
9567 | dpyinfo
->alt_mod_mask
);
9569 /* In case Meta is ComposeCharacter,
9570 clear its status. According to Markus Ehrnsperger
9571 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9572 this enables ComposeCharacter to work whether or
9573 not it is combined with Meta. */
9574 if (modifiers
& dpyinfo
->meta_mod_mask
)
9575 bzero (&compose_status
, sizeof (compose_status
));
9580 Status status_return
;
9582 nbytes
= XmbLookupString (FRAME_XIC (f
),
9583 &event
.xkey
, copy_bufptr
,
9584 copy_bufsiz
, &keysym
,
9586 if (status_return
== XBufferOverflow
)
9588 copy_bufsiz
= nbytes
+ 1;
9589 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9590 nbytes
= XmbLookupString (FRAME_XIC (f
),
9591 &event
.xkey
, copy_bufptr
,
9592 copy_bufsiz
, &keysym
,
9596 if (status_return
== XLookupNone
)
9598 else if (status_return
== XLookupChars
)
9603 else if (status_return
!= XLookupKeySym
9604 && status_return
!= XLookupBoth
)
9608 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9609 copy_bufsiz
, &keysym
,
9612 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9613 copy_bufsiz
, &keysym
,
9617 orig_keysym
= keysym
;
9621 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9622 || keysym
== XK_Delete
9623 #ifdef XK_ISO_Left_Tab
9624 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9626 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9627 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9628 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9630 /* This recognizes the "extended function keys".
9631 It seems there's no cleaner way.
9632 Test IsModifierKey to avoid handling mode_switch
9634 || ((unsigned) (keysym
) >= XK_Select
9635 && (unsigned)(keysym
) < XK_KP_Space
)
9637 #ifdef XK_dead_circumflex
9638 || orig_keysym
== XK_dead_circumflex
9640 #ifdef XK_dead_grave
9641 || orig_keysym
== XK_dead_grave
9643 #ifdef XK_dead_tilde
9644 || orig_keysym
== XK_dead_tilde
9646 #ifdef XK_dead_diaeresis
9647 || orig_keysym
== XK_dead_diaeresis
9649 #ifdef XK_dead_macron
9650 || orig_keysym
== XK_dead_macron
9652 #ifdef XK_dead_degree
9653 || orig_keysym
== XK_dead_degree
9655 #ifdef XK_dead_acute
9656 || orig_keysym
== XK_dead_acute
9658 #ifdef XK_dead_cedilla
9659 || orig_keysym
== XK_dead_cedilla
9661 #ifdef XK_dead_breve
9662 || orig_keysym
== XK_dead_breve
9664 #ifdef XK_dead_ogonek
9665 || orig_keysym
== XK_dead_ogonek
9667 #ifdef XK_dead_caron
9668 || orig_keysym
== XK_dead_caron
9670 #ifdef XK_dead_doubleacute
9671 || orig_keysym
== XK_dead_doubleacute
9673 #ifdef XK_dead_abovedot
9674 || orig_keysym
== XK_dead_abovedot
9676 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9677 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9678 /* Any "vendor-specific" key is ok. */
9679 || (orig_keysym
& (1 << 28)))
9680 && ! (IsModifierKey (orig_keysym
)
9682 #ifdef XK_Mode_switch
9683 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9686 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9688 #endif /* not HAVE_X11R5 */
9691 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9693 temp_buffer
[temp_index
++] = keysym
;
9694 bufp
->kind
= non_ascii_keystroke
;
9695 bufp
->code
= keysym
;
9696 XSETFRAME (bufp
->frame_or_window
, f
);
9699 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9701 bufp
->timestamp
= event
.xkey
.time
;
9706 else if (numchars
> nbytes
)
9710 unsigned char *p
, *pend
;
9713 for (i
= 0; i
< nbytes
; i
++)
9715 if (temp_index
== (sizeof temp_buffer
9718 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
9721 if (/* If the event is not from XIM, */
9722 event
.xkey
.keycode
!= 0
9723 /* or the current locale doesn't request
9724 decoding of the intup data, ... */
9725 || coding
.type
== coding_type_raw_text
9726 || coding
.type
== coding_type_no_conversion
)
9728 /* ... we can use the input data as is. */
9733 /* We have to decode the input data. */
9737 require
= decoding_buffer_size (&coding
, nbytes
);
9738 p
= (unsigned char *) alloca (require
);
9739 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
9740 decode_coding (&coding
, copy_bufptr
, p
,
9742 nbytes
= coding
.produced
;
9743 nchars
= coding
.produced_char
;
9747 /* Convert the input data to a sequence of
9748 character events. */
9749 for (i
= 0; i
< nbytes
; i
+= len
)
9751 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
9753 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
9755 : multibyte_char_keystroke
);
9757 XSETFRAME (bufp
->frame_or_window
, f
);
9760 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9762 bufp
->timestamp
= event
.xkey
.time
;
9769 if (keysym
== NoSymbol
)
9779 /* Don't dispatch this event since XtDispatchEvent calls
9780 XFilterEvent, and two calls in a row may freeze the
9789 /* Don't dispatch this event since XtDispatchEvent calls
9790 XFilterEvent, and two calls in a row may freeze the
9797 /* Here's a possible interpretation of the whole
9798 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9799 you get a FocusIn event, you have to get a FocusOut
9800 event before you relinquish the focus. If you
9801 haven't received a FocusIn event, then a mere
9802 LeaveNotify is enough to free you. */
9806 int from_menu_bar_p
= 0;
9808 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9810 #ifdef LESSTIF_VERSION
9811 /* When clicking outside of a menu bar popup to close
9812 it, we get a FocusIn/ EnterNotify sequence of
9813 events. The flag event.xcrossing.focus is not set
9814 in the EnterNotify event of that sequence because
9815 the focus is in the menu bar,
9816 event.xcrossing.window is the frame's X window.
9817 Unconditionally setting the focus frame to null in
9818 this case is not the right thing, because no event
9819 follows that could set the focus frame to the right
9822 This could be a LessTif bug, but I wasn't able to
9823 reproduce the behavior in a simple test program.
9825 (gerd, LessTif 0.88.1). */
9827 if (!event
.xcrossing
.focus
9829 && f
->output_data
.x
->menubar_widget
)
9834 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9835 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9836 from_menu_bar_p
= 1;
9838 #endif /* LESSTIF_VERSION */
9840 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9842 /* Avoid nasty pop/raise loops. */
9843 if (f
&& (!(f
->auto_raise
)
9845 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9847 x_new_focus_frame (dpyinfo
, f
);
9848 enter_timestamp
= event
.xcrossing
.time
;
9851 else if (f
== dpyinfo
->x_focus_frame
)
9852 x_new_focus_frame (dpyinfo
, 0);
9854 /* EnterNotify counts as mouse movement,
9855 so update things that depend on mouse position. */
9856 if (f
&& !f
->output_data
.x
->busy_p
)
9857 note_mouse_movement (f
, &event
.xmotion
);
9862 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9863 if (event
.xfocus
.detail
!= NotifyPointer
)
9864 dpyinfo
->x_focus_event_frame
= f
;
9867 x_new_focus_frame (dpyinfo
, f
);
9869 /* Don't stop displaying the initial startup message
9870 for a switch-frame event we don't need. */
9871 if (GC_NILP (Vterminal_frame
)
9872 && GC_CONSP (Vframe_list
)
9873 && !GC_NILP (XCDR (Vframe_list
)))
9875 bufp
->kind
= FOCUS_IN_EVENT
;
9876 XSETFRAME (bufp
->frame_or_window
, f
);
9878 ++bufp
, ++count
, --numchars
;
9883 if (f
&& FRAME_XIC (f
))
9884 XSetICFocus (FRAME_XIC (f
));
9890 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9894 int from_menu_bar_p
= 0;
9896 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9898 /* If we move outside the frame, then we're
9899 certainly no longer on any text in the frame. */
9900 clear_mouse_face (dpyinfo
);
9901 dpyinfo
->mouse_face_mouse_frame
= 0;
9904 /* Generate a nil HELP_EVENT to cancel a help-echo.
9905 Do it only if there's something to cancel.
9906 Otherwise, the startup message is cleared when
9907 the mouse leaves the frame. */
9908 if (any_help_event_p
)
9913 XSETFRAME (frame
, f
);
9914 n
= gen_help_event (bufp
, numchars
,
9915 Qnil
, frame
, Qnil
, Qnil
, 0);
9916 bufp
+= n
, count
+= n
, numchars
-= n
;
9919 #ifdef LESSTIF_VERSION
9920 /* Please see the comment at the start of the
9921 EnterNotify case. */
9922 if (!event
.xcrossing
.focus
9923 && f
->output_data
.x
->menubar_widget
)
9927 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9928 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9929 from_menu_bar_p
= 1;
9931 #endif /* LESSTIF_VERSION */
9933 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9934 x_mouse_leave (dpyinfo
);
9937 if (f
== dpyinfo
->x_focus_event_frame
)
9938 dpyinfo
->x_focus_event_frame
= 0;
9939 if (f
== dpyinfo
->x_focus_frame
)
9940 x_new_focus_frame (dpyinfo
, 0);
9946 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9947 if (event
.xfocus
.detail
!= NotifyPointer
9948 && f
== dpyinfo
->x_focus_event_frame
)
9949 dpyinfo
->x_focus_event_frame
= 0;
9950 if (f
&& f
== dpyinfo
->x_focus_frame
)
9951 x_new_focus_frame (dpyinfo
, 0);
9954 if (f
&& FRAME_XIC (f
))
9955 XUnsetICFocus (FRAME_XIC (f
));
9962 previous_help_echo
= help_echo
;
9963 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
9966 if (dpyinfo
->grabbed
&& last_mouse_frame
9967 && FRAME_LIVE_P (last_mouse_frame
))
9968 f
= last_mouse_frame
;
9970 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9973 note_mouse_movement (f
, &event
.xmotion
);
9976 #ifndef USE_TOOLKIT_SCROLL_BARS
9977 struct scroll_bar
*bar
9978 = x_window_to_scroll_bar (event
.xmotion
.window
);
9981 x_scroll_bar_note_movement (bar
, &event
);
9982 #endif /* USE_TOOLKIT_SCROLL_BARS */
9984 /* If we move outside the frame, then we're
9985 certainly no longer on any text in the frame. */
9986 clear_mouse_face (dpyinfo
);
9989 /* If the contents of the global variable help_echo
9990 has changed, generate a HELP_EVENT. */
9991 if (!NILP (help_echo
)
9992 || !NILP (previous_help_echo
))
9998 XSETFRAME (frame
, f
);
10002 any_help_event_p
= 1;
10003 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10004 help_echo_window
, help_echo_object
,
10006 bufp
+= n
, count
+= n
, numchars
-= n
;
10012 case ConfigureNotify
:
10013 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10016 #ifndef USE_X_TOOLKIT
10017 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10018 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10020 /* In the toolkit version, change_frame_size
10021 is called by the code that handles resizing
10022 of the EmacsFrame widget. */
10024 /* Even if the number of character rows and columns has
10025 not changed, the font size may have changed, so we need
10026 to check the pixel dimensions as well. */
10027 if (columns
!= f
->width
10028 || rows
!= f
->height
10029 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10030 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10032 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10033 SET_FRAME_GARBAGED (f
);
10034 cancel_mouse_face (f
);
10038 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10039 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10041 /* What we have now is the position of Emacs's own window.
10042 Convert that to the position of the window manager window. */
10043 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10044 &f
->output_data
.x
->top_pos
);
10047 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10048 xic_set_statusarea (f
);
10051 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10053 /* Since the WM decorations come below top_pos now,
10054 we must put them below top_pos in the future. */
10055 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10056 x_wm_set_size_hint (f
, (long) 0, 0);
10059 /* Some window managers pass (0,0) as the location of
10060 the window, and the Motif event handler stores it
10061 in the emacs widget, which messes up Motif menus. */
10062 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10064 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10065 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10067 #endif /* USE_MOTIF */
10072 case ButtonRelease
:
10074 /* If we decide we want to generate an event to be seen
10075 by the rest of Emacs, we put it here. */
10076 struct input_event emacs_event
;
10077 int tool_bar_p
= 0;
10079 emacs_event
.kind
= no_event
;
10080 bzero (&compose_status
, sizeof (compose_status
));
10082 if (dpyinfo
->grabbed
10083 && last_mouse_frame
10084 && FRAME_LIVE_P (last_mouse_frame
))
10085 f
= last_mouse_frame
;
10087 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10091 /* Is this in the tool-bar? */
10092 if (WINDOWP (f
->tool_bar_window
)
10093 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10095 Lisp_Object window
;
10098 x
= event
.xbutton
.x
;
10099 y
= event
.xbutton
.y
;
10102 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10103 if (EQ (window
, f
->tool_bar_window
))
10105 x_handle_tool_bar_click (f
, &event
.xbutton
);
10111 if (!dpyinfo
->x_focus_frame
10112 || f
== dpyinfo
->x_focus_frame
)
10113 construct_mouse_click (&emacs_event
, &event
, f
);
10117 #ifndef USE_TOOLKIT_SCROLL_BARS
10118 struct scroll_bar
*bar
10119 = x_window_to_scroll_bar (event
.xbutton
.window
);
10122 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10123 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10126 if (event
.type
== ButtonPress
)
10128 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10129 last_mouse_frame
= f
;
10130 /* Ignore any mouse motion that happened
10131 before this event; any subsequent mouse-movement
10132 Emacs events should reflect only motion after
10133 the ButtonPress. */
10135 f
->mouse_moved
= 0;
10138 last_tool_bar_item
= -1;
10142 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10145 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10147 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10153 #ifdef USE_X_TOOLKIT
10154 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10155 /* For a down-event in the menu bar,
10156 don't pass it to Xt right now.
10157 Instead, save it away
10158 and we will pass it to Xt from kbd_buffer_get_event.
10159 That way, we can run some Lisp code first. */
10160 if (f
&& event
.type
== ButtonPress
10161 /* Verify the event is really within the menu bar
10162 and not just sent to it due to grabbing. */
10163 && event
.xbutton
.x
>= 0
10164 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10165 && event
.xbutton
.y
>= 0
10166 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10167 && event
.xbutton
.same_screen
)
10169 SET_SAVED_BUTTON_EVENT
;
10170 XSETFRAME (last_mouse_press_frame
, f
);
10172 else if (event
.type
== ButtonPress
)
10174 last_mouse_press_frame
= Qnil
;
10178 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10179 but I am trying to be cautious. */
10180 else if (event
.type
== ButtonRelease
)
10182 if (!NILP (last_mouse_press_frame
))
10184 f
= XFRAME (last_mouse_press_frame
);
10185 if (f
->output_data
.x
)
10186 SET_SAVED_BUTTON_EVENT
;
10191 #endif /* USE_MOTIF */
10194 #endif /* USE_X_TOOLKIT */
10198 case CirculateNotify
:
10201 case CirculateRequest
:
10204 case VisibilityNotify
:
10207 case MappingNotify
:
10208 /* Someone has changed the keyboard mapping - update the
10210 switch (event
.xmapping
.request
)
10212 case MappingModifier
:
10213 x_find_modifier_meanings (dpyinfo
);
10214 /* This is meant to fall through. */
10215 case MappingKeyboard
:
10216 XRefreshKeyboardMapping (&event
.xmapping
);
10222 #ifdef USE_X_TOOLKIT
10224 XtDispatchEvent (&event
);
10226 #endif /* USE_X_TOOLKIT */
10234 /* On some systems, an X bug causes Emacs to get no more events
10235 when the window is destroyed. Detect that. (1994.) */
10238 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10239 One XNOOP in 100 loops will make Emacs terminate.
10240 B. Bretthauer, 1994 */
10242 if (x_noop_count
>= 100)
10246 if (next_noop_dpyinfo
== 0)
10247 next_noop_dpyinfo
= x_display_list
;
10249 XNoOp (next_noop_dpyinfo
->display
);
10251 /* Each time we get here, cycle through the displays now open. */
10252 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10256 /* If the focus was just given to an auto-raising frame,
10258 /* ??? This ought to be able to handle more than one such frame. */
10259 if (pending_autoraise_frame
)
10261 x_raise_frame (pending_autoraise_frame
);
10262 pending_autoraise_frame
= 0;
10273 /***********************************************************************
10275 ***********************************************************************/
10277 /* Note if the text cursor of window W has been overwritten by a
10278 drawing operation that outputs N glyphs starting at HPOS in the
10279 line given by output_cursor.vpos. N < 0 means all the rest of the
10280 line after HPOS has been written. */
10283 note_overwritten_text_cursor (w
, hpos
, n
)
10287 if (updated_area
== TEXT_AREA
10288 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10289 && hpos
<= w
->phys_cursor
.hpos
10291 || hpos
+ n
> w
->phys_cursor
.hpos
))
10292 w
->phys_cursor_on_p
= 0;
10296 /* Set clipping for output in glyph row ROW. W is the window in which
10297 we operate. GC is the graphics context to set clipping in.
10298 WHOLE_LINE_P non-zero means include the areas used for truncation
10299 mark display and alike in the clipping rectangle.
10301 ROW may be a text row or, e.g., a mode line. Text rows must be
10302 clipped to the interior of the window dedicated to text display,
10303 mode lines must be clipped to the whole window. */
10306 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10308 struct glyph_row
*row
;
10312 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10313 XRectangle clip_rect
;
10314 int window_x
, window_y
, window_width
, window_height
;
10316 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10318 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10319 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10320 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10321 clip_rect
.width
= window_width
;
10322 clip_rect
.height
= row
->visible_height
;
10324 /* If clipping to the whole line, including trunc marks, extend
10325 the rectangle to the left and increase its width. */
10328 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10329 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10332 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10336 /* Draw a hollow box cursor on window W in glyph row ROW. */
10339 x_draw_hollow_cursor (w
, row
)
10341 struct glyph_row
*row
;
10343 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10344 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10345 Display
*dpy
= FRAME_X_DISPLAY (f
);
10348 struct glyph
*cursor_glyph
;
10351 /* Compute frame-relative coordinates from window-relative
10353 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10354 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10355 + row
->ascent
- w
->phys_cursor_ascent
);
10356 h
= row
->height
- 1;
10358 /* Get the glyph the cursor is on. If we can't tell because
10359 the current matrix is invalid or such, give up. */
10360 cursor_glyph
= get_phys_cursor_glyph (w
);
10361 if (cursor_glyph
== NULL
)
10364 /* Compute the width of the rectangle to draw. If on a stretch
10365 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10366 rectangle as wide as the glyph, but use a canonical character
10368 wd
= cursor_glyph
->pixel_width
- 1;
10369 if (cursor_glyph
->type
== STRETCH_GLYPH
10370 && !x_stretch_cursor_p
)
10371 wd
= min (CANON_X_UNIT (f
), wd
);
10373 /* The foreground of cursor_gc is typically the same as the normal
10374 background color, which can cause the cursor box to be invisible. */
10375 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10376 if (dpyinfo
->scratch_cursor_gc
)
10377 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10379 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10380 GCForeground
, &xgcv
);
10381 gc
= dpyinfo
->scratch_cursor_gc
;
10383 /* Set clipping, draw the rectangle, and reset clipping again. */
10384 x_clip_to_row (w
, row
, gc
, 0);
10385 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10386 XSetClipMask (dpy
, gc
, None
);
10390 /* Draw a bar cursor on window W in glyph row ROW.
10392 Implementation note: One would like to draw a bar cursor with an
10393 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10394 Unfortunately, I didn't find a font yet that has this property set.
10398 x_draw_bar_cursor (w
, row
, width
)
10400 struct glyph_row
*row
;
10403 struct frame
*f
= XFRAME (w
->frame
);
10404 struct glyph
*cursor_glyph
;
10407 unsigned long mask
;
10412 /* If cursor is out of bounds, don't draw garbage. This can happen
10413 in mini-buffer windows when switching between echo area glyphs
10414 and mini-buffer. */
10415 cursor_glyph
= get_phys_cursor_glyph (w
);
10416 if (cursor_glyph
== NULL
)
10419 /* If on an image, draw like a normal cursor. That's usually better
10420 visible than drawing a bar, esp. if the image is large so that
10421 the bar might not be in the window. */
10422 if (cursor_glyph
->type
== IMAGE_GLYPH
)
10424 struct glyph_row
*row
;
10425 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
10426 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
10430 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10431 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10432 xgcv
.graphics_exposures
= 0;
10433 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10434 dpy
= FRAME_X_DISPLAY (f
);
10435 window
= FRAME_X_WINDOW (f
);
10436 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10439 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10442 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10443 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10447 width
= f
->output_data
.x
->cursor_width
;
10449 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10450 x_clip_to_row (w
, row
, gc
, 0);
10451 XFillRectangle (dpy
, window
, gc
,
10453 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10454 min (cursor_glyph
->pixel_width
, width
),
10456 XSetClipMask (dpy
, gc
, None
);
10461 /* Clear the cursor of window W to background color, and mark the
10462 cursor as not shown. This is used when the text where the cursor
10463 is is about to be rewritten. */
10469 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10470 x_update_window_cursor (w
, 0);
10474 /* Draw the cursor glyph of window W in glyph row ROW. See the
10475 comment of x_draw_glyphs for the meaning of HL. */
10478 x_draw_phys_cursor_glyph (w
, row
, hl
)
10480 struct glyph_row
*row
;
10481 enum draw_glyphs_face hl
;
10483 /* If cursor hpos is out of bounds, don't draw garbage. This can
10484 happen in mini-buffer windows when switching between echo area
10485 glyphs and mini-buffer. */
10486 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10488 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10489 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10492 /* When we erase the cursor, and ROW is overlapped by other
10493 rows, make sure that these overlapping parts of other rows
10495 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10497 if (row
> w
->current_matrix
->rows
10498 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10499 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10501 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10502 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10503 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10509 /* Erase the image of a cursor of window W from the screen. */
10512 x_erase_phys_cursor (w
)
10515 struct frame
*f
= XFRAME (w
->frame
);
10516 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10517 int hpos
= w
->phys_cursor
.hpos
;
10518 int vpos
= w
->phys_cursor
.vpos
;
10519 int mouse_face_here_p
= 0;
10520 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10521 struct glyph_row
*cursor_row
;
10522 struct glyph
*cursor_glyph
;
10523 enum draw_glyphs_face hl
;
10525 /* No cursor displayed or row invalidated => nothing to do on the
10527 if (w
->phys_cursor_type
== NO_CURSOR
)
10528 goto mark_cursor_off
;
10530 /* VPOS >= active_glyphs->nrows means that window has been resized.
10531 Don't bother to erase the cursor. */
10532 if (vpos
>= active_glyphs
->nrows
)
10533 goto mark_cursor_off
;
10535 /* If row containing cursor is marked invalid, there is nothing we
10537 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10538 if (!cursor_row
->enabled_p
)
10539 goto mark_cursor_off
;
10541 /* This can happen when the new row is shorter than the old one.
10542 In this case, either x_draw_glyphs or clear_end_of_line
10543 should have cleared the cursor. Note that we wouldn't be
10544 able to erase the cursor in this case because we don't have a
10545 cursor glyph at hand. */
10546 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10547 goto mark_cursor_off
;
10549 /* If the cursor is in the mouse face area, redisplay that when
10550 we clear the cursor. */
10551 if (! NILP (dpyinfo
->mouse_face_window
)
10552 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10553 && (vpos
> dpyinfo
->mouse_face_beg_row
10554 || (vpos
== dpyinfo
->mouse_face_beg_row
10555 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10556 && (vpos
< dpyinfo
->mouse_face_end_row
10557 || (vpos
== dpyinfo
->mouse_face_end_row
10558 && hpos
< dpyinfo
->mouse_face_end_col
))
10559 /* Don't redraw the cursor's spot in mouse face if it is at the
10560 end of a line (on a newline). The cursor appears there, but
10561 mouse highlighting does not. */
10562 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10563 mouse_face_here_p
= 1;
10565 /* Maybe clear the display under the cursor. */
10566 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10569 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10571 cursor_glyph
= get_phys_cursor_glyph (w
);
10572 if (cursor_glyph
== NULL
)
10573 goto mark_cursor_off
;
10575 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10577 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10579 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10581 cursor_glyph
->pixel_width
,
10582 cursor_row
->visible_height
,
10586 /* Erase the cursor by redrawing the character underneath it. */
10587 if (mouse_face_here_p
)
10588 hl
= DRAW_MOUSE_FACE
;
10589 else if (cursor_row
->inverse_p
)
10590 hl
= DRAW_INVERSE_VIDEO
;
10592 hl
= DRAW_NORMAL_TEXT
;
10593 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10596 w
->phys_cursor_on_p
= 0;
10597 w
->phys_cursor_type
= NO_CURSOR
;
10601 /* Display or clear cursor of window W. If ON is zero, clear the
10602 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10603 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10606 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10608 int on
, hpos
, vpos
, x
, y
;
10610 struct frame
*f
= XFRAME (w
->frame
);
10611 int new_cursor_type
;
10612 int new_cursor_width
;
10613 struct glyph_matrix
*current_glyphs
;
10614 struct glyph_row
*glyph_row
;
10615 struct glyph
*glyph
;
10617 /* This is pointless on invisible frames, and dangerous on garbaged
10618 windows and frames; in the latter case, the frame or window may
10619 be in the midst of changing its size, and x and y may be off the
10621 if (! FRAME_VISIBLE_P (f
)
10622 || FRAME_GARBAGED_P (f
)
10623 || vpos
>= w
->current_matrix
->nrows
10624 || hpos
>= w
->current_matrix
->matrix_w
)
10627 /* If cursor is off and we want it off, return quickly. */
10628 if (!on
&& !w
->phys_cursor_on_p
)
10631 current_glyphs
= w
->current_matrix
;
10632 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10633 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10635 /* If cursor row is not enabled, we don't really know where to
10636 display the cursor. */
10637 if (!glyph_row
->enabled_p
)
10639 w
->phys_cursor_on_p
= 0;
10643 xassert (interrupt_input_blocked
);
10645 /* Set new_cursor_type to the cursor we want to be displayed. In a
10646 mini-buffer window, we want the cursor only to appear if we are
10647 reading input from this window. For the selected window, we want
10648 the cursor type given by the frame parameter. If explicitly
10649 marked off, draw no cursor. In all other cases, we want a hollow
10651 new_cursor_width
= -1;
10652 if (cursor_in_echo_area
10653 && FRAME_HAS_MINIBUF_P (f
)
10654 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10656 if (w
== XWINDOW (echo_area_window
))
10657 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10659 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10663 if (w
!= XWINDOW (selected_window
)
10664 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10666 extern int cursor_in_non_selected_windows
;
10668 if (MINI_WINDOW_P (w
) || !cursor_in_non_selected_windows
)
10669 new_cursor_type
= NO_CURSOR
;
10671 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10673 else if (w
->cursor_off_p
)
10674 new_cursor_type
= NO_CURSOR
;
10677 struct buffer
*b
= XBUFFER (w
->buffer
);
10679 if (EQ (b
->cursor_type
, Qt
))
10680 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10682 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10683 &new_cursor_width
);
10687 /* If cursor is currently being shown and we don't want it to be or
10688 it is in the wrong place, or the cursor type is not what we want,
10690 if (w
->phys_cursor_on_p
10692 || w
->phys_cursor
.x
!= x
10693 || w
->phys_cursor
.y
!= y
10694 || new_cursor_type
!= w
->phys_cursor_type
))
10695 x_erase_phys_cursor (w
);
10697 /* If the cursor is now invisible and we want it to be visible,
10699 if (on
&& !w
->phys_cursor_on_p
)
10701 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10702 w
->phys_cursor_height
= glyph_row
->height
;
10704 /* Set phys_cursor_.* before x_draw_.* is called because some
10705 of them may need the information. */
10706 w
->phys_cursor
.x
= x
;
10707 w
->phys_cursor
.y
= glyph_row
->y
;
10708 w
->phys_cursor
.hpos
= hpos
;
10709 w
->phys_cursor
.vpos
= vpos
;
10710 w
->phys_cursor_type
= new_cursor_type
;
10711 w
->phys_cursor_on_p
= 1;
10713 switch (new_cursor_type
)
10715 case HOLLOW_BOX_CURSOR
:
10716 x_draw_hollow_cursor (w
, glyph_row
);
10719 case FILLED_BOX_CURSOR
:
10720 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10724 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10735 if (w
== XWINDOW (f
->selected_window
))
10736 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10737 xic_set_preeditarea (w
, x
, y
);
10742 if (updating_frame
!= f
)
10743 XFlush (FRAME_X_DISPLAY (f
));
10748 /* Display the cursor on window W, or clear it. X and Y are window
10749 relative pixel coordinates. HPOS and VPOS are glyph matrix
10750 positions. If W is not the selected window, display a hollow
10751 cursor. ON non-zero means display the cursor at X, Y which
10752 correspond to HPOS, VPOS, otherwise it is cleared. */
10755 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10757 int on
, hpos
, vpos
, x
, y
;
10760 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10765 /* Display the cursor on window W, or clear it, according to ON_P.
10766 Don't change the cursor's position. */
10769 x_update_cursor (f
, on_p
)
10772 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10776 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10777 in the window tree rooted at W. */
10780 x_update_cursor_in_window_tree (w
, on_p
)
10786 if (!NILP (w
->hchild
))
10787 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10788 else if (!NILP (w
->vchild
))
10789 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10791 x_update_window_cursor (w
, on_p
);
10793 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10798 /* Switch the display of W's cursor on or off, according to the value
10802 x_update_window_cursor (w
, on
)
10806 /* Don't update cursor in windows whose frame is in the process
10807 of being deleted. */
10808 if (w
->current_matrix
)
10811 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10812 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10822 /* Refresh bitmap kitchen sink icon for frame F
10823 when we get an expose event for it. */
10829 /* Normally, the window manager handles this function. */
10832 /* Make the x-window of frame F use the gnu icon bitmap. */
10835 x_bitmap_icon (f
, file
)
10841 if (FRAME_X_WINDOW (f
) == 0)
10844 /* Free up our existing icon bitmap if any. */
10845 if (f
->output_data
.x
->icon_bitmap
> 0)
10846 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10847 f
->output_data
.x
->icon_bitmap
= 0;
10849 if (STRINGP (file
))
10850 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10853 /* Create the GNU bitmap if necessary. */
10854 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10855 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10856 = x_create_bitmap_from_data (f
, gnu_bits
,
10857 gnu_width
, gnu_height
);
10859 /* The first time we create the GNU bitmap,
10860 this increments the ref-count one extra time.
10861 As a result, the GNU bitmap is never freed.
10862 That way, we don't have to worry about allocating it again. */
10863 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10865 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10868 x_wm_set_icon_pixmap (f
, bitmap_id
);
10869 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10875 /* Make the x-window of frame F use a rectangle with text.
10876 Use ICON_NAME as the text. */
10879 x_text_icon (f
, icon_name
)
10883 if (FRAME_X_WINDOW (f
) == 0)
10888 XTextProperty text
;
10889 text
.value
= (unsigned char *) icon_name
;
10890 text
.encoding
= XA_STRING
;
10892 text
.nitems
= strlen (icon_name
);
10893 #ifdef USE_X_TOOLKIT
10894 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10896 #else /* not USE_X_TOOLKIT */
10897 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10898 #endif /* not USE_X_TOOLKIT */
10900 #else /* not HAVE_X11R4 */
10901 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10902 #endif /* not HAVE_X11R4 */
10904 if (f
->output_data
.x
->icon_bitmap
> 0)
10905 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10906 f
->output_data
.x
->icon_bitmap
= 0;
10907 x_wm_set_icon_pixmap (f
, 0);
10912 #define X_ERROR_MESSAGE_SIZE 200
10914 /* If non-nil, this should be a string.
10915 It means catch X errors and store the error message in this string. */
10917 static Lisp_Object x_error_message_string
;
10919 /* An X error handler which stores the error message in
10920 x_error_message_string. This is called from x_error_handler if
10921 x_catch_errors is in effect. */
10924 x_error_catcher (display
, error
)
10926 XErrorEvent
*error
;
10928 XGetErrorText (display
, error
->error_code
,
10929 XSTRING (x_error_message_string
)->data
,
10930 X_ERROR_MESSAGE_SIZE
);
10933 /* Begin trapping X errors for display DPY. Actually we trap X errors
10934 for all displays, but DPY should be the display you are actually
10937 After calling this function, X protocol errors no longer cause
10938 Emacs to exit; instead, they are recorded in the string
10939 stored in x_error_message_string.
10941 Calling x_check_errors signals an Emacs error if an X error has
10942 occurred since the last call to x_catch_errors or x_check_errors.
10944 Calling x_uncatch_errors resumes the normal error handling. */
10946 void x_check_errors ();
10947 static Lisp_Object
x_catch_errors_unwind ();
10950 x_catch_errors (dpy
)
10953 int count
= specpdl_ptr
- specpdl
;
10955 /* Make sure any errors from previous requests have been dealt with. */
10956 XSync (dpy
, False
);
10958 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10960 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10961 XSTRING (x_error_message_string
)->data
[0] = 0;
10966 /* Unbind the binding that we made to check for X errors. */
10969 x_catch_errors_unwind (old_val
)
10970 Lisp_Object old_val
;
10972 x_error_message_string
= old_val
;
10976 /* If any X protocol errors have arrived since the last call to
10977 x_catch_errors or x_check_errors, signal an Emacs error using
10978 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10981 x_check_errors (dpy
, format
)
10985 /* Make sure to catch any errors incurred so far. */
10986 XSync (dpy
, False
);
10988 if (XSTRING (x_error_message_string
)->data
[0])
10989 error (format
, XSTRING (x_error_message_string
)->data
);
10992 /* Nonzero if we had any X protocol errors
10993 since we did x_catch_errors on DPY. */
10996 x_had_errors_p (dpy
)
10999 /* Make sure to catch any errors incurred so far. */
11000 XSync (dpy
, False
);
11002 return XSTRING (x_error_message_string
)->data
[0] != 0;
11005 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11008 x_clear_errors (dpy
)
11011 XSTRING (x_error_message_string
)->data
[0] = 0;
11014 /* Stop catching X protocol errors and let them make Emacs die.
11015 DPY should be the display that was passed to x_catch_errors.
11016 COUNT should be the value that was returned by
11017 the corresponding call to x_catch_errors. */
11020 x_uncatch_errors (dpy
, count
)
11024 unbind_to (count
, Qnil
);
11028 static unsigned int x_wire_count
;
11031 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11036 /* Handle SIGPIPE, which can happen when the connection to a server
11037 simply goes away. SIGPIPE is handled by x_connection_signal.
11038 Don't need to do anything, because the write which caused the
11039 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11040 which will do the appropriate cleanup for us. */
11043 x_connection_signal (signalnum
) /* If we don't have an argument, */
11044 int signalnum
; /* some compilers complain in signal calls. */
11047 /* USG systems forget handlers when they are used;
11048 must reestablish each time */
11049 signal (signalnum
, x_connection_signal
);
11053 /* Handling X errors. */
11055 /* Handle the loss of connection to display DISPLAY. */
11058 x_connection_closed (display
, error_message
)
11060 char *error_message
;
11062 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
11063 Lisp_Object frame
, tail
;
11065 /* Indicate that this display is dead. */
11067 #if 0 /* Closing the display caused a bus error on OpenWindows. */
11068 #ifdef USE_X_TOOLKIT
11069 XtCloseDisplay (display
);
11074 dpyinfo
->display
= 0;
11076 /* First delete frames whose mini-buffers are on frames
11077 that are on the dead display. */
11078 FOR_EACH_FRAME (tail
, frame
)
11080 Lisp_Object minibuf_frame
;
11082 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11083 if (FRAME_X_P (XFRAME (frame
))
11084 && FRAME_X_P (XFRAME (minibuf_frame
))
11085 && ! EQ (frame
, minibuf_frame
)
11086 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11087 Fdelete_frame (frame
, Qt
);
11090 /* Now delete all remaining frames on the dead display.
11091 We are now sure none of these is used as the mini-buffer
11092 for another frame that we need to delete. */
11093 FOR_EACH_FRAME (tail
, frame
)
11094 if (FRAME_X_P (XFRAME (frame
))
11095 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11097 /* Set this to t so that Fdelete_frame won't get confused
11098 trying to find a replacement. */
11099 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11100 Fdelete_frame (frame
, Qt
);
11104 x_delete_display (dpyinfo
);
11106 if (x_display_list
== 0)
11108 fprintf (stderr
, "%s\n", error_message
);
11109 shut_down_emacs (0, 0, Qnil
);
11113 /* Ordinary stack unwind doesn't deal with these. */
11115 sigunblock (sigmask (SIGIO
));
11117 sigunblock (sigmask (SIGALRM
));
11118 TOTALLY_UNBLOCK_INPUT
;
11120 clear_waiting_for_input ();
11121 error ("%s", error_message
);
11124 /* This is the usual handler for X protocol errors.
11125 It kills all frames on the display that we got the error for.
11126 If that was the only one, it prints an error message and kills Emacs. */
11129 x_error_quitter (display
, error
)
11131 XErrorEvent
*error
;
11133 char buf
[256], buf1
[356];
11135 /* Note that there is no real way portable across R3/R4 to get the
11136 original error handler. */
11138 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11139 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11140 buf
, error
->request_code
);
11141 x_connection_closed (display
, buf1
);
11144 /* This is the first-level handler for X protocol errors.
11145 It calls x_error_quitter or x_error_catcher. */
11148 x_error_handler (display
, error
)
11150 XErrorEvent
*error
;
11152 if (! NILP (x_error_message_string
))
11153 x_error_catcher (display
, error
);
11155 x_error_quitter (display
, error
);
11159 /* This is the handler for X IO errors, always.
11160 It kills all frames on the display that we lost touch with.
11161 If that was the only one, it prints an error message and kills Emacs. */
11164 x_io_error_quitter (display
)
11169 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11170 x_connection_closed (display
, buf
);
11174 /* Changing the font of the frame. */
11176 /* Give frame F the font named FONTNAME as its default font, and
11177 return the full name of that font. FONTNAME may be a wildcard
11178 pattern; in that case, we choose some font that fits the pattern.
11179 The return value shows which font we chose. */
11182 x_new_font (f
, fontname
)
11184 register char *fontname
;
11186 struct font_info
*fontp
11187 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11192 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11193 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11194 f
->output_data
.x
->fontset
= -1;
11196 /* Compute the scroll bar width in character columns. */
11197 if (f
->scroll_bar_pixel_width
> 0)
11199 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11200 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11204 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11205 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11208 /* Now make the frame display the given font. */
11209 if (FRAME_X_WINDOW (f
) != 0)
11211 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11212 f
->output_data
.x
->font
->fid
);
11213 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11214 f
->output_data
.x
->font
->fid
);
11215 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11216 f
->output_data
.x
->font
->fid
);
11218 frame_update_line_height (f
);
11219 x_set_window_size (f
, 0, f
->width
, f
->height
);
11222 /* If we are setting a new frame's font for the first time,
11223 there are no faces yet, so this font's height is the line height. */
11224 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11226 return build_string (fontp
->full_name
);
11229 /* Give frame F the fontset named FONTSETNAME as its default font, and
11230 return the full name of that fontset. FONTSETNAME may be a wildcard
11231 pattern; in that case, we choose some fontset that fits the pattern.
11232 The return value shows which fontset we chose. */
11235 x_new_fontset (f
, fontsetname
)
11239 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11240 Lisp_Object result
;
11245 if (f
->output_data
.x
->fontset
== fontset
)
11246 /* This fontset is already set in frame F. There's nothing more
11248 return fontset_name (fontset
);
11250 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11252 if (!STRINGP (result
))
11253 /* Can't load ASCII font. */
11256 /* Since x_new_font doesn't update any fontset information, do it now. */
11257 f
->output_data
.x
->fontset
= fontset
;
11261 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11262 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11265 return build_string (fontsetname
);
11269 /***********************************************************************
11271 ***********************************************************************/
11277 /* XIM destroy callback function, which is called whenever the
11278 connection to input method XIM dies. CLIENT_DATA contains a
11279 pointer to the x_display_info structure corresponding to XIM. */
11282 xim_destroy_callback (xim
, client_data
, call_data
)
11284 XPointer client_data
;
11285 XPointer call_data
;
11287 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11288 Lisp_Object frame
, tail
;
11292 /* No need to call XDestroyIC.. */
11293 FOR_EACH_FRAME (tail
, frame
)
11295 struct frame
*f
= XFRAME (frame
);
11296 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11298 FRAME_XIC (f
) = NULL
;
11299 if (FRAME_XIC_FONTSET (f
))
11301 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11302 FRAME_XIC_FONTSET (f
) = NULL
;
11307 /* No need to call XCloseIM. */
11308 dpyinfo
->xim
= NULL
;
11309 XFree (dpyinfo
->xim_styles
);
11313 #endif /* HAVE_X11R6 */
11315 /* Open the connection to the XIM server on display DPYINFO.
11316 RESOURCE_NAME is the resource name Emacs uses. */
11319 xim_open_dpy (dpyinfo
, resource_name
)
11320 struct x_display_info
*dpyinfo
;
11321 char *resource_name
;
11326 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11327 dpyinfo
->xim
= xim
;
11332 XIMCallback destroy
;
11335 /* Get supported styles and XIM values. */
11336 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11339 destroy
.callback
= xim_destroy_callback
;
11340 destroy
.client_data
= (XPointer
)dpyinfo
;
11341 /* This isn't prptotyped in OSF 5.0. */
11342 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11346 #else /* not USE_XIM */
11347 dpyinfo
->xim
= NULL
;
11348 #endif /* not USE_XIM */
11352 #ifdef HAVE_X11R6_XIM
11356 struct x_display_info
*dpyinfo
;
11357 char *resource_name
;
11360 /* XIM instantiate callback function, which is called whenever an XIM
11361 server is available. DISPLAY is teh display of the XIM.
11362 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11363 when the callback was registered. */
11366 xim_instantiate_callback (display
, client_data
, call_data
)
11368 XPointer client_data
;
11369 XPointer call_data
;
11371 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11372 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11374 /* We don't support multiple XIM connections. */
11378 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11380 /* Create XIC for the existing frames on the same display, as long
11381 as they have no XIC. */
11382 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11384 Lisp_Object tail
, frame
;
11387 FOR_EACH_FRAME (tail
, frame
)
11389 struct frame
*f
= XFRAME (frame
);
11391 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11392 if (FRAME_XIC (f
) == NULL
)
11394 create_frame_xic (f
);
11395 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11396 xic_set_statusarea (f
);
11397 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11399 struct window
*w
= XWINDOW (f
->selected_window
);
11400 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11409 #endif /* HAVE_X11R6_XIM */
11412 /* Open a connection to the XIM server on display DPYINFO.
11413 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11414 connection only at the first time. On X11R6, open the connection
11415 in the XIM instantiate callback function. */
11418 xim_initialize (dpyinfo
, resource_name
)
11419 struct x_display_info
*dpyinfo
;
11420 char *resource_name
;
11423 #ifdef HAVE_X11R6_XIM
11424 struct xim_inst_t
*xim_inst
;
11427 dpyinfo
->xim
= NULL
;
11428 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11429 xim_inst
->dpyinfo
= dpyinfo
;
11430 len
= strlen (resource_name
);
11431 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11432 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11433 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11434 resource_name
, EMACS_CLASS
,
11435 xim_instantiate_callback
,
11436 /* Fixme: This is XPointer in
11437 XFree86 but (XPointer *) on
11438 Tru64, at least. */
11439 (XPointer
) xim_inst
);
11440 #else /* not HAVE_X11R6_XIM */
11441 dpyinfo
->xim
= NULL
;
11442 xim_open_dpy (dpyinfo
, resource_name
);
11443 #endif /* not HAVE_X11R6_XIM */
11445 #else /* not USE_XIM */
11446 dpyinfo
->xim
= NULL
;
11447 #endif /* not USE_XIM */
11451 /* Close the connection to the XIM server on display DPYINFO. */
11454 xim_close_dpy (dpyinfo
)
11455 struct x_display_info
*dpyinfo
;
11458 #ifdef HAVE_X11R6_XIM
11459 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11461 xim_instantiate_callback
, NULL
);
11462 #endif /* not HAVE_X11R6_XIM */
11463 XCloseIM (dpyinfo
->xim
);
11464 dpyinfo
->xim
= NULL
;
11465 XFree (dpyinfo
->xim_styles
);
11466 #endif /* USE_XIM */
11469 #endif /* not HAVE_X11R6_XIM */
11473 /* Calculate the absolute position in frame F
11474 from its current recorded position values and gravity. */
11477 x_calc_absolute_position (f
)
11481 int win_x
= 0, win_y
= 0;
11482 int flags
= f
->output_data
.x
->size_hint_flags
;
11485 /* We have nothing to do if the current position
11486 is already for the top-left corner. */
11487 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11490 #ifdef USE_X_TOOLKIT
11491 this_window
= XtWindow (f
->output_data
.x
->widget
);
11493 this_window
= FRAME_X_WINDOW (f
);
11496 /* Find the position of the outside upper-left corner of
11497 the inner window, with respect to the outer window.
11498 But do this only if we will need the results. */
11499 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11504 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11507 x_clear_errors (FRAME_X_DISPLAY (f
));
11508 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11510 /* From-window, to-window. */
11512 f
->output_data
.x
->parent_desc
,
11514 /* From-position, to-position. */
11515 0, 0, &win_x
, &win_y
,
11517 /* Child of win. */
11519 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11521 Window newroot
, newparent
= 0xdeadbeef;
11522 Window
*newchildren
;
11523 unsigned int nchildren
;
11525 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11526 &newparent
, &newchildren
, &nchildren
))
11529 XFree ((char *) newchildren
);
11531 f
->output_data
.x
->parent_desc
= newparent
;
11537 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11541 /* Treat negative positions as relative to the leftmost bottommost
11542 position that fits on the screen. */
11543 if (flags
& XNegative
)
11544 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11545 - 2 * f
->output_data
.x
->border_width
- win_x
11547 + f
->output_data
.x
->left_pos
);
11549 if (flags
& YNegative
)
11551 int menubar_height
= 0;
11553 #ifdef USE_X_TOOLKIT
11554 if (f
->output_data
.x
->menubar_widget
)
11556 = (f
->output_data
.x
->menubar_widget
->core
.height
11557 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
11560 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11561 - 2 * f
->output_data
.x
->border_width
11565 + f
->output_data
.x
->top_pos
);
11568 /* The left_pos and top_pos
11569 are now relative to the top and left screen edges,
11570 so the flags should correspond. */
11571 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11574 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11575 to really change the position, and 0 when calling from
11576 x_make_frame_visible (in that case, XOFF and YOFF are the current
11577 position values). It is -1 when calling from x_set_frame_parameters,
11578 which means, do adjust for borders but don't change the gravity. */
11581 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11583 register int xoff
, yoff
;
11584 int change_gravity
;
11586 int modified_top
, modified_left
;
11588 if (change_gravity
> 0)
11590 f
->output_data
.x
->top_pos
= yoff
;
11591 f
->output_data
.x
->left_pos
= xoff
;
11592 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11594 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11596 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11597 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11599 x_calc_absolute_position (f
);
11602 x_wm_set_size_hint (f
, (long) 0, 0);
11604 modified_left
= f
->output_data
.x
->left_pos
;
11605 modified_top
= f
->output_data
.x
->top_pos
;
11606 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11607 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11608 /* It is a mystery why we need to add the border_width here
11609 when the frame is already visible, but experiment says we do. */
11610 if (change_gravity
!= 0)
11612 modified_left
+= f
->output_data
.x
->border_width
;
11613 modified_top
+= f
->output_data
.x
->border_width
;
11617 #ifdef USE_X_TOOLKIT
11618 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11619 modified_left
, modified_top
);
11620 #else /* not USE_X_TOOLKIT */
11621 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11622 modified_left
, modified_top
);
11623 #endif /* not USE_X_TOOLKIT */
11627 /* Call this to change the size of frame F's x-window.
11628 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11629 for this size change and subsequent size changes.
11630 Otherwise we leave the window gravity unchanged. */
11633 x_set_window_size (f
, change_gravity
, cols
, rows
)
11635 int change_gravity
;
11638 #ifndef USE_X_TOOLKIT
11639 int pixelwidth
, pixelheight
;
11644 #ifdef USE_X_TOOLKIT
11646 /* The x and y position of the widget is clobbered by the
11647 call to XtSetValues within EmacsFrameSetCharSize.
11648 This is a real kludge, but I don't understand Xt so I can't
11649 figure out a correct fix. Can anyone else tell me? -- rms. */
11650 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11651 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11652 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11653 f
->output_data
.x
->widget
->core
.x
= xpos
;
11654 f
->output_data
.x
->widget
->core
.y
= ypos
;
11657 #else /* not USE_X_TOOLKIT */
11659 check_frame_size (f
, &rows
, &cols
);
11660 f
->output_data
.x
->vertical_scroll_bar_extra
11661 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11663 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11664 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11665 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11666 f
->output_data
.x
->flags_areas_extra
11667 = FRAME_FLAGS_AREA_WIDTH (f
);
11668 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11669 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11671 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11672 x_wm_set_size_hint (f
, (long) 0, 0);
11674 XSync (FRAME_X_DISPLAY (f
), False
);
11675 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11676 pixelwidth
, pixelheight
);
11678 /* Now, strictly speaking, we can't be sure that this is accurate,
11679 but the window manager will get around to dealing with the size
11680 change request eventually, and we'll hear how it went when the
11681 ConfigureNotify event gets here.
11683 We could just not bother storing any of this information here,
11684 and let the ConfigureNotify event set everything up, but that
11685 might be kind of confusing to the Lisp code, since size changes
11686 wouldn't be reported in the frame parameters until some random
11687 point in the future when the ConfigureNotify event arrives.
11689 We pass 1 for DELAY since we can't run Lisp code inside of
11691 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11692 PIXEL_WIDTH (f
) = pixelwidth
;
11693 PIXEL_HEIGHT (f
) = pixelheight
;
11695 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11696 receive in the ConfigureNotify event; if we get what we asked
11697 for, then the event won't cause the screen to become garbaged, so
11698 we have to make sure to do it here. */
11699 SET_FRAME_GARBAGED (f
);
11701 XFlush (FRAME_X_DISPLAY (f
));
11703 #endif /* not USE_X_TOOLKIT */
11705 /* If cursor was outside the new size, mark it as off. */
11706 mark_window_cursors_off (XWINDOW (f
->root_window
));
11708 /* Clear out any recollection of where the mouse highlighting was,
11709 since it might be in a place that's outside the new frame size.
11710 Actually checking whether it is outside is a pain in the neck,
11711 so don't try--just let the highlighting be done afresh with new size. */
11712 cancel_mouse_face (f
);
11717 /* Mouse warping. */
11720 x_set_mouse_position (f
, x
, y
)
11726 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11727 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11729 if (pix_x
< 0) pix_x
= 0;
11730 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11732 if (pix_y
< 0) pix_y
= 0;
11733 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11737 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11738 0, 0, 0, 0, pix_x
, pix_y
);
11742 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11745 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11751 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11752 0, 0, 0, 0, pix_x
, pix_y
);
11756 /* focus shifting, raising and lowering. */
11759 x_focus_on_frame (f
)
11762 #if 0 /* This proves to be unpleasant. */
11766 /* I don't think that the ICCCM allows programs to do things like this
11767 without the interaction of the window manager. Whatever you end up
11768 doing with this code, do it to x_unfocus_frame too. */
11769 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11770 RevertToPointerRoot
, CurrentTime
);
11775 x_unfocus_frame (f
)
11779 /* Look at the remarks in x_focus_on_frame. */
11780 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11781 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11782 RevertToPointerRoot
, CurrentTime
);
11786 /* Raise frame F. */
11792 if (f
->async_visible
)
11795 #ifdef USE_X_TOOLKIT
11796 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11797 #else /* not USE_X_TOOLKIT */
11798 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11799 #endif /* not USE_X_TOOLKIT */
11800 XFlush (FRAME_X_DISPLAY (f
));
11805 /* Lower frame F. */
11811 if (f
->async_visible
)
11814 #ifdef USE_X_TOOLKIT
11815 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11816 #else /* not USE_X_TOOLKIT */
11817 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11818 #endif /* not USE_X_TOOLKIT */
11819 XFlush (FRAME_X_DISPLAY (f
));
11825 XTframe_raise_lower (f
, raise_flag
)
11835 /* Change of visibility. */
11837 /* This tries to wait until the frame is really visible.
11838 However, if the window manager asks the user where to position
11839 the frame, this will return before the user finishes doing that.
11840 The frame will not actually be visible at that time,
11841 but it will become visible later when the window manager
11842 finishes with it. */
11845 x_make_frame_visible (f
)
11849 int original_top
, original_left
;
11853 type
= x_icon_type (f
);
11855 x_bitmap_icon (f
, type
);
11857 if (! FRAME_VISIBLE_P (f
))
11859 /* We test FRAME_GARBAGED_P here to make sure we don't
11860 call x_set_offset a second time
11861 if we get to x_make_frame_visible a second time
11862 before the window gets really visible. */
11863 if (! FRAME_ICONIFIED_P (f
)
11864 && ! f
->output_data
.x
->asked_for_visible
)
11865 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11867 f
->output_data
.x
->asked_for_visible
= 1;
11869 if (! EQ (Vx_no_window_manager
, Qt
))
11870 x_wm_set_window_state (f
, NormalState
);
11871 #ifdef USE_X_TOOLKIT
11872 /* This was XtPopup, but that did nothing for an iconified frame. */
11873 XtMapWidget (f
->output_data
.x
->widget
);
11874 #else /* not USE_X_TOOLKIT */
11875 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11876 #endif /* not USE_X_TOOLKIT */
11877 #if 0 /* This seems to bring back scroll bars in the wrong places
11878 if the window configuration has changed. They seem
11879 to come back ok without this. */
11880 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11881 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11885 XFlush (FRAME_X_DISPLAY (f
));
11887 /* Synchronize to ensure Emacs knows the frame is visible
11888 before we do anything else. We do this loop with input not blocked
11889 so that incoming events are handled. */
11893 /* This must be before UNBLOCK_INPUT
11894 since events that arrive in response to the actions above
11895 will set it when they are handled. */
11896 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11898 original_left
= f
->output_data
.x
->left_pos
;
11899 original_top
= f
->output_data
.x
->top_pos
;
11901 /* This must come after we set COUNT. */
11904 /* We unblock here so that arriving X events are processed. */
11906 /* Now move the window back to where it was "supposed to be".
11907 But don't do it if the gravity is negative.
11908 When the gravity is negative, this uses a position
11909 that is 3 pixels too low. Perhaps that's really the border width.
11911 Don't do this if the window has never been visible before,
11912 because the window manager may choose the position
11913 and we don't want to override it. */
11915 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11916 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11917 && previously_visible
)
11921 unsigned int width
, height
, border
, depth
;
11925 /* On some window managers (such as FVWM) moving an existing
11926 window, even to the same place, causes the window manager
11927 to introduce an offset. This can cause the window to move
11928 to an unexpected location. Check the geometry (a little
11929 slow here) and then verify that the window is in the right
11930 place. If the window is not in the right place, move it
11931 there, and take the potential window manager hit. */
11932 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11933 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11935 if (original_left
!= x
|| original_top
!= y
)
11936 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11937 original_left
, original_top
);
11942 XSETFRAME (frame
, f
);
11944 /* Wait until the frame is visible. Process X events until a
11945 MapNotify event has been seen, or until we think we won't get a
11946 MapNotify at all.. */
11947 for (count
= input_signal_count
+ 10;
11948 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
11950 /* Force processing of queued events. */
11953 /* Machines that do polling rather than SIGIO have been
11954 observed to go into a busy-wait here. So we'll fake an
11955 alarm signal to let the handler know that there's something
11956 to be read. We used to raise a real alarm, but it seems
11957 that the handler isn't always enabled here. This is
11959 if (input_polling_used ())
11961 /* It could be confusing if a real alarm arrives while
11962 processing the fake one. Turn it off and let the
11963 handler reset it. */
11964 extern void poll_for_input_1
P_ ((void));
11965 int old_poll_suppress_count
= poll_suppress_count
;
11966 poll_suppress_count
= 1;
11967 poll_for_input_1 ();
11968 poll_suppress_count
= old_poll_suppress_count
;
11971 /* See if a MapNotify event has been processed. */
11972 FRAME_SAMPLE_VISIBILITY (f
);
11977 /* Change from mapped state to withdrawn state. */
11979 /* Make the frame visible (mapped and not iconified). */
11982 x_make_frame_invisible (f
)
11987 #ifdef USE_X_TOOLKIT
11988 /* Use the frame's outermost window, not the one we normally draw on. */
11989 window
= XtWindow (f
->output_data
.x
->widget
);
11990 #else /* not USE_X_TOOLKIT */
11991 window
= FRAME_X_WINDOW (f
);
11992 #endif /* not USE_X_TOOLKIT */
11994 /* Don't keep the highlight on an invisible frame. */
11995 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11996 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11998 #if 0/* This might add unreliability; I don't trust it -- rms. */
11999 if (! f
->async_visible
&& ! f
->async_iconified
)
12005 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12006 that the current position of the window is user-specified, rather than
12007 program-specified, so that when the window is mapped again, it will be
12008 placed at the same location, without forcing the user to position it
12009 by hand again (they have already done that once for this window.) */
12010 x_wm_set_size_hint (f
, (long) 0, 1);
12014 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12015 DefaultScreen (FRAME_X_DISPLAY (f
))))
12017 UNBLOCK_INPUT_RESIGNAL
;
12018 error ("Can't notify window manager of window withdrawal");
12020 #else /* ! defined (HAVE_X11R4) */
12022 /* Tell the window manager what we're going to do. */
12023 if (! EQ (Vx_no_window_manager
, Qt
))
12027 unmap
.xunmap
.type
= UnmapNotify
;
12028 unmap
.xunmap
.window
= window
;
12029 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12030 unmap
.xunmap
.from_configure
= False
;
12031 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12032 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12034 SubstructureRedirectMaskSubstructureNotifyMask
,
12037 UNBLOCK_INPUT_RESIGNAL
;
12038 error ("Can't notify window manager of withdrawal");
12042 /* Unmap the window ourselves. Cheeky! */
12043 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12044 #endif /* ! defined (HAVE_X11R4) */
12046 /* We can't distinguish this from iconification
12047 just by the event that we get from the server.
12048 So we can't win using the usual strategy of letting
12049 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12050 and synchronize with the server to make sure we agree. */
12052 FRAME_ICONIFIED_P (f
) = 0;
12053 f
->async_visible
= 0;
12054 f
->async_iconified
= 0;
12061 /* Change window state from mapped to iconified. */
12064 x_iconify_frame (f
)
12070 /* Don't keep the highlight on an invisible frame. */
12071 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12072 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12074 if (f
->async_iconified
)
12079 FRAME_SAMPLE_VISIBILITY (f
);
12081 type
= x_icon_type (f
);
12083 x_bitmap_icon (f
, type
);
12085 #ifdef USE_X_TOOLKIT
12087 if (! FRAME_VISIBLE_P (f
))
12089 if (! EQ (Vx_no_window_manager
, Qt
))
12090 x_wm_set_window_state (f
, IconicState
);
12091 /* This was XtPopup, but that did nothing for an iconified frame. */
12092 XtMapWidget (f
->output_data
.x
->widget
);
12093 /* The server won't give us any event to indicate
12094 that an invisible frame was changed to an icon,
12095 so we have to record it here. */
12098 f
->async_iconified
= 1;
12099 f
->async_visible
= 0;
12104 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12105 XtWindow (f
->output_data
.x
->widget
),
12106 DefaultScreen (FRAME_X_DISPLAY (f
)));
12110 error ("Can't notify window manager of iconification");
12112 f
->async_iconified
= 1;
12113 f
->async_visible
= 0;
12117 XFlush (FRAME_X_DISPLAY (f
));
12119 #else /* not USE_X_TOOLKIT */
12121 /* Make sure the X server knows where the window should be positioned,
12122 in case the user deiconifies with the window manager. */
12123 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12124 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12126 /* Since we don't know which revision of X we're running, we'll use both
12127 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12129 /* X11R4: send a ClientMessage to the window manager using the
12130 WM_CHANGE_STATE type. */
12134 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12135 message
.xclient
.type
= ClientMessage
;
12136 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12137 message
.xclient
.format
= 32;
12138 message
.xclient
.data
.l
[0] = IconicState
;
12140 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12141 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12143 SubstructureRedirectMask
| SubstructureNotifyMask
,
12146 UNBLOCK_INPUT_RESIGNAL
;
12147 error ("Can't notify window manager of iconification");
12151 /* X11R3: set the initial_state field of the window manager hints to
12153 x_wm_set_window_state (f
, IconicState
);
12155 if (!FRAME_VISIBLE_P (f
))
12157 /* If the frame was withdrawn, before, we must map it. */
12158 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12161 f
->async_iconified
= 1;
12162 f
->async_visible
= 0;
12164 XFlush (FRAME_X_DISPLAY (f
));
12166 #endif /* not USE_X_TOOLKIT */
12169 /* Destroy the X window of frame F. */
12172 x_destroy_window (f
)
12175 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12179 /* If a display connection is dead, don't try sending more
12180 commands to the X server. */
12181 if (dpyinfo
->display
!= 0)
12183 if (f
->output_data
.x
->icon_desc
!= 0)
12184 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12187 free_frame_xic (f
);
12189 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
12190 #ifdef USE_X_TOOLKIT
12191 if (f
->output_data
.x
->widget
)
12192 XtDestroyWidget (f
->output_data
.x
->widget
);
12193 free_frame_menubar (f
);
12194 #endif /* USE_X_TOOLKIT */
12196 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12197 unload_color (f
, f
->output_data
.x
->background_pixel
);
12198 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12199 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12200 unload_color (f
, f
->output_data
.x
->border_pixel
);
12201 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12202 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12203 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12204 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12205 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12206 if (f
->output_data
.x
->white_relief
.allocated_p
)
12207 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12208 if (f
->output_data
.x
->black_relief
.allocated_p
)
12209 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12211 free_frame_faces (f
);
12212 XFlush (FRAME_X_DISPLAY (f
));
12215 if (f
->output_data
.x
->saved_menu_event
)
12216 xfree (f
->output_data
.x
->saved_menu_event
);
12218 xfree (f
->output_data
.x
);
12219 f
->output_data
.x
= 0;
12220 if (f
== dpyinfo
->x_focus_frame
)
12221 dpyinfo
->x_focus_frame
= 0;
12222 if (f
== dpyinfo
->x_focus_event_frame
)
12223 dpyinfo
->x_focus_event_frame
= 0;
12224 if (f
== dpyinfo
->x_highlight_frame
)
12225 dpyinfo
->x_highlight_frame
= 0;
12227 dpyinfo
->reference_count
--;
12229 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12231 dpyinfo
->mouse_face_beg_row
12232 = dpyinfo
->mouse_face_beg_col
= -1;
12233 dpyinfo
->mouse_face_end_row
12234 = dpyinfo
->mouse_face_end_col
= -1;
12235 dpyinfo
->mouse_face_window
= Qnil
;
12236 dpyinfo
->mouse_face_deferred_gc
= 0;
12237 dpyinfo
->mouse_face_mouse_frame
= 0;
12243 /* Setting window manager hints. */
12245 /* Set the normal size hints for the window manager, for frame F.
12246 FLAGS is the flags word to use--or 0 meaning preserve the flags
12247 that the window now has.
12248 If USER_POSITION is nonzero, we set the USPosition
12249 flag (this is useful when FLAGS is 0). */
12252 x_wm_set_size_hint (f
, flags
, user_position
)
12257 XSizeHints size_hints
;
12259 #ifdef USE_X_TOOLKIT
12262 Dimension widget_width
, widget_height
;
12263 Window window
= XtWindow (f
->output_data
.x
->widget
);
12264 #else /* not USE_X_TOOLKIT */
12265 Window window
= FRAME_X_WINDOW (f
);
12266 #endif /* not USE_X_TOOLKIT */
12268 /* Setting PMaxSize caused various problems. */
12269 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12271 size_hints
.x
= f
->output_data
.x
->left_pos
;
12272 size_hints
.y
= f
->output_data
.x
->top_pos
;
12274 #ifdef USE_X_TOOLKIT
12275 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12276 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12277 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12278 size_hints
.height
= widget_height
;
12279 size_hints
.width
= widget_width
;
12280 #else /* not USE_X_TOOLKIT */
12281 size_hints
.height
= PIXEL_HEIGHT (f
);
12282 size_hints
.width
= PIXEL_WIDTH (f
);
12283 #endif /* not USE_X_TOOLKIT */
12285 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12286 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12287 size_hints
.max_width
12288 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12289 size_hints
.max_height
12290 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12292 /* Calculate the base and minimum sizes.
12294 (When we use the X toolkit, we don't do it here.
12295 Instead we copy the values that the widgets are using, below.) */
12296 #ifndef USE_X_TOOLKIT
12298 int base_width
, base_height
;
12299 int min_rows
= 0, min_cols
= 0;
12301 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12302 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12304 check_frame_size (f
, &min_rows
, &min_cols
);
12306 /* The window manager uses the base width hints to calculate the
12307 current number of rows and columns in the frame while
12308 resizing; min_width and min_height aren't useful for this
12309 purpose, since they might not give the dimensions for a
12310 zero-row, zero-column frame.
12312 We use the base_width and base_height members if we have
12313 them; otherwise, we set the min_width and min_height members
12314 to the size for a zero x zero frame. */
12317 size_hints
.flags
|= PBaseSize
;
12318 size_hints
.base_width
= base_width
;
12319 size_hints
.base_height
= base_height
;
12320 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12321 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12323 size_hints
.min_width
= base_width
;
12324 size_hints
.min_height
= base_height
;
12328 /* If we don't need the old flags, we don't need the old hint at all. */
12331 size_hints
.flags
|= flags
;
12334 #endif /* not USE_X_TOOLKIT */
12337 XSizeHints hints
; /* Sometimes I hate X Windows... */
12338 long supplied_return
;
12342 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12345 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12348 #ifdef USE_X_TOOLKIT
12349 size_hints
.base_height
= hints
.base_height
;
12350 size_hints
.base_width
= hints
.base_width
;
12351 size_hints
.min_height
= hints
.min_height
;
12352 size_hints
.min_width
= hints
.min_width
;
12356 size_hints
.flags
|= flags
;
12361 if (hints
.flags
& PSize
)
12362 size_hints
.flags
|= PSize
;
12363 if (hints
.flags
& PPosition
)
12364 size_hints
.flags
|= PPosition
;
12365 if (hints
.flags
& USPosition
)
12366 size_hints
.flags
|= USPosition
;
12367 if (hints
.flags
& USSize
)
12368 size_hints
.flags
|= USSize
;
12372 #ifndef USE_X_TOOLKIT
12377 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12378 size_hints
.flags
|= PWinGravity
;
12382 size_hints
.flags
&= ~ PPosition
;
12383 size_hints
.flags
|= USPosition
;
12385 #endif /* PWinGravity */
12388 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12390 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12394 /* Used for IconicState or NormalState */
12397 x_wm_set_window_state (f
, state
)
12401 #ifdef USE_X_TOOLKIT
12404 XtSetArg (al
[0], XtNinitialState
, state
);
12405 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12406 #else /* not USE_X_TOOLKIT */
12407 Window window
= FRAME_X_WINDOW (f
);
12409 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12410 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12412 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12413 #endif /* not USE_X_TOOLKIT */
12417 x_wm_set_icon_pixmap (f
, pixmap_id
)
12421 Pixmap icon_pixmap
;
12423 #ifndef USE_X_TOOLKIT
12424 Window window
= FRAME_X_WINDOW (f
);
12429 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12430 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12434 /* It seems there is no way to turn off use of an icon pixmap.
12435 The following line does it, only if no icon has yet been created,
12436 for some window managers. But with mwm it crashes.
12437 Some people say it should clear the IconPixmapHint bit in this case,
12438 but that doesn't work, and the X consortium said it isn't the
12439 right thing at all. Since there is no way to win,
12440 best to explicitly give up. */
12442 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12448 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12452 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12453 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12456 #else /* not USE_X_TOOLKIT */
12458 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12459 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12461 #endif /* not USE_X_TOOLKIT */
12465 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12467 int icon_x
, icon_y
;
12469 #ifdef USE_X_TOOLKIT
12470 Window window
= XtWindow (f
->output_data
.x
->widget
);
12472 Window window
= FRAME_X_WINDOW (f
);
12475 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12476 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12477 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12479 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12483 /***********************************************************************
12485 ***********************************************************************/
12487 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12490 x_get_font_info (f
, font_idx
)
12494 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12498 /* Return a list of names of available fonts matching PATTERN on frame
12499 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
12500 to be listed. Frame F NULL means we have not yet created any
12501 frame on X, and consult the first display in x_display_list.
12502 MAXNAMES sets a limit on how many fonts to match. */
12505 x_list_fonts (f
, pattern
, size
, maxnames
)
12507 Lisp_Object pattern
;
12511 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12512 Lisp_Object tem
, second_best
;
12513 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
12514 int try_XLoadQueryFont
= 0;
12517 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12518 if (NILP (patterns
))
12519 patterns
= Fcons (pattern
, Qnil
);
12521 if (maxnames
== 1 && !size
)
12522 /* We can return any single font matching PATTERN. */
12523 try_XLoadQueryFont
= 1;
12525 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12528 char **names
= NULL
;
12530 pattern
= XCAR (patterns
);
12531 /* See if we cached the result for this particular query.
12532 The cache is an alist of the form:
12533 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
12535 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
12536 key
= Fcons (pattern
, make_number (maxnames
)),
12537 !NILP (list
= Fassoc (key
, tem
))))
12539 list
= Fcdr_safe (list
);
12540 /* We have a cashed list. Don't have to get the list again. */
12544 /* At first, put PATTERN in the cache. */
12547 count
= x_catch_errors (dpy
);
12549 if (try_XLoadQueryFont
)
12552 unsigned long value
;
12554 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12555 if (x_had_errors_p (dpy
))
12557 /* This error is perhaps due to insufficient memory on X
12558 server. Let's just ignore it. */
12560 x_clear_errors (dpy
);
12564 && XGetFontProperty (font
, XA_FONT
, &value
))
12566 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12567 int len
= strlen (name
);
12570 /* If DXPC (a Differential X Protocol Compressor)
12571 Ver.3.7 is running, XGetAtomName will return null
12572 string. We must avoid such a name. */
12574 try_XLoadQueryFont
= 0;
12578 names
= (char **) alloca (sizeof (char *));
12579 /* Some systems only allow alloca assigned to a
12581 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12582 bcopy (name
, names
[0], len
+ 1);
12587 try_XLoadQueryFont
= 0;
12590 XFreeFont (dpy
, font
);
12593 if (!try_XLoadQueryFont
)
12595 /* We try at least 10 fonts because XListFonts will return
12596 auto-scaled fonts at the head. */
12597 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12599 if (x_had_errors_p (dpy
))
12601 /* This error is perhaps due to insufficient memory on X
12602 server. Let's just ignore it. */
12604 x_clear_errors (dpy
);
12608 x_uncatch_errors (dpy
, count
);
12615 /* Make a list of all the fonts we got back.
12616 Store that in the font cache for the display. */
12617 for (i
= 0; i
< num_fonts
; i
++)
12620 char *p
= names
[i
];
12621 int average_width
= -1, dashes
= 0;
12623 /* Count the number of dashes in NAMES[I]. If there are
12624 14 dashes, and the field value following 12th dash
12625 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12626 is usually too ugly to be used for editing. Let's
12632 if (dashes
== 7) /* PIXEL_SIZE field */
12634 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12635 average_width
= atoi (p
);
12637 if (dashes
< 14 || average_width
!= 0)
12639 tem
= build_string (names
[i
]);
12640 if (NILP (Fassoc (tem
, list
)))
12642 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12643 && ((fast_c_string_match_ignore_case
12644 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12646 /* We can set the value of PIXEL_SIZE to the
12647 width of this font. */
12648 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12650 /* For the moment, width is not known. */
12651 list
= Fcons (Fcons (tem
, Qnil
), list
);
12655 if (!try_XLoadQueryFont
)
12656 XFreeFontNames (names
);
12659 /* Now store the result in the cache. */
12661 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
12662 = Fcons (Fcons (key
, list
),
12663 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
12666 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12668 newlist
= second_best
= Qnil
;
12669 /* Make a list of the fonts that have the right width. */
12670 for (; CONSP (list
); list
= XCDR (list
))
12676 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12680 newlist
= Fcons (XCAR (tem
), newlist
);
12684 if (!INTEGERP (XCDR (tem
)))
12686 /* Since we have not yet known the size of this font, we
12687 must try slow function call XLoadQueryFont. */
12688 XFontStruct
*thisinfo
;
12691 count
= x_catch_errors (dpy
);
12692 thisinfo
= XLoadQueryFont (dpy
,
12693 XSTRING (XCAR (tem
))->data
);
12694 if (x_had_errors_p (dpy
))
12696 /* This error is perhaps due to insufficient memory on X
12697 server. Let's just ignore it. */
12699 x_clear_errors (dpy
);
12701 x_uncatch_errors (dpy
, count
);
12707 = (thisinfo
->min_bounds
.width
== 0
12709 : make_number (thisinfo
->max_bounds
.width
));
12710 XFreeFont (dpy
, thisinfo
);
12713 /* For unknown reason, the previous call of XListFont had
12714 returned a font which can't be opened. Record the size
12715 as 0 not to try to open it again. */
12716 XCDR (tem
) = make_number (0);
12719 found_size
= XINT (XCDR (tem
));
12720 if (found_size
== size
)
12721 newlist
= Fcons (XCAR (tem
), newlist
);
12722 else if (found_size
> 0)
12724 if (NILP (second_best
))
12726 else if (found_size
< size
)
12728 if (XINT (XCDR (second_best
)) > size
12729 || XINT (XCDR (second_best
)) < found_size
)
12734 if (XINT (XCDR (second_best
)) > size
12735 && XINT (XCDR (second_best
)) > found_size
)
12740 if (!NILP (newlist
))
12742 else if (!NILP (second_best
))
12744 newlist
= Fcons (XCAR (second_best
), Qnil
);
12755 /* Check that FONT is valid on frame F. It is if it can be found in F's
12759 x_check_font (f
, font
)
12764 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12766 xassert (font
!= NULL
);
12768 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12769 if (dpyinfo
->font_table
[i
].name
12770 && font
== dpyinfo
->font_table
[i
].font
)
12773 xassert (i
< dpyinfo
->n_fonts
);
12776 #endif /* GLYPH_DEBUG != 0 */
12778 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12779 Note: There are (broken) X fonts out there with invalid XFontStruct
12780 min_bounds contents. For example, handa@etl.go.jp reports that
12781 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
12782 have font->min_bounds.width == 0. */
12785 x_font_min_bounds (font
, w
, h
)
12789 *h
= FONT_HEIGHT (font
);
12790 *w
= font
->min_bounds
.width
;
12792 /* Try to handle the case where FONT->min_bounds has invalid
12793 contents. Since the only font known to have invalid min_bounds
12794 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12796 *w
= font
->max_bounds
.width
;
12800 /* Compute the smallest character width and smallest font height over
12801 all fonts available on frame F. Set the members smallest_char_width
12802 and smallest_font_height in F's x_display_info structure to
12803 the values computed. Value is non-zero if smallest_font_height or
12804 smallest_char_width become smaller than they were before. */
12807 x_compute_min_glyph_bounds (f
)
12811 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12813 int old_width
= dpyinfo
->smallest_char_width
;
12814 int old_height
= dpyinfo
->smallest_font_height
;
12816 dpyinfo
->smallest_font_height
= 100000;
12817 dpyinfo
->smallest_char_width
= 100000;
12819 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12820 if (dpyinfo
->font_table
[i
].name
)
12822 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12825 font
= (XFontStruct
*) fontp
->font
;
12826 xassert (font
!= (XFontStruct
*) ~0);
12827 x_font_min_bounds (font
, &w
, &h
);
12829 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12830 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12833 xassert (dpyinfo
->smallest_char_width
> 0
12834 && dpyinfo
->smallest_font_height
> 0);
12836 return (dpyinfo
->n_fonts
== 1
12837 || dpyinfo
->smallest_char_width
< old_width
12838 || dpyinfo
->smallest_font_height
< old_height
);
12842 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12843 pointer to the structure font_info while allocating it dynamically.
12844 If SIZE is 0, load any size of font.
12845 If loading is failed, return NULL. */
12848 x_load_font (f
, fontname
, size
)
12850 register char *fontname
;
12853 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12854 Lisp_Object font_names
;
12857 /* Get a list of all the fonts that match this name. Once we
12858 have a list of matching fonts, we compare them against the fonts
12859 we already have by comparing names. */
12860 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12862 if (!NILP (font_names
))
12867 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12868 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12869 if (dpyinfo
->font_table
[i
].name
12870 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12871 XSTRING (XCAR (tail
))->data
)
12872 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12873 XSTRING (XCAR (tail
))->data
)))
12874 return (dpyinfo
->font_table
+ i
);
12877 /* Load the font and add it to the table. */
12881 struct font_info
*fontp
;
12882 unsigned long value
;
12885 /* If we have found fonts by x_list_font, load one of them. If
12886 not, we still try to load a font by the name given as FONTNAME
12887 because XListFonts (called in x_list_font) of some X server has
12888 a bug of not finding a font even if the font surely exists and
12889 is loadable by XLoadQueryFont. */
12890 if (size
> 0 && !NILP (font_names
))
12891 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12894 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12895 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12896 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12898 /* This error is perhaps due to insufficient memory on X
12899 server. Let's just ignore it. */
12901 x_clear_errors (FRAME_X_DISPLAY (f
));
12903 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12908 /* Find a free slot in the font table. */
12909 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12910 if (dpyinfo
->font_table
[i
].name
== NULL
)
12913 /* If no free slot found, maybe enlarge the font table. */
12914 if (i
== dpyinfo
->n_fonts
12915 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12918 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12919 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12920 dpyinfo
->font_table
12921 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12924 fontp
= dpyinfo
->font_table
+ i
;
12925 if (i
== dpyinfo
->n_fonts
)
12926 ++dpyinfo
->n_fonts
;
12928 /* Now fill in the slots of *FONTP. */
12930 fontp
->font
= font
;
12931 fontp
->font_idx
= i
;
12932 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12933 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12935 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12937 if (XGetFontProperty (font
, XA_FONT
, &value
))
12939 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12943 /* Count the number of dashes in the "full name".
12944 If it is too few, this isn't really the font's full name,
12946 In X11R4, the fonts did not come with their canonical names
12957 full_name
= (char *) xmalloc (p
- name
+ 1);
12958 bcopy (name
, full_name
, p
- name
+ 1);
12964 if (full_name
!= 0)
12965 fontp
->full_name
= full_name
;
12967 fontp
->full_name
= fontp
->name
;
12969 fontp
->size
= font
->max_bounds
.width
;
12970 fontp
->height
= FONT_HEIGHT (font
);
12972 /* For some font, ascent and descent in max_bounds field is
12973 larger than the above value. */
12974 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12975 if (max_height
> fontp
->height
)
12976 fontp
->height
= max_height
;
12979 if (NILP (font_names
))
12981 /* We come here because of a bug of XListFonts mentioned at
12982 the head of this block. Let's store this information in
12983 the cache for x_list_fonts. */
12984 Lisp_Object lispy_name
= build_string (fontname
);
12985 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12987 XCDR (dpyinfo
->name_list_element
)
12988 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
12989 Fcons (Fcons (lispy_full_name
,
12990 make_number (fontp
->size
)),
12992 XCDR (dpyinfo
->name_list_element
));
12994 XCDR (dpyinfo
->name_list_element
)
12995 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
12996 Fcons (Fcons (lispy_full_name
,
12997 make_number (fontp
->size
)),
12999 XCDR (dpyinfo
->name_list_element
));
13002 /* The slot `encoding' specifies how to map a character
13003 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13004 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13005 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13006 2:0xA020..0xFF7F). For the moment, we don't know which charset
13007 uses this font. So, we set information in fontp->encoding[1]
13008 which is never used by any charset. If mapping can't be
13009 decided, set FONT_ENCODING_NOT_DECIDED. */
13011 = (font
->max_byte1
== 0
13013 ? (font
->min_char_or_byte2
< 0x80
13014 ? (font
->max_char_or_byte2
< 0x80
13015 ? 0 /* 0x20..0x7F */
13016 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13017 : 1) /* 0xA0..0xFF */
13019 : (font
->min_byte1
< 0x80
13020 ? (font
->max_byte1
< 0x80
13021 ? (font
->min_char_or_byte2
< 0x80
13022 ? (font
->max_char_or_byte2
< 0x80
13023 ? 0 /* 0x2020..0x7F7F */
13024 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13025 : 3) /* 0x20A0..0x7FFF */
13026 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13027 : (font
->min_char_or_byte2
< 0x80
13028 ? (font
->max_char_or_byte2
< 0x80
13029 ? 2 /* 0xA020..0xFF7F */
13030 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13031 : 1))); /* 0xA0A0..0xFFFF */
13033 fontp
->baseline_offset
13034 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13035 ? (long) value
: 0);
13036 fontp
->relative_compose
13037 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13038 ? (long) value
: 0);
13039 fontp
->default_ascent
13040 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13041 ? (long) value
: 0);
13043 /* Set global flag fonts_changed_p to non-zero if the font loaded
13044 has a character with a smaller width than any other character
13045 before, or if the font loaded has a smalle>r height than any
13046 other font loaded before. If this happens, it will make a
13047 glyph matrix reallocation necessary. */
13048 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13055 /* Return a pointer to struct font_info of a font named FONTNAME for
13056 frame F. If no such font is loaded, return NULL. */
13059 x_query_font (f
, fontname
)
13061 register char *fontname
;
13063 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13066 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13067 if (dpyinfo
->font_table
[i
].name
13068 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13069 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13070 return (dpyinfo
->font_table
+ i
);
13075 /* Find a CCL program for a font specified by FONTP, and set the member
13076 `encoder' of the structure. */
13079 x_find_ccl_program (fontp
)
13080 struct font_info
*fontp
;
13082 Lisp_Object list
, elt
;
13084 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13088 && STRINGP (XCAR (elt
))
13089 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13095 struct ccl_program
*ccl
13096 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13098 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13101 fontp
->font_encoder
= ccl
;
13107 /***********************************************************************
13109 ***********************************************************************/
13111 #ifdef USE_X_TOOLKIT
13112 static XrmOptionDescRec emacs_options
[] = {
13113 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13114 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13116 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13117 XrmoptionSepArg
, NULL
},
13118 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13120 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13121 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13122 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13123 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13124 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13125 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13126 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13128 #endif /* USE_X_TOOLKIT */
13130 static int x_initialized
;
13132 #ifdef MULTI_KBOARD
13133 /* Test whether two display-name strings agree up to the dot that separates
13134 the screen number from the server number. */
13136 same_x_server (name1
, name2
)
13137 char *name1
, *name2
;
13139 int seen_colon
= 0;
13140 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13141 int system_name_length
= strlen (system_name
);
13142 int length_until_period
= 0;
13144 while (system_name
[length_until_period
] != 0
13145 && system_name
[length_until_period
] != '.')
13146 length_until_period
++;
13148 /* Treat `unix' like an empty host name. */
13149 if (! strncmp (name1
, "unix:", 5))
13151 if (! strncmp (name2
, "unix:", 5))
13153 /* Treat this host's name like an empty host name. */
13154 if (! strncmp (name1
, system_name
, system_name_length
)
13155 && name1
[system_name_length
] == ':')
13156 name1
+= system_name_length
;
13157 if (! strncmp (name2
, system_name
, system_name_length
)
13158 && name2
[system_name_length
] == ':')
13159 name2
+= system_name_length
;
13160 /* Treat this host's domainless name like an empty host name. */
13161 if (! strncmp (name1
, system_name
, length_until_period
)
13162 && name1
[length_until_period
] == ':')
13163 name1
+= length_until_period
;
13164 if (! strncmp (name2
, system_name
, length_until_period
)
13165 && name2
[length_until_period
] == ':')
13166 name2
+= length_until_period
;
13168 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13172 if (seen_colon
&& *name1
== '.')
13176 && (*name1
== '.' || *name1
== '\0')
13177 && (*name2
== '.' || *name2
== '\0'));
13181 struct x_display_info
*
13182 x_term_init (display_name
, xrm_option
, resource_name
)
13183 Lisp_Object display_name
;
13185 char *resource_name
;
13189 struct x_display_info
*dpyinfo
;
13194 if (!x_initialized
)
13200 #ifdef USE_X_TOOLKIT
13201 /* weiner@footloose.sps.mot.com reports that this causes
13203 X protocol error: BadAtom (invalid Atom parameter)
13204 on protocol request 18skiloaf.
13205 So let's not use it until R6. */
13206 #ifdef HAVE_X11XTR6
13207 XtSetLanguageProc (NULL
, NULL
, NULL
);
13218 argv
[argc
++] = "-xrm";
13219 argv
[argc
++] = xrm_option
;
13221 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13222 resource_name
, EMACS_CLASS
,
13223 emacs_options
, XtNumber (emacs_options
),
13226 #ifdef HAVE_X11XTR6
13227 /* I think this is to compensate for XtSetLanguageProc. */
13232 #else /* not USE_X_TOOLKIT */
13234 XSetLocaleModifiers ("");
13236 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13237 #endif /* not USE_X_TOOLKIT */
13239 /* Detect failure. */
13246 /* We have definitely succeeded. Record the new connection. */
13248 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13250 #ifdef MULTI_KBOARD
13252 struct x_display_info
*share
;
13255 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13256 share
= share
->next
, tail
= XCDR (tail
))
13257 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13258 XSTRING (display_name
)->data
))
13261 dpyinfo
->kboard
= share
->kboard
;
13264 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13265 init_kboard (dpyinfo
->kboard
);
13266 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13268 char *vendor
= ServerVendor (dpy
);
13270 dpyinfo
->kboard
->Vsystem_key_alist
13271 = call1 (Qvendor_specific_keysyms
,
13272 build_string (vendor
? vendor
: ""));
13276 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13277 all_kboards
= dpyinfo
->kboard
;
13278 /* Don't let the initial kboard remain current longer than necessary.
13279 That would cause problems if a file loaded on startup tries to
13280 prompt in the mini-buffer. */
13281 if (current_kboard
== initial_kboard
)
13282 current_kboard
= dpyinfo
->kboard
;
13284 dpyinfo
->kboard
->reference_count
++;
13288 /* Put this display on the chain. */
13289 dpyinfo
->next
= x_display_list
;
13290 x_display_list
= dpyinfo
;
13292 /* Put it on x_display_name_list as well, to keep them parallel. */
13293 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13294 x_display_name_list
);
13295 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13297 dpyinfo
->display
= dpy
;
13300 XSetAfterFunction (x_current_display
, x_trace_wire
);
13304 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13305 + STRING_BYTES (XSTRING (Vsystem_name
))
13307 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13308 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13310 /* Figure out which modifier bits mean what. */
13311 x_find_modifier_meanings (dpyinfo
);
13313 /* Get the scroll bar cursor. */
13314 dpyinfo
->vertical_scroll_bar_cursor
13315 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13317 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13318 resource_name
, EMACS_CLASS
);
13319 #ifdef HAVE_XRMSETDATABASE
13320 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13322 dpyinfo
->display
->db
= xrdb
;
13324 /* Put the rdb where we can find it in a way that works on
13326 dpyinfo
->xrdb
= xrdb
;
13328 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13329 DefaultScreen (dpyinfo
->display
));
13330 select_visual (dpyinfo
);
13331 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13332 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13333 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13334 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13335 dpyinfo
->grabbed
= 0;
13336 dpyinfo
->reference_count
= 0;
13337 dpyinfo
->icon_bitmap_id
= -1;
13338 dpyinfo
->font_table
= NULL
;
13339 dpyinfo
->n_fonts
= 0;
13340 dpyinfo
->font_table_size
= 0;
13341 dpyinfo
->bitmaps
= 0;
13342 dpyinfo
->bitmaps_size
= 0;
13343 dpyinfo
->bitmaps_last
= 0;
13344 dpyinfo
->scratch_cursor_gc
= 0;
13345 dpyinfo
->mouse_face_mouse_frame
= 0;
13346 dpyinfo
->mouse_face_deferred_gc
= 0;
13347 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13348 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13349 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13350 dpyinfo
->mouse_face_window
= Qnil
;
13351 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13352 dpyinfo
->mouse_face_defer
= 0;
13353 dpyinfo
->x_focus_frame
= 0;
13354 dpyinfo
->x_focus_event_frame
= 0;
13355 dpyinfo
->x_highlight_frame
= 0;
13356 dpyinfo
->image_cache
= make_image_cache ();
13358 /* See if a private colormap is requested. */
13359 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13361 if (dpyinfo
->visual
->class == PseudoColor
)
13364 value
= display_x_get_resource (dpyinfo
,
13365 build_string ("privateColormap"),
13366 build_string ("PrivateColormap"),
13368 if (STRINGP (value
)
13369 && (!strcmp (XSTRING (value
)->data
, "true")
13370 || !strcmp (XSTRING (value
)->data
, "on")))
13371 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13375 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13376 dpyinfo
->visual
, AllocNone
);
13379 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13380 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13381 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13382 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13383 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13384 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13385 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13388 dpyinfo
->Xatom_wm_protocols
13389 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13390 dpyinfo
->Xatom_wm_take_focus
13391 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13392 dpyinfo
->Xatom_wm_save_yourself
13393 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13394 dpyinfo
->Xatom_wm_delete_window
13395 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13396 dpyinfo
->Xatom_wm_change_state
13397 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13398 dpyinfo
->Xatom_wm_configure_denied
13399 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13400 dpyinfo
->Xatom_wm_window_moved
13401 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13402 dpyinfo
->Xatom_editres
13403 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13404 dpyinfo
->Xatom_CLIPBOARD
13405 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13406 dpyinfo
->Xatom_TIMESTAMP
13407 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13408 dpyinfo
->Xatom_TEXT
13409 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13410 dpyinfo
->Xatom_COMPOUND_TEXT
13411 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13412 dpyinfo
->Xatom_DELETE
13413 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13414 dpyinfo
->Xatom_MULTIPLE
13415 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13416 dpyinfo
->Xatom_INCR
13417 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13418 dpyinfo
->Xatom_EMACS_TMP
13419 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13420 dpyinfo
->Xatom_TARGETS
13421 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13422 dpyinfo
->Xatom_NULL
13423 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13424 dpyinfo
->Xatom_ATOM_PAIR
13425 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13426 /* For properties of font. */
13427 dpyinfo
->Xatom_PIXEL_SIZE
13428 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13429 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13430 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13431 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13432 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13433 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13434 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13436 /* Ghostscript support. */
13437 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13438 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13440 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13443 dpyinfo
->cut_buffers_initialized
= 0;
13445 connection
= ConnectionNumber (dpyinfo
->display
);
13446 dpyinfo
->connection
= connection
;
13451 null_bits
[0] = 0x00;
13453 dpyinfo
->null_pixel
13454 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13455 null_bits
, 1, 1, (long) 0, (long) 0,
13460 extern int gray_bitmap_width
, gray_bitmap_height
;
13461 extern unsigned char *gray_bitmap_bits
;
13463 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13465 gray_bitmap_width
, gray_bitmap_height
,
13466 (unsigned long) 1, (unsigned long) 0, 1);
13470 xim_initialize (dpyinfo
, resource_name
);
13473 #ifdef subprocesses
13474 /* This is only needed for distinguishing keyboard and process input. */
13475 if (connection
!= 0)
13476 add_keyboard_wait_descriptor (connection
);
13479 #ifndef F_SETOWN_BUG
13481 #ifdef F_SETOWN_SOCK_NEG
13482 /* stdin is a socket here */
13483 fcntl (connection
, F_SETOWN
, -getpid ());
13484 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13485 fcntl (connection
, F_SETOWN
, getpid ());
13486 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13487 #endif /* ! defined (F_SETOWN) */
13488 #endif /* F_SETOWN_BUG */
13491 if (interrupt_input
)
13492 init_sigio (connection
);
13493 #endif /* ! defined (SIGIO) */
13496 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13497 /* Make sure that we have a valid font for dialog boxes
13498 so that Xt does not crash. */
13500 Display
*dpy
= dpyinfo
->display
;
13501 XrmValue d
, fr
, to
;
13505 d
.addr
= (XPointer
)&dpy
;
13506 d
.size
= sizeof (Display
*);
13507 fr
.addr
= XtDefaultFont
;
13508 fr
.size
= sizeof (XtDefaultFont
);
13509 to
.size
= sizeof (Font
*);
13510 to
.addr
= (XPointer
)&font
;
13511 count
= x_catch_errors (dpy
);
13512 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13514 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13515 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13516 x_uncatch_errors (dpy
, count
);
13521 /* See if we should run in synchronous mode. This is useful
13522 for debugging X code. */
13525 value
= display_x_get_resource (dpyinfo
,
13526 build_string ("synchronous"),
13527 build_string ("Synchronous"),
13529 if (STRINGP (value
)
13530 && (!strcmp (XSTRING (value
)->data
, "true")
13531 || !strcmp (XSTRING (value
)->data
, "on")))
13532 XSynchronize (dpyinfo
->display
, True
);
13540 /* Get rid of display DPYINFO, assuming all frames are already gone,
13541 and without sending any more commands to the X server. */
13544 x_delete_display (dpyinfo
)
13545 struct x_display_info
*dpyinfo
;
13547 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13549 /* Discard this display from x_display_name_list and x_display_list.
13550 We can't use Fdelq because that can quit. */
13551 if (! NILP (x_display_name_list
)
13552 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13553 x_display_name_list
= XCDR (x_display_name_list
);
13558 tail
= x_display_name_list
;
13559 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13561 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13563 XCDR (tail
) = XCDR (XCDR (tail
));
13566 tail
= XCDR (tail
);
13570 if (next_noop_dpyinfo
== dpyinfo
)
13571 next_noop_dpyinfo
= dpyinfo
->next
;
13573 if (x_display_list
== dpyinfo
)
13574 x_display_list
= dpyinfo
->next
;
13577 struct x_display_info
*tail
;
13579 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13580 if (tail
->next
== dpyinfo
)
13581 tail
->next
= tail
->next
->next
;
13584 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13585 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13586 XrmDestroyDatabase (dpyinfo
->xrdb
);
13589 #ifdef MULTI_KBOARD
13590 if (--dpyinfo
->kboard
->reference_count
== 0)
13591 delete_kboard (dpyinfo
->kboard
);
13595 xim_close_dpy (dpyinfo
);
13598 xfree (dpyinfo
->font_table
);
13599 xfree (dpyinfo
->x_id_name
);
13603 /* Set up use of X before we make the first connection. */
13605 static struct redisplay_interface x_redisplay_interface
=
13610 x_clear_end_of_line
,
13612 x_after_update_window_line
,
13613 x_update_window_begin
,
13614 x_update_window_end
,
13617 x_clear_mouse_face
,
13618 x_get_glyph_overhangs
,
13619 x_fix_overlapping_area
13625 rif
= &x_redisplay_interface
;
13627 clear_frame_hook
= x_clear_frame
;
13628 ins_del_lines_hook
= x_ins_del_lines
;
13629 change_line_highlight_hook
= x_change_line_highlight
;
13630 delete_glyphs_hook
= x_delete_glyphs
;
13631 ring_bell_hook
= XTring_bell
;
13632 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13633 set_terminal_modes_hook
= XTset_terminal_modes
;
13634 update_begin_hook
= x_update_begin
;
13635 update_end_hook
= x_update_end
;
13636 set_terminal_window_hook
= XTset_terminal_window
;
13637 read_socket_hook
= XTread_socket
;
13638 frame_up_to_date_hook
= XTframe_up_to_date
;
13639 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13640 mouse_position_hook
= XTmouse_position
;
13641 frame_rehighlight_hook
= XTframe_rehighlight
;
13642 frame_raise_lower_hook
= XTframe_raise_lower
;
13643 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13644 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13645 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13646 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13647 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13649 scroll_region_ok
= 1; /* we'll scroll partial frames */
13650 char_ins_del_ok
= 0; /* just as fast to write the line */
13651 line_ins_del_ok
= 1; /* we'll just blt 'em */
13652 fast_clear_end_of_line
= 1; /* X does this well */
13653 memory_below_frame
= 0; /* we don't remember what scrolls
13658 last_tool_bar_item
= -1;
13659 any_help_event_p
= 0;
13661 /* Try to use interrupt input; if we can't, then start polling. */
13662 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13664 #ifdef USE_X_TOOLKIT
13665 XtToolkitInitialize ();
13666 Xt_app_con
= XtCreateApplicationContext ();
13667 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13669 /* Install an asynchronous timer that processes Xt timeout events
13670 every 0.1s. This is necessary because some widget sets use
13671 timeouts internally, for example the LessTif menu bar, or the
13672 Xaw3d scroll bar. When Xt timouts aren't processed, these
13673 widgets don't behave normally. */
13675 EMACS_TIME interval
;
13676 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13677 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13681 #if USE_TOOLKIT_SCROLL_BARS
13682 xaw3d_arrow_scroll
= False
;
13683 xaw3d_pick_top
= True
;
13686 /* Note that there is no real way portable across R3/R4 to get the
13687 original error handler. */
13688 XSetErrorHandler (x_error_handler
);
13689 XSetIOErrorHandler (x_io_error_quitter
);
13691 /* Disable Window Change signals; they are handled by X events. */
13693 signal (SIGWINCH
, SIG_DFL
);
13694 #endif /* ! defined (SIGWINCH) */
13696 signal (SIGPIPE
, x_connection_signal
);
13703 staticpro (&x_error_message_string
);
13704 x_error_message_string
= Qnil
;
13706 staticpro (&x_display_name_list
);
13707 x_display_name_list
= Qnil
;
13709 staticpro (&last_mouse_scroll_bar
);
13710 last_mouse_scroll_bar
= Qnil
;
13712 staticpro (&Qvendor_specific_keysyms
);
13713 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13715 staticpro (&last_mouse_press_frame
);
13716 last_mouse_press_frame
= Qnil
;
13719 staticpro (&help_echo
);
13720 help_echo_object
= Qnil
;
13721 staticpro (&help_echo_object
);
13722 help_echo_window
= Qnil
;
13723 staticpro (&help_echo_window
);
13724 previous_help_echo
= Qnil
;
13725 staticpro (&previous_help_echo
);
13726 help_echo_pos
= -1;
13728 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13729 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
13730 For example, if a block cursor is over a tab, it will be drawn as\n\
13731 wide as that tab on the display.");
13732 x_stretch_cursor_p
= 0;
13734 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
13735 "If not nil, Emacs uses toolkit scroll bars.");
13736 #if USE_TOOLKIT_SCROLL_BARS
13737 x_toolkit_scroll_bars_p
= 1;
13739 x_toolkit_scroll_bars_p
= 0;
13742 staticpro (&last_mouse_motion_frame
);
13743 last_mouse_motion_frame
= Qnil
;
13746 #endif /* not HAVE_X_WINDOWS */