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 #endif /* USE_X_TOOLKIT */
3258 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3259 CMAP. If an exact match can't be allocated, try the nearest color
3260 available. Value is non-zero if successful. Set *COLOR to the
3264 x_alloc_nearest_color (f
, cmap
, color
)
3269 Display
*display
= FRAME_X_DISPLAY (f
);
3270 Screen
*screen
= FRAME_X_SCREEN (f
);
3273 gamma_correct (f
, color
);
3274 rc
= XAllocColor (display
, cmap
, color
);
3277 /* If we got to this point, the colormap is full, so we're going
3278 to try to get the next closest color. The algorithm used is
3279 a least-squares matching, which is what X uses for closest
3280 color matching with StaticColor visuals. */
3282 unsigned long nearest_delta
= ~0;
3283 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3284 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3286 for (i
= 0; i
< ncells
; ++i
)
3288 XQueryColors (display
, cmap
, cells
, ncells
);
3290 for (nearest
= i
= 0; i
< ncells
; ++i
)
3292 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3293 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3294 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3295 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3297 if (delta
< nearest_delta
)
3300 nearest_delta
= delta
;
3304 color
->red
= cells
[nearest
].red
;
3305 color
->green
= cells
[nearest
].green
;
3306 color
->blue
= cells
[nearest
].blue
;
3307 rc
= XAllocColor (display
, cmap
, color
);
3310 #ifdef DEBUG_X_COLORS
3312 register_color (color
->pixel
);
3313 #endif /* DEBUG_X_COLORS */
3319 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3320 It's necessary to do this instead of just using PIXEL directly to
3321 get color reference counts right. */
3324 x_copy_color (f
, pixel
)
3326 unsigned long pixel
;
3330 color
.pixel
= pixel
;
3332 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3333 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3335 #ifdef DEBUG_X_COLORS
3336 register_color (pixel
);
3342 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3343 It's necessary to do this instead of just using PIXEL directly to
3344 get color reference counts right. */
3347 x_copy_dpy_color (dpy
, cmap
, pixel
)
3350 unsigned long pixel
;
3354 color
.pixel
= pixel
;
3356 XQueryColor (dpy
, cmap
, &color
);
3357 XAllocColor (dpy
, cmap
, &color
);
3359 #ifdef DEBUG_X_COLORS
3360 register_color (pixel
);
3366 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3367 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3368 If this produces the same color as PIXEL, try a color where all RGB
3369 values have DELTA added. Return the allocated color in *PIXEL.
3370 DISPLAY is the X display, CMAP is the colormap to operate on.
3371 Value is non-zero if successful. */
3374 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3378 unsigned long *pixel
;
3385 /* Get RGB color values. */
3386 color
.pixel
= *pixel
;
3387 XQueryColor (display
, cmap
, &color
);
3389 /* Change RGB values by specified FACTOR. Avoid overflow! */
3390 xassert (factor
>= 0);
3391 new.red
= min (0xffff, factor
* color
.red
);
3392 new.green
= min (0xffff, factor
* color
.green
);
3393 new.blue
= min (0xffff, factor
* color
.blue
);
3395 /* Try to allocate the color. */
3396 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3399 if (new.pixel
== *pixel
)
3401 /* If we end up with the same color as before, try adding
3402 delta to the RGB values. */
3403 x_free_colors (f
, &new.pixel
, 1);
3405 new.red
= min (0xffff, delta
+ color
.red
);
3406 new.green
= min (0xffff, delta
+ color
.green
);
3407 new.blue
= min (0xffff, delta
+ color
.blue
);
3408 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3419 /* Set up the foreground color for drawing relief lines of glyph
3420 string S. RELIEF is a pointer to a struct relief containing the GC
3421 with which lines will be drawn. Use a color that is FACTOR or
3422 DELTA lighter or darker than the relief's background which is found
3423 in S->f->output_data.x->relief_background. If such a color cannot
3424 be allocated, use DEFAULT_PIXEL, instead. */
3427 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3429 struct relief
*relief
;
3432 unsigned long default_pixel
;
3435 struct x_output
*di
= f
->output_data
.x
;
3436 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3437 unsigned long pixel
;
3438 unsigned long background
= di
->relief_background
;
3439 Colormap cmap
= FRAME_X_COLORMAP (f
);
3440 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3441 Display
*dpy
= FRAME_X_DISPLAY (f
);
3443 xgcv
.graphics_exposures
= False
;
3444 xgcv
.line_width
= 1;
3446 /* Free previously allocated color. The color cell will be reused
3447 when it has been freed as many times as it was allocated, so this
3448 doesn't affect faces using the same colors. */
3450 && relief
->allocated_p
)
3452 x_free_colors (f
, &relief
->pixel
, 1);
3453 relief
->allocated_p
= 0;
3456 /* Allocate new color. */
3457 xgcv
.foreground
= default_pixel
;
3459 if (dpyinfo
->n_planes
!= 1
3460 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3462 relief
->allocated_p
= 1;
3463 xgcv
.foreground
= relief
->pixel
= pixel
;
3466 if (relief
->gc
== 0)
3468 xgcv
.stipple
= dpyinfo
->gray
;
3470 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3473 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3477 /* Set up colors for the relief lines around glyph string S. */
3480 x_setup_relief_colors (s
)
3481 struct glyph_string
*s
;
3483 struct x_output
*di
= s
->f
->output_data
.x
;
3484 unsigned long color
;
3486 if (s
->face
->use_box_color_for_shadows_p
)
3487 color
= s
->face
->box_color
;
3492 /* Get the background color of the face. */
3493 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3494 color
= xgcv
.background
;
3497 if (di
->white_relief
.gc
== 0
3498 || color
!= di
->relief_background
)
3500 di
->relief_background
= color
;
3501 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3502 WHITE_PIX_DEFAULT (s
->f
));
3503 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3504 BLACK_PIX_DEFAULT (s
->f
));
3509 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3510 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3511 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3512 relief. LEFT_P non-zero means draw a relief on the left side of
3513 the rectangle. RIGHT_P non-zero means draw a relief on the right
3514 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3518 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3519 raised_p
, left_p
, right_p
, clip_rect
)
3521 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3522 XRectangle
*clip_rect
;
3528 gc
= f
->output_data
.x
->white_relief
.gc
;
3530 gc
= f
->output_data
.x
->black_relief
.gc
;
3531 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3534 for (i
= 0; i
< width
; ++i
)
3535 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3536 left_x
+ i
* left_p
, top_y
+ i
,
3537 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3541 for (i
= 0; i
< width
; ++i
)
3542 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3543 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3545 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3547 gc
= f
->output_data
.x
->black_relief
.gc
;
3549 gc
= f
->output_data
.x
->white_relief
.gc
;
3550 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3553 for (i
= 0; i
< width
; ++i
)
3554 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3555 left_x
+ i
* left_p
, bottom_y
- i
,
3556 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3560 for (i
= 0; i
< width
; ++i
)
3561 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3562 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3564 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3568 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3569 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3570 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3571 left side of the rectangle. RIGHT_P non-zero means draw a line
3572 on the right side of the rectangle. CLIP_RECT is the clipping
3573 rectangle to use when drawing. */
3576 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3577 left_p
, right_p
, clip_rect
)
3578 struct glyph_string
*s
;
3579 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3580 XRectangle
*clip_rect
;
3584 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3585 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3586 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3589 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3590 left_x
, top_y
, right_x
- left_x
, width
);
3594 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3595 left_x
, top_y
, width
, bottom_y
- top_y
);
3598 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3599 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3603 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3604 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3606 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3607 XSetClipMask (s
->display
, s
->gc
, None
);
3611 /* Draw a box around glyph string S. */
3614 x_draw_glyph_string_box (s
)
3615 struct glyph_string
*s
;
3617 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3618 int left_p
, right_p
;
3619 struct glyph
*last_glyph
;
3620 XRectangle clip_rect
;
3622 last_x
= window_box_right (s
->w
, s
->area
);
3623 if (s
->row
->full_width_p
3624 && !s
->w
->pseudo_window_p
)
3626 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3627 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3628 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3631 /* The glyph that may have a right box line. */
3632 last_glyph
= (s
->cmp
|| s
->img
3634 : s
->first_glyph
+ s
->nchars
- 1);
3636 width
= s
->face
->box_line_width
;
3637 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3639 right_x
= ((s
->row
->full_width_p
3641 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3643 bottom_y
= top_y
+ s
->height
- 1;
3645 left_p
= (s
->first_glyph
->left_box_line_p
3646 || (s
->hl
== DRAW_MOUSE_FACE
3648 || s
->prev
->hl
!= s
->hl
)));
3649 right_p
= (last_glyph
->right_box_line_p
3650 || (s
->hl
== DRAW_MOUSE_FACE
3652 || s
->next
->hl
!= s
->hl
)));
3654 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3656 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3657 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3658 left_p
, right_p
, &clip_rect
);
3661 x_setup_relief_colors (s
);
3662 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3663 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3668 /* Draw foreground of image glyph string S. */
3671 x_draw_image_foreground (s
)
3672 struct glyph_string
*s
;
3675 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3677 /* If first glyph of S has a left box line, start drawing it to the
3678 right of that line. */
3679 if (s
->face
->box
!= FACE_NO_BOX
3680 && s
->first_glyph
->left_box_line_p
)
3681 x
= s
->x
+ s
->face
->box_line_width
;
3685 /* If there is a margin around the image, adjust x- and y-position
3689 x
+= s
->img
->margin
;
3690 y
+= s
->img
->margin
;
3697 /* We can't set both a clip mask and use XSetClipRectangles
3698 because the latter also sets a clip mask. We also can't
3699 trust on the shape extension to be available
3700 (XShapeCombineRegion). So, compute the rectangle to draw
3702 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3705 XRectangle clip_rect
, image_rect
, r
;
3707 xgcv
.clip_mask
= s
->img
->mask
;
3708 xgcv
.clip_x_origin
= x
;
3709 xgcv
.clip_y_origin
= y
;
3710 xgcv
.function
= GXcopy
;
3711 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3713 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3716 image_rect
.width
= s
->img
->width
;
3717 image_rect
.height
= s
->img
->height
;
3718 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3719 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3720 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3724 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
3726 XRectangle clip_rect
, image_rect
, r
;
3728 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3731 image_rect
.width
= s
->img
->width
;
3732 image_rect
.height
= s
->img
->height
;
3733 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3734 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3735 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3737 /* When the image has a mask, we can expect that at
3738 least part of a mouse highlight or a block cursor will
3739 be visible. If the image doesn't have a mask, make
3740 a block cursor visible by drawing a rectangle around
3741 the image. I believe it's looking better if we do
3742 nothing here for mouse-face. */
3743 if (s
->hl
== DRAW_CURSOR
)
3744 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3745 s
->img
->width
- 1, s
->img
->height
- 1);
3749 /* Draw a rectangle if image could not be loaded. */
3750 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3751 s
->img
->width
- 1, s
->img
->height
- 1);
3755 /* Draw a relief around the image glyph string S. */
3758 x_draw_image_relief (s
)
3759 struct glyph_string
*s
;
3761 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3764 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3766 /* If first glyph of S has a left box line, start drawing it to the
3767 right of that line. */
3768 if (s
->face
->box
!= FACE_NO_BOX
3769 && s
->first_glyph
->left_box_line_p
)
3770 x
= s
->x
+ s
->face
->box_line_width
;
3774 /* If there is a margin around the image, adjust x- and y-position
3778 x
+= s
->img
->margin
;
3779 y
+= s
->img
->margin
;
3782 if (s
->hl
== DRAW_IMAGE_SUNKEN
3783 || s
->hl
== DRAW_IMAGE_RAISED
)
3785 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3786 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3790 thick
= abs (s
->img
->relief
);
3791 raised_p
= s
->img
->relief
> 0;
3796 x1
= x
+ s
->img
->width
+ thick
- 1;
3797 y1
= y
+ s
->img
->height
+ thick
- 1;
3799 x_setup_relief_colors (s
);
3800 x_get_glyph_string_clip_rect (s
, &r
);
3801 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3805 /* Draw the foreground of image glyph string S to PIXMAP. */
3808 x_draw_image_foreground_1 (s
, pixmap
)
3809 struct glyph_string
*s
;
3813 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3815 /* If first glyph of S has a left box line, start drawing it to the
3816 right of that line. */
3817 if (s
->face
->box
!= FACE_NO_BOX
3818 && s
->first_glyph
->left_box_line_p
)
3819 x
= s
->face
->box_line_width
;
3823 /* If there is a margin around the image, adjust x- and y-position
3827 x
+= s
->img
->margin
;
3828 y
+= s
->img
->margin
;
3835 /* We can't set both a clip mask and use XSetClipRectangles
3836 because the latter also sets a clip mask. We also can't
3837 trust on the shape extension to be available
3838 (XShapeCombineRegion). So, compute the rectangle to draw
3840 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3844 xgcv
.clip_mask
= s
->img
->mask
;
3845 xgcv
.clip_x_origin
= x
;
3846 xgcv
.clip_y_origin
= y
;
3847 xgcv
.function
= GXcopy
;
3848 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3850 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3851 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3852 XSetClipMask (s
->display
, s
->gc
, None
);
3856 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3857 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3859 /* When the image has a mask, we can expect that at
3860 least part of a mouse highlight or a block cursor will
3861 be visible. If the image doesn't have a mask, make
3862 a block cursor visible by drawing a rectangle around
3863 the image. I believe it's looking better if we do
3864 nothing here for mouse-face. */
3865 if (s
->hl
== DRAW_CURSOR
)
3866 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3867 s
->img
->width
- 1, s
->img
->height
- 1);
3871 /* Draw a rectangle if image could not be loaded. */
3872 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3873 s
->img
->width
- 1, s
->img
->height
- 1);
3877 /* Draw part of the background of glyph string S. X, Y, W, and H
3878 give the rectangle to draw. */
3881 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3882 struct glyph_string
*s
;
3887 /* Fill background with a stipple pattern. */
3888 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3889 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3890 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3893 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3897 /* Draw image glyph string S.
3900 s->x +-------------------------
3903 | +-------------------------
3906 | | +-------------------
3912 x_draw_image_glyph_string (s
)
3913 struct glyph_string
*s
;
3916 int box_line_width
= s
->face
->box_line_width
;
3917 int margin
= s
->img
->margin
;
3919 Pixmap pixmap
= None
;
3921 height
= s
->height
- 2 * box_line_width
;
3923 /* Fill background with face under the image. Do it only if row is
3924 taller than image or if image has a clip mask to reduce
3926 s
->stippled_p
= s
->face
->stipple
!= 0;
3927 if (height
> s
->img
->height
3930 || s
->img
->pixmap
== 0
3931 || s
->width
!= s
->background_width
)
3933 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3934 x
= s
->x
+ box_line_width
;
3938 y
= s
->y
+ box_line_width
;
3942 /* Create a pixmap as large as the glyph string Fill it with
3943 the background color. Copy the image to it, using its
3944 mask. Copy the temporary pixmap to the display. */
3945 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3946 int depth
= DefaultDepthOfScreen (screen
);
3948 /* Create a pixmap as large as the glyph string. */
3949 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3950 s
->background_width
,
3953 /* Don't clip in the following because we're working on the
3955 XSetClipMask (s
->display
, s
->gc
, None
);
3957 /* Fill the pixmap with the background color/stipple. */
3960 /* Fill background with a stipple pattern. */
3961 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3962 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3963 0, 0, s
->background_width
, s
->height
);
3964 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3969 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3971 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3972 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3973 0, 0, s
->background_width
, s
->height
);
3974 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3978 /* Implementation idea: Is it possible to construct a mask?
3979 We could look at the color at the margins of the image, and
3980 say that this color is probably the background color of the
3982 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3984 s
->background_filled_p
= 1;
3987 /* Draw the foreground. */
3990 x_draw_image_foreground_1 (s
, pixmap
);
3991 x_set_glyph_string_clipping (s
);
3992 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
3993 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3994 XFreePixmap (s
->display
, pixmap
);
3997 x_draw_image_foreground (s
);
3999 /* If we must draw a relief around the image, do it. */
4001 || s
->hl
== DRAW_IMAGE_RAISED
4002 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4003 x_draw_image_relief (s
);
4007 /* Draw stretch glyph string S. */
4010 x_draw_stretch_glyph_string (s
)
4011 struct glyph_string
*s
;
4013 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4014 s
->stippled_p
= s
->face
->stipple
!= 0;
4016 if (s
->hl
== DRAW_CURSOR
4017 && !x_stretch_cursor_p
)
4019 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4020 as wide as the stretch glyph. */
4021 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4024 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4026 /* Clear rest using the GC of the original non-cursor face. */
4027 if (width
< s
->background_width
)
4029 GC gc
= s
->face
->gc
;
4030 int x
= s
->x
+ width
, y
= s
->y
;
4031 int w
= s
->background_width
- width
, h
= s
->height
;
4034 x_get_glyph_string_clip_rect (s
, &r
);
4035 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4037 if (s
->face
->stipple
)
4039 /* Fill background with a stipple pattern. */
4040 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4041 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4042 XSetFillStyle (s
->display
, gc
, FillSolid
);
4047 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4048 XSetForeground (s
->display
, gc
, xgcv
.background
);
4049 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4050 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4055 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4058 s
->background_filled_p
= 1;
4062 /* Draw glyph string S. */
4065 x_draw_glyph_string (s
)
4066 struct glyph_string
*s
;
4068 /* If S draws into the background of its successor, draw the
4069 background of the successor first so that S can draw into it.
4070 This makes S->next use XDrawString instead of XDrawImageString. */
4071 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4073 xassert (s
->next
->img
== NULL
);
4074 x_set_glyph_string_gc (s
->next
);
4075 x_set_glyph_string_clipping (s
->next
);
4076 x_draw_glyph_string_background (s
->next
, 1);
4079 /* Set up S->gc, set clipping and draw S. */
4080 x_set_glyph_string_gc (s
);
4081 x_set_glyph_string_clipping (s
);
4083 switch (s
->first_glyph
->type
)
4086 x_draw_image_glyph_string (s
);
4090 x_draw_stretch_glyph_string (s
);
4094 if (s
->for_overlaps_p
)
4095 s
->background_filled_p
= 1;
4097 x_draw_glyph_string_background (s
, 0);
4098 x_draw_glyph_string_foreground (s
);
4101 case COMPOSITE_GLYPH
:
4102 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4103 s
->background_filled_p
= 1;
4105 x_draw_glyph_string_background (s
, 1);
4106 x_draw_composite_glyph_string_foreground (s
);
4113 if (!s
->for_overlaps_p
)
4115 /* Draw underline. */
4116 if (s
->face
->underline_p
)
4118 unsigned long dy
, h
;
4120 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4122 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
4125 if (s
->face
->underline_defaulted_p
)
4126 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4131 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4132 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4133 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4135 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4139 /* Draw overline. */
4140 if (s
->face
->overline_p
)
4142 unsigned long dy
= 0, h
= 1;
4144 if (s
->face
->overline_color_defaulted_p
)
4145 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4150 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4151 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4152 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4154 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4158 /* Draw strike-through. */
4159 if (s
->face
->strike_through_p
)
4161 unsigned long h
= 1;
4162 unsigned long dy
= (s
->height
- h
) / 2;
4164 if (s
->face
->strike_through_color_defaulted_p
)
4165 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4170 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4171 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4172 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4174 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4179 if (s
->face
->box
!= FACE_NO_BOX
)
4180 x_draw_glyph_string_box (s
);
4183 /* Reset clipping. */
4184 XSetClipMask (s
->display
, s
->gc
, None
);
4188 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4189 struct face
**, int));
4192 /* Fill glyph string S with composition components specified by S->cmp.
4194 FACES is an array of faces for all components of this composition.
4195 S->gidx is the index of the first component for S.
4196 OVERLAPS_P non-zero means S should draw the foreground only, and
4197 use its physical height for clipping.
4199 Value is the index of a component not in S. */
4202 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4203 struct glyph_string
*s
;
4204 struct face
**faces
;
4211 s
->for_overlaps_p
= overlaps_p
;
4213 s
->face
= faces
[s
->gidx
];
4214 s
->font
= s
->face
->font
;
4215 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4217 /* For all glyphs of this composition, starting at the offset
4218 S->gidx, until we reach the end of the definition or encounter a
4219 glyph that requires the different face, add it to S. */
4221 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4224 /* All glyph strings for the same composition has the same width,
4225 i.e. the width set for the first component of the composition. */
4227 s
->width
= s
->first_glyph
->pixel_width
;
4229 /* If the specified font could not be loaded, use the frame's
4230 default font, but record the fact that we couldn't load it in
4231 the glyph string so that we can draw rectangles for the
4232 characters of the glyph string. */
4233 if (s
->font
== NULL
)
4235 s
->font_not_found_p
= 1;
4236 s
->font
= FRAME_FONT (s
->f
);
4239 /* Adjust base line for subscript/superscript text. */
4240 s
->ybase
+= s
->first_glyph
->voffset
;
4242 xassert (s
->face
&& s
->face
->gc
);
4244 /* This glyph string must always be drawn with 16-bit functions. */
4247 return s
->gidx
+ s
->nchars
;
4251 /* Fill glyph string S from a sequence of character glyphs.
4253 FACE_ID is the face id of the string. START is the index of the
4254 first glyph to consider, END is the index of the last + 1.
4255 OVERLAPS_P non-zero means S should draw the foreground only, and
4256 use its physical height for clipping.
4258 Value is the index of the first glyph not in S. */
4261 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4262 struct glyph_string
*s
;
4264 int start
, end
, overlaps_p
;
4266 struct glyph
*glyph
, *last
;
4268 int glyph_not_available_p
;
4270 xassert (s
->f
== XFRAME (s
->w
->frame
));
4271 xassert (s
->nchars
== 0);
4272 xassert (start
>= 0 && end
> start
);
4274 s
->for_overlaps_p
= overlaps_p
,
4275 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4276 last
= s
->row
->glyphs
[s
->area
] + end
;
4277 voffset
= glyph
->voffset
;
4279 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4282 && glyph
->type
== CHAR_GLYPH
4283 && glyph
->voffset
== voffset
4284 /* Same face id implies same font, nowadays. */
4285 && glyph
->face_id
== face_id
4286 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4290 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4291 s
->char2b
+ s
->nchars
,
4293 s
->two_byte_p
= two_byte_p
;
4295 xassert (s
->nchars
<= end
- start
);
4296 s
->width
+= glyph
->pixel_width
;
4300 s
->font
= s
->face
->font
;
4301 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4303 /* If the specified font could not be loaded, use the frame's font,
4304 but record the fact that we couldn't load it in
4305 S->font_not_found_p so that we can draw rectangles for the
4306 characters of the glyph string. */
4307 if (s
->font
== NULL
|| glyph_not_available_p
)
4309 s
->font_not_found_p
= 1;
4310 s
->font
= FRAME_FONT (s
->f
);
4313 /* Adjust base line for subscript/superscript text. */
4314 s
->ybase
+= voffset
;
4316 xassert (s
->face
&& s
->face
->gc
);
4317 return glyph
- s
->row
->glyphs
[s
->area
];
4321 /* Fill glyph string S from image glyph S->first_glyph. */
4324 x_fill_image_glyph_string (s
)
4325 struct glyph_string
*s
;
4327 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4328 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4330 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4331 s
->font
= s
->face
->font
;
4332 s
->width
= s
->first_glyph
->pixel_width
;
4334 /* Adjust base line for subscript/superscript text. */
4335 s
->ybase
+= s
->first_glyph
->voffset
;
4339 /* Fill glyph string S from a sequence of stretch glyphs.
4341 ROW is the glyph row in which the glyphs are found, AREA is the
4342 area within the row. START is the index of the first glyph to
4343 consider, END is the index of the last + 1.
4345 Value is the index of the first glyph not in S. */
4348 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4349 struct glyph_string
*s
;
4350 struct glyph_row
*row
;
4351 enum glyph_row_area area
;
4354 struct glyph
*glyph
, *last
;
4355 int voffset
, face_id
;
4357 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4359 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4360 last
= s
->row
->glyphs
[s
->area
] + end
;
4361 face_id
= glyph
->face_id
;
4362 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4363 s
->font
= s
->face
->font
;
4364 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4365 s
->width
= glyph
->pixel_width
;
4366 voffset
= glyph
->voffset
;
4370 && glyph
->type
== STRETCH_GLYPH
4371 && glyph
->voffset
== voffset
4372 && glyph
->face_id
== face_id
);
4374 s
->width
+= glyph
->pixel_width
;
4376 /* Adjust base line for subscript/superscript text. */
4377 s
->ybase
+= voffset
;
4379 xassert (s
->face
&& s
->face
->gc
);
4380 return glyph
- s
->row
->glyphs
[s
->area
];
4384 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4385 of XChar2b structures for S; it can't be allocated in
4386 x_init_glyph_string because it must be allocated via `alloca'. W
4387 is the window on which S is drawn. ROW and AREA are the glyph row
4388 and area within the row from which S is constructed. START is the
4389 index of the first glyph structure covered by S. HL is a
4390 face-override for drawing S. */
4393 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4394 struct glyph_string
*s
;
4397 struct glyph_row
*row
;
4398 enum glyph_row_area area
;
4400 enum draw_glyphs_face hl
;
4402 bzero (s
, sizeof *s
);
4404 s
->f
= XFRAME (w
->frame
);
4405 s
->display
= FRAME_X_DISPLAY (s
->f
);
4406 s
->window
= FRAME_X_WINDOW (s
->f
);
4411 s
->first_glyph
= row
->glyphs
[area
] + start
;
4412 s
->height
= row
->height
;
4413 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4415 /* Display the internal border below the tool-bar window. */
4416 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4417 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4419 s
->ybase
= s
->y
+ row
->ascent
;
4423 /* Set background width of glyph string S. START is the index of the
4424 first glyph following S. LAST_X is the right-most x-position + 1
4425 in the drawing area. */
4428 x_set_glyph_string_background_width (s
, start
, last_x
)
4429 struct glyph_string
*s
;
4433 /* If the face of this glyph string has to be drawn to the end of
4434 the drawing area, set S->extends_to_end_of_line_p. */
4435 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4437 if (start
== s
->row
->used
[s
->area
]
4438 && s
->hl
== DRAW_NORMAL_TEXT
4439 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4440 || s
->face
->background
!= default_face
->background
4441 || s
->face
->stipple
!= default_face
->stipple
))
4442 s
->extends_to_end_of_line_p
= 1;
4444 /* If S extends its face to the end of the line, set its
4445 background_width to the distance to the right edge of the drawing
4447 if (s
->extends_to_end_of_line_p
)
4448 s
->background_width
= last_x
- s
->x
+ 1;
4450 s
->background_width
= s
->width
;
4454 /* Add a glyph string for a stretch glyph to the list of strings
4455 between HEAD and TAIL. START is the index of the stretch glyph in
4456 row area AREA of glyph row ROW. END is the index of the last glyph
4457 in that glyph row area. X is the current output position assigned
4458 to the new glyph string constructed. HL overrides that face of the
4459 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4460 is the right-most x-position of the drawing area. */
4462 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4463 and below -- keep them on one line. */
4464 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4467 s = (struct glyph_string *) alloca (sizeof *s); \
4468 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4469 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4470 x_append_glyph_string (&HEAD, &TAIL, s); \
4476 /* Add a glyph string for an image glyph to the list of strings
4477 between HEAD and TAIL. START is the index of the image glyph in
4478 row area AREA of glyph row ROW. END is the index of the last glyph
4479 in that glyph row area. X is the current output position assigned
4480 to the new glyph string constructed. HL overrides that face of the
4481 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4482 is the right-most x-position of the drawing area. */
4484 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4487 s = (struct glyph_string *) alloca (sizeof *s); \
4488 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4489 x_fill_image_glyph_string (s); \
4490 x_append_glyph_string (&HEAD, &TAIL, s); \
4497 /* Add a glyph string for a sequence of character glyphs to the list
4498 of strings between HEAD and TAIL. START is the index of the first
4499 glyph in row area AREA of glyph row ROW that is part of the new
4500 glyph string. END is the index of the last glyph in that glyph row
4501 area. X is the current output position assigned to the new glyph
4502 string constructed. HL overrides that face of the glyph; e.g. it
4503 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4504 right-most x-position of the drawing area. */
4506 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4512 c = (ROW)->glyphs[AREA][START].u.ch; \
4513 face_id = (ROW)->glyphs[AREA][START].face_id; \
4515 s = (struct glyph_string *) alloca (sizeof *s); \
4516 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4517 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4518 x_append_glyph_string (&HEAD, &TAIL, s); \
4520 START = x_fill_glyph_string (s, face_id, START, END, \
4526 /* Add a glyph string for a composite sequence to the list of strings
4527 between HEAD and TAIL. START is the index of the first glyph in
4528 row area AREA of glyph row ROW that is part of the new glyph
4529 string. END is the index of the last glyph in that glyph row area.
4530 X is the current output position assigned to the new glyph string
4531 constructed. HL overrides that face of the glyph; e.g. it is
4532 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4533 x-position of the drawing area. */
4535 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4537 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4538 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4539 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4540 struct composition *cmp = composition_table[cmp_id]; \
4541 int glyph_len = cmp->glyph_len; \
4543 struct face **faces; \
4544 struct glyph_string *first_s = NULL; \
4547 base_face = base_face->ascii_face; \
4548 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4549 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4550 /* At first, fill in `char2b' and `faces'. */ \
4551 for (n = 0; n < glyph_len; n++) \
4553 int c = COMPOSITION_GLYPH (cmp, n); \
4554 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4555 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4556 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4557 this_face_id, char2b + n, 1); \
4560 /* Make glyph_strings for each glyph sequence that is drawable by \
4561 the same face, and append them to HEAD/TAIL. */ \
4562 for (n = 0; n < cmp->glyph_len;) \
4564 s = (struct glyph_string *) alloca (sizeof *s); \
4565 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4566 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4574 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4582 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4583 of AREA of glyph row ROW on window W between indices START and END.
4584 HL overrides the face for drawing glyph strings, e.g. it is
4585 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4586 x-positions of the drawing area.
4588 This is an ugly monster macro construct because we must use alloca
4589 to allocate glyph strings (because x_draw_glyphs can be called
4592 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4595 HEAD = TAIL = NULL; \
4596 while (START < END) \
4598 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4599 switch (first_glyph->type) \
4602 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4603 TAIL, HL, X, LAST_X, \
4607 case COMPOSITE_GLYPH: \
4608 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4609 HEAD, TAIL, HL, X, LAST_X,\
4613 case STRETCH_GLYPH: \
4614 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4615 HEAD, TAIL, HL, X, LAST_X); \
4619 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4620 TAIL, HL, X, LAST_X); \
4627 x_set_glyph_string_background_width (s, START, LAST_X); \
4634 /* Draw glyphs between START and END in AREA of ROW on window W,
4635 starting at x-position X. X is relative to AREA in W. HL is a
4636 face-override with the following meaning:
4638 DRAW_NORMAL_TEXT draw normally
4639 DRAW_CURSOR draw in cursor face
4640 DRAW_MOUSE_FACE draw in mouse face.
4641 DRAW_INVERSE_VIDEO draw in mode line face
4642 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4643 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4645 If REAL_START is non-null, return in *REAL_START the real starting
4646 position for display. This can be different from START in case
4647 overlapping glyphs must be displayed. If REAL_END is non-null,
4648 return in *REAL_END the real end position for display. This can be
4649 different from END in case overlapping glyphs must be displayed.
4651 If OVERLAPS_P is non-zero, draw only the foreground of characters
4652 and clip to the physical height of ROW.
4654 Value is the x-position reached, relative to AREA of W. */
4657 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4661 struct glyph_row
*row
;
4662 enum glyph_row_area area
;
4664 enum draw_glyphs_face hl
;
4665 int *real_start
, *real_end
;
4668 struct glyph_string
*head
, *tail
;
4669 struct glyph_string
*s
;
4670 int last_x
, area_width
;
4674 /* Let's rather be paranoid than getting a SEGV. */
4675 start
= max (0, start
);
4676 end
= min (end
, row
->used
[area
]);
4678 *real_start
= start
;
4682 /* Translate X to frame coordinates. Set last_x to the right
4683 end of the drawing area. */
4684 if (row
->full_width_p
)
4686 /* X is relative to the left edge of W, without scroll bars
4688 struct frame
*f
= XFRAME (w
->frame
);
4689 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4690 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4693 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4694 last_x
= window_left_x
+ area_width
;
4696 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4698 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4699 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4705 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4706 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4710 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4711 area_width
= window_box_width (w
, area
);
4712 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4715 /* Build a doubly-linked list of glyph_string structures between
4716 head and tail from what we have to draw. Note that the macro
4717 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4718 the reason we use a separate variable `i'. */
4720 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4723 x_reached
= tail
->x
+ tail
->background_width
;
4727 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4728 the row, redraw some glyphs in front or following the glyph
4729 strings built above. */
4730 if (!overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4733 struct glyph_string
*h
, *t
;
4735 /* Compute overhangs for all glyph strings. */
4736 for (s
= head
; s
; s
= s
->next
)
4737 x_compute_glyph_string_overhangs (s
);
4739 /* Prepend glyph strings for glyphs in front of the first glyph
4740 string that are overwritten because of the first glyph
4741 string's left overhang. The background of all strings
4742 prepended must be drawn because the first glyph string
4744 i
= x_left_overwritten (head
);
4748 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4749 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4753 *real_start
= start
;
4754 x_compute_overhangs_and_x (t
, head
->x
, 1);
4755 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4758 /* Prepend glyph strings for glyphs in front of the first glyph
4759 string that overwrite that glyph string because of their
4760 right overhang. For these strings, only the foreground must
4761 be drawn, because it draws over the glyph string at `head'.
4762 The background must not be drawn because this would overwrite
4763 right overhangs of preceding glyphs for which no glyph
4765 i
= x_left_overwriting (head
);
4768 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4769 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4771 for (s
= h
; s
; s
= s
->next
)
4772 s
->background_filled_p
= 1;
4775 x_compute_overhangs_and_x (t
, head
->x
, 1);
4776 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4779 /* Append glyphs strings for glyphs following the last glyph
4780 string tail that are overwritten by tail. The background of
4781 these strings has to be drawn because tail's foreground draws
4783 i
= x_right_overwritten (tail
);
4786 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4787 DRAW_NORMAL_TEXT
, x
, last_x
,
4789 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4790 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4795 /* Append glyph strings for glyphs following the last glyph
4796 string tail that overwrite tail. The foreground of such
4797 glyphs has to be drawn because it writes into the background
4798 of tail. The background must not be drawn because it could
4799 paint over the foreground of following glyphs. */
4800 i
= x_right_overwriting (tail
);
4803 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4804 DRAW_NORMAL_TEXT
, x
, last_x
,
4806 for (s
= h
; s
; s
= s
->next
)
4807 s
->background_filled_p
= 1;
4808 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4809 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4815 /* Draw all strings. */
4816 for (s
= head
; s
; s
= s
->next
)
4817 x_draw_glyph_string (s
);
4819 /* Value is the x-position up to which drawn, relative to AREA of W.
4820 This doesn't include parts drawn because of overhangs. */
4821 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4822 if (!row
->full_width_p
)
4824 if (area
> LEFT_MARGIN_AREA
)
4825 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4826 if (area
> TEXT_AREA
)
4827 x_reached
-= window_box_width (w
, TEXT_AREA
);
4833 /* Fix the display of area AREA of overlapping row ROW in window W. */
4836 x_fix_overlapping_area (w
, row
, area
)
4838 struct glyph_row
*row
;
4839 enum glyph_row_area area
;
4845 if (area
== LEFT_MARGIN_AREA
)
4847 else if (area
== TEXT_AREA
)
4848 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4850 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4851 + window_box_width (w
, TEXT_AREA
));
4853 for (i
= 0; i
< row
->used
[area
];)
4855 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4857 int start
= i
, start_x
= x
;
4861 x
+= row
->glyphs
[area
][i
].pixel_width
;
4864 while (i
< row
->used
[area
]
4865 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4867 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4869 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4874 x
+= row
->glyphs
[area
][i
].pixel_width
;
4883 /* Output LEN glyphs starting at START at the nominal cursor position.
4884 Advance the nominal cursor over the text. The global variable
4885 updated_window contains the window being updated, updated_row is
4886 the glyph row being updated, and updated_area is the area of that
4887 row being updated. */
4890 x_write_glyphs (start
, len
)
4891 struct glyph
*start
;
4894 int x
, hpos
, real_start
, real_end
;
4896 xassert (updated_window
&& updated_row
);
4901 hpos
= start
- updated_row
->glyphs
[updated_area
];
4902 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4903 updated_row
, updated_area
,
4905 (updated_row
->inverse_p
4906 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4907 &real_start
, &real_end
, 0);
4909 /* If we drew over the cursor, note that it is not visible any more. */
4910 note_overwritten_text_cursor (updated_window
, real_start
,
4911 real_end
- real_start
);
4915 /* Advance the output cursor. */
4916 output_cursor
.hpos
+= len
;
4917 output_cursor
.x
= x
;
4921 /* Insert LEN glyphs from START at the nominal cursor position. */
4924 x_insert_glyphs (start
, len
)
4925 struct glyph
*start
;
4930 int line_height
, shift_by_width
, shifted_region_width
;
4931 struct glyph_row
*row
;
4932 struct glyph
*glyph
;
4933 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4935 xassert (updated_window
&& updated_row
);
4938 f
= XFRAME (WINDOW_FRAME (w
));
4940 /* Get the height of the line we are in. */
4942 line_height
= row
->height
;
4944 /* Get the width of the glyphs to insert. */
4946 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4947 shift_by_width
+= glyph
->pixel_width
;
4949 /* Get the width of the region to shift right. */
4950 shifted_region_width
= (window_box_width (w
, updated_area
)
4955 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4956 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4957 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4958 f
->output_data
.x
->normal_gc
,
4960 shifted_region_width
, line_height
,
4961 frame_x
+ shift_by_width
, frame_y
);
4963 /* Write the glyphs. */
4964 hpos
= start
- row
->glyphs
[updated_area
];
4965 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4966 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4967 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4969 /* Advance the output cursor. */
4970 output_cursor
.hpos
+= len
;
4971 output_cursor
.x
+= shift_by_width
;
4976 /* Delete N glyphs at the nominal cursor position. Not implemented
4987 /* Erase the current text line from the nominal cursor position
4988 (inclusive) to pixel column TO_X (exclusive). The idea is that
4989 everything from TO_X onward is already erased.
4991 TO_X is a pixel position relative to updated_area of
4992 updated_window. TO_X == -1 means clear to the end of this area. */
4995 x_clear_end_of_line (to_x
)
4999 struct window
*w
= updated_window
;
5000 int max_x
, min_y
, max_y
;
5001 int from_x
, from_y
, to_y
;
5003 xassert (updated_window
&& updated_row
);
5004 f
= XFRAME (w
->frame
);
5006 if (updated_row
->full_width_p
)
5008 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5009 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5010 && !w
->pseudo_window_p
)
5011 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5014 max_x
= window_box_width (w
, updated_area
);
5015 max_y
= window_text_bottom_y (w
);
5017 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5018 of window. For TO_X > 0, truncate to end of drawing area. */
5024 to_x
= min (to_x
, max_x
);
5026 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5028 /* Notice if the cursor will be cleared by this operation. */
5029 if (!updated_row
->full_width_p
)
5030 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5032 from_x
= output_cursor
.x
;
5034 /* Translate to frame coordinates. */
5035 if (updated_row
->full_width_p
)
5037 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5038 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5042 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5043 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5046 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5047 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5048 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5050 /* Prevent inadvertently clearing to end of the X window. */
5051 if (to_x
> from_x
&& to_y
> from_y
)
5054 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5055 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5062 /* Clear entire frame. If updating_frame is non-null, clear that
5063 frame. Otherwise clear the selected frame. */
5073 f
= SELECTED_FRAME ();
5075 /* Clearing the frame will erase any cursor, so mark them all as no
5077 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5078 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5079 output_cursor
.x
= -1;
5081 /* We don't set the output cursor here because there will always
5082 follow an explicit cursor_to. */
5084 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5086 /* We have to clear the scroll bars, too. If we have changed
5087 colors or something like that, then they should be notified. */
5088 x_scroll_bar_clear (f
);
5090 XFlush (FRAME_X_DISPLAY (f
));
5096 /* Invert the middle quarter of the frame for .15 sec. */
5098 /* We use the select system call to do the waiting, so we have to make
5099 sure it's available. If it isn't, we just won't do visual bells. */
5101 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5104 /* Subtract the `struct timeval' values X and Y, storing the result in
5105 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5108 timeval_subtract (result
, x
, y
)
5109 struct timeval
*result
, x
, y
;
5111 /* Perform the carry for the later subtraction by updating y. This
5112 is safer because on some systems the tv_sec member is unsigned. */
5113 if (x
.tv_usec
< y
.tv_usec
)
5115 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5116 y
.tv_usec
-= 1000000 * nsec
;
5120 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5122 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5123 y
.tv_usec
+= 1000000 * nsec
;
5127 /* Compute the time remaining to wait. tv_usec is certainly
5129 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5130 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5132 /* Return indication of whether the result should be considered
5134 return x
.tv_sec
< y
.tv_sec
;
5146 /* Create a GC that will use the GXxor function to flip foreground
5147 pixels into background pixels. */
5151 values
.function
= GXxor
;
5152 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5153 ^ f
->output_data
.x
->background_pixel
);
5155 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5156 GCFunction
| GCForeground
, &values
);
5160 /* Get the height not including a menu bar widget. */
5161 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5162 /* Height of each line to flash. */
5163 int flash_height
= FRAME_LINE_HEIGHT (f
);
5164 /* These will be the left and right margins of the rectangles. */
5165 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5166 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5170 /* Don't flash the area between a scroll bar and the frame
5171 edge it is next to. */
5172 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5174 case vertical_scroll_bar_left
:
5175 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5178 case vertical_scroll_bar_right
:
5179 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5186 width
= flash_right
- flash_left
;
5188 /* If window is tall, flash top and bottom line. */
5189 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5191 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5193 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5194 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5195 width
, flash_height
);
5196 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5198 (height
- flash_height
5199 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5200 width
, flash_height
);
5203 /* If it is short, flash it all. */
5204 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5205 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5206 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5211 struct timeval wakeup
;
5213 EMACS_GET_TIME (wakeup
);
5215 /* Compute time to wait until, propagating carry from usecs. */
5216 wakeup
.tv_usec
+= 150000;
5217 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5218 wakeup
.tv_usec
%= 1000000;
5220 /* Keep waiting until past the time wakeup. */
5223 struct timeval timeout
;
5225 EMACS_GET_TIME (timeout
);
5227 /* In effect, timeout = wakeup - timeout.
5228 Break if result would be negative. */
5229 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5232 /* Try to wait that long--but we might wake up sooner. */
5233 select (0, NULL
, NULL
, NULL
, &timeout
);
5237 /* If window is tall, flash top and bottom line. */
5238 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5240 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5242 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5243 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5244 width
, flash_height
);
5245 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5247 (height
- flash_height
5248 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5249 width
, flash_height
);
5252 /* If it is short, flash it all. */
5253 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5254 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5255 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5257 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5265 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5268 /* Make audible bell. */
5273 struct frame
*f
= SELECTED_FRAME ();
5275 if (FRAME_X_DISPLAY (f
))
5277 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5284 XBell (FRAME_X_DISPLAY (f
), 0);
5285 XFlush (FRAME_X_DISPLAY (f
));
5292 /* Specify how many text lines, from the top of the window,
5293 should be affected by insert-lines and delete-lines operations.
5294 This, and those operations, are used only within an update
5295 that is bounded by calls to x_update_begin and x_update_end. */
5298 XTset_terminal_window (n
)
5301 /* This function intentionally left blank. */
5306 /***********************************************************************
5308 ***********************************************************************/
5310 /* Perform an insert-lines or delete-lines operation, inserting N
5311 lines or deleting -N lines at vertical position VPOS. */
5314 x_ins_del_lines (vpos
, n
)
5321 /* Scroll part of the display as described by RUN. */
5324 x_scroll_run (w
, run
)
5328 struct frame
*f
= XFRAME (w
->frame
);
5329 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5331 /* Get frame-relative bounding box of the text display area of W,
5332 without mode lines. Include in this box the flags areas to the
5333 left and right of W. */
5334 window_box (w
, -1, &x
, &y
, &width
, &height
);
5335 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5336 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5338 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5339 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5340 bottom_y
= y
+ height
;
5344 /* Scrolling up. Make sure we don't copy part of the mode
5345 line at the bottom. */
5346 if (from_y
+ run
->height
> bottom_y
)
5347 height
= bottom_y
- from_y
;
5349 height
= run
->height
;
5353 /* Scolling down. Make sure we don't copy over the mode line.
5355 if (to_y
+ run
->height
> bottom_y
)
5356 height
= bottom_y
- to_y
;
5358 height
= run
->height
;
5363 /* Cursor off. Will be switched on again in x_update_window_end. */
5367 XCopyArea (FRAME_X_DISPLAY (f
),
5368 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5369 f
->output_data
.x
->normal_gc
,
5379 /***********************************************************************
5381 ***********************************************************************/
5383 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5384 corner of the exposed rectangle. W and H are width and height of
5385 the exposed area. All are pixel values. W or H zero means redraw
5386 the entire frame. */
5389 expose_frame (f
, x
, y
, w
, h
)
5395 TRACE ((stderr
, "expose_frame "));
5397 /* No need to redraw if frame will be redrawn soon. */
5398 if (FRAME_GARBAGED_P (f
))
5400 TRACE ((stderr
, " garbaged\n"));
5404 /* If basic faces haven't been realized yet, there is no point in
5405 trying to redraw anything. This can happen when we get an expose
5406 event while Emacs is starting, e.g. by moving another window. */
5407 if (FRAME_FACE_CACHE (f
) == NULL
5408 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5410 TRACE ((stderr
, " no faces\n"));
5414 if (w
== 0 || h
== 0)
5417 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5418 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5428 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5429 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5431 if (WINDOWP (f
->tool_bar_window
))
5433 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5434 XRectangle window_rect
;
5435 XRectangle intersection_rect
;
5436 int window_x
, window_y
, window_width
, window_height
;
5439 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5440 window_rect
.x
= window_x
;
5441 window_rect
.y
= window_y
;
5442 window_rect
.width
= window_width
;
5443 window_rect
.height
= window_height
;
5445 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5446 expose_window (w
, &intersection_rect
);
5449 #ifndef USE_X_TOOLKIT
5450 if (WINDOWP (f
->menu_bar_window
))
5452 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5453 XRectangle window_rect
;
5454 XRectangle intersection_rect
;
5455 int window_x
, window_y
, window_width
, window_height
;
5458 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5459 window_rect
.x
= window_x
;
5460 window_rect
.y
= window_y
;
5461 window_rect
.width
= window_width
;
5462 window_rect
.height
= window_height
;
5464 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5465 expose_window (w
, &intersection_rect
);
5467 #endif /* not USE_X_TOOLKIT */
5471 /* Redraw (parts) of all windows in the window tree rooted at W that
5472 intersect R. R contains frame pixel coordinates. */
5475 expose_window_tree (w
, r
)
5481 if (!NILP (w
->hchild
))
5482 expose_window_tree (XWINDOW (w
->hchild
), r
);
5483 else if (!NILP (w
->vchild
))
5484 expose_window_tree (XWINDOW (w
->vchild
), r
);
5487 XRectangle window_rect
;
5488 XRectangle intersection_rect
;
5489 struct frame
*f
= XFRAME (w
->frame
);
5490 int window_x
, window_y
, window_width
, window_height
;
5492 /* Frame-relative pixel rectangle of W. */
5493 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5497 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5498 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5499 window_rect
.y
= window_y
;
5502 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5503 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5505 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5507 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5508 expose_window (w
, &intersection_rect
);
5511 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5516 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5517 which intersects rectangle R. R is in window-relative coordinates. */
5520 expose_area (w
, row
, r
, area
)
5522 struct glyph_row
*row
;
5524 enum glyph_row_area area
;
5527 struct glyph
*first
= row
->glyphs
[area
];
5528 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5532 /* Set x to the window-relative start position for drawing glyphs of
5533 AREA. The first glyph of the text area can be partially visible.
5534 The first glyphs of other areas cannot. */
5535 if (area
== LEFT_MARGIN_AREA
)
5537 else if (area
== TEXT_AREA
)
5538 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5540 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5541 + window_box_width (w
, TEXT_AREA
));
5543 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5544 /* If row extends face to end of line write the whole line. */
5545 x_draw_glyphs (w
, x
, row
, area
,
5547 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5551 /* Find the first glyph that must be redrawn. */
5553 && x
+ first
->pixel_width
< r
->x
)
5555 x
+= first
->pixel_width
;
5559 /* Find the last one. */
5563 && x
< r
->x
+ r
->width
)
5565 x
+= last
->pixel_width
;
5571 x_draw_glyphs (w
, first_x
, row
, area
,
5572 first
- row
->glyphs
[area
],
5573 last
- row
->glyphs
[area
],
5574 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5580 /* Redraw the parts of the glyph row ROW on window W intersecting
5581 rectangle R. R is in window-relative coordinates. */
5584 expose_line (w
, row
, r
)
5586 struct glyph_row
*row
;
5589 xassert (row
->enabled_p
);
5591 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5592 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5593 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5597 if (row
->used
[LEFT_MARGIN_AREA
])
5598 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5599 if (row
->used
[TEXT_AREA
])
5600 expose_area (w
, row
, r
, TEXT_AREA
);
5601 if (row
->used
[RIGHT_MARGIN_AREA
])
5602 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5603 x_draw_row_bitmaps (w
, row
);
5608 /* Return non-zero if W's cursor intersects rectangle R. */
5611 x_phys_cursor_in_rect_p (w
, r
)
5615 XRectangle cr
, result
;
5616 struct glyph
*cursor_glyph
;
5618 cursor_glyph
= get_phys_cursor_glyph (w
);
5621 cr
.x
= w
->phys_cursor
.x
;
5622 cr
.y
= w
->phys_cursor
.y
;
5623 cr
.width
= cursor_glyph
->pixel_width
;
5624 cr
.height
= w
->phys_cursor_height
;
5625 return x_intersect_rectangles (&cr
, r
, &result
);
5632 /* Redraw a rectangle of window W. R is a rectangle in window
5633 relative coordinates. Call this function with input blocked. */
5636 expose_window (w
, r
)
5640 struct glyph_row
*row
;
5642 int yb
= window_text_bottom_y (w
);
5643 int cursor_cleared_p
;
5645 /* If window is not yet fully initialized, do nothing. This can
5646 happen when toolkit scroll bars are used and a window is split.
5647 Reconfiguring the scroll bar will generate an expose for a newly
5649 if (w
->current_matrix
== NULL
)
5652 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5653 r
->x
, r
->y
, r
->width
, r
->height
));
5655 /* Convert to window coordinates. */
5656 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5657 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5659 /* Turn off the cursor. */
5660 if (!w
->pseudo_window_p
5661 && x_phys_cursor_in_rect_p (w
, r
))
5664 cursor_cleared_p
= 1;
5667 cursor_cleared_p
= 0;
5669 /* Find the first row intersecting the rectangle R. */
5670 row
= w
->current_matrix
->rows
;
5672 while (row
->enabled_p
5674 && y
+ row
->height
< r
->y
)
5680 /* Display the text in the rectangle, one text line at a time. */
5681 while (row
->enabled_p
5683 && y
< r
->y
+ r
->height
)
5685 expose_line (w
, row
, r
);
5690 /* Display the mode line if there is one. */
5691 if (WINDOW_WANTS_MODELINE_P (w
)
5692 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5694 && row
->y
< r
->y
+ r
->height
)
5695 expose_line (w
, row
, r
);
5697 if (!w
->pseudo_window_p
)
5699 /* Draw border between windows. */
5700 x_draw_vertical_border (w
);
5702 /* Turn the cursor on again. */
5703 if (cursor_cleared_p
)
5704 x_update_window_cursor (w
, 1);
5709 /* Determine the intersection of two rectangles R1 and R2. Return
5710 the intersection in *RESULT. Value is non-zero if RESULT is not
5714 x_intersect_rectangles (r1
, r2
, result
)
5715 XRectangle
*r1
, *r2
, *result
;
5717 XRectangle
*left
, *right
;
5718 XRectangle
*upper
, *lower
;
5719 int intersection_p
= 0;
5721 /* Rearrange so that R1 is the left-most rectangle. */
5723 left
= r1
, right
= r2
;
5725 left
= r2
, right
= r1
;
5727 /* X0 of the intersection is right.x0, if this is inside R1,
5728 otherwise there is no intersection. */
5729 if (right
->x
<= left
->x
+ left
->width
)
5731 result
->x
= right
->x
;
5733 /* The right end of the intersection is the minimum of the
5734 the right ends of left and right. */
5735 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5738 /* Same game for Y. */
5740 upper
= r1
, lower
= r2
;
5742 upper
= r2
, lower
= r1
;
5744 /* The upper end of the intersection is lower.y0, if this is inside
5745 of upper. Otherwise, there is no intersection. */
5746 if (lower
->y
<= upper
->y
+ upper
->height
)
5748 result
->y
= lower
->y
;
5750 /* The lower end of the intersection is the minimum of the lower
5751 ends of upper and lower. */
5752 result
->height
= (min (lower
->y
+ lower
->height
,
5753 upper
->y
+ upper
->height
)
5759 return intersection_p
;
5770 /* We used to only do this if Vx_no_window_manager was non-nil, but
5771 the ICCCM (section 4.1.6) says that the window's border pixmap
5772 and border pixel are window attributes which are "private to the
5773 client", so we can always change it to whatever we want. */
5775 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5776 f
->output_data
.x
->border_pixel
);
5778 x_update_cursor (f
, 1);
5782 frame_unhighlight (f
)
5785 /* We used to only do this if Vx_no_window_manager was non-nil, but
5786 the ICCCM (section 4.1.6) says that the window's border pixmap
5787 and border pixel are window attributes which are "private to the
5788 client", so we can always change it to whatever we want. */
5790 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5791 f
->output_data
.x
->border_tile
);
5793 x_update_cursor (f
, 1);
5796 /* The focus has changed. Update the frames as necessary to reflect
5797 the new situation. Note that we can't change the selected frame
5798 here, because the Lisp code we are interrupting might become confused.
5799 Each event gets marked with the frame in which it occurred, so the
5800 Lisp code can tell when the switch took place by examining the events. */
5803 x_new_focus_frame (dpyinfo
, frame
)
5804 struct x_display_info
*dpyinfo
;
5805 struct frame
*frame
;
5807 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5809 if (frame
!= dpyinfo
->x_focus_frame
)
5811 /* Set this before calling other routines, so that they see
5812 the correct value of x_focus_frame. */
5813 dpyinfo
->x_focus_frame
= frame
;
5815 if (old_focus
&& old_focus
->auto_lower
)
5816 x_lower_frame (old_focus
);
5819 selected_frame
= frame
;
5820 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5822 Fselect_window (selected_frame
->selected_window
);
5823 choose_minibuf_frame ();
5826 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5827 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5829 pending_autoraise_frame
= 0;
5832 x_frame_rehighlight (dpyinfo
);
5835 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5838 x_mouse_leave (dpyinfo
)
5839 struct x_display_info
*dpyinfo
;
5841 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5844 /* The focus has changed, or we have redirected a frame's focus to
5845 another frame (this happens when a frame uses a surrogate
5846 mini-buffer frame). Shift the highlight as appropriate.
5848 The FRAME argument doesn't necessarily have anything to do with which
5849 frame is being highlighted or un-highlighted; we only use it to find
5850 the appropriate X display info. */
5853 XTframe_rehighlight (frame
)
5854 struct frame
*frame
;
5856 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5860 x_frame_rehighlight (dpyinfo
)
5861 struct x_display_info
*dpyinfo
;
5863 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5865 if (dpyinfo
->x_focus_frame
)
5867 dpyinfo
->x_highlight_frame
5868 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5869 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5870 : dpyinfo
->x_focus_frame
);
5871 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5873 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5874 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5878 dpyinfo
->x_highlight_frame
= 0;
5880 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5883 frame_unhighlight (old_highlight
);
5884 if (dpyinfo
->x_highlight_frame
)
5885 frame_highlight (dpyinfo
->x_highlight_frame
);
5891 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5893 /* Initialize mode_switch_bit and modifier_meaning. */
5895 x_find_modifier_meanings (dpyinfo
)
5896 struct x_display_info
*dpyinfo
;
5898 int min_code
, max_code
;
5901 XModifierKeymap
*mods
;
5903 dpyinfo
->meta_mod_mask
= 0;
5904 dpyinfo
->shift_lock_mask
= 0;
5905 dpyinfo
->alt_mod_mask
= 0;
5906 dpyinfo
->super_mod_mask
= 0;
5907 dpyinfo
->hyper_mod_mask
= 0;
5910 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5912 min_code
= dpyinfo
->display
->min_keycode
;
5913 max_code
= dpyinfo
->display
->max_keycode
;
5916 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5917 min_code
, max_code
- min_code
+ 1,
5919 mods
= XGetModifierMapping (dpyinfo
->display
);
5921 /* Scan the modifier table to see which modifier bits the Meta and
5922 Alt keysyms are on. */
5924 int row
, col
; /* The row and column in the modifier table. */
5926 for (row
= 3; row
< 8; row
++)
5927 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5930 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5932 /* Zeroes are used for filler. Skip them. */
5936 /* Are any of this keycode's keysyms a meta key? */
5940 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5942 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5948 dpyinfo
->meta_mod_mask
|= (1 << row
);
5953 dpyinfo
->alt_mod_mask
|= (1 << row
);
5958 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5963 dpyinfo
->super_mod_mask
|= (1 << row
);
5967 /* Ignore this if it's not on the lock modifier. */
5968 if ((1 << row
) == LockMask
)
5969 dpyinfo
->shift_lock_mask
= LockMask
;
5977 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5978 if (! dpyinfo
->meta_mod_mask
)
5980 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
5981 dpyinfo
->alt_mod_mask
= 0;
5984 /* If some keys are both alt and meta,
5985 make them just meta, not alt. */
5986 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
5988 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
5991 XFree ((char *) syms
);
5992 XFreeModifiermap (mods
);
5995 /* Convert between the modifier bits X uses and the modifier bits
5999 x_x_to_emacs_modifiers (dpyinfo
, state
)
6000 struct x_display_info
*dpyinfo
;
6003 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6004 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6005 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6006 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6007 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6008 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6012 x_emacs_to_x_modifiers (dpyinfo
, state
)
6013 struct x_display_info
*dpyinfo
;
6016 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6017 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6018 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6019 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6020 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6021 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6024 /* Convert a keysym to its name. */
6027 x_get_keysym_name (keysym
)
6033 value
= XKeysymToString (keysym
);
6041 /* Mouse clicks and mouse movement. Rah. */
6043 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6044 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6045 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6046 not force the value into range. */
6049 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6051 register int pix_x
, pix_y
;
6052 register int *x
, *y
;
6056 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6057 even for negative values. */
6059 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6061 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6063 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6064 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6068 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6069 bounds
->height
= f
->output_data
.x
->line_height
;
6070 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6071 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6078 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6079 pix_x
= FRAME_WINDOW_WIDTH (f
);
6083 else if (pix_y
> f
->height
)
6092 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6093 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6094 can't tell the positions because W's display is not up to date,
6098 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6101 int *frame_x
, *frame_y
;
6105 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6106 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6108 if (display_completed
)
6110 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6111 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6112 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6118 *frame_x
+= glyph
->pixel_width
;
6126 *frame_y
= *frame_x
= 0;
6130 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6131 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6136 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6138 If the event is a button press, then note that we have grabbed
6142 construct_mouse_click (result
, event
, f
)
6143 struct input_event
*result
;
6144 XButtonEvent
*event
;
6147 /* Make the event type no_event; we'll change that when we decide
6149 result
->kind
= mouse_click
;
6150 result
->code
= event
->button
- Button1
;
6151 result
->timestamp
= event
->time
;
6152 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6154 | (event
->type
== ButtonRelease
6158 XSETINT (result
->x
, event
->x
);
6159 XSETINT (result
->y
, event
->y
);
6160 XSETFRAME (result
->frame_or_window
, f
);
6166 /* Function to report a mouse movement to the mainstream Emacs code.
6167 The input handler calls this.
6169 We have received a mouse movement event, which is given in *event.
6170 If the mouse is over a different glyph than it was last time, tell
6171 the mainstream emacs code by setting mouse_moved. If not, ask for
6172 another motion event, so we can check again the next time it moves. */
6174 static XMotionEvent last_mouse_motion_event
;
6175 static Lisp_Object last_mouse_motion_frame
;
6178 note_mouse_movement (frame
, event
)
6180 XMotionEvent
*event
;
6182 last_mouse_movement_time
= event
->time
;
6183 last_mouse_motion_event
= *event
;
6184 XSETFRAME (last_mouse_motion_frame
, frame
);
6186 if (event
->window
!= FRAME_X_WINDOW (frame
))
6188 frame
->mouse_moved
= 1;
6189 last_mouse_scroll_bar
= Qnil
;
6190 note_mouse_highlight (frame
, -1, -1);
6193 /* Has the mouse moved off the glyph it was on at the last sighting? */
6194 else if (event
->x
< last_mouse_glyph
.x
6195 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6196 || event
->y
< last_mouse_glyph
.y
6197 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6199 frame
->mouse_moved
= 1;
6200 last_mouse_scroll_bar
= Qnil
;
6201 note_mouse_highlight (frame
, event
->x
, event
->y
);
6205 /* This is used for debugging, to turn off note_mouse_highlight. */
6207 int disable_mouse_highlight
;
6211 /************************************************************************
6213 ************************************************************************/
6215 /* Find the glyph under window-relative coordinates X/Y in window W.
6216 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6217 strings. Return in *HPOS and *VPOS the row and column number of
6218 the glyph found. Return in *AREA the glyph area containing X.
6219 Value is a pointer to the glyph found or null if X/Y is not on
6220 text, or we can't tell because W's current matrix is not up to
6223 static struct glyph
*
6224 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6227 int *hpos
, *vpos
, *area
;
6229 struct glyph
*glyph
, *end
;
6230 struct glyph_row
*row
= NULL
;
6231 int x0
, i
, left_area_width
;
6233 /* Find row containing Y. Give up if some row is not enabled. */
6234 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6236 row
= MATRIX_ROW (w
->current_matrix
, i
);
6237 if (!row
->enabled_p
)
6239 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6246 /* Give up if Y is not in the window. */
6247 if (i
== w
->current_matrix
->nrows
)
6250 /* Get the glyph area containing X. */
6251 if (w
->pseudo_window_p
)
6258 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6259 if (x
< left_area_width
)
6261 *area
= LEFT_MARGIN_AREA
;
6264 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6267 x0
= row
->x
+ left_area_width
;
6271 *area
= RIGHT_MARGIN_AREA
;
6272 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6276 /* Find glyph containing X. */
6277 glyph
= row
->glyphs
[*area
];
6278 end
= glyph
+ row
->used
[*area
];
6281 if (x
< x0
+ glyph
->pixel_width
)
6283 if (w
->pseudo_window_p
)
6285 else if (BUFFERP (glyph
->object
))
6289 x0
+= glyph
->pixel_width
;
6296 *hpos
= glyph
- row
->glyphs
[*area
];
6301 /* Convert frame-relative x/y to coordinates relative to window W.
6302 Takes pseudo-windows into account. */
6305 frame_to_window_pixel_xy (w
, x
, y
)
6309 if (w
->pseudo_window_p
)
6311 /* A pseudo-window is always full-width, and starts at the
6312 left edge of the frame, plus a frame border. */
6313 struct frame
*f
= XFRAME (w
->frame
);
6314 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6315 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6319 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6320 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6325 /* Take proper action when mouse has moved to the mode or top line of
6326 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6327 mode line. X is relative to the start of the text display area of
6328 W, so the width of bitmap areas and scroll bars must be subtracted
6329 to get a position relative to the start of the mode line. */
6332 note_mode_line_highlight (w
, x
, mode_line_p
)
6336 struct frame
*f
= XFRAME (w
->frame
);
6337 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6338 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6339 struct glyph_row
*row
;
6342 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6344 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6348 struct glyph
*glyph
, *end
;
6349 Lisp_Object help
, map
;
6352 /* Find the glyph under X. */
6353 glyph
= row
->glyphs
[TEXT_AREA
];
6354 end
= glyph
+ row
->used
[TEXT_AREA
];
6355 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6356 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6358 && x
>= x0
+ glyph
->pixel_width
)
6360 x0
+= glyph
->pixel_width
;
6365 && STRINGP (glyph
->object
)
6366 && XSTRING (glyph
->object
)->intervals
6367 && glyph
->charpos
>= 0
6368 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6370 /* If we're on a string with `help-echo' text property,
6371 arrange for the help to be displayed. This is done by
6372 setting the global variable help_echo to the help string. */
6373 help
= Fget_text_property (make_number (glyph
->charpos
),
6374 Qhelp_echo
, glyph
->object
);
6378 XSETWINDOW (help_echo_window
, w
);
6379 help_echo_object
= glyph
->object
;
6380 help_echo_pos
= glyph
->charpos
;
6383 /* Change the mouse pointer according to what is under X/Y. */
6384 map
= Fget_text_property (make_number (glyph
->charpos
),
6385 Qlocal_map
, glyph
->object
);
6386 if (!NILP (Fkeymapp (map
)))
6387 cursor
= f
->output_data
.x
->nontext_cursor
;
6390 map
= Fget_text_property (make_number (glyph
->charpos
),
6391 Qkeymap
, glyph
->object
);
6392 if (!NILP (Fkeymapp (map
)))
6393 cursor
= f
->output_data
.x
->nontext_cursor
;
6398 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6402 /* Take proper action when the mouse has moved to position X, Y on
6403 frame F as regards highlighting characters that have mouse-face
6404 properties. Also de-highlighting chars where the mouse was before.
6405 X and Y can be negative or out of range. */
6408 note_mouse_highlight (f
, x
, y
)
6412 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6417 /* When a menu is active, don't highlight because this looks odd. */
6418 #ifdef USE_X_TOOLKIT
6419 if (popup_activated ())
6423 if (disable_mouse_highlight
6424 || !f
->glyphs_initialized_p
)
6427 dpyinfo
->mouse_face_mouse_x
= x
;
6428 dpyinfo
->mouse_face_mouse_y
= y
;
6429 dpyinfo
->mouse_face_mouse_frame
= f
;
6431 if (dpyinfo
->mouse_face_defer
)
6436 dpyinfo
->mouse_face_deferred_gc
= 1;
6440 /* Which window is that in? */
6441 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6443 /* If we were displaying active text in another window, clear that. */
6444 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6445 clear_mouse_face (dpyinfo
);
6447 /* Not on a window -> return. */
6448 if (!WINDOWP (window
))
6451 /* Convert to window-relative pixel coordinates. */
6452 w
= XWINDOW (window
);
6453 frame_to_window_pixel_xy (w
, &x
, &y
);
6455 /* Handle tool-bar window differently since it doesn't display a
6457 if (EQ (window
, f
->tool_bar_window
))
6459 note_tool_bar_highlight (f
, x
, y
);
6463 if (portion
== 1 || portion
== 3)
6465 /* Mouse is on the mode or top line. */
6466 note_mode_line_highlight (w
, x
, portion
== 1);
6470 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6471 f
->output_data
.x
->text_cursor
);
6473 /* Are we in a window whose display is up to date?
6474 And verify the buffer's text has not changed. */
6475 if (/* Within text portion of the window. */
6477 && EQ (w
->window_end_valid
, w
->buffer
)
6478 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6479 && (XFASTINT (w
->last_overlay_modified
)
6480 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6482 int hpos
, vpos
, pos
, i
, area
;
6483 struct glyph
*glyph
;
6485 /* Find the glyph under X/Y. */
6486 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6488 /* Clear mouse face if X/Y not over text. */
6490 || area
!= TEXT_AREA
6491 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6493 clear_mouse_face (dpyinfo
);
6497 pos
= glyph
->charpos
;
6498 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6500 /* Check for mouse-face and help-echo. */
6502 Lisp_Object mouse_face
, overlay
, position
;
6503 Lisp_Object
*overlay_vec
;
6505 struct buffer
*obuf
;
6508 /* If we get an out-of-range value, return now; avoid an error. */
6509 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6512 /* Make the window's buffer temporarily current for
6513 overlays_at and compute_char_face. */
6514 obuf
= current_buffer
;
6515 current_buffer
= XBUFFER (w
->buffer
);
6521 /* Is this char mouse-active or does it have help-echo? */
6522 XSETINT (position
, pos
);
6524 /* Put all the overlays we want in a vector in overlay_vec.
6525 Store the length in len. If there are more than 10, make
6526 enough space for all, and try again. */
6528 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6529 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6530 if (noverlays
> len
)
6533 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6534 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6537 /* Sort overlays into increasing priority order. */
6538 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6540 /* Check mouse-face highlighting. */
6541 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6542 && vpos
>= dpyinfo
->mouse_face_beg_row
6543 && vpos
<= dpyinfo
->mouse_face_end_row
6544 && (vpos
> dpyinfo
->mouse_face_beg_row
6545 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6546 && (vpos
< dpyinfo
->mouse_face_end_row
6547 || hpos
< dpyinfo
->mouse_face_end_col
6548 || dpyinfo
->mouse_face_past_end
)))
6550 /* Clear the display of the old active region, if any. */
6551 clear_mouse_face (dpyinfo
);
6553 /* Find the highest priority overlay that has a mouse-face prop. */
6555 for (i
= noverlays
- 1; i
>= 0; --i
)
6557 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6558 if (!NILP (mouse_face
))
6560 overlay
= overlay_vec
[i
];
6565 /* If no overlay applies, get a text property. */
6567 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6569 /* Handle the overlay case. */
6570 if (! NILP (overlay
))
6572 /* Find the range of text around this char that
6573 should be active. */
6574 Lisp_Object before
, after
;
6577 before
= Foverlay_start (overlay
);
6578 after
= Foverlay_end (overlay
);
6579 /* Record this as the current active region. */
6580 fast_find_position (w
, XFASTINT (before
),
6581 &dpyinfo
->mouse_face_beg_col
,
6582 &dpyinfo
->mouse_face_beg_row
,
6583 &dpyinfo
->mouse_face_beg_x
,
6584 &dpyinfo
->mouse_face_beg_y
);
6585 dpyinfo
->mouse_face_past_end
6586 = !fast_find_position (w
, XFASTINT (after
),
6587 &dpyinfo
->mouse_face_end_col
,
6588 &dpyinfo
->mouse_face_end_row
,
6589 &dpyinfo
->mouse_face_end_x
,
6590 &dpyinfo
->mouse_face_end_y
);
6591 dpyinfo
->mouse_face_window
= window
;
6592 dpyinfo
->mouse_face_face_id
6593 = face_at_buffer_position (w
, pos
, 0, 0,
6594 &ignore
, pos
+ 1, 1);
6596 /* Display it as active. */
6597 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6599 /* Handle the text property case. */
6600 else if (! NILP (mouse_face
))
6602 /* Find the range of text around this char that
6603 should be active. */
6604 Lisp_Object before
, after
, beginning
, end
;
6607 beginning
= Fmarker_position (w
->start
);
6608 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6609 - XFASTINT (w
->window_end_pos
)));
6611 = Fprevious_single_property_change (make_number (pos
+ 1),
6613 w
->buffer
, beginning
);
6615 = Fnext_single_property_change (position
, Qmouse_face
,
6617 /* Record this as the current active region. */
6618 fast_find_position (w
, XFASTINT (before
),
6619 &dpyinfo
->mouse_face_beg_col
,
6620 &dpyinfo
->mouse_face_beg_row
,
6621 &dpyinfo
->mouse_face_beg_x
,
6622 &dpyinfo
->mouse_face_beg_y
);
6623 dpyinfo
->mouse_face_past_end
6624 = !fast_find_position (w
, XFASTINT (after
),
6625 &dpyinfo
->mouse_face_end_col
,
6626 &dpyinfo
->mouse_face_end_row
,
6627 &dpyinfo
->mouse_face_end_x
,
6628 &dpyinfo
->mouse_face_end_y
);
6629 dpyinfo
->mouse_face_window
= window
;
6630 dpyinfo
->mouse_face_face_id
6631 = face_at_buffer_position (w
, pos
, 0, 0,
6632 &ignore
, pos
+ 1, 1);
6634 /* Display it as active. */
6635 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6639 /* Look for a `help-echo' property. */
6641 Lisp_Object help
, overlay
;
6643 /* Check overlays first. */
6645 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6647 overlay
= overlay_vec
[i
];
6648 help
= Foverlay_get (overlay
, Qhelp_echo
);
6654 help_echo_window
= window
;
6655 help_echo_object
= overlay
;
6656 help_echo_pos
= pos
;
6660 /* Try text properties. */
6661 if ((STRINGP (glyph
->object
)
6662 && glyph
->charpos
>= 0
6663 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6664 || (BUFFERP (glyph
->object
)
6665 && glyph
->charpos
>= BEGV
6666 && glyph
->charpos
< ZV
))
6667 help
= Fget_text_property (make_number (glyph
->charpos
),
6668 Qhelp_echo
, glyph
->object
);
6673 help_echo_window
= window
;
6674 help_echo_object
= glyph
->object
;
6675 help_echo_pos
= glyph
->charpos
;
6682 current_buffer
= obuf
;
6688 redo_mouse_highlight ()
6690 if (!NILP (last_mouse_motion_frame
)
6691 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6692 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6693 last_mouse_motion_event
.x
,
6694 last_mouse_motion_event
.y
);
6699 /***********************************************************************
6701 ***********************************************************************/
6703 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6704 struct glyph
**, int *, int *, int *));
6706 /* Tool-bar item index of the item on which a mouse button was pressed
6709 static int last_tool_bar_item
;
6712 /* Get information about the tool-bar item at position X/Y on frame F.
6713 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6714 the current matrix of the tool-bar window of F, or NULL if not
6715 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6716 item in F->current_tool_bar_items. Value is
6718 -1 if X/Y is not on a tool-bar item
6719 0 if X/Y is on the same item that was highlighted before.
6723 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6726 struct glyph
**glyph
;
6727 int *hpos
, *vpos
, *prop_idx
;
6729 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6730 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6733 /* Find the glyph under X/Y. */
6734 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6738 /* Get the start of this tool-bar item's properties in
6739 f->current_tool_bar_items. */
6740 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6743 /* Is mouse on the highlighted item? */
6744 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6745 && *vpos
>= dpyinfo
->mouse_face_beg_row
6746 && *vpos
<= dpyinfo
->mouse_face_end_row
6747 && (*vpos
> dpyinfo
->mouse_face_beg_row
6748 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6749 && (*vpos
< dpyinfo
->mouse_face_end_row
6750 || *hpos
< dpyinfo
->mouse_face_end_col
6751 || dpyinfo
->mouse_face_past_end
))
6758 /* Handle mouse button event on the tool-bar of frame F, at
6759 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6763 x_handle_tool_bar_click (f
, button_event
)
6765 XButtonEvent
*button_event
;
6767 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6768 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6769 int hpos
, vpos
, prop_idx
;
6770 struct glyph
*glyph
;
6771 Lisp_Object enabled_p
;
6772 int x
= button_event
->x
;
6773 int y
= button_event
->y
;
6775 /* If not on the highlighted tool-bar item, return. */
6776 frame_to_window_pixel_xy (w
, &x
, &y
);
6777 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6780 /* If item is disabled, do nothing. */
6781 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6782 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6783 if (NILP (enabled_p
))
6786 if (button_event
->type
== ButtonPress
)
6788 /* Show item in pressed state. */
6789 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6790 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6791 last_tool_bar_item
= prop_idx
;
6795 Lisp_Object key
, frame
;
6796 struct input_event event
;
6798 /* Show item in released state. */
6799 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6800 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6802 key
= (XVECTOR (f
->current_tool_bar_items
)
6803 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6805 XSETFRAME (frame
, f
);
6806 event
.kind
= TOOL_BAR_EVENT
;
6807 event
.frame_or_window
= frame
;
6809 kbd_buffer_store_event (&event
);
6811 event
.kind
= TOOL_BAR_EVENT
;
6812 event
.frame_or_window
= frame
;
6814 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6815 button_event
->state
);
6816 kbd_buffer_store_event (&event
);
6817 last_tool_bar_item
= -1;
6822 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6823 tool-bar window-relative coordinates X/Y. Called from
6824 note_mouse_highlight. */
6827 note_tool_bar_highlight (f
, x
, y
)
6831 Lisp_Object window
= f
->tool_bar_window
;
6832 struct window
*w
= XWINDOW (window
);
6833 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6835 struct glyph
*glyph
;
6836 struct glyph_row
*row
;
6838 Lisp_Object enabled_p
;
6840 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6841 int mouse_down_p
, rc
;
6843 /* Function note_mouse_highlight is called with negative x(y
6844 values when mouse moves outside of the frame. */
6845 if (x
<= 0 || y
<= 0)
6847 clear_mouse_face (dpyinfo
);
6851 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6854 /* Not on tool-bar item. */
6855 clear_mouse_face (dpyinfo
);
6859 /* On same tool-bar item as before. */
6862 clear_mouse_face (dpyinfo
);
6864 /* Mouse is down, but on different tool-bar item? */
6865 mouse_down_p
= (dpyinfo
->grabbed
6866 && f
== last_mouse_frame
6867 && FRAME_LIVE_P (f
));
6869 && last_tool_bar_item
!= prop_idx
)
6872 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6873 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6875 /* If tool-bar item is not enabled, don't highlight it. */
6876 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6877 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6878 if (!NILP (enabled_p
))
6880 /* Compute the x-position of the glyph. In front and past the
6881 image is a space. We include this is the highlighted area. */
6882 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6883 for (i
= x
= 0; i
< hpos
; ++i
)
6884 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6886 /* Record this as the current active region. */
6887 dpyinfo
->mouse_face_beg_col
= hpos
;
6888 dpyinfo
->mouse_face_beg_row
= vpos
;
6889 dpyinfo
->mouse_face_beg_x
= x
;
6890 dpyinfo
->mouse_face_beg_y
= row
->y
;
6891 dpyinfo
->mouse_face_past_end
= 0;
6893 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6894 dpyinfo
->mouse_face_end_row
= vpos
;
6895 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6896 dpyinfo
->mouse_face_end_y
= row
->y
;
6897 dpyinfo
->mouse_face_window
= window
;
6898 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6900 /* Display it as active. */
6901 show_mouse_face (dpyinfo
, draw
);
6902 dpyinfo
->mouse_face_image_state
= draw
;
6907 /* Set help_echo to a help string.to display for this tool-bar item.
6908 XTread_socket does the rest. */
6909 help_echo_object
= help_echo_window
= Qnil
;
6911 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6912 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6913 if (NILP (help_echo
))
6914 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6915 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6920 /* Find the glyph matrix position of buffer position POS in window W.
6921 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6922 current glyphs must be up to date. If POS is above window start
6923 return (0, 0, 0, 0). If POS is after end of W, return end of
6927 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6930 int *hpos
, *vpos
, *x
, *y
;
6934 int maybe_next_line_p
= 0;
6935 int line_start_position
;
6936 int yb
= window_text_bottom_y (w
);
6937 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6938 struct glyph_row
*best_row
= row
;
6939 int row_vpos
= 0, best_row_vpos
= 0;
6944 if (row
->used
[TEXT_AREA
])
6945 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6947 line_start_position
= 0;
6949 if (line_start_position
> pos
)
6951 /* If the position sought is the end of the buffer,
6952 don't include the blank lines at the bottom of the window. */
6953 else if (line_start_position
== pos
6954 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6956 maybe_next_line_p
= 1;
6959 else if (line_start_position
> 0)
6962 best_row_vpos
= row_vpos
;
6965 if (row
->y
+ row
->height
>= yb
)
6972 /* Find the right column within BEST_ROW. */
6974 current_x
= best_row
->x
;
6975 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6977 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6980 charpos
= glyph
->charpos
;
6984 *vpos
= best_row_vpos
;
6989 else if (charpos
> pos
)
6991 else if (charpos
> 0)
6994 current_x
+= glyph
->pixel_width
;
6997 /* If we're looking for the end of the buffer,
6998 and we didn't find it in the line we scanned,
6999 use the start of the following line. */
7000 if (maybe_next_line_p
)
7005 current_x
= best_row
->x
;
7008 *vpos
= best_row_vpos
;
7009 *hpos
= lastcol
+ 1;
7016 /* Display the active region described by mouse_face_*
7017 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7020 show_mouse_face (dpyinfo
, draw
)
7021 struct x_display_info
*dpyinfo
;
7022 enum draw_glyphs_face draw
;
7024 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7025 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7027 int cursor_off_p
= 0;
7028 struct cursor_pos saved_cursor
;
7030 saved_cursor
= output_cursor
;
7032 /* If window is in the process of being destroyed, don't bother
7034 if (w
->current_matrix
== NULL
)
7037 /* Recognize when we are called to operate on rows that don't exist
7038 anymore. This can happen when a window is split. */
7039 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7042 set_output_cursor (&w
->phys_cursor
);
7044 /* Note that mouse_face_beg_row etc. are window relative. */
7045 for (i
= dpyinfo
->mouse_face_beg_row
;
7046 i
<= dpyinfo
->mouse_face_end_row
;
7049 int start_hpos
, end_hpos
, start_x
;
7050 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7052 /* Don't do anything if row doesn't have valid contents. */
7053 if (!row
->enabled_p
)
7056 /* For all but the first row, the highlight starts at column 0. */
7057 if (i
== dpyinfo
->mouse_face_beg_row
)
7059 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7060 start_x
= dpyinfo
->mouse_face_beg_x
;
7068 if (i
== dpyinfo
->mouse_face_end_row
)
7069 end_hpos
= dpyinfo
->mouse_face_end_col
;
7071 end_hpos
= row
->used
[TEXT_AREA
];
7073 /* If the cursor's in the text we are about to rewrite, turn the
7075 if (!w
->pseudo_window_p
7076 && i
== output_cursor
.vpos
7077 && output_cursor
.hpos
>= start_hpos
- 1
7078 && output_cursor
.hpos
<= end_hpos
)
7080 x_update_window_cursor (w
, 0);
7084 if (end_hpos
> start_hpos
)
7086 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7087 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7088 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7092 /* If we turned the cursor off, turn it back on. */
7094 x_display_cursor (w
, 1,
7095 output_cursor
.hpos
, output_cursor
.vpos
,
7096 output_cursor
.x
, output_cursor
.y
);
7098 output_cursor
= saved_cursor
;
7102 /* Change the mouse cursor. */
7103 if (draw
== DRAW_NORMAL_TEXT
)
7104 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7105 f
->output_data
.x
->text_cursor
);
7106 else if (draw
== DRAW_MOUSE_FACE
)
7107 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7108 f
->output_data
.x
->cross_cursor
);
7110 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7111 f
->output_data
.x
->nontext_cursor
);
7114 /* Clear out the mouse-highlighted active region.
7115 Redraw it un-highlighted first. */
7118 clear_mouse_face (dpyinfo
)
7119 struct x_display_info
*dpyinfo
;
7124 if (! NILP (dpyinfo
->mouse_face_window
))
7125 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7127 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7128 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7129 dpyinfo
->mouse_face_window
= Qnil
;
7133 /* Clear any mouse-face on window W. This function is part of the
7134 redisplay interface, and is called from try_window_id and similar
7135 functions to ensure the mouse-highlight is off. */
7138 x_clear_mouse_face (w
)
7141 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7144 XSETWINDOW (window
, w
);
7145 if (EQ (window
, dpyinfo
->mouse_face_window
))
7146 clear_mouse_face (dpyinfo
);
7150 /* Just discard the mouse face information for frame F, if any.
7151 This is used when the size of F is changed. */
7154 cancel_mouse_face (f
)
7158 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7160 window
= dpyinfo
->mouse_face_window
;
7161 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7163 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7164 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7165 dpyinfo
->mouse_face_window
= Qnil
;
7169 static struct scroll_bar
*x_window_to_scroll_bar ();
7170 static void x_scroll_bar_report_motion ();
7172 /* Return the current position of the mouse.
7173 *fp should be a frame which indicates which display to ask about.
7175 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7176 and *part to the frame, window, and scroll bar part that the mouse
7177 is over. Set *x and *y to the portion and whole of the mouse's
7178 position on the scroll bar.
7180 If the mouse movement started elsewhere, set *fp to the frame the
7181 mouse is on, *bar_window to nil, and *x and *y to the character cell
7184 Set *time to the server time-stamp for the time at which the mouse
7185 was at this position.
7187 Don't store anything if we don't have a valid set of values to report.
7189 This clears the mouse_moved flag, so we can wait for the next mouse
7193 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7196 Lisp_Object
*bar_window
;
7197 enum scroll_bar_part
*part
;
7199 unsigned long *time
;
7205 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7206 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7212 Window dummy_window
;
7215 Lisp_Object frame
, tail
;
7217 /* Clear the mouse-moved flag for every frame on this display. */
7218 FOR_EACH_FRAME (tail
, frame
)
7219 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7220 XFRAME (frame
)->mouse_moved
= 0;
7222 last_mouse_scroll_bar
= Qnil
;
7224 /* Figure out which root window we're on. */
7225 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7226 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7228 /* The root window which contains the pointer. */
7231 /* Trash which we can't trust if the pointer is on
7232 a different screen. */
7235 /* The position on that root window. */
7238 /* More trash we can't trust. */
7241 /* Modifier keys and pointer buttons, about which
7243 (unsigned int *) &dummy
);
7245 /* Now we have a position on the root; find the innermost window
7246 containing the pointer. */
7250 int parent_x
= 0, parent_y
= 0;
7255 /* XTranslateCoordinates can get errors if the window
7256 structure is changing at the same time this function
7257 is running. So at least we must not crash from them. */
7259 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7261 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7262 && FRAME_LIVE_P (last_mouse_frame
))
7264 /* If mouse was grabbed on a frame, give coords for that frame
7265 even if the mouse is now outside it. */
7266 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7268 /* From-window, to-window. */
7269 root
, FRAME_X_WINDOW (last_mouse_frame
),
7271 /* From-position, to-position. */
7272 root_x
, root_y
, &win_x
, &win_y
,
7276 f1
= last_mouse_frame
;
7282 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7284 /* From-window, to-window. */
7287 /* From-position, to-position. */
7288 root_x
, root_y
, &win_x
, &win_y
,
7293 if (child
== None
|| child
== win
)
7301 /* Now we know that:
7302 win is the innermost window containing the pointer
7303 (XTC says it has no child containing the pointer),
7304 win_x and win_y are the pointer's position in it
7305 (XTC did this the last time through), and
7306 parent_x and parent_y are the pointer's position in win's parent.
7307 (They are what win_x and win_y were when win was child.
7308 If win is the root window, it has no parent, and
7309 parent_{x,y} are invalid, but that's okay, because we'll
7310 never use them in that case.) */
7312 /* Is win one of our frames? */
7313 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7316 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7319 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7321 /* If not, is it one of our scroll bars? */
7324 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7328 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7334 if (f1
== 0 && insist
> 0)
7335 f1
= SELECTED_FRAME ();
7339 /* Ok, we found a frame. Store all the values.
7340 last_mouse_glyph is a rectangle used to reduce the
7341 generation of mouse events. To not miss any motion
7342 events, we must divide the frame into rectangles of the
7343 size of the smallest character that could be displayed
7344 on it, i.e. into the same rectangles that matrices on
7345 the frame are divided into. */
7347 #if OLD_REDISPLAY_CODE
7348 int ignore1
, ignore2
;
7349 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7351 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7355 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7356 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7360 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7361 round down even for negative values. */
7367 last_mouse_glyph
.width
= width
;
7368 last_mouse_glyph
.height
= height
;
7369 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7370 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7377 XSETINT (*x
, win_x
);
7378 XSETINT (*y
, win_y
);
7379 *time
= last_mouse_movement_time
;
7388 #ifdef USE_X_TOOLKIT
7390 /* Atimer callback function for TIMER. Called every 0.1s to process
7391 Xt timeouts, if needed. We must avoid calling XtAppPending as
7392 much as possible because that function does an implicit XFlush
7393 that slows us down. */
7396 x_process_timeouts (timer
)
7397 struct atimer
*timer
;
7399 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7402 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7403 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7408 #endif /* USE_X_TOOLKIT */
7411 /* Scroll bar support. */
7413 /* Given an X window ID, find the struct scroll_bar which manages it.
7414 This can be called in GC, so we have to make sure to strip off mark
7417 static struct scroll_bar
*
7418 x_window_to_scroll_bar (window_id
)
7423 for (tail
= Vframe_list
;
7424 XGCTYPE (tail
) == Lisp_Cons
;
7427 Lisp_Object frame
, bar
, condemned
;
7429 frame
= XCAR (tail
);
7430 /* All elements of Vframe_list should be frames. */
7431 if (! GC_FRAMEP (frame
))
7434 /* Scan this frame's scroll bar list for a scroll bar with the
7436 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7437 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7438 /* This trick allows us to search both the ordinary and
7439 condemned scroll bar lists with one loop. */
7440 ! GC_NILP (bar
) || (bar
= condemned
,
7443 bar
= XSCROLL_BAR (bar
)->next
)
7444 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7445 return XSCROLL_BAR (bar
);
7453 /************************************************************************
7455 ************************************************************************/
7457 #if USE_TOOLKIT_SCROLL_BARS
7459 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7460 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7461 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7462 struct scroll_bar
*));
7463 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7467 /* Id of action hook installed for scroll bars. */
7469 static XtActionHookId action_hook_id
;
7471 /* Lisp window being scrolled. Set when starting to interact with
7472 a toolkit scroll bar, reset to nil when ending the interaction. */
7474 static Lisp_Object window_being_scrolled
;
7476 /* Last scroll bar part sent in xm_scroll_callback. */
7478 static int last_scroll_bar_part
;
7480 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7481 that movements of 1/20 of the screen size are mapped to up/down. */
7483 static Boolean xaw3d_arrow_scroll
;
7485 /* Whether the drag scrolling maintains the mouse at the top of the
7486 thumb. If not, resizing the thumb needs to be done more carefully
7487 to avoid jerkyness. */
7489 static Boolean xaw3d_pick_top
;
7492 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7493 bars are used.. The hook is responsible for detecting when
7494 the user ends an interaction with the scroll bar, and generates
7495 a `end-scroll' scroll_bar_click' event if so. */
7498 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7501 XtPointer client_data
;
7505 Cardinal
*num_params
;
7511 scroll_bar_p
= XmIsScrollBar (widget
);
7512 end_action
= "Release";
7513 #else /* !USE_MOTIF i.e. use Xaw */
7514 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7515 end_action
= "EndScroll";
7516 #endif /* USE_MOTIF */
7519 && strcmp (action_name
, end_action
) == 0
7520 && WINDOWP (window_being_scrolled
))
7524 x_send_scroll_bar_event (window_being_scrolled
,
7525 scroll_bar_end_scroll
, 0, 0);
7526 w
= XWINDOW (window_being_scrolled
);
7527 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7528 window_being_scrolled
= Qnil
;
7529 last_scroll_bar_part
= -1;
7531 /* Xt timeouts no longer needed. */
7532 toolkit_scroll_bar_interaction
= 0;
7537 /* Send a client message with message type Xatom_Scrollbar for a
7538 scroll action to the frame of WINDOW. PART is a value identifying
7539 the part of the scroll bar that was clicked on. PORTION is the
7540 amount to scroll of a whole of WHOLE. */
7543 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7545 int part
, portion
, whole
;
7548 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7549 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7551 /* Construct a ClientMessage event to send to the frame. */
7552 ev
->type
= ClientMessage
;
7553 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7554 ev
->display
= FRAME_X_DISPLAY (f
);
7555 ev
->window
= FRAME_X_WINDOW (f
);
7557 ev
->data
.l
[0] = (long) XFASTINT (window
);
7558 ev
->data
.l
[1] = (long) part
;
7559 ev
->data
.l
[2] = (long) 0;
7560 ev
->data
.l
[3] = (long) portion
;
7561 ev
->data
.l
[4] = (long) whole
;
7563 /* Make Xt timeouts work while the scroll bar is active. */
7564 toolkit_scroll_bar_interaction
= 1;
7566 /* Setting the event mask to zero means that the message will
7567 be sent to the client that created the window, and if that
7568 window no longer exists, no event will be sent. */
7570 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7575 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7579 x_scroll_bar_to_input_event (event
, ievent
)
7581 struct input_event
*ievent
;
7583 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7587 XSETFASTINT (window
, ev
->data
.l
[0]);
7588 f
= XFRAME (XWINDOW (window
)->frame
);
7590 ievent
->kind
= scroll_bar_click
;
7591 ievent
->frame_or_window
= window
;
7593 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7594 ievent
->part
= ev
->data
.l
[1];
7595 ievent
->code
= ev
->data
.l
[2];
7596 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7597 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7598 ievent
->modifiers
= 0;
7604 /* Minimum and maximum values used for Motif scroll bars. */
7607 #define XM_SB_MAX 10000000
7608 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7611 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7612 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7613 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7616 xm_scroll_callback (widget
, client_data
, call_data
)
7618 XtPointer client_data
, call_data
;
7620 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7621 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7623 int part
= -1, whole
= 0, portion
= 0;
7627 case XmCR_DECREMENT
:
7628 bar
->dragging
= Qnil
;
7629 part
= scroll_bar_up_arrow
;
7632 case XmCR_INCREMENT
:
7633 bar
->dragging
= Qnil
;
7634 part
= scroll_bar_down_arrow
;
7637 case XmCR_PAGE_DECREMENT
:
7638 bar
->dragging
= Qnil
;
7639 part
= scroll_bar_above_handle
;
7642 case XmCR_PAGE_INCREMENT
:
7643 bar
->dragging
= Qnil
;
7644 part
= scroll_bar_below_handle
;
7648 bar
->dragging
= Qnil
;
7649 part
= scroll_bar_to_top
;
7652 case XmCR_TO_BOTTOM
:
7653 bar
->dragging
= Qnil
;
7654 part
= scroll_bar_to_bottom
;
7660 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7661 && XINT (bar
->dragging
) <= cs
->value
);
7663 /* Get the slider size. */
7665 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7668 /* At the max position of the scroll bar, do a line-wise
7669 movement. Without doing anything, the LessTif scroll bar
7670 calls us with the same cs->value again and again. If we
7671 want to make sure that we can reach the end of the buffer,
7672 we have to do something.
7674 Implementation note: setting bar->dragging always to
7675 cs->value gives a smoother movement at the max position.
7676 Setting it to nil when doing line-wise movement gives
7677 a better slider behavior. */
7679 if (cs
->value
+ slider_size
== XM_SB_MAX
7681 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7683 part
= scroll_bar_down_arrow
;
7684 bar
->dragging
= Qnil
;
7688 whole
= XM_SB_RANGE
;
7689 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7690 part
= scroll_bar_handle
;
7691 bar
->dragging
= make_number (cs
->value
);
7696 case XmCR_VALUE_CHANGED
:
7702 window_being_scrolled
= bar
->window
;
7703 last_scroll_bar_part
= part
;
7704 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7709 #else /* !USE_MOTIF, i.e. Xaw. */
7712 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7713 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7714 scroll bar struct. CALL_DATA is a pointer to a float saying where
7718 xaw_jump_callback (widget
, client_data
, call_data
)
7720 XtPointer client_data
, call_data
;
7722 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7723 float top
= *(float *) call_data
;
7725 int whole
, portion
, height
;
7728 /* Get the size of the thumb, a value between 0 and 1. */
7730 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7734 portion
= shown
< 1 ? top
* whole
: 0;
7736 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7737 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7738 the bottom, so we force the scrolling whenever we see that we're
7739 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7740 we try to ensure that we always stay two pixels away from the
7742 part
= scroll_bar_down_arrow
;
7744 part
= scroll_bar_handle
;
7746 window_being_scrolled
= bar
->window
;
7747 bar
->dragging
= make_number (portion
);
7748 last_scroll_bar_part
= part
;
7749 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7753 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7754 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7755 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7756 the scroll bar. CALL_DATA is an integer specifying the action that
7757 has taken place. It's magnitude is in the range 0..height of the
7758 scroll bar. Negative values mean scroll towards buffer start.
7759 Values < height of scroll bar mean line-wise movement. */
7762 xaw_scroll_callback (widget
, client_data
, call_data
)
7764 XtPointer client_data
, call_data
;
7766 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7767 int position
= (int) call_data
;
7771 /* Get the height of the scroll bar. */
7773 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7776 if (abs (position
) >= height
)
7777 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
7779 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
7780 it maps line-movement to call_data = max(5, height/20). */
7781 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
7782 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
7784 part
= scroll_bar_move_ratio
;
7786 window_being_scrolled
= bar
->window
;
7787 bar
->dragging
= Qnil
;
7788 last_scroll_bar_part
= part
;
7789 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
7793 #endif /* not USE_MOTIF */
7796 /* Create the widget for scroll bar BAR on frame F. Record the widget
7797 and X window of the scroll bar in BAR. */
7800 x_create_toolkit_scroll_bar (f
, bar
)
7802 struct scroll_bar
*bar
;
7808 char *scroll_bar_name
= "verticalScrollBar";
7809 unsigned long pixel
;
7814 /* LessTif 0.85, problems:
7816 1. When the mouse if over the scroll bar, the scroll bar will
7817 get keyboard events. I didn't find a way to turn this off.
7819 2. Do we have to explicitly set the cursor to get an arrow
7820 cursor (see below)? */
7822 /* Set resources. Create the widget. */
7823 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7824 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7825 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7826 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7827 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7828 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7829 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7831 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7834 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7838 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7841 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7845 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7846 scroll_bar_name
, av
, ac
);
7848 /* Add one callback for everything that can happen. */
7849 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7851 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7853 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7855 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7857 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7859 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7861 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7864 /* Realize the widget. Only after that is the X window created. */
7865 XtRealizeWidget (widget
);
7867 /* Set the cursor to an arrow. I didn't find a resource to do that.
7868 And I'm wondering why it hasn't an arrow cursor by default. */
7869 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7870 f
->output_data
.x
->nontext_cursor
);
7872 #else /* !USE_MOTIF i.e. use Xaw */
7874 /* Set resources. Create the widget. The background of the
7875 Xaw3d scroll bar widget is a little bit light for my taste.
7876 We don't alter it here to let users change it according
7877 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7878 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7879 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7880 /* For smoother scrolling with Xaw3d -sm */
7881 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
7882 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
7884 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7887 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7891 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7894 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7898 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7899 f
->output_data
.x
->edit_widget
, av
, ac
);
7903 char *val
= initial
;
7904 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
7905 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
7907 { /* ARROW_SCROLL */
7908 xaw3d_arrow_scroll
= True
;
7909 /* Isn't that just a personal preference ? -sm */
7910 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
7914 /* Define callbacks. */
7915 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
7916 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
7919 /* Realize the widget. Only after that is the X window created. */
7920 XtRealizeWidget (widget
);
7922 #endif /* !USE_MOTIF */
7924 /* Install an action hook that let's us detect when the user
7925 finishes interacting with a scroll bar. */
7926 if (action_hook_id
== 0)
7927 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7929 /* Remember X window and widget in the scroll bar vector. */
7930 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7931 xwindow
= XtWindow (widget
);
7932 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7938 /* Set the thumb size and position of scroll bar BAR. We are currently
7939 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7942 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7943 struct scroll_bar
*bar
;
7944 int portion
, position
, whole
;
7947 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7953 top
= (float) position
/ whole
;
7954 shown
= (float) portion
/ whole
;
7962 Boolean arrow1_selected
, arrow2_selected
;
7963 unsigned char flags
;
7964 XmScrollBarWidget sb
;
7966 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
7967 is the scroll bar's maximum and MIN is the scroll bar's minimum
7969 size
= shown
* XM_SB_RANGE
;
7970 size
= min (size
, XM_SB_RANGE
);
7971 size
= max (size
, 1);
7973 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7974 value
= top
* XM_SB_RANGE
;
7975 value
= min (value
, XM_SB_MAX
- size
);
7976 value
= max (value
, XM_SB_MIN
);
7978 /* LessTif: Calling XmScrollBarSetValues after an increment or
7979 decrement turns off auto-repeat LessTif-internally. This can
7980 be seen in ScrollBar.c which resets Arrow1Selected and
7981 Arrow2Selected. It also sets internal flags so that LessTif
7982 believes the mouse is in the slider. We either have to change
7983 our code, or work around that by accessing private data. */
7985 sb
= (XmScrollBarWidget
) widget
;
7986 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
7987 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
7988 flags
= sb
->scrollBar
.flags
;
7990 if (NILP (bar
->dragging
))
7991 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
7992 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7993 /* This has the negative side effect that the slider value is
7994 not what it would be if we scrolled here using line-wise or
7995 page-wise movement. */
7996 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
7999 /* If currently dragging, only update the slider size.
8000 This reduces flicker effects. */
8001 int old_value
, old_size
, increment
, page_increment
;
8003 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8004 &increment
, &page_increment
);
8005 XmScrollBarSetValues (widget
, old_value
,
8006 min (size
, XM_SB_RANGE
- old_value
),
8010 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
8011 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
8012 sb
->scrollBar
.flags
= flags
;
8014 #else /* !USE_MOTIF i.e. use Xaw */
8016 float old_top
, old_shown
;
8018 XtVaGetValues (widget
,
8019 XtNtopOfThumb
, &old_top
,
8020 XtNshown
, &old_shown
,
8024 /* Massage the top+shown values. */
8025 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8026 top
= max (0, min (1, top
));
8029 /* Keep two pixels available for moving the thumb down. */
8030 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8032 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8033 check that your system's configuration file contains a define
8034 for `NARROWPROTO'. See s/freebsd.h for an example. */
8035 if (top
!= old_top
|| shown
!= old_shown
)
8037 if (NILP (bar
->dragging
))
8038 XawScrollbarSetThumb (widget
, top
, shown
);
8042 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8043 int scroll_mode
= 0;
8045 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8046 if (xaw3d_arrow_scroll
)
8048 /* Xaw3d stupidly ignores resize requests while dragging
8049 so we have to make it believe it's not in dragging mode. */
8050 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8051 if (scroll_mode
== 2)
8052 sb
->scrollbar
.scroll_mode
= 0;
8055 /* Try to make the scrolling a tad smoother. */
8056 if (!xaw3d_pick_top
)
8057 shown
= min (shown
, old_shown
);
8059 XawScrollbarSetThumb (widget
, top
, shown
);
8062 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8063 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8068 #endif /* !USE_MOTIF */
8073 #endif /* USE_TOOLKIT_SCROLL_BARS */
8077 /************************************************************************
8078 Scroll bars, general
8079 ************************************************************************/
8081 /* Create a scroll bar and return the scroll bar vector for it. W is
8082 the Emacs window on which to create the scroll bar. TOP, LEFT,
8083 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8086 static struct scroll_bar
*
8087 x_scroll_bar_create (w
, top
, left
, width
, height
)
8089 int top
, left
, width
, height
;
8091 struct frame
*f
= XFRAME (w
->frame
);
8092 struct scroll_bar
*bar
8093 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8097 #if USE_TOOLKIT_SCROLL_BARS
8098 x_create_toolkit_scroll_bar (f
, bar
);
8099 #else /* not USE_TOOLKIT_SCROLL_BARS */
8101 XSetWindowAttributes a
;
8105 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8106 if (a
.background_pixel
== -1)
8107 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8109 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8110 | ButtonMotionMask
| PointerMotionHintMask
8112 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8114 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8116 /* Clear the area of W that will serve as a scroll bar. This is
8117 for the case that a window has been split horizontally. In
8118 this case, no clear_frame is generated to reduce flickering. */
8119 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8121 window_box_height (w
), False
);
8123 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8124 /* Position and size of scroll bar. */
8125 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8127 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8129 /* Border width, depth, class, and visual. */
8136 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8138 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8140 XSETWINDOW (bar
->window
, w
);
8141 XSETINT (bar
->top
, top
);
8142 XSETINT (bar
->left
, left
);
8143 XSETINT (bar
->width
, width
);
8144 XSETINT (bar
->height
, height
);
8145 XSETINT (bar
->start
, 0);
8146 XSETINT (bar
->end
, 0);
8147 bar
->dragging
= Qnil
;
8149 /* Add bar to its frame's list of scroll bars. */
8150 bar
->next
= FRAME_SCROLL_BARS (f
);
8152 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8153 if (!NILP (bar
->next
))
8154 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8156 /* Map the window/widget. */
8157 #if USE_TOOLKIT_SCROLL_BARS
8158 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
8159 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8160 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8162 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8164 #else /* not USE_TOOLKIT_SCROLL_BARS */
8165 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8166 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8173 /* Draw BAR's handle in the proper position.
8175 If the handle is already drawn from START to END, don't bother
8176 redrawing it, unless REBUILD is non-zero; in that case, always
8177 redraw it. (REBUILD is handy for drawing the handle after expose
8180 Normally, we want to constrain the start and end of the handle to
8181 fit inside its rectangle, but if the user is dragging the scroll
8182 bar handle, we want to let them drag it down all the way, so that
8183 the bar's top is as far down as it goes; otherwise, there's no way
8184 to move to the very end of the buffer. */
8186 #ifndef USE_TOOLKIT_SCROLL_BARS
8189 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8190 struct scroll_bar
*bar
;
8194 int dragging
= ! NILP (bar
->dragging
);
8195 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8196 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8197 GC gc
= f
->output_data
.x
->normal_gc
;
8199 /* If the display is already accurate, do nothing. */
8201 && start
== XINT (bar
->start
)
8202 && end
== XINT (bar
->end
))
8208 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8209 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8210 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8212 /* Make sure the values are reasonable, and try to preserve
8213 the distance between start and end. */
8215 int length
= end
- start
;
8219 else if (start
> top_range
)
8221 end
= start
+ length
;
8225 else if (end
> top_range
&& ! dragging
)
8229 /* Store the adjusted setting in the scroll bar. */
8230 XSETINT (bar
->start
, start
);
8231 XSETINT (bar
->end
, end
);
8233 /* Clip the end position, just for display. */
8234 if (end
> top_range
)
8237 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8238 below top positions, to make sure the handle is always at least
8239 that many pixels tall. */
8240 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8242 /* Draw the empty space above the handle. Note that we can't clear
8243 zero-height areas; that means "clear to end of window." */
8245 XClearArea (FRAME_X_DISPLAY (f
), w
,
8247 /* x, y, width, height, and exposures. */
8248 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8249 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8250 inside_width
, start
,
8253 /* Change to proper foreground color if one is specified. */
8254 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8255 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8256 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8258 /* Draw the handle itself. */
8259 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8261 /* x, y, width, height */
8262 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8263 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8264 inside_width
, end
- start
);
8266 /* Restore the foreground color of the GC if we changed it above. */
8267 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8268 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8269 f
->output_data
.x
->foreground_pixel
);
8271 /* Draw the empty space below the handle. Note that we can't
8272 clear zero-height areas; that means "clear to end of window." */
8273 if (end
< inside_height
)
8274 XClearArea (FRAME_X_DISPLAY (f
), w
,
8276 /* x, y, width, height, and exposures. */
8277 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8278 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8279 inside_width
, inside_height
- end
,
8287 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8289 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8293 x_scroll_bar_remove (bar
)
8294 struct scroll_bar
*bar
;
8298 #if USE_TOOLKIT_SCROLL_BARS
8299 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
8300 #else /* not USE_TOOLKIT_SCROLL_BARS */
8302 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8303 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8305 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8307 /* Disassociate this scroll bar from its window. */
8308 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8314 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8315 that we are displaying PORTION characters out of a total of WHOLE
8316 characters, starting at POSITION. If WINDOW has no scroll bar,
8320 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8322 int portion
, whole
, position
;
8324 struct frame
*f
= XFRAME (w
->frame
);
8325 struct scroll_bar
*bar
;
8326 int top
, height
, left
, sb_left
, width
, sb_width
;
8327 int window_x
, window_y
, window_width
, window_height
;
8329 /* Get window dimensions. */
8330 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8332 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8333 height
= window_height
;
8335 /* Compute the left edge of the scroll bar area. */
8336 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8337 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8339 left
= XFASTINT (w
->left
);
8340 left
*= CANON_X_UNIT (f
);
8341 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8343 /* Compute the width of the scroll bar which might be less than
8344 the width of the area reserved for the scroll bar. */
8345 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8346 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8350 /* Compute the left edge of the scroll bar. */
8351 #ifdef USE_TOOLKIT_SCROLL_BARS
8352 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8353 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8355 sb_left
= left
+ (width
- sb_width
) / 2;
8357 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8358 sb_left
= left
+ width
- sb_width
;
8363 /* Does the scroll bar exist yet? */
8364 if (NILP (w
->vertical_scroll_bar
))
8367 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8368 left
, top
, width
, height
, False
);
8370 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8374 /* It may just need to be moved and resized. */
8375 unsigned int mask
= 0;
8377 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8381 if (sb_left
!= XINT (bar
->left
))
8383 if (top
!= XINT (bar
->top
))
8385 if (sb_width
!= XINT (bar
->width
))
8387 if (height
!= XINT (bar
->height
))
8390 #ifdef USE_TOOLKIT_SCROLL_BARS
8392 /* Since toolkit scroll bars are smaller than the space reserved
8393 for them on the frame, we have to clear "under" them. */
8394 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8395 left
, top
, width
, height
, False
);
8397 /* Move/size the scroll bar widget. */
8399 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8400 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8402 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8405 #else /* not USE_TOOLKIT_SCROLL_BARS */
8407 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8409 /* Clear areas not covered by the scroll bar. This makes sure a
8410 previous mode line display is cleared after C-x 2 C-x 1, for
8411 example. Non-toolkit scroll bars are as wide as the area
8412 reserved for scroll bars - trim at both sides. */
8413 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8414 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8416 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8417 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8418 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8422 /* Move/size the scroll bar window. */
8427 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8429 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8431 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8435 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8437 /* Remember new settings. */
8438 XSETINT (bar
->left
, sb_left
);
8439 XSETINT (bar
->top
, top
);
8440 XSETINT (bar
->width
, sb_width
);
8441 XSETINT (bar
->height
, height
);
8446 #if USE_TOOLKIT_SCROLL_BARS
8447 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8448 #else /* not USE_TOOLKIT_SCROLL_BARS */
8449 /* Set the scroll bar's current state, unless we're currently being
8451 if (NILP (bar
->dragging
))
8453 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8456 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8459 int start
= ((double) position
* top_range
) / whole
;
8460 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8461 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8464 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8466 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8470 /* The following three hooks are used when we're doing a thorough
8471 redisplay of the frame. We don't explicitly know which scroll bars
8472 are going to be deleted, because keeping track of when windows go
8473 away is a real pain - "Can you say set-window-configuration, boys
8474 and girls?" Instead, we just assert at the beginning of redisplay
8475 that *all* scroll bars are to be removed, and then save a scroll bar
8476 from the fiery pit when we actually redisplay its window. */
8478 /* Arrange for all scroll bars on FRAME to be removed at the next call
8479 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8480 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8483 XTcondemn_scroll_bars (frame
)
8486 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8487 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8490 bar
= FRAME_SCROLL_BARS (frame
);
8491 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8492 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8493 XSCROLL_BAR (bar
)->prev
= Qnil
;
8494 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8495 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8496 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8500 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8501 Note that WINDOW isn't necessarily condemned at all. */
8503 XTredeem_scroll_bar (window
)
8504 struct window
*window
;
8506 struct scroll_bar
*bar
;
8508 /* We can't redeem this window's scroll bar if it doesn't have one. */
8509 if (NILP (window
->vertical_scroll_bar
))
8512 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8514 /* Unlink it from the condemned list. */
8516 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8518 if (NILP (bar
->prev
))
8520 /* If the prev pointer is nil, it must be the first in one of
8522 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8523 /* It's not condemned. Everything's fine. */
8525 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8526 window
->vertical_scroll_bar
))
8527 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8529 /* If its prev pointer is nil, it must be at the front of
8530 one or the other! */
8534 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8536 if (! NILP (bar
->next
))
8537 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8539 bar
->next
= FRAME_SCROLL_BARS (f
);
8541 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8542 if (! NILP (bar
->next
))
8543 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8547 /* Remove all scroll bars on FRAME that haven't been saved since the
8548 last call to `*condemn_scroll_bars_hook'. */
8551 XTjudge_scroll_bars (f
)
8554 Lisp_Object bar
, next
;
8556 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8558 /* Clear out the condemned list now so we won't try to process any
8559 more events on the hapless scroll bars. */
8560 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8562 for (; ! NILP (bar
); bar
= next
)
8564 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8566 x_scroll_bar_remove (b
);
8569 b
->next
= b
->prev
= Qnil
;
8572 /* Now there should be no references to the condemned scroll bars,
8573 and they should get garbage-collected. */
8577 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8578 is a no-op when using toolkit scroll bars.
8580 This may be called from a signal handler, so we have to ignore GC
8584 x_scroll_bar_expose (bar
, event
)
8585 struct scroll_bar
*bar
;
8588 #ifndef USE_TOOLKIT_SCROLL_BARS
8590 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8591 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8592 GC gc
= f
->output_data
.x
->normal_gc
;
8593 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8597 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8599 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8600 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8602 /* x, y, width, height */
8604 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8605 XINT (bar
->height
) - 1);
8609 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8612 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8613 is set to something other than no_event, it is enqueued.
8615 This may be called from a signal handler, so we have to ignore GC
8618 #ifndef USE_TOOLKIT_SCROLL_BARS
8621 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8622 struct scroll_bar
*bar
;
8624 struct input_event
*emacs_event
;
8626 if (! GC_WINDOWP (bar
->window
))
8629 emacs_event
->kind
= scroll_bar_click
;
8630 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8631 emacs_event
->modifiers
8632 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8633 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8634 event
->xbutton
.state
)
8635 | (event
->type
== ButtonRelease
8638 emacs_event
->frame_or_window
= bar
->window
;
8639 emacs_event
->arg
= Qnil
;
8640 emacs_event
->timestamp
= event
->xbutton
.time
;
8643 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8645 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8648 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8649 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8652 if (y
> top_range
) y
= top_range
;
8654 if (y
< XINT (bar
->start
))
8655 emacs_event
->part
= scroll_bar_above_handle
;
8656 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8657 emacs_event
->part
= scroll_bar_handle
;
8659 emacs_event
->part
= scroll_bar_below_handle
;
8661 /* Just because the user has clicked on the handle doesn't mean
8662 they want to drag it. Lisp code needs to be able to decide
8663 whether or not we're dragging. */
8665 /* If the user has just clicked on the handle, record where they're
8667 if (event
->type
== ButtonPress
8668 && emacs_event
->part
== scroll_bar_handle
)
8669 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8672 /* If the user has released the handle, set it to its final position. */
8673 if (event
->type
== ButtonRelease
8674 && ! NILP (bar
->dragging
))
8676 int new_start
= y
- XINT (bar
->dragging
);
8677 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8679 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8680 bar
->dragging
= Qnil
;
8683 /* Same deal here as the other #if 0. */
8685 /* Clicks on the handle are always reported as occurring at the top of
8687 if (emacs_event
->part
== scroll_bar_handle
)
8688 emacs_event
->x
= bar
->start
;
8690 XSETINT (emacs_event
->x
, y
);
8692 XSETINT (emacs_event
->x
, y
);
8695 XSETINT (emacs_event
->y
, top_range
);
8699 /* Handle some mouse motion while someone is dragging the scroll bar.
8701 This may be called from a signal handler, so we have to ignore GC
8705 x_scroll_bar_note_movement (bar
, event
)
8706 struct scroll_bar
*bar
;
8709 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8711 last_mouse_movement_time
= event
->xmotion
.time
;
8714 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8716 /* If we're dragging the bar, display it. */
8717 if (! GC_NILP (bar
->dragging
))
8719 /* Where should the handle be now? */
8720 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8722 if (new_start
!= XINT (bar
->start
))
8724 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8726 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8731 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8733 /* Return information to the user about the current position of the mouse
8734 on the scroll bar. */
8737 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8739 Lisp_Object
*bar_window
;
8740 enum scroll_bar_part
*part
;
8742 unsigned long *time
;
8744 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8745 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8746 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8748 Window dummy_window
;
8750 unsigned int dummy_mask
;
8754 /* Get the mouse's position relative to the scroll bar window, and
8756 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8758 /* Root, child, root x and root y. */
8759 &dummy_window
, &dummy_window
,
8760 &dummy_coord
, &dummy_coord
,
8762 /* Position relative to scroll bar. */
8765 /* Mouse buttons and modifier keys. */
8772 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8775 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8777 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8779 if (! NILP (bar
->dragging
))
8780 win_y
-= XINT (bar
->dragging
);
8784 if (win_y
> top_range
)
8788 *bar_window
= bar
->window
;
8790 if (! NILP (bar
->dragging
))
8791 *part
= scroll_bar_handle
;
8792 else if (win_y
< XINT (bar
->start
))
8793 *part
= scroll_bar_above_handle
;
8794 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8795 *part
= scroll_bar_handle
;
8797 *part
= scroll_bar_below_handle
;
8799 XSETINT (*x
, win_y
);
8800 XSETINT (*y
, top_range
);
8803 last_mouse_scroll_bar
= Qnil
;
8806 *time
= last_mouse_movement_time
;
8812 /* The screen has been cleared so we may have changed foreground or
8813 background colors, and the scroll bars may need to be redrawn.
8814 Clear out the scroll bars, and ask for expose events, so we can
8818 x_scroll_bar_clear (f
)
8821 #ifndef USE_TOOLKIT_SCROLL_BARS
8824 /* We can have scroll bars even if this is 0,
8825 if we just turned off scroll bar mode.
8826 But in that case we should not clear them. */
8827 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8828 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8829 bar
= XSCROLL_BAR (bar
)->next
)
8830 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8832 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8835 /* This processes Expose events from the menu-bar specific X event
8836 loop in xmenu.c. This allows to redisplay the frame if necessary
8837 when handling menu-bar or pop-up items. */
8840 process_expose_from_menu (event
)
8844 struct x_display_info
*dpyinfo
;
8845 int frame_exposed_p
= 0;
8849 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8850 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8853 if (f
->async_visible
== 0)
8855 f
->async_visible
= 1;
8856 f
->async_iconified
= 0;
8857 f
->output_data
.x
->has_been_visible
= 1;
8858 SET_FRAME_GARBAGED (f
);
8862 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8863 event
.xexpose
.x
, event
.xexpose
.y
,
8864 event
.xexpose
.width
, event
.xexpose
.height
);
8865 frame_exposed_p
= 1;
8870 struct scroll_bar
*bar
8871 = x_window_to_scroll_bar (event
.xexpose
.window
);
8874 x_scroll_bar_expose (bar
, &event
);
8878 return frame_exposed_p
;
8881 /* Define a queue to save up SelectionRequest events for later handling. */
8883 struct selection_event_queue
8886 struct selection_event_queue
*next
;
8889 static struct selection_event_queue
*queue
;
8891 /* Nonzero means queue up certain events--don't process them yet. */
8893 static int x_queue_selection_requests
;
8895 /* Queue up an X event *EVENT, to be processed later. */
8898 x_queue_event (f
, event
)
8902 struct selection_event_queue
*queue_tmp
8903 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8905 if (queue_tmp
!= NULL
)
8907 queue_tmp
->event
= *event
;
8908 queue_tmp
->next
= queue
;
8913 /* Take all the queued events and put them back
8914 so that they get processed afresh. */
8917 x_unqueue_events (display
)
8920 while (queue
!= NULL
)
8922 struct selection_event_queue
*queue_tmp
= queue
;
8923 XPutBackEvent (display
, &queue_tmp
->event
);
8924 queue
= queue_tmp
->next
;
8925 xfree ((char *)queue_tmp
);
8929 /* Start queuing SelectionRequest events. */
8932 x_start_queuing_selection_requests (display
)
8935 x_queue_selection_requests
++;
8938 /* Stop queuing SelectionRequest events. */
8941 x_stop_queuing_selection_requests (display
)
8944 x_queue_selection_requests
--;
8945 x_unqueue_events (display
);
8948 /* The main X event-reading loop - XTread_socket. */
8950 /* Time stamp of enter window event. This is only used by XTread_socket,
8951 but we have to put it out here, since static variables within functions
8952 sometimes don't work. */
8954 static Time enter_timestamp
;
8956 /* This holds the state XLookupString needs to implement dead keys
8957 and other tricks known as "compose processing". _X Window System_
8958 says that a portable program can't use this, but Stephen Gildea assures
8959 me that letting the compiler initialize it to zeros will work okay.
8961 This must be defined outside of XTread_socket, for the same reasons
8962 given for enter_time stamp, above. */
8964 static XComposeStatus compose_status
;
8966 /* Record the last 100 characters stored
8967 to help debug the loss-of-chars-during-GC problem. */
8969 static int temp_index
;
8970 static short temp_buffer
[100];
8972 /* Set this to nonzero to fake an "X I/O error"
8973 on a particular display. */
8975 struct x_display_info
*XTread_socket_fake_io_error
;
8977 /* When we find no input here, we occasionally do a no-op command
8978 to verify that the X server is still running and we can still talk with it.
8979 We try all the open displays, one by one.
8980 This variable is used for cycling thru the displays. */
8982 static struct x_display_info
*next_noop_dpyinfo
;
8984 #define SET_SAVED_MENU_EVENT(size) \
8987 if (f->output_data.x->saved_menu_event == 0) \
8988 f->output_data.x->saved_menu_event \
8989 = (XEvent *) xmalloc (sizeof (XEvent)); \
8990 bcopy (&event, f->output_data.x->saved_menu_event, size); \
8991 if (numchars >= 1) \
8993 bufp->kind = menu_bar_activate_event; \
8994 XSETFRAME (bufp->frame_or_window, f); \
9003 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9004 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9006 /* Read events coming from the X server.
9007 This routine is called by the SIGIO handler.
9008 We return as soon as there are no more events to be read.
9010 Events representing keys are stored in buffer BUFP,
9011 which can hold up to NUMCHARS characters.
9012 We return the number of characters stored into the buffer,
9013 thus pretending to be `read'.
9015 EXPECTED is nonzero if the caller knows input is available. */
9018 XTread_socket (sd
, bufp
, numchars
, expected
)
9020 /* register */ struct input_event
*bufp
;
9021 /* register */ int numchars
;
9028 int event_found
= 0;
9029 struct x_display_info
*dpyinfo
;
9030 struct coding_system coding
;
9032 if (interrupt_input_blocked
)
9034 interrupt_input_pending
= 1;
9038 interrupt_input_pending
= 0;
9041 /* So people can tell when we have read the available input. */
9042 input_signal_count
++;
9045 abort (); /* Don't think this happens. */
9049 /* The input should be decoded if it is from XIM. Currently the
9050 locale of XIM is the same as that of the system. So, we can use
9051 Vlocale_coding_system which is initialized properly at Emacs
9053 setup_coding_system (Vlocale_coding_system
, &coding
);
9054 coding
.src_multibyte
= 0;
9055 coding
.dst_multibyte
= 1;
9056 /* The input is converted to events, thus we can't handle
9057 composition. Anyway, there's no XIM that gives us composition
9059 coding
.composing
= COMPOSITION_DISABLED
;
9061 /* Find the display we are supposed to read input for.
9062 It's the one communicating on descriptor SD. */
9063 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9065 #if 0 /* This ought to be unnecessary; let's verify it. */
9067 /* If available, Xlib uses FIOSNBIO to make the socket
9068 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9069 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9070 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9071 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9072 #endif /* ! defined (FIOSNBIO) */
9075 #if 0 /* This code can't be made to work, with multiple displays,
9076 and appears not to be used on any system any more.
9077 Also keyboard.c doesn't turn O_NDELAY on and off
9078 for X connections. */
9081 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9083 extern int read_alarm_should_throw
;
9084 read_alarm_should_throw
= 1;
9085 XPeekEvent (dpyinfo
->display
, &event
);
9086 read_alarm_should_throw
= 0;
9088 #endif /* HAVE_SELECT */
9092 /* For debugging, this gives a way to fake an I/O error. */
9093 if (dpyinfo
== XTread_socket_fake_io_error
)
9095 XTread_socket_fake_io_error
= 0;
9096 x_io_error_quitter (dpyinfo
->display
);
9099 while (XPending (dpyinfo
->display
))
9101 XNextEvent (dpyinfo
->display
, &event
);
9105 /* Filter events for the current X input method.
9106 XFilterEvent returns non-zero if the input method has
9107 consumed the event. We pass the frame's X window to
9108 XFilterEvent because that's the one for which the IC
9110 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9111 event
.xclient
.window
);
9112 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9122 if (event
.xclient
.message_type
9123 == dpyinfo
->Xatom_wm_protocols
9124 && event
.xclient
.format
== 32)
9126 if (event
.xclient
.data
.l
[0]
9127 == dpyinfo
->Xatom_wm_take_focus
)
9129 /* Use x_any_window_to_frame because this
9130 could be the shell widget window
9131 if the frame has no title bar. */
9132 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9134 /* Not quite sure this is needed -pd */
9135 if (f
&& FRAME_XIC (f
))
9136 XSetICFocus (FRAME_XIC (f
));
9138 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9139 instructs the WM to set the input focus automatically for
9140 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9141 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9142 it has set the focus. So, XSetInputFocus below is not
9145 The call to XSetInputFocus below has also caused trouble. In
9146 cases where the XSetInputFocus done by the WM and the one
9147 below are temporally close (on a fast machine), the call
9148 below can generate additional FocusIn events which confuse
9151 /* Since we set WM_TAKE_FOCUS, we must call
9152 XSetInputFocus explicitly. But not if f is null,
9153 since that might be an event for a deleted frame. */
9156 Display
*d
= event
.xclient
.display
;
9157 /* Catch and ignore errors, in case window has been
9158 iconified by a window manager such as GWM. */
9159 int count
= x_catch_errors (d
);
9160 XSetInputFocus (d
, event
.xclient
.window
,
9161 /* The ICCCM says this is
9162 the only valid choice. */
9164 event
.xclient
.data
.l
[1]);
9165 /* This is needed to detect the error
9166 if there is an error. */
9168 x_uncatch_errors (d
, count
);
9170 /* Not certain about handling scroll bars here */
9173 else if (event
.xclient
.data
.l
[0]
9174 == dpyinfo
->Xatom_wm_save_yourself
)
9176 /* Save state modify the WM_COMMAND property to
9177 something which can reinstate us. This notifies
9178 the session manager, who's looking for such a
9179 PropertyNotify. Can restart processing when
9180 a keyboard or mouse event arrives. */
9183 f
= x_top_window_to_frame (dpyinfo
,
9184 event
.xclient
.window
);
9186 /* This is just so we only give real data once
9187 for a single Emacs process. */
9188 if (f
== SELECTED_FRAME ())
9189 XSetCommand (FRAME_X_DISPLAY (f
),
9190 event
.xclient
.window
,
9191 initial_argv
, initial_argc
);
9193 XSetCommand (FRAME_X_DISPLAY (f
),
9194 event
.xclient
.window
,
9198 else if (event
.xclient
.data
.l
[0]
9199 == dpyinfo
->Xatom_wm_delete_window
)
9202 = x_any_window_to_frame (dpyinfo
,
9203 event
.xclient
.window
);
9210 bufp
->kind
= delete_window_event
;
9211 XSETFRAME (bufp
->frame_or_window
, f
);
9220 else if (event
.xclient
.message_type
9221 == dpyinfo
->Xatom_wm_configure_denied
)
9224 else if (event
.xclient
.message_type
9225 == dpyinfo
->Xatom_wm_window_moved
)
9229 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9231 new_x
= event
.xclient
.data
.s
[0];
9232 new_y
= event
.xclient
.data
.s
[1];
9236 f
->output_data
.x
->left_pos
= new_x
;
9237 f
->output_data
.x
->top_pos
= new_y
;
9241 else if (event
.xclient
.message_type
9242 == dpyinfo
->Xatom_editres
)
9245 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9246 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9249 #endif /* HACK_EDITRES */
9250 else if ((event
.xclient
.message_type
9251 == dpyinfo
->Xatom_DONE
)
9252 || (event
.xclient
.message_type
9253 == dpyinfo
->Xatom_PAGE
))
9255 /* Ghostview job completed. Kill it. We could
9256 reply with "Next" if we received "Page", but we
9257 currently never do because we are interested in
9258 images, only, which should have 1 page. */
9259 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9261 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9262 x_kill_gs_process (pixmap
, f
);
9263 expose_frame (f
, 0, 0, 0, 0);
9265 #ifdef USE_TOOLKIT_SCROLL_BARS
9266 /* Scroll bar callbacks send a ClientMessage from which
9267 we construct an input_event. */
9268 else if (event
.xclient
.message_type
9269 == dpyinfo
->Xatom_Scrollbar
)
9271 x_scroll_bar_to_input_event (&event
, bufp
);
9272 ++bufp
, ++count
, --numchars
;
9275 #endif /* USE_TOOLKIT_SCROLL_BARS */
9281 case SelectionNotify
:
9282 #ifdef USE_X_TOOLKIT
9283 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9285 #endif /* not USE_X_TOOLKIT */
9286 x_handle_selection_notify (&event
.xselection
);
9289 case SelectionClear
: /* Someone has grabbed ownership. */
9290 #ifdef USE_X_TOOLKIT
9291 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9293 #endif /* USE_X_TOOLKIT */
9295 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9300 bufp
->kind
= selection_clear_event
;
9301 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9302 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9303 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9304 bufp
->frame_or_window
= Qnil
;
9313 case SelectionRequest
: /* Someone wants our selection. */
9314 #ifdef USE_X_TOOLKIT
9315 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9317 #endif /* USE_X_TOOLKIT */
9318 if (x_queue_selection_requests
)
9319 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9323 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9328 bufp
->kind
= selection_request_event
;
9329 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9330 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9331 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9332 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9333 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9334 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9335 bufp
->frame_or_window
= Qnil
;
9344 case PropertyNotify
:
9345 #ifdef USE_X_TOOLKIT
9346 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9348 #endif /* not USE_X_TOOLKIT */
9349 x_handle_property_notify (&event
.xproperty
);
9352 case ReparentNotify
:
9353 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9357 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9358 x_real_positions (f
, &x
, &y
);
9359 f
->output_data
.x
->left_pos
= x
;
9360 f
->output_data
.x
->top_pos
= y
;
9365 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9368 if (f
->async_visible
== 0)
9370 f
->async_visible
= 1;
9371 f
->async_iconified
= 0;
9372 f
->output_data
.x
->has_been_visible
= 1;
9373 SET_FRAME_GARBAGED (f
);
9376 expose_frame (x_window_to_frame (dpyinfo
,
9377 event
.xexpose
.window
),
9378 event
.xexpose
.x
, event
.xexpose
.y
,
9379 event
.xexpose
.width
, event
.xexpose
.height
);
9383 #ifdef USE_TOOLKIT_SCROLL_BARS
9384 /* Dispatch event to the widget. */
9386 #else /* not USE_TOOLKIT_SCROLL_BARS */
9387 struct scroll_bar
*bar
9388 = x_window_to_scroll_bar (event
.xexpose
.window
);
9391 x_scroll_bar_expose (bar
, &event
);
9392 #ifdef USE_X_TOOLKIT
9395 #endif /* USE_X_TOOLKIT */
9396 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9400 case GraphicsExpose
: /* This occurs when an XCopyArea's
9401 source area was obscured or not
9403 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9407 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9408 event
.xgraphicsexpose
.width
,
9409 event
.xgraphicsexpose
.height
);
9411 #ifdef USE_X_TOOLKIT
9414 #endif /* USE_X_TOOLKIT */
9417 case NoExpose
: /* This occurs when an XCopyArea's
9418 source area was completely
9423 /* Redo the mouse-highlight after the tooltip has gone. */
9424 if (event
.xmap
.window
== tip_window
)
9427 redo_mouse_highlight ();
9430 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9431 if (f
) /* F may no longer exist if
9432 the frame was deleted. */
9434 /* While a frame is unmapped, display generation is
9435 disabled; you don't want to spend time updating a
9436 display that won't ever be seen. */
9437 f
->async_visible
= 0;
9438 /* We can't distinguish, from the event, whether the window
9439 has become iconified or invisible. So assume, if it
9440 was previously visible, than now it is iconified.
9441 But x_make_frame_invisible clears both
9442 the visible flag and the iconified flag;
9443 and that way, we know the window is not iconified now. */
9444 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9446 f
->async_iconified
= 1;
9448 bufp
->kind
= iconify_event
;
9449 XSETFRAME (bufp
->frame_or_window
, f
);
9459 if (event
.xmap
.window
== tip_window
)
9460 /* The tooltip has been drawn already. Avoid
9461 the SET_FRAME_GARBAGED below. */
9464 /* We use x_top_window_to_frame because map events can
9465 come for sub-windows and they don't mean that the
9466 frame is visible. */
9467 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9470 f
->async_visible
= 1;
9471 f
->async_iconified
= 0;
9472 f
->output_data
.x
->has_been_visible
= 1;
9474 /* wait_reading_process_input will notice this and update
9475 the frame's display structures. */
9476 SET_FRAME_GARBAGED (f
);
9480 bufp
->kind
= deiconify_event
;
9481 XSETFRAME (bufp
->frame_or_window
, f
);
9487 else if (! NILP (Vframe_list
)
9488 && ! NILP (XCDR (Vframe_list
)))
9489 /* Force a redisplay sooner or later
9490 to update the frame titles
9491 in case this is the second frame. */
9492 record_asynch_buffer_change ();
9497 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9500 /* I couldn't find a way to prevent LessTif scroll bars
9501 from consuming key events. */
9504 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9506 if (widget
&& XmIsScrollBar (widget
))
9508 widget
= XtParent (widget
);
9509 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9512 #endif /* USE_MOTIF */
9516 KeySym keysym
, orig_keysym
;
9517 /* al%imercury@uunet.uu.net says that making this 81
9518 instead of 80 fixed a bug whereby meta chars made
9521 It seems that some version of XmbLookupString has
9522 a bug of not returning XBufferOverflow in
9523 status_return even if the input is too long to
9524 fit in 81 bytes. So, we must prepare sufficient
9525 bytes for copy_buffer. 513 bytes (256 chars for
9526 two-byte character set) seems to be a faily good
9527 approximation. -- 2000.8.10 handa@etl.go.jp */
9528 unsigned char copy_buffer
[513];
9529 unsigned char *copy_bufptr
= copy_buffer
;
9530 int copy_bufsiz
= sizeof (copy_buffer
);
9534 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9535 extra_keyboard_modifiers
);
9536 modifiers
= event
.xkey
.state
;
9538 /* This will have to go some day... */
9540 /* make_lispy_event turns chars into control chars.
9541 Don't do it here because XLookupString is too eager. */
9542 event
.xkey
.state
&= ~ControlMask
;
9543 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9544 | dpyinfo
->super_mod_mask
9545 | dpyinfo
->hyper_mod_mask
9546 | dpyinfo
->alt_mod_mask
);
9548 /* In case Meta is ComposeCharacter,
9549 clear its status. According to Markus Ehrnsperger
9550 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9551 this enables ComposeCharacter to work whether or
9552 not it is combined with Meta. */
9553 if (modifiers
& dpyinfo
->meta_mod_mask
)
9554 bzero (&compose_status
, sizeof (compose_status
));
9559 Status status_return
;
9561 nbytes
= XmbLookupString (FRAME_XIC (f
),
9562 &event
.xkey
, copy_bufptr
,
9563 copy_bufsiz
, &keysym
,
9565 if (status_return
== XBufferOverflow
)
9567 copy_bufsiz
= nbytes
+ 1;
9568 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9569 nbytes
= XmbLookupString (FRAME_XIC (f
),
9570 &event
.xkey
, copy_bufptr
,
9571 copy_bufsiz
, &keysym
,
9575 if (status_return
== XLookupNone
)
9577 else if (status_return
== XLookupChars
)
9582 else if (status_return
!= XLookupKeySym
9583 && status_return
!= XLookupBoth
)
9587 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9588 copy_bufsiz
, &keysym
,
9591 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9592 copy_bufsiz
, &keysym
,
9596 orig_keysym
= keysym
;
9600 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9601 || keysym
== XK_Delete
9602 #ifdef XK_ISO_Left_Tab
9603 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9605 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9606 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9607 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9609 /* This recognizes the "extended function keys".
9610 It seems there's no cleaner way.
9611 Test IsModifierKey to avoid handling mode_switch
9613 || ((unsigned) (keysym
) >= XK_Select
9614 && (unsigned)(keysym
) < XK_KP_Space
)
9616 #ifdef XK_dead_circumflex
9617 || orig_keysym
== XK_dead_circumflex
9619 #ifdef XK_dead_grave
9620 || orig_keysym
== XK_dead_grave
9622 #ifdef XK_dead_tilde
9623 || orig_keysym
== XK_dead_tilde
9625 #ifdef XK_dead_diaeresis
9626 || orig_keysym
== XK_dead_diaeresis
9628 #ifdef XK_dead_macron
9629 || orig_keysym
== XK_dead_macron
9631 #ifdef XK_dead_degree
9632 || orig_keysym
== XK_dead_degree
9634 #ifdef XK_dead_acute
9635 || orig_keysym
== XK_dead_acute
9637 #ifdef XK_dead_cedilla
9638 || orig_keysym
== XK_dead_cedilla
9640 #ifdef XK_dead_breve
9641 || orig_keysym
== XK_dead_breve
9643 #ifdef XK_dead_ogonek
9644 || orig_keysym
== XK_dead_ogonek
9646 #ifdef XK_dead_caron
9647 || orig_keysym
== XK_dead_caron
9649 #ifdef XK_dead_doubleacute
9650 || orig_keysym
== XK_dead_doubleacute
9652 #ifdef XK_dead_abovedot
9653 || orig_keysym
== XK_dead_abovedot
9655 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9656 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9657 /* Any "vendor-specific" key is ok. */
9658 || (orig_keysym
& (1 << 28)))
9659 && ! (IsModifierKey (orig_keysym
)
9661 #ifdef XK_Mode_switch
9662 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9665 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9667 #endif /* not HAVE_X11R5 */
9670 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9672 temp_buffer
[temp_index
++] = keysym
;
9673 bufp
->kind
= non_ascii_keystroke
;
9674 bufp
->code
= keysym
;
9675 XSETFRAME (bufp
->frame_or_window
, f
);
9678 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9680 bufp
->timestamp
= event
.xkey
.time
;
9685 else if (numchars
> nbytes
)
9689 unsigned char *p
, *pend
;
9692 for (i
= 0; i
< nbytes
; i
++)
9694 if (temp_index
== (sizeof temp_buffer
9697 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
9700 if (/* If the event is not from XIM, */
9701 event
.xkey
.keycode
!= 0
9702 /* or the current locale doesn't request
9703 decoding of the intup data, ... */
9704 || coding
.type
== coding_type_raw_text
9705 || coding
.type
== coding_type_no_conversion
)
9707 /* ... we can use the input data as is. */
9712 /* We have to decode the input data. */
9716 require
= decoding_buffer_size (&coding
, nbytes
);
9717 p
= (unsigned char *) alloca (require
);
9718 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
9719 decode_coding (&coding
, copy_bufptr
, p
,
9721 nbytes
= coding
.produced
;
9722 nchars
= coding
.produced_char
;
9726 /* Convert the input data to a sequence of
9727 character events. */
9728 for (i
= 0; i
< nbytes
; i
+= len
)
9730 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
9732 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
9734 : multibyte_char_keystroke
);
9736 XSETFRAME (bufp
->frame_or_window
, f
);
9739 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9741 bufp
->timestamp
= event
.xkey
.time
;
9748 if (keysym
== NoSymbol
)
9758 /* Don't dispatch this event since XtDispatchEvent calls
9759 XFilterEvent, and two calls in a row may freeze the
9768 /* Don't dispatch this event since XtDispatchEvent calls
9769 XFilterEvent, and two calls in a row may freeze the
9776 /* Here's a possible interpretation of the whole
9777 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9778 you get a FocusIn event, you have to get a FocusOut
9779 event before you relinquish the focus. If you
9780 haven't received a FocusIn event, then a mere
9781 LeaveNotify is enough to free you. */
9785 int from_menu_bar_p
= 0;
9787 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9789 #ifdef LESSTIF_VERSION
9790 /* When clicking outside of a menu bar popup to close
9791 it, we get a FocusIn/ EnterNotify sequence of
9792 events. The flag event.xcrossing.focus is not set
9793 in the EnterNotify event of that sequence because
9794 the focus is in the menu bar,
9795 event.xcrossing.window is the frame's X window.
9796 Unconditionally setting the focus frame to null in
9797 this case is not the right thing, because no event
9798 follows that could set the focus frame to the right
9801 This could be a LessTif bug, but I wasn't able to
9802 reproduce the behavior in a simple test program.
9804 (gerd, LessTif 0.88.1). */
9806 if (!event
.xcrossing
.focus
9808 && f
->output_data
.x
->menubar_widget
)
9813 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9814 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9815 from_menu_bar_p
= 1;
9817 #endif /* LESSTIF_VERSION */
9819 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9821 /* Avoid nasty pop/raise loops. */
9822 if (f
&& (!(f
->auto_raise
)
9824 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9826 x_new_focus_frame (dpyinfo
, f
);
9827 enter_timestamp
= event
.xcrossing
.time
;
9830 else if (f
== dpyinfo
->x_focus_frame
)
9831 x_new_focus_frame (dpyinfo
, 0);
9833 /* EnterNotify counts as mouse movement,
9834 so update things that depend on mouse position. */
9835 if (f
&& !f
->output_data
.x
->busy_p
)
9836 note_mouse_movement (f
, &event
.xmotion
);
9841 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9842 if (event
.xfocus
.detail
!= NotifyPointer
)
9843 dpyinfo
->x_focus_event_frame
= f
;
9846 x_new_focus_frame (dpyinfo
, f
);
9848 /* Don't stop displaying the initial startup message
9849 for a switch-frame event we don't need. */
9850 if (GC_NILP (Vterminal_frame
)
9851 && GC_CONSP (Vframe_list
)
9852 && !GC_NILP (XCDR (Vframe_list
)))
9854 bufp
->kind
= FOCUS_IN_EVENT
;
9855 XSETFRAME (bufp
->frame_or_window
, f
);
9857 ++bufp
, ++count
, --numchars
;
9862 if (f
&& FRAME_XIC (f
))
9863 XSetICFocus (FRAME_XIC (f
));
9869 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9873 int from_menu_bar_p
= 0;
9875 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9877 /* If we move outside the frame, then we're
9878 certainly no longer on any text in the frame. */
9879 clear_mouse_face (dpyinfo
);
9880 dpyinfo
->mouse_face_mouse_frame
= 0;
9883 /* Generate a nil HELP_EVENT to cancel a help-echo.
9884 Do it only if there's something to cancel.
9885 Otherwise, the startup message is cleared when
9886 the mouse leaves the frame. */
9887 if (any_help_event_p
)
9892 XSETFRAME (frame
, f
);
9893 n
= gen_help_event (bufp
, Qnil
, frame
, Qnil
, Qnil
, 0);
9894 bufp
+= n
, count
+= n
, numchars
-= n
;
9897 #ifdef LESSTIF_VERSION
9898 /* Please see the comment at the start of the
9899 EnterNotify case. */
9900 if (!event
.xcrossing
.focus
9901 && f
->output_data
.x
->menubar_widget
)
9905 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9906 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9907 from_menu_bar_p
= 1;
9909 #endif /* LESSTIF_VERSION */
9911 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9912 x_mouse_leave (dpyinfo
);
9915 if (f
== dpyinfo
->x_focus_event_frame
)
9916 dpyinfo
->x_focus_event_frame
= 0;
9917 if (f
== dpyinfo
->x_focus_frame
)
9918 x_new_focus_frame (dpyinfo
, 0);
9924 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9925 if (event
.xfocus
.detail
!= NotifyPointer
9926 && f
== dpyinfo
->x_focus_event_frame
)
9927 dpyinfo
->x_focus_event_frame
= 0;
9928 if (f
&& f
== dpyinfo
->x_focus_frame
)
9929 x_new_focus_frame (dpyinfo
, 0);
9932 if (f
&& FRAME_XIC (f
))
9933 XUnsetICFocus (FRAME_XIC (f
));
9940 previous_help_echo
= help_echo
;
9941 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
9944 if (dpyinfo
->grabbed
&& last_mouse_frame
9945 && FRAME_LIVE_P (last_mouse_frame
))
9946 f
= last_mouse_frame
;
9948 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9951 note_mouse_movement (f
, &event
.xmotion
);
9954 #ifndef USE_TOOLKIT_SCROLL_BARS
9955 struct scroll_bar
*bar
9956 = x_window_to_scroll_bar (event
.xmotion
.window
);
9959 x_scroll_bar_note_movement (bar
, &event
);
9960 #endif /* USE_TOOLKIT_SCROLL_BARS */
9962 /* If we move outside the frame, then we're
9963 certainly no longer on any text in the frame. */
9964 clear_mouse_face (dpyinfo
);
9967 /* If the contents of the global variable help_echo
9968 has changed, generate a HELP_EVENT. */
9969 if (!NILP (help_echo
)
9970 || !NILP (previous_help_echo
))
9976 XSETFRAME (frame
, f
);
9980 any_help_event_p
= 1;
9981 n
= gen_help_event (bufp
, help_echo
, frame
,
9982 help_echo_window
, help_echo_object
,
9984 bufp
+= n
, count
+= n
, numchars
-= n
;
9990 case ConfigureNotify
:
9991 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
9994 #ifndef USE_X_TOOLKIT
9995 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
9996 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
9998 /* In the toolkit version, change_frame_size
9999 is called by the code that handles resizing
10000 of the EmacsFrame widget. */
10002 /* Even if the number of character rows and columns has
10003 not changed, the font size may have changed, so we need
10004 to check the pixel dimensions as well. */
10005 if (columns
!= f
->width
10006 || rows
!= f
->height
10007 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10008 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10010 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10011 SET_FRAME_GARBAGED (f
);
10012 cancel_mouse_face (f
);
10016 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10017 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10019 /* What we have now is the position of Emacs's own window.
10020 Convert that to the position of the window manager window. */
10021 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10022 &f
->output_data
.x
->top_pos
);
10025 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10026 xic_set_statusarea (f
);
10029 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10031 /* Since the WM decorations come below top_pos now,
10032 we must put them below top_pos in the future. */
10033 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10034 x_wm_set_size_hint (f
, (long) 0, 0);
10037 /* Some window managers pass (0,0) as the location of
10038 the window, and the Motif event handler stores it
10039 in the emacs widget, which messes up Motif menus. */
10040 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10042 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10043 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10045 #endif /* USE_MOTIF */
10050 case ButtonRelease
:
10052 /* If we decide we want to generate an event to be seen
10053 by the rest of Emacs, we put it here. */
10054 struct input_event emacs_event
;
10055 int tool_bar_p
= 0;
10057 emacs_event
.kind
= no_event
;
10058 bzero (&compose_status
, sizeof (compose_status
));
10060 if (dpyinfo
->grabbed
10061 && last_mouse_frame
10062 && FRAME_LIVE_P (last_mouse_frame
))
10063 f
= last_mouse_frame
;
10065 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10069 /* Is this in the tool-bar? */
10070 if (WINDOWP (f
->tool_bar_window
)
10071 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10073 Lisp_Object window
;
10076 x
= event
.xbutton
.x
;
10077 y
= event
.xbutton
.y
;
10080 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10081 if (EQ (window
, f
->tool_bar_window
))
10083 x_handle_tool_bar_click (f
, &event
.xbutton
);
10089 if (!dpyinfo
->x_focus_frame
10090 || f
== dpyinfo
->x_focus_frame
)
10091 construct_mouse_click (&emacs_event
, &event
, f
);
10095 #ifndef USE_TOOLKIT_SCROLL_BARS
10096 struct scroll_bar
*bar
10097 = x_window_to_scroll_bar (event
.xbutton
.window
);
10100 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10101 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10104 if (event
.type
== ButtonPress
)
10106 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10107 last_mouse_frame
= f
;
10108 /* Ignore any mouse motion that happened
10109 before this event; any subsequent mouse-movement
10110 Emacs events should reflect only motion after
10111 the ButtonPress. */
10113 f
->mouse_moved
= 0;
10116 last_tool_bar_item
= -1;
10120 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10123 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10125 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10131 #ifdef USE_X_TOOLKIT
10132 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10133 /* For a down-event in the menu bar,
10134 don't pass it to Xt right now.
10135 Instead, save it away
10136 and we will pass it to Xt from kbd_buffer_get_event.
10137 That way, we can run some Lisp code first. */
10138 if (f
&& event
.type
== ButtonPress
10139 /* Verify the event is really within the menu bar
10140 and not just sent to it due to grabbing. */
10141 && event
.xbutton
.x
>= 0
10142 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10143 && event
.xbutton
.y
>= 0
10144 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10145 && event
.xbutton
.same_screen
)
10147 SET_SAVED_BUTTON_EVENT
;
10148 XSETFRAME (last_mouse_press_frame
, f
);
10150 else if (event
.type
== ButtonPress
)
10152 last_mouse_press_frame
= Qnil
;
10156 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10157 but I am trying to be cautious. */
10158 else if (event
.type
== ButtonRelease
)
10160 if (!NILP (last_mouse_press_frame
))
10162 f
= XFRAME (last_mouse_press_frame
);
10163 if (f
->output_data
.x
)
10164 SET_SAVED_BUTTON_EVENT
;
10169 #endif /* USE_MOTIF */
10172 #endif /* USE_X_TOOLKIT */
10176 case CirculateNotify
:
10179 case CirculateRequest
:
10182 case VisibilityNotify
:
10185 case MappingNotify
:
10186 /* Someone has changed the keyboard mapping - update the
10188 switch (event
.xmapping
.request
)
10190 case MappingModifier
:
10191 x_find_modifier_meanings (dpyinfo
);
10192 /* This is meant to fall through. */
10193 case MappingKeyboard
:
10194 XRefreshKeyboardMapping (&event
.xmapping
);
10200 #ifdef USE_X_TOOLKIT
10202 XtDispatchEvent (&event
);
10204 #endif /* USE_X_TOOLKIT */
10212 /* On some systems, an X bug causes Emacs to get no more events
10213 when the window is destroyed. Detect that. (1994.) */
10216 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10217 One XNOOP in 100 loops will make Emacs terminate.
10218 B. Bretthauer, 1994 */
10220 if (x_noop_count
>= 100)
10224 if (next_noop_dpyinfo
== 0)
10225 next_noop_dpyinfo
= x_display_list
;
10227 XNoOp (next_noop_dpyinfo
->display
);
10229 /* Each time we get here, cycle through the displays now open. */
10230 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10234 /* If the focus was just given to an auto-raising frame,
10236 /* ??? This ought to be able to handle more than one such frame. */
10237 if (pending_autoraise_frame
)
10239 x_raise_frame (pending_autoraise_frame
);
10240 pending_autoraise_frame
= 0;
10251 /***********************************************************************
10253 ***********************************************************************/
10255 /* Note if the text cursor of window W has been overwritten by a
10256 drawing operation that outputs N glyphs starting at HPOS in the
10257 line given by output_cursor.vpos. N < 0 means all the rest of the
10258 line after HPOS has been written. */
10261 note_overwritten_text_cursor (w
, hpos
, n
)
10265 if (updated_area
== TEXT_AREA
10266 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10267 && hpos
<= w
->phys_cursor
.hpos
10269 || hpos
+ n
> w
->phys_cursor
.hpos
))
10270 w
->phys_cursor_on_p
= 0;
10274 /* Set clipping for output in glyph row ROW. W is the window in which
10275 we operate. GC is the graphics context to set clipping in.
10276 WHOLE_LINE_P non-zero means include the areas used for truncation
10277 mark display and alike in the clipping rectangle.
10279 ROW may be a text row or, e.g., a mode line. Text rows must be
10280 clipped to the interior of the window dedicated to text display,
10281 mode lines must be clipped to the whole window. */
10284 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10286 struct glyph_row
*row
;
10290 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10291 XRectangle clip_rect
;
10292 int window_x
, window_y
, window_width
, window_height
;
10294 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10296 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10297 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10298 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10299 clip_rect
.width
= window_width
;
10300 clip_rect
.height
= row
->visible_height
;
10302 /* If clipping to the whole line, including trunc marks, extend
10303 the rectangle to the left and increase its width. */
10306 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10307 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10310 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10314 /* Draw a hollow box cursor on window W in glyph row ROW. */
10317 x_draw_hollow_cursor (w
, row
)
10319 struct glyph_row
*row
;
10321 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10322 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10323 Display
*dpy
= FRAME_X_DISPLAY (f
);
10326 struct glyph
*cursor_glyph
;
10329 /* Compute frame-relative coordinates from window-relative
10331 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10332 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10333 + row
->ascent
- w
->phys_cursor_ascent
);
10334 h
= row
->height
- 1;
10336 /* Get the glyph the cursor is on. If we can't tell because
10337 the current matrix is invalid or such, give up. */
10338 cursor_glyph
= get_phys_cursor_glyph (w
);
10339 if (cursor_glyph
== NULL
)
10342 /* Compute the width of the rectangle to draw. If on a stretch
10343 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10344 rectangle as wide as the glyph, but use a canonical character
10346 wd
= cursor_glyph
->pixel_width
- 1;
10347 if (cursor_glyph
->type
== STRETCH_GLYPH
10348 && !x_stretch_cursor_p
)
10349 wd
= min (CANON_X_UNIT (f
), wd
);
10351 /* The foreground of cursor_gc is typically the same as the normal
10352 background color, which can cause the cursor box to be invisible. */
10353 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10354 if (dpyinfo
->scratch_cursor_gc
)
10355 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10357 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10358 GCForeground
, &xgcv
);
10359 gc
= dpyinfo
->scratch_cursor_gc
;
10361 /* Set clipping, draw the rectangle, and reset clipping again. */
10362 x_clip_to_row (w
, row
, gc
, 0);
10363 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10364 XSetClipMask (dpy
, gc
, None
);
10368 /* Draw a bar cursor on window W in glyph row ROW.
10370 Implementation note: One would like to draw a bar cursor with an
10371 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10372 Unfortunately, I didn't find a font yet that has this property set.
10376 x_draw_bar_cursor (w
, row
, width
)
10378 struct glyph_row
*row
;
10381 struct frame
*f
= XFRAME (w
->frame
);
10382 struct glyph
*cursor_glyph
;
10385 unsigned long mask
;
10390 /* If cursor is out of bounds, don't draw garbage. This can happen
10391 in mini-buffer windows when switching between echo area glyphs
10392 and mini-buffer. */
10393 cursor_glyph
= get_phys_cursor_glyph (w
);
10394 if (cursor_glyph
== NULL
)
10397 /* If on an image, draw like a normal cursor. That's usually better
10398 visible than drawing a bar, esp. if the image is large so that
10399 the bar might not be in the window. */
10400 if (cursor_glyph
->type
== IMAGE_GLYPH
)
10402 struct glyph_row
*row
;
10403 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
10404 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
10408 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10409 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10410 xgcv
.graphics_exposures
= 0;
10411 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10412 dpy
= FRAME_X_DISPLAY (f
);
10413 window
= FRAME_X_WINDOW (f
);
10414 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10417 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10420 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10421 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10425 width
= f
->output_data
.x
->cursor_width
;
10427 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10428 x_clip_to_row (w
, row
, gc
, 0);
10429 XFillRectangle (dpy
, window
, gc
,
10431 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10432 min (cursor_glyph
->pixel_width
, width
),
10434 XSetClipMask (dpy
, gc
, None
);
10439 /* Clear the cursor of window W to background color, and mark the
10440 cursor as not shown. This is used when the text where the cursor
10441 is is about to be rewritten. */
10447 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10448 x_update_window_cursor (w
, 0);
10452 /* Draw the cursor glyph of window W in glyph row ROW. See the
10453 comment of x_draw_glyphs for the meaning of HL. */
10456 x_draw_phys_cursor_glyph (w
, row
, hl
)
10458 struct glyph_row
*row
;
10459 enum draw_glyphs_face hl
;
10461 /* If cursor hpos is out of bounds, don't draw garbage. This can
10462 happen in mini-buffer windows when switching between echo area
10463 glyphs and mini-buffer. */
10464 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10466 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10467 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10470 /* When we erase the cursor, and ROW is overlapped by other
10471 rows, make sure that these overlapping parts of other rows
10473 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10475 if (row
> w
->current_matrix
->rows
10476 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10477 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10479 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10480 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10481 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10487 /* Erase the image of a cursor of window W from the screen. */
10490 x_erase_phys_cursor (w
)
10493 struct frame
*f
= XFRAME (w
->frame
);
10494 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10495 int hpos
= w
->phys_cursor
.hpos
;
10496 int vpos
= w
->phys_cursor
.vpos
;
10497 int mouse_face_here_p
= 0;
10498 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10499 struct glyph_row
*cursor_row
;
10500 struct glyph
*cursor_glyph
;
10501 enum draw_glyphs_face hl
;
10503 /* No cursor displayed or row invalidated => nothing to do on the
10505 if (w
->phys_cursor_type
== NO_CURSOR
)
10506 goto mark_cursor_off
;
10508 /* VPOS >= active_glyphs->nrows means that window has been resized.
10509 Don't bother to erase the cursor. */
10510 if (vpos
>= active_glyphs
->nrows
)
10511 goto mark_cursor_off
;
10513 /* If row containing cursor is marked invalid, there is nothing we
10515 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10516 if (!cursor_row
->enabled_p
)
10517 goto mark_cursor_off
;
10519 /* This can happen when the new row is shorter than the old one.
10520 In this case, either x_draw_glyphs or clear_end_of_line
10521 should have cleared the cursor. Note that we wouldn't be
10522 able to erase the cursor in this case because we don't have a
10523 cursor glyph at hand. */
10524 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10525 goto mark_cursor_off
;
10527 /* If the cursor is in the mouse face area, redisplay that when
10528 we clear the cursor. */
10529 if (! NILP (dpyinfo
->mouse_face_window
)
10530 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10531 && (vpos
> dpyinfo
->mouse_face_beg_row
10532 || (vpos
== dpyinfo
->mouse_face_beg_row
10533 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10534 && (vpos
< dpyinfo
->mouse_face_end_row
10535 || (vpos
== dpyinfo
->mouse_face_end_row
10536 && hpos
< dpyinfo
->mouse_face_end_col
))
10537 /* Don't redraw the cursor's spot in mouse face if it is at the
10538 end of a line (on a newline). The cursor appears there, but
10539 mouse highlighting does not. */
10540 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10541 mouse_face_here_p
= 1;
10543 /* Maybe clear the display under the cursor. */
10544 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10547 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10549 cursor_glyph
= get_phys_cursor_glyph (w
);
10550 if (cursor_glyph
== NULL
)
10551 goto mark_cursor_off
;
10553 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10555 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10557 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10559 cursor_glyph
->pixel_width
,
10560 cursor_row
->visible_height
,
10564 /* Erase the cursor by redrawing the character underneath it. */
10565 if (mouse_face_here_p
)
10566 hl
= DRAW_MOUSE_FACE
;
10567 else if (cursor_row
->inverse_p
)
10568 hl
= DRAW_INVERSE_VIDEO
;
10570 hl
= DRAW_NORMAL_TEXT
;
10571 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10574 w
->phys_cursor_on_p
= 0;
10575 w
->phys_cursor_type
= NO_CURSOR
;
10579 /* Display or clear cursor of window W. If ON is zero, clear the
10580 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10581 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10584 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10586 int on
, hpos
, vpos
, x
, y
;
10588 struct frame
*f
= XFRAME (w
->frame
);
10589 int new_cursor_type
;
10590 int new_cursor_width
;
10591 struct glyph_matrix
*current_glyphs
;
10592 struct glyph_row
*glyph_row
;
10593 struct glyph
*glyph
;
10595 /* This is pointless on invisible frames, and dangerous on garbaged
10596 windows and frames; in the latter case, the frame or window may
10597 be in the midst of changing its size, and x and y may be off the
10599 if (! FRAME_VISIBLE_P (f
)
10600 || FRAME_GARBAGED_P (f
)
10601 || vpos
>= w
->current_matrix
->nrows
10602 || hpos
>= w
->current_matrix
->matrix_w
)
10605 /* If cursor is off and we want it off, return quickly. */
10606 if (!on
&& !w
->phys_cursor_on_p
)
10609 current_glyphs
= w
->current_matrix
;
10610 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10611 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10613 /* If cursor row is not enabled, we don't really know where to
10614 display the cursor. */
10615 if (!glyph_row
->enabled_p
)
10617 w
->phys_cursor_on_p
= 0;
10621 xassert (interrupt_input_blocked
);
10623 /* Set new_cursor_type to the cursor we want to be displayed. In a
10624 mini-buffer window, we want the cursor only to appear if we are
10625 reading input from this window. For the selected window, we want
10626 the cursor type given by the frame parameter. If explicitly
10627 marked off, draw no cursor. In all other cases, we want a hollow
10629 new_cursor_width
= -1;
10630 if (cursor_in_echo_area
10631 && FRAME_HAS_MINIBUF_P (f
)
10632 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10634 if (w
== XWINDOW (echo_area_window
))
10635 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10637 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10641 if (w
!= XWINDOW (selected_window
)
10642 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10644 extern int cursor_in_non_selected_windows
;
10646 if (MINI_WINDOW_P (w
) || !cursor_in_non_selected_windows
)
10647 new_cursor_type
= NO_CURSOR
;
10649 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10651 else if (w
->cursor_off_p
)
10652 new_cursor_type
= NO_CURSOR
;
10655 struct buffer
*b
= XBUFFER (w
->buffer
);
10657 if (EQ (b
->cursor_type
, Qt
))
10658 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10660 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10661 &new_cursor_width
);
10665 /* If cursor is currently being shown and we don't want it to be or
10666 it is in the wrong place, or the cursor type is not what we want,
10668 if (w
->phys_cursor_on_p
10670 || w
->phys_cursor
.x
!= x
10671 || w
->phys_cursor
.y
!= y
10672 || new_cursor_type
!= w
->phys_cursor_type
))
10673 x_erase_phys_cursor (w
);
10675 /* If the cursor is now invisible and we want it to be visible,
10677 if (on
&& !w
->phys_cursor_on_p
)
10679 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10680 w
->phys_cursor_height
= glyph_row
->height
;
10682 /* Set phys_cursor_.* before x_draw_.* is called because some
10683 of them may need the information. */
10684 w
->phys_cursor
.x
= x
;
10685 w
->phys_cursor
.y
= glyph_row
->y
;
10686 w
->phys_cursor
.hpos
= hpos
;
10687 w
->phys_cursor
.vpos
= vpos
;
10688 w
->phys_cursor_type
= new_cursor_type
;
10689 w
->phys_cursor_on_p
= 1;
10691 switch (new_cursor_type
)
10693 case HOLLOW_BOX_CURSOR
:
10694 x_draw_hollow_cursor (w
, glyph_row
);
10697 case FILLED_BOX_CURSOR
:
10698 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10702 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10713 if (w
== XWINDOW (f
->selected_window
))
10714 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10715 xic_set_preeditarea (w
, x
, y
);
10720 if (updating_frame
!= f
)
10721 XFlush (FRAME_X_DISPLAY (f
));
10726 /* Display the cursor on window W, or clear it. X and Y are window
10727 relative pixel coordinates. HPOS and VPOS are glyph matrix
10728 positions. If W is not the selected window, display a hollow
10729 cursor. ON non-zero means display the cursor at X, Y which
10730 correspond to HPOS, VPOS, otherwise it is cleared. */
10733 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10735 int on
, hpos
, vpos
, x
, y
;
10738 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10743 /* Display the cursor on window W, or clear it, according to ON_P.
10744 Don't change the cursor's position. */
10747 x_update_cursor (f
, on_p
)
10750 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10754 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10755 in the window tree rooted at W. */
10758 x_update_cursor_in_window_tree (w
, on_p
)
10764 if (!NILP (w
->hchild
))
10765 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10766 else if (!NILP (w
->vchild
))
10767 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10769 x_update_window_cursor (w
, on_p
);
10771 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10776 /* Switch the display of W's cursor on or off, according to the value
10780 x_update_window_cursor (w
, on
)
10784 /* Don't update cursor in windows whose frame is in the process
10785 of being deleted. */
10786 if (w
->current_matrix
)
10789 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10790 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10800 /* Refresh bitmap kitchen sink icon for frame F
10801 when we get an expose event for it. */
10807 /* Normally, the window manager handles this function. */
10810 /* Make the x-window of frame F use the gnu icon bitmap. */
10813 x_bitmap_icon (f
, file
)
10819 if (FRAME_X_WINDOW (f
) == 0)
10822 /* Free up our existing icon bitmap if any. */
10823 if (f
->output_data
.x
->icon_bitmap
> 0)
10824 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10825 f
->output_data
.x
->icon_bitmap
= 0;
10827 if (STRINGP (file
))
10828 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10831 /* Create the GNU bitmap if necessary. */
10832 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10833 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10834 = x_create_bitmap_from_data (f
, gnu_bits
,
10835 gnu_width
, gnu_height
);
10837 /* The first time we create the GNU bitmap,
10838 this increments the ref-count one extra time.
10839 As a result, the GNU bitmap is never freed.
10840 That way, we don't have to worry about allocating it again. */
10841 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10843 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10846 x_wm_set_icon_pixmap (f
, bitmap_id
);
10847 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10853 /* Make the x-window of frame F use a rectangle with text.
10854 Use ICON_NAME as the text. */
10857 x_text_icon (f
, icon_name
)
10861 if (FRAME_X_WINDOW (f
) == 0)
10866 XTextProperty text
;
10867 text
.value
= (unsigned char *) icon_name
;
10868 text
.encoding
= XA_STRING
;
10870 text
.nitems
= strlen (icon_name
);
10871 #ifdef USE_X_TOOLKIT
10872 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10874 #else /* not USE_X_TOOLKIT */
10875 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10876 #endif /* not USE_X_TOOLKIT */
10878 #else /* not HAVE_X11R4 */
10879 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10880 #endif /* not HAVE_X11R4 */
10882 if (f
->output_data
.x
->icon_bitmap
> 0)
10883 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10884 f
->output_data
.x
->icon_bitmap
= 0;
10885 x_wm_set_icon_pixmap (f
, 0);
10890 #define X_ERROR_MESSAGE_SIZE 200
10892 /* If non-nil, this should be a string.
10893 It means catch X errors and store the error message in this string. */
10895 static Lisp_Object x_error_message_string
;
10897 /* An X error handler which stores the error message in
10898 x_error_message_string. This is called from x_error_handler if
10899 x_catch_errors is in effect. */
10902 x_error_catcher (display
, error
)
10904 XErrorEvent
*error
;
10906 XGetErrorText (display
, error
->error_code
,
10907 XSTRING (x_error_message_string
)->data
,
10908 X_ERROR_MESSAGE_SIZE
);
10911 /* Begin trapping X errors for display DPY. Actually we trap X errors
10912 for all displays, but DPY should be the display you are actually
10915 After calling this function, X protocol errors no longer cause
10916 Emacs to exit; instead, they are recorded in the string
10917 stored in x_error_message_string.
10919 Calling x_check_errors signals an Emacs error if an X error has
10920 occurred since the last call to x_catch_errors or x_check_errors.
10922 Calling x_uncatch_errors resumes the normal error handling. */
10924 void x_check_errors ();
10925 static Lisp_Object
x_catch_errors_unwind ();
10928 x_catch_errors (dpy
)
10931 int count
= specpdl_ptr
- specpdl
;
10933 /* Make sure any errors from previous requests have been dealt with. */
10934 XSync (dpy
, False
);
10936 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10938 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10939 XSTRING (x_error_message_string
)->data
[0] = 0;
10944 /* Unbind the binding that we made to check for X errors. */
10947 x_catch_errors_unwind (old_val
)
10948 Lisp_Object old_val
;
10950 x_error_message_string
= old_val
;
10954 /* If any X protocol errors have arrived since the last call to
10955 x_catch_errors or x_check_errors, signal an Emacs error using
10956 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10959 x_check_errors (dpy
, format
)
10963 /* Make sure to catch any errors incurred so far. */
10964 XSync (dpy
, False
);
10966 if (XSTRING (x_error_message_string
)->data
[0])
10967 error (format
, XSTRING (x_error_message_string
)->data
);
10970 /* Nonzero if we had any X protocol errors
10971 since we did x_catch_errors on DPY. */
10974 x_had_errors_p (dpy
)
10977 /* Make sure to catch any errors incurred so far. */
10978 XSync (dpy
, False
);
10980 return XSTRING (x_error_message_string
)->data
[0] != 0;
10983 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
10986 x_clear_errors (dpy
)
10989 XSTRING (x_error_message_string
)->data
[0] = 0;
10992 /* Stop catching X protocol errors and let them make Emacs die.
10993 DPY should be the display that was passed to x_catch_errors.
10994 COUNT should be the value that was returned by
10995 the corresponding call to x_catch_errors. */
10998 x_uncatch_errors (dpy
, count
)
11002 unbind_to (count
, Qnil
);
11006 static unsigned int x_wire_count
;
11009 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11014 /* Handle SIGPIPE, which can happen when the connection to a server
11015 simply goes away. SIGPIPE is handled by x_connection_signal.
11016 Don't need to do anything, because the write which caused the
11017 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11018 which will do the appropriate cleanup for us. */
11021 x_connection_signal (signalnum
) /* If we don't have an argument, */
11022 int signalnum
; /* some compilers complain in signal calls. */
11025 /* USG systems forget handlers when they are used;
11026 must reestablish each time */
11027 signal (signalnum
, x_connection_signal
);
11031 /* Handling X errors. */
11033 /* Handle the loss of connection to display DISPLAY. */
11036 x_connection_closed (display
, error_message
)
11038 char *error_message
;
11040 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
11041 Lisp_Object frame
, tail
;
11043 /* Indicate that this display is dead. */
11045 #if 0 /* Closing the display caused a bus error on OpenWindows. */
11046 #ifdef USE_X_TOOLKIT
11047 XtCloseDisplay (display
);
11052 dpyinfo
->display
= 0;
11054 /* First delete frames whose mini-buffers are on frames
11055 that are on the dead display. */
11056 FOR_EACH_FRAME (tail
, frame
)
11058 Lisp_Object minibuf_frame
;
11060 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11061 if (FRAME_X_P (XFRAME (frame
))
11062 && FRAME_X_P (XFRAME (minibuf_frame
))
11063 && ! EQ (frame
, minibuf_frame
)
11064 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11065 Fdelete_frame (frame
, Qt
);
11068 /* Now delete all remaining frames on the dead display.
11069 We are now sure none of these is used as the mini-buffer
11070 for another frame that we need to delete. */
11071 FOR_EACH_FRAME (tail
, frame
)
11072 if (FRAME_X_P (XFRAME (frame
))
11073 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11075 /* Set this to t so that Fdelete_frame won't get confused
11076 trying to find a replacement. */
11077 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11078 Fdelete_frame (frame
, Qt
);
11082 x_delete_display (dpyinfo
);
11084 if (x_display_list
== 0)
11086 fprintf (stderr
, "%s\n", error_message
);
11087 shut_down_emacs (0, 0, Qnil
);
11091 /* Ordinary stack unwind doesn't deal with these. */
11093 sigunblock (sigmask (SIGIO
));
11095 sigunblock (sigmask (SIGALRM
));
11096 TOTALLY_UNBLOCK_INPUT
;
11098 clear_waiting_for_input ();
11099 error ("%s", error_message
);
11102 /* This is the usual handler for X protocol errors.
11103 It kills all frames on the display that we got the error for.
11104 If that was the only one, it prints an error message and kills Emacs. */
11107 x_error_quitter (display
, error
)
11109 XErrorEvent
*error
;
11111 char buf
[256], buf1
[356];
11113 /* Note that there is no real way portable across R3/R4 to get the
11114 original error handler. */
11116 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11117 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11118 buf
, error
->request_code
);
11119 x_connection_closed (display
, buf1
);
11122 /* This is the first-level handler for X protocol errors.
11123 It calls x_error_quitter or x_error_catcher. */
11126 x_error_handler (display
, error
)
11128 XErrorEvent
*error
;
11130 if (! NILP (x_error_message_string
))
11131 x_error_catcher (display
, error
);
11133 x_error_quitter (display
, error
);
11137 /* This is the handler for X IO errors, always.
11138 It kills all frames on the display that we lost touch with.
11139 If that was the only one, it prints an error message and kills Emacs. */
11142 x_io_error_quitter (display
)
11147 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11148 x_connection_closed (display
, buf
);
11152 /* Changing the font of the frame. */
11154 /* Give frame F the font named FONTNAME as its default font, and
11155 return the full name of that font. FONTNAME may be a wildcard
11156 pattern; in that case, we choose some font that fits the pattern.
11157 The return value shows which font we chose. */
11160 x_new_font (f
, fontname
)
11162 register char *fontname
;
11164 struct font_info
*fontp
11165 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11170 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11171 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11172 f
->output_data
.x
->fontset
= -1;
11174 /* Compute the scroll bar width in character columns. */
11175 if (f
->scroll_bar_pixel_width
> 0)
11177 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11178 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11182 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11183 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11186 /* Now make the frame display the given font. */
11187 if (FRAME_X_WINDOW (f
) != 0)
11189 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11190 f
->output_data
.x
->font
->fid
);
11191 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11192 f
->output_data
.x
->font
->fid
);
11193 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11194 f
->output_data
.x
->font
->fid
);
11196 frame_update_line_height (f
);
11197 x_set_window_size (f
, 0, f
->width
, f
->height
);
11200 /* If we are setting a new frame's font for the first time,
11201 there are no faces yet, so this font's height is the line height. */
11202 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11204 return build_string (fontp
->full_name
);
11207 /* Give frame F the fontset named FONTSETNAME as its default font, and
11208 return the full name of that fontset. FONTSETNAME may be a wildcard
11209 pattern; in that case, we choose some fontset that fits the pattern.
11210 The return value shows which fontset we chose. */
11213 x_new_fontset (f
, fontsetname
)
11217 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11218 Lisp_Object result
;
11223 if (f
->output_data
.x
->fontset
== fontset
)
11224 /* This fontset is already set in frame F. There's nothing more
11226 return fontset_name (fontset
);
11228 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11230 if (!STRINGP (result
))
11231 /* Can't load ASCII font. */
11234 /* Since x_new_font doesn't update any fontset information, do it now. */
11235 f
->output_data
.x
->fontset
= fontset
;
11239 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11240 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11243 return build_string (fontsetname
);
11247 /***********************************************************************
11249 ***********************************************************************/
11255 /* XIM destroy callback function, which is called whenever the
11256 connection to input method XIM dies. CLIENT_DATA contains a
11257 pointer to the x_display_info structure corresponding to XIM. */
11260 xim_destroy_callback (xim
, client_data
, call_data
)
11262 XPointer client_data
;
11263 XPointer call_data
;
11265 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11266 Lisp_Object frame
, tail
;
11270 /* No need to call XDestroyIC.. */
11271 FOR_EACH_FRAME (tail
, frame
)
11273 struct frame
*f
= XFRAME (frame
);
11274 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11276 FRAME_XIC (f
) = NULL
;
11277 if (FRAME_XIC_FONTSET (f
))
11279 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11280 FRAME_XIC_FONTSET (f
) = NULL
;
11285 /* No need to call XCloseIM. */
11286 dpyinfo
->xim
= NULL
;
11287 XFree (dpyinfo
->xim_styles
);
11291 #endif /* HAVE_X11R6 */
11293 /* Open the connection to the XIM server on display DPYINFO.
11294 RESOURCE_NAME is the resource name Emacs uses. */
11297 xim_open_dpy (dpyinfo
, resource_name
)
11298 struct x_display_info
*dpyinfo
;
11299 char *resource_name
;
11304 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11305 dpyinfo
->xim
= xim
;
11310 XIMCallback destroy
;
11313 /* Get supported styles and XIM values. */
11314 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11317 destroy
.callback
= xim_destroy_callback
;
11318 destroy
.client_data
= (XPointer
)dpyinfo
;
11319 /* This isn't prptotyped in OSF 5.0. */
11320 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11324 #else /* not USE_XIM */
11325 dpyinfo
->xim
= NULL
;
11326 #endif /* not USE_XIM */
11330 #ifdef HAVE_X11R6_XIM
11334 struct x_display_info
*dpyinfo
;
11335 char *resource_name
;
11338 /* XIM instantiate callback function, which is called whenever an XIM
11339 server is available. DISPLAY is teh display of the XIM.
11340 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11341 when the callback was registered. */
11344 xim_instantiate_callback (display
, client_data
, call_data
)
11346 XPointer client_data
;
11347 XPointer call_data
;
11349 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11350 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11352 /* We don't support multiple XIM connections. */
11356 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11358 /* Create XIC for the existing frames on the same display, as long
11359 as they have no XIC. */
11360 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11362 Lisp_Object tail
, frame
;
11365 FOR_EACH_FRAME (tail
, frame
)
11367 struct frame
*f
= XFRAME (frame
);
11369 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11370 if (FRAME_XIC (f
) == NULL
)
11372 create_frame_xic (f
);
11373 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11374 xic_set_statusarea (f
);
11375 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11377 struct window
*w
= XWINDOW (f
->selected_window
);
11378 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11387 #endif /* HAVE_X11R6_XIM */
11390 /* Open a connection to the XIM server on display DPYINFO.
11391 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11392 connection only at the first time. On X11R6, open the connection
11393 in the XIM instantiate callback function. */
11396 xim_initialize (dpyinfo
, resource_name
)
11397 struct x_display_info
*dpyinfo
;
11398 char *resource_name
;
11401 #ifdef HAVE_X11R6_XIM
11402 struct xim_inst_t
*xim_inst
;
11405 dpyinfo
->xim
= NULL
;
11406 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11407 xim_inst
->dpyinfo
= dpyinfo
;
11408 len
= strlen (resource_name
);
11409 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11410 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11411 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11412 resource_name
, EMACS_CLASS
,
11413 xim_instantiate_callback
,
11414 /* Fixme: This is XPointer in
11415 XFree86 but (XPointer *) on
11416 Tru64, at least. */
11417 (XPointer
) xim_inst
);
11418 #else /* not HAVE_X11R6_XIM */
11419 dpyinfo
->xim
= NULL
;
11420 xim_open_dpy (dpyinfo
, resource_name
);
11421 #endif /* not HAVE_X11R6_XIM */
11423 #else /* not USE_XIM */
11424 dpyinfo
->xim
= NULL
;
11425 #endif /* not USE_XIM */
11429 /* Close the connection to the XIM server on display DPYINFO. */
11432 xim_close_dpy (dpyinfo
)
11433 struct x_display_info
*dpyinfo
;
11436 #ifdef HAVE_X11R6_XIM
11437 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11439 xim_instantiate_callback
, NULL
);
11440 #endif /* not HAVE_X11R6_XIM */
11441 XCloseIM (dpyinfo
->xim
);
11442 dpyinfo
->xim
= NULL
;
11443 XFree (dpyinfo
->xim_styles
);
11444 #endif /* USE_XIM */
11447 #endif /* not HAVE_X11R6_XIM */
11451 /* Calculate the absolute position in frame F
11452 from its current recorded position values and gravity. */
11455 x_calc_absolute_position (f
)
11459 int win_x
= 0, win_y
= 0;
11460 int flags
= f
->output_data
.x
->size_hint_flags
;
11463 /* We have nothing to do if the current position
11464 is already for the top-left corner. */
11465 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11468 #ifdef USE_X_TOOLKIT
11469 this_window
= XtWindow (f
->output_data
.x
->widget
);
11471 this_window
= FRAME_X_WINDOW (f
);
11474 /* Find the position of the outside upper-left corner of
11475 the inner window, with respect to the outer window.
11476 But do this only if we will need the results. */
11477 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11482 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11485 x_clear_errors (FRAME_X_DISPLAY (f
));
11486 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11488 /* From-window, to-window. */
11490 f
->output_data
.x
->parent_desc
,
11492 /* From-position, to-position. */
11493 0, 0, &win_x
, &win_y
,
11495 /* Child of win. */
11497 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11499 Window newroot
, newparent
= 0xdeadbeef;
11500 Window
*newchildren
;
11501 unsigned int nchildren
;
11503 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11504 &newparent
, &newchildren
, &nchildren
))
11507 XFree ((char *) newchildren
);
11509 f
->output_data
.x
->parent_desc
= newparent
;
11515 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11519 /* Treat negative positions as relative to the leftmost bottommost
11520 position that fits on the screen. */
11521 if (flags
& XNegative
)
11522 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11523 - 2 * f
->output_data
.x
->border_width
- win_x
11525 + f
->output_data
.x
->left_pos
);
11527 if (flags
& YNegative
)
11529 int menubar_height
= 0;
11531 #ifdef USE_X_TOOLKIT
11532 if (f
->output_data
.x
->menubar_widget
)
11534 = (f
->output_data
.x
->menubar_widget
->core
.height
11535 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
11538 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11539 - 2 * f
->output_data
.x
->border_width
11543 + f
->output_data
.x
->top_pos
);
11546 /* The left_pos and top_pos
11547 are now relative to the top and left screen edges,
11548 so the flags should correspond. */
11549 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11552 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11553 to really change the position, and 0 when calling from
11554 x_make_frame_visible (in that case, XOFF and YOFF are the current
11555 position values). It is -1 when calling from x_set_frame_parameters,
11556 which means, do adjust for borders but don't change the gravity. */
11559 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11561 register int xoff
, yoff
;
11562 int change_gravity
;
11564 int modified_top
, modified_left
;
11566 if (change_gravity
> 0)
11568 f
->output_data
.x
->top_pos
= yoff
;
11569 f
->output_data
.x
->left_pos
= xoff
;
11570 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11572 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11574 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11575 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11577 x_calc_absolute_position (f
);
11580 x_wm_set_size_hint (f
, (long) 0, 0);
11582 modified_left
= f
->output_data
.x
->left_pos
;
11583 modified_top
= f
->output_data
.x
->top_pos
;
11584 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11585 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11586 /* It is a mystery why we need to add the border_width here
11587 when the frame is already visible, but experiment says we do. */
11588 if (change_gravity
!= 0)
11590 modified_left
+= f
->output_data
.x
->border_width
;
11591 modified_top
+= f
->output_data
.x
->border_width
;
11595 #ifdef USE_X_TOOLKIT
11596 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11597 modified_left
, modified_top
);
11598 #else /* not USE_X_TOOLKIT */
11599 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11600 modified_left
, modified_top
);
11601 #endif /* not USE_X_TOOLKIT */
11605 /* Call this to change the size of frame F's x-window.
11606 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11607 for this size change and subsequent size changes.
11608 Otherwise we leave the window gravity unchanged. */
11611 x_set_window_size (f
, change_gravity
, cols
, rows
)
11613 int change_gravity
;
11616 #ifndef USE_X_TOOLKIT
11617 int pixelwidth
, pixelheight
;
11622 #ifdef USE_X_TOOLKIT
11624 /* The x and y position of the widget is clobbered by the
11625 call to XtSetValues within EmacsFrameSetCharSize.
11626 This is a real kludge, but I don't understand Xt so I can't
11627 figure out a correct fix. Can anyone else tell me? -- rms. */
11628 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11629 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11630 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11631 f
->output_data
.x
->widget
->core
.x
= xpos
;
11632 f
->output_data
.x
->widget
->core
.y
= ypos
;
11635 #else /* not USE_X_TOOLKIT */
11637 check_frame_size (f
, &rows
, &cols
);
11638 f
->output_data
.x
->vertical_scroll_bar_extra
11639 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11641 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11642 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11643 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11644 f
->output_data
.x
->flags_areas_extra
11645 = FRAME_FLAGS_AREA_WIDTH (f
);
11646 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11647 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11649 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11650 x_wm_set_size_hint (f
, (long) 0, 0);
11652 XSync (FRAME_X_DISPLAY (f
), False
);
11653 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11654 pixelwidth
, pixelheight
);
11656 /* Now, strictly speaking, we can't be sure that this is accurate,
11657 but the window manager will get around to dealing with the size
11658 change request eventually, and we'll hear how it went when the
11659 ConfigureNotify event gets here.
11661 We could just not bother storing any of this information here,
11662 and let the ConfigureNotify event set everything up, but that
11663 might be kind of confusing to the Lisp code, since size changes
11664 wouldn't be reported in the frame parameters until some random
11665 point in the future when the ConfigureNotify event arrives.
11667 We pass 1 for DELAY since we can't run Lisp code inside of
11669 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11670 PIXEL_WIDTH (f
) = pixelwidth
;
11671 PIXEL_HEIGHT (f
) = pixelheight
;
11673 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11674 receive in the ConfigureNotify event; if we get what we asked
11675 for, then the event won't cause the screen to become garbaged, so
11676 we have to make sure to do it here. */
11677 SET_FRAME_GARBAGED (f
);
11679 XFlush (FRAME_X_DISPLAY (f
));
11681 #endif /* not USE_X_TOOLKIT */
11683 /* If cursor was outside the new size, mark it as off. */
11684 mark_window_cursors_off (XWINDOW (f
->root_window
));
11686 /* Clear out any recollection of where the mouse highlighting was,
11687 since it might be in a place that's outside the new frame size.
11688 Actually checking whether it is outside is a pain in the neck,
11689 so don't try--just let the highlighting be done afresh with new size. */
11690 cancel_mouse_face (f
);
11695 /* Mouse warping. */
11698 x_set_mouse_position (f
, x
, y
)
11704 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11705 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11707 if (pix_x
< 0) pix_x
= 0;
11708 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11710 if (pix_y
< 0) pix_y
= 0;
11711 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11715 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11716 0, 0, 0, 0, pix_x
, pix_y
);
11720 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11723 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11729 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11730 0, 0, 0, 0, pix_x
, pix_y
);
11734 /* focus shifting, raising and lowering. */
11737 x_focus_on_frame (f
)
11740 #if 0 /* This proves to be unpleasant. */
11744 /* I don't think that the ICCCM allows programs to do things like this
11745 without the interaction of the window manager. Whatever you end up
11746 doing with this code, do it to x_unfocus_frame too. */
11747 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11748 RevertToPointerRoot
, CurrentTime
);
11753 x_unfocus_frame (f
)
11757 /* Look at the remarks in x_focus_on_frame. */
11758 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11759 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11760 RevertToPointerRoot
, CurrentTime
);
11764 /* Raise frame F. */
11770 if (f
->async_visible
)
11773 #ifdef USE_X_TOOLKIT
11774 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11775 #else /* not USE_X_TOOLKIT */
11776 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11777 #endif /* not USE_X_TOOLKIT */
11778 XFlush (FRAME_X_DISPLAY (f
));
11783 /* Lower frame F. */
11789 if (f
->async_visible
)
11792 #ifdef USE_X_TOOLKIT
11793 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11794 #else /* not USE_X_TOOLKIT */
11795 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11796 #endif /* not USE_X_TOOLKIT */
11797 XFlush (FRAME_X_DISPLAY (f
));
11803 XTframe_raise_lower (f
, raise_flag
)
11813 /* Change of visibility. */
11815 /* This tries to wait until the frame is really visible.
11816 However, if the window manager asks the user where to position
11817 the frame, this will return before the user finishes doing that.
11818 The frame will not actually be visible at that time,
11819 but it will become visible later when the window manager
11820 finishes with it. */
11823 x_make_frame_visible (f
)
11827 int original_top
, original_left
;
11831 type
= x_icon_type (f
);
11833 x_bitmap_icon (f
, type
);
11835 if (! FRAME_VISIBLE_P (f
))
11837 /* We test FRAME_GARBAGED_P here to make sure we don't
11838 call x_set_offset a second time
11839 if we get to x_make_frame_visible a second time
11840 before the window gets really visible. */
11841 if (! FRAME_ICONIFIED_P (f
)
11842 && ! f
->output_data
.x
->asked_for_visible
)
11843 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11845 f
->output_data
.x
->asked_for_visible
= 1;
11847 if (! EQ (Vx_no_window_manager
, Qt
))
11848 x_wm_set_window_state (f
, NormalState
);
11849 #ifdef USE_X_TOOLKIT
11850 /* This was XtPopup, but that did nothing for an iconified frame. */
11851 XtMapWidget (f
->output_data
.x
->widget
);
11852 #else /* not USE_X_TOOLKIT */
11853 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11854 #endif /* not USE_X_TOOLKIT */
11855 #if 0 /* This seems to bring back scroll bars in the wrong places
11856 if the window configuration has changed. They seem
11857 to come back ok without this. */
11858 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11859 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11863 XFlush (FRAME_X_DISPLAY (f
));
11865 /* Synchronize to ensure Emacs knows the frame is visible
11866 before we do anything else. We do this loop with input not blocked
11867 so that incoming events are handled. */
11871 /* This must be before UNBLOCK_INPUT
11872 since events that arrive in response to the actions above
11873 will set it when they are handled. */
11874 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11876 original_left
= f
->output_data
.x
->left_pos
;
11877 original_top
= f
->output_data
.x
->top_pos
;
11879 /* This must come after we set COUNT. */
11882 /* We unblock here so that arriving X events are processed. */
11884 /* Now move the window back to where it was "supposed to be".
11885 But don't do it if the gravity is negative.
11886 When the gravity is negative, this uses a position
11887 that is 3 pixels too low. Perhaps that's really the border width.
11889 Don't do this if the window has never been visible before,
11890 because the window manager may choose the position
11891 and we don't want to override it. */
11893 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11894 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11895 && previously_visible
)
11899 unsigned int width
, height
, border
, depth
;
11903 /* On some window managers (such as FVWM) moving an existing
11904 window, even to the same place, causes the window manager
11905 to introduce an offset. This can cause the window to move
11906 to an unexpected location. Check the geometry (a little
11907 slow here) and then verify that the window is in the right
11908 place. If the window is not in the right place, move it
11909 there, and take the potential window manager hit. */
11910 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11911 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11913 if (original_left
!= x
|| original_top
!= y
)
11914 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11915 original_left
, original_top
);
11920 XSETFRAME (frame
, f
);
11922 /* Wait until the frame is visible. Process X events until a
11923 MapNotify event has been seen, or until we think we won't get a
11924 MapNotify at all.. */
11925 for (count
= input_signal_count
+ 10;
11926 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
11928 /* Force processing of queued events. */
11931 /* Machines that do polling rather than SIGIO have been
11932 observed to go into a busy-wait here. So we'll fake an
11933 alarm signal to let the handler know that there's something
11934 to be read. We used to raise a real alarm, but it seems
11935 that the handler isn't always enabled here. This is
11937 if (input_polling_used ())
11939 /* It could be confusing if a real alarm arrives while
11940 processing the fake one. Turn it off and let the
11941 handler reset it. */
11942 extern void poll_for_input_1
P_ ((void));
11943 int old_poll_suppress_count
= poll_suppress_count
;
11944 poll_suppress_count
= 1;
11945 poll_for_input_1 ();
11946 poll_suppress_count
= old_poll_suppress_count
;
11949 /* See if a MapNotify event has been processed. */
11950 FRAME_SAMPLE_VISIBILITY (f
);
11955 /* Change from mapped state to withdrawn state. */
11957 /* Make the frame visible (mapped and not iconified). */
11960 x_make_frame_invisible (f
)
11965 #ifdef USE_X_TOOLKIT
11966 /* Use the frame's outermost window, not the one we normally draw on. */
11967 window
= XtWindow (f
->output_data
.x
->widget
);
11968 #else /* not USE_X_TOOLKIT */
11969 window
= FRAME_X_WINDOW (f
);
11970 #endif /* not USE_X_TOOLKIT */
11972 /* Don't keep the highlight on an invisible frame. */
11973 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11974 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11976 #if 0/* This might add unreliability; I don't trust it -- rms. */
11977 if (! f
->async_visible
&& ! f
->async_iconified
)
11983 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11984 that the current position of the window is user-specified, rather than
11985 program-specified, so that when the window is mapped again, it will be
11986 placed at the same location, without forcing the user to position it
11987 by hand again (they have already done that once for this window.) */
11988 x_wm_set_size_hint (f
, (long) 0, 1);
11992 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11993 DefaultScreen (FRAME_X_DISPLAY (f
))))
11995 UNBLOCK_INPUT_RESIGNAL
;
11996 error ("Can't notify window manager of window withdrawal");
11998 #else /* ! defined (HAVE_X11R4) */
12000 /* Tell the window manager what we're going to do. */
12001 if (! EQ (Vx_no_window_manager
, Qt
))
12005 unmap
.xunmap
.type
= UnmapNotify
;
12006 unmap
.xunmap
.window
= window
;
12007 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12008 unmap
.xunmap
.from_configure
= False
;
12009 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12010 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12012 SubstructureRedirectMaskSubstructureNotifyMask
,
12015 UNBLOCK_INPUT_RESIGNAL
;
12016 error ("Can't notify window manager of withdrawal");
12020 /* Unmap the window ourselves. Cheeky! */
12021 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12022 #endif /* ! defined (HAVE_X11R4) */
12024 /* We can't distinguish this from iconification
12025 just by the event that we get from the server.
12026 So we can't win using the usual strategy of letting
12027 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12028 and synchronize with the server to make sure we agree. */
12030 FRAME_ICONIFIED_P (f
) = 0;
12031 f
->async_visible
= 0;
12032 f
->async_iconified
= 0;
12039 /* Change window state from mapped to iconified. */
12042 x_iconify_frame (f
)
12048 /* Don't keep the highlight on an invisible frame. */
12049 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12050 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12052 if (f
->async_iconified
)
12057 FRAME_SAMPLE_VISIBILITY (f
);
12059 type
= x_icon_type (f
);
12061 x_bitmap_icon (f
, type
);
12063 #ifdef USE_X_TOOLKIT
12065 if (! FRAME_VISIBLE_P (f
))
12067 if (! EQ (Vx_no_window_manager
, Qt
))
12068 x_wm_set_window_state (f
, IconicState
);
12069 /* This was XtPopup, but that did nothing for an iconified frame. */
12070 XtMapWidget (f
->output_data
.x
->widget
);
12071 /* The server won't give us any event to indicate
12072 that an invisible frame was changed to an icon,
12073 so we have to record it here. */
12076 f
->async_iconified
= 1;
12077 f
->async_visible
= 0;
12082 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12083 XtWindow (f
->output_data
.x
->widget
),
12084 DefaultScreen (FRAME_X_DISPLAY (f
)));
12088 error ("Can't notify window manager of iconification");
12090 f
->async_iconified
= 1;
12091 f
->async_visible
= 0;
12095 XFlush (FRAME_X_DISPLAY (f
));
12097 #else /* not USE_X_TOOLKIT */
12099 /* Make sure the X server knows where the window should be positioned,
12100 in case the user deiconifies with the window manager. */
12101 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12102 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12104 /* Since we don't know which revision of X we're running, we'll use both
12105 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12107 /* X11R4: send a ClientMessage to the window manager using the
12108 WM_CHANGE_STATE type. */
12112 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12113 message
.xclient
.type
= ClientMessage
;
12114 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12115 message
.xclient
.format
= 32;
12116 message
.xclient
.data
.l
[0] = IconicState
;
12118 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12119 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12121 SubstructureRedirectMask
| SubstructureNotifyMask
,
12124 UNBLOCK_INPUT_RESIGNAL
;
12125 error ("Can't notify window manager of iconification");
12129 /* X11R3: set the initial_state field of the window manager hints to
12131 x_wm_set_window_state (f
, IconicState
);
12133 if (!FRAME_VISIBLE_P (f
))
12135 /* If the frame was withdrawn, before, we must map it. */
12136 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12139 f
->async_iconified
= 1;
12140 f
->async_visible
= 0;
12142 XFlush (FRAME_X_DISPLAY (f
));
12144 #endif /* not USE_X_TOOLKIT */
12147 /* Destroy the X window of frame F. */
12150 x_destroy_window (f
)
12153 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12157 /* If a display connection is dead, don't try sending more
12158 commands to the X server. */
12159 if (dpyinfo
->display
!= 0)
12161 if (f
->output_data
.x
->icon_desc
!= 0)
12162 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12165 free_frame_xic (f
);
12167 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
12168 #ifdef USE_X_TOOLKIT
12169 if (f
->output_data
.x
->widget
)
12170 XtDestroyWidget (f
->output_data
.x
->widget
);
12171 free_frame_menubar (f
);
12172 #endif /* USE_X_TOOLKIT */
12174 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12175 unload_color (f
, f
->output_data
.x
->background_pixel
);
12176 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12177 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12178 unload_color (f
, f
->output_data
.x
->border_pixel
);
12179 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12180 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12181 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12182 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12183 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12184 if (f
->output_data
.x
->white_relief
.allocated_p
)
12185 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12186 if (f
->output_data
.x
->black_relief
.allocated_p
)
12187 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12189 free_frame_faces (f
);
12190 XFlush (FRAME_X_DISPLAY (f
));
12193 if (f
->output_data
.x
->saved_menu_event
)
12194 xfree (f
->output_data
.x
->saved_menu_event
);
12196 xfree (f
->output_data
.x
);
12197 f
->output_data
.x
= 0;
12198 if (f
== dpyinfo
->x_focus_frame
)
12199 dpyinfo
->x_focus_frame
= 0;
12200 if (f
== dpyinfo
->x_focus_event_frame
)
12201 dpyinfo
->x_focus_event_frame
= 0;
12202 if (f
== dpyinfo
->x_highlight_frame
)
12203 dpyinfo
->x_highlight_frame
= 0;
12205 dpyinfo
->reference_count
--;
12207 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12209 dpyinfo
->mouse_face_beg_row
12210 = dpyinfo
->mouse_face_beg_col
= -1;
12211 dpyinfo
->mouse_face_end_row
12212 = dpyinfo
->mouse_face_end_col
= -1;
12213 dpyinfo
->mouse_face_window
= Qnil
;
12214 dpyinfo
->mouse_face_deferred_gc
= 0;
12215 dpyinfo
->mouse_face_mouse_frame
= 0;
12221 /* Setting window manager hints. */
12223 /* Set the normal size hints for the window manager, for frame F.
12224 FLAGS is the flags word to use--or 0 meaning preserve the flags
12225 that the window now has.
12226 If USER_POSITION is nonzero, we set the USPosition
12227 flag (this is useful when FLAGS is 0). */
12230 x_wm_set_size_hint (f
, flags
, user_position
)
12235 XSizeHints size_hints
;
12237 #ifdef USE_X_TOOLKIT
12240 Dimension widget_width
, widget_height
;
12241 Window window
= XtWindow (f
->output_data
.x
->widget
);
12242 #else /* not USE_X_TOOLKIT */
12243 Window window
= FRAME_X_WINDOW (f
);
12244 #endif /* not USE_X_TOOLKIT */
12246 /* Setting PMaxSize caused various problems. */
12247 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12249 size_hints
.x
= f
->output_data
.x
->left_pos
;
12250 size_hints
.y
= f
->output_data
.x
->top_pos
;
12252 #ifdef USE_X_TOOLKIT
12253 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12254 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12255 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12256 size_hints
.height
= widget_height
;
12257 size_hints
.width
= widget_width
;
12258 #else /* not USE_X_TOOLKIT */
12259 size_hints
.height
= PIXEL_HEIGHT (f
);
12260 size_hints
.width
= PIXEL_WIDTH (f
);
12261 #endif /* not USE_X_TOOLKIT */
12263 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12264 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12265 size_hints
.max_width
12266 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12267 size_hints
.max_height
12268 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12270 /* Calculate the base and minimum sizes.
12272 (When we use the X toolkit, we don't do it here.
12273 Instead we copy the values that the widgets are using, below.) */
12274 #ifndef USE_X_TOOLKIT
12276 int base_width
, base_height
;
12277 int min_rows
= 0, min_cols
= 0;
12279 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12280 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12282 check_frame_size (f
, &min_rows
, &min_cols
);
12284 /* The window manager uses the base width hints to calculate the
12285 current number of rows and columns in the frame while
12286 resizing; min_width and min_height aren't useful for this
12287 purpose, since they might not give the dimensions for a
12288 zero-row, zero-column frame.
12290 We use the base_width and base_height members if we have
12291 them; otherwise, we set the min_width and min_height members
12292 to the size for a zero x zero frame. */
12295 size_hints
.flags
|= PBaseSize
;
12296 size_hints
.base_width
= base_width
;
12297 size_hints
.base_height
= base_height
;
12298 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12299 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12301 size_hints
.min_width
= base_width
;
12302 size_hints
.min_height
= base_height
;
12306 /* If we don't need the old flags, we don't need the old hint at all. */
12309 size_hints
.flags
|= flags
;
12312 #endif /* not USE_X_TOOLKIT */
12315 XSizeHints hints
; /* Sometimes I hate X Windows... */
12316 long supplied_return
;
12320 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12323 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12326 #ifdef USE_X_TOOLKIT
12327 size_hints
.base_height
= hints
.base_height
;
12328 size_hints
.base_width
= hints
.base_width
;
12329 size_hints
.min_height
= hints
.min_height
;
12330 size_hints
.min_width
= hints
.min_width
;
12334 size_hints
.flags
|= flags
;
12339 if (hints
.flags
& PSize
)
12340 size_hints
.flags
|= PSize
;
12341 if (hints
.flags
& PPosition
)
12342 size_hints
.flags
|= PPosition
;
12343 if (hints
.flags
& USPosition
)
12344 size_hints
.flags
|= USPosition
;
12345 if (hints
.flags
& USSize
)
12346 size_hints
.flags
|= USSize
;
12350 #ifndef USE_X_TOOLKIT
12355 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12356 size_hints
.flags
|= PWinGravity
;
12360 size_hints
.flags
&= ~ PPosition
;
12361 size_hints
.flags
|= USPosition
;
12363 #endif /* PWinGravity */
12366 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12368 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12372 /* Used for IconicState or NormalState */
12375 x_wm_set_window_state (f
, state
)
12379 #ifdef USE_X_TOOLKIT
12382 XtSetArg (al
[0], XtNinitialState
, state
);
12383 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12384 #else /* not USE_X_TOOLKIT */
12385 Window window
= FRAME_X_WINDOW (f
);
12387 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12388 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12390 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12391 #endif /* not USE_X_TOOLKIT */
12395 x_wm_set_icon_pixmap (f
, pixmap_id
)
12399 Pixmap icon_pixmap
;
12401 #ifndef USE_X_TOOLKIT
12402 Window window
= FRAME_X_WINDOW (f
);
12407 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12408 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12412 /* It seems there is no way to turn off use of an icon pixmap.
12413 The following line does it, only if no icon has yet been created,
12414 for some window managers. But with mwm it crashes.
12415 Some people say it should clear the IconPixmapHint bit in this case,
12416 but that doesn't work, and the X consortium said it isn't the
12417 right thing at all. Since there is no way to win,
12418 best to explicitly give up. */
12420 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12426 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12430 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12431 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12434 #else /* not USE_X_TOOLKIT */
12436 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12437 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12439 #endif /* not USE_X_TOOLKIT */
12443 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12445 int icon_x
, icon_y
;
12447 #ifdef USE_X_TOOLKIT
12448 Window window
= XtWindow (f
->output_data
.x
->widget
);
12450 Window window
= FRAME_X_WINDOW (f
);
12453 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12454 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12455 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12457 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12461 /***********************************************************************
12463 ***********************************************************************/
12465 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12468 x_get_font_info (f
, font_idx
)
12472 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12476 /* Return a list of names of available fonts matching PATTERN on frame
12477 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
12478 to be listed. Frame F NULL means we have not yet created any
12479 frame on X, and consult the first display in x_display_list.
12480 MAXNAMES sets a limit on how many fonts to match. */
12483 x_list_fonts (f
, pattern
, size
, maxnames
)
12485 Lisp_Object pattern
;
12489 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12490 Lisp_Object tem
, second_best
;
12491 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
12492 int try_XLoadQueryFont
= 0;
12495 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12496 if (NILP (patterns
))
12497 patterns
= Fcons (pattern
, Qnil
);
12499 if (maxnames
== 1 && !size
)
12500 /* We can return any single font matching PATTERN. */
12501 try_XLoadQueryFont
= 1;
12503 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12506 char **names
= NULL
;
12508 pattern
= XCAR (patterns
);
12509 /* See if we cached the result for this particular query.
12510 The cache is an alist of the form:
12511 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
12513 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
12514 key
= Fcons (pattern
, make_number (maxnames
)),
12515 !NILP (list
= Fassoc (key
, tem
))))
12517 list
= Fcdr_safe (list
);
12518 /* We have a cashed list. Don't have to get the list again. */
12522 /* At first, put PATTERN in the cache. */
12525 count
= x_catch_errors (dpy
);
12527 if (try_XLoadQueryFont
)
12530 unsigned long value
;
12532 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12533 if (x_had_errors_p (dpy
))
12535 /* This error is perhaps due to insufficient memory on X
12536 server. Let's just ignore it. */
12538 x_clear_errors (dpy
);
12542 && XGetFontProperty (font
, XA_FONT
, &value
))
12544 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12545 int len
= strlen (name
);
12548 /* If DXPC (a Differential X Protocol Compressor)
12549 Ver.3.7 is running, XGetAtomName will return null
12550 string. We must avoid such a name. */
12552 try_XLoadQueryFont
= 0;
12556 names
= (char **) alloca (sizeof (char *));
12557 /* Some systems only allow alloca assigned to a
12559 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12560 bcopy (name
, names
[0], len
+ 1);
12565 try_XLoadQueryFont
= 0;
12568 XFreeFont (dpy
, font
);
12571 if (!try_XLoadQueryFont
)
12573 /* We try at least 10 fonts because XListFonts will return
12574 auto-scaled fonts at the head. */
12575 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12577 if (x_had_errors_p (dpy
))
12579 /* This error is perhaps due to insufficient memory on X
12580 server. Let's just ignore it. */
12582 x_clear_errors (dpy
);
12586 x_uncatch_errors (dpy
, count
);
12593 /* Make a list of all the fonts we got back.
12594 Store that in the font cache for the display. */
12595 for (i
= 0; i
< num_fonts
; i
++)
12598 char *p
= names
[i
];
12599 int average_width
= -1, dashes
= 0;
12601 /* Count the number of dashes in NAMES[I]. If there are
12602 14 dashes, and the field value following 12th dash
12603 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12604 is usually too ugly to be used for editing. Let's
12610 if (dashes
== 7) /* PIXEL_SIZE field */
12612 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12613 average_width
= atoi (p
);
12615 if (dashes
< 14 || average_width
!= 0)
12617 tem
= build_string (names
[i
]);
12618 if (NILP (Fassoc (tem
, list
)))
12620 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12621 && ((fast_c_string_match_ignore_case
12622 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12624 /* We can set the value of PIXEL_SIZE to the
12625 width of this font. */
12626 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12628 /* For the moment, width is not known. */
12629 list
= Fcons (Fcons (tem
, Qnil
), list
);
12633 if (!try_XLoadQueryFont
)
12634 XFreeFontNames (names
);
12637 /* Now store the result in the cache. */
12639 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
12640 = Fcons (Fcons (key
, list
),
12641 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
12644 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12646 newlist
= second_best
= Qnil
;
12647 /* Make a list of the fonts that have the right width. */
12648 for (; CONSP (list
); list
= XCDR (list
))
12654 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12658 newlist
= Fcons (XCAR (tem
), newlist
);
12662 if (!INTEGERP (XCDR (tem
)))
12664 /* Since we have not yet known the size of this font, we
12665 must try slow function call XLoadQueryFont. */
12666 XFontStruct
*thisinfo
;
12669 count
= x_catch_errors (dpy
);
12670 thisinfo
= XLoadQueryFont (dpy
,
12671 XSTRING (XCAR (tem
))->data
);
12672 if (x_had_errors_p (dpy
))
12674 /* This error is perhaps due to insufficient memory on X
12675 server. Let's just ignore it. */
12677 x_clear_errors (dpy
);
12679 x_uncatch_errors (dpy
, count
);
12685 = (thisinfo
->min_bounds
.width
== 0
12687 : make_number (thisinfo
->max_bounds
.width
));
12688 XFreeFont (dpy
, thisinfo
);
12691 /* For unknown reason, the previous call of XListFont had
12692 returned a font which can't be opened. Record the size
12693 as 0 not to try to open it again. */
12694 XCDR (tem
) = make_number (0);
12697 found_size
= XINT (XCDR (tem
));
12698 if (found_size
== size
)
12699 newlist
= Fcons (XCAR (tem
), newlist
);
12700 else if (found_size
> 0)
12702 if (NILP (second_best
))
12704 else if (found_size
< size
)
12706 if (XINT (XCDR (second_best
)) > size
12707 || XINT (XCDR (second_best
)) < found_size
)
12712 if (XINT (XCDR (second_best
)) > size
12713 && XINT (XCDR (second_best
)) > found_size
)
12718 if (!NILP (newlist
))
12720 else if (!NILP (second_best
))
12722 newlist
= Fcons (XCAR (second_best
), Qnil
);
12733 /* Check that FONT is valid on frame F. It is if it can be found in F's
12737 x_check_font (f
, font
)
12742 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12744 xassert (font
!= NULL
);
12746 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12747 if (dpyinfo
->font_table
[i
].name
12748 && font
== dpyinfo
->font_table
[i
].font
)
12751 xassert (i
< dpyinfo
->n_fonts
);
12754 #endif /* GLYPH_DEBUG != 0 */
12756 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12757 Note: There are (broken) X fonts out there with invalid XFontStruct
12758 min_bounds contents. For example, handa@etl.go.jp reports that
12759 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
12760 have font->min_bounds.width == 0. */
12763 x_font_min_bounds (font
, w
, h
)
12767 *h
= FONT_HEIGHT (font
);
12768 *w
= font
->min_bounds
.width
;
12770 /* Try to handle the case where FONT->min_bounds has invalid
12771 contents. Since the only font known to have invalid min_bounds
12772 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12774 *w
= font
->max_bounds
.width
;
12778 /* Compute the smallest character width and smallest font height over
12779 all fonts available on frame F. Set the members smallest_char_width
12780 and smallest_font_height in F's x_display_info structure to
12781 the values computed. Value is non-zero if smallest_font_height or
12782 smallest_char_width become smaller than they were before. */
12785 x_compute_min_glyph_bounds (f
)
12789 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12791 int old_width
= dpyinfo
->smallest_char_width
;
12792 int old_height
= dpyinfo
->smallest_font_height
;
12794 dpyinfo
->smallest_font_height
= 100000;
12795 dpyinfo
->smallest_char_width
= 100000;
12797 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12798 if (dpyinfo
->font_table
[i
].name
)
12800 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12803 font
= (XFontStruct
*) fontp
->font
;
12804 xassert (font
!= (XFontStruct
*) ~0);
12805 x_font_min_bounds (font
, &w
, &h
);
12807 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12808 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12811 xassert (dpyinfo
->smallest_char_width
> 0
12812 && dpyinfo
->smallest_font_height
> 0);
12814 return (dpyinfo
->n_fonts
== 1
12815 || dpyinfo
->smallest_char_width
< old_width
12816 || dpyinfo
->smallest_font_height
< old_height
);
12820 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12821 pointer to the structure font_info while allocating it dynamically.
12822 If SIZE is 0, load any size of font.
12823 If loading is failed, return NULL. */
12826 x_load_font (f
, fontname
, size
)
12828 register char *fontname
;
12831 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12832 Lisp_Object font_names
;
12835 /* Get a list of all the fonts that match this name. Once we
12836 have a list of matching fonts, we compare them against the fonts
12837 we already have by comparing names. */
12838 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12840 if (!NILP (font_names
))
12845 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12846 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12847 if (dpyinfo
->font_table
[i
].name
12848 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12849 XSTRING (XCAR (tail
))->data
)
12850 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12851 XSTRING (XCAR (tail
))->data
)))
12852 return (dpyinfo
->font_table
+ i
);
12855 /* Load the font and add it to the table. */
12859 struct font_info
*fontp
;
12860 unsigned long value
;
12863 /* If we have found fonts by x_list_font, load one of them. If
12864 not, we still try to load a font by the name given as FONTNAME
12865 because XListFonts (called in x_list_font) of some X server has
12866 a bug of not finding a font even if the font surely exists and
12867 is loadable by XLoadQueryFont. */
12868 if (size
> 0 && !NILP (font_names
))
12869 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12872 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12873 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12874 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12876 /* This error is perhaps due to insufficient memory on X
12877 server. Let's just ignore it. */
12879 x_clear_errors (FRAME_X_DISPLAY (f
));
12881 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12886 /* Find a free slot in the font table. */
12887 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12888 if (dpyinfo
->font_table
[i
].name
== NULL
)
12891 /* If no free slot found, maybe enlarge the font table. */
12892 if (i
== dpyinfo
->n_fonts
12893 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12896 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12897 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12898 dpyinfo
->font_table
12899 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12902 fontp
= dpyinfo
->font_table
+ i
;
12903 if (i
== dpyinfo
->n_fonts
)
12904 ++dpyinfo
->n_fonts
;
12906 /* Now fill in the slots of *FONTP. */
12908 fontp
->font
= font
;
12909 fontp
->font_idx
= i
;
12910 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12911 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12913 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12915 if (XGetFontProperty (font
, XA_FONT
, &value
))
12917 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12921 /* Count the number of dashes in the "full name".
12922 If it is too few, this isn't really the font's full name,
12924 In X11R4, the fonts did not come with their canonical names
12935 full_name
= (char *) xmalloc (p
- name
+ 1);
12936 bcopy (name
, full_name
, p
- name
+ 1);
12942 if (full_name
!= 0)
12943 fontp
->full_name
= full_name
;
12945 fontp
->full_name
= fontp
->name
;
12947 fontp
->size
= font
->max_bounds
.width
;
12948 fontp
->height
= FONT_HEIGHT (font
);
12950 /* For some font, ascent and descent in max_bounds field is
12951 larger than the above value. */
12952 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12953 if (max_height
> fontp
->height
)
12954 fontp
->height
= max_height
;
12957 if (NILP (font_names
))
12959 /* We come here because of a bug of XListFonts mentioned at
12960 the head of this block. Let's store this information in
12961 the cache for x_list_fonts. */
12962 Lisp_Object lispy_name
= build_string (fontname
);
12963 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12965 XCDR (dpyinfo
->name_list_element
)
12966 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
12967 Fcons (Fcons (lispy_full_name
,
12968 make_number (fontp
->size
)),
12970 XCDR (dpyinfo
->name_list_element
));
12972 XCDR (dpyinfo
->name_list_element
)
12973 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
12974 Fcons (Fcons (lispy_full_name
,
12975 make_number (fontp
->size
)),
12977 XCDR (dpyinfo
->name_list_element
));
12980 /* The slot `encoding' specifies how to map a character
12981 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
12982 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
12983 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
12984 2:0xA020..0xFF7F). For the moment, we don't know which charset
12985 uses this font. So, we set information in fontp->encoding[1]
12986 which is never used by any charset. If mapping can't be
12987 decided, set FONT_ENCODING_NOT_DECIDED. */
12989 = (font
->max_byte1
== 0
12991 ? (font
->min_char_or_byte2
< 0x80
12992 ? (font
->max_char_or_byte2
< 0x80
12993 ? 0 /* 0x20..0x7F */
12994 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
12995 : 1) /* 0xA0..0xFF */
12997 : (font
->min_byte1
< 0x80
12998 ? (font
->max_byte1
< 0x80
12999 ? (font
->min_char_or_byte2
< 0x80
13000 ? (font
->max_char_or_byte2
< 0x80
13001 ? 0 /* 0x2020..0x7F7F */
13002 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13003 : 3) /* 0x20A0..0x7FFF */
13004 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13005 : (font
->min_char_or_byte2
< 0x80
13006 ? (font
->max_char_or_byte2
< 0x80
13007 ? 2 /* 0xA020..0xFF7F */
13008 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13009 : 1))); /* 0xA0A0..0xFFFF */
13011 fontp
->baseline_offset
13012 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13013 ? (long) value
: 0);
13014 fontp
->relative_compose
13015 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13016 ? (long) value
: 0);
13017 fontp
->default_ascent
13018 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13019 ? (long) value
: 0);
13021 /* Set global flag fonts_changed_p to non-zero if the font loaded
13022 has a character with a smaller width than any other character
13023 before, or if the font loaded has a smalle>r height than any
13024 other font loaded before. If this happens, it will make a
13025 glyph matrix reallocation necessary. */
13026 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13033 /* Return a pointer to struct font_info of a font named FONTNAME for
13034 frame F. If no such font is loaded, return NULL. */
13037 x_query_font (f
, fontname
)
13039 register char *fontname
;
13041 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13044 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13045 if (dpyinfo
->font_table
[i
].name
13046 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13047 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13048 return (dpyinfo
->font_table
+ i
);
13053 /* Find a CCL program for a font specified by FONTP, and set the member
13054 `encoder' of the structure. */
13057 x_find_ccl_program (fontp
)
13058 struct font_info
*fontp
;
13060 Lisp_Object list
, elt
;
13062 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13066 && STRINGP (XCAR (elt
))
13067 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13073 struct ccl_program
*ccl
13074 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13076 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13079 fontp
->font_encoder
= ccl
;
13085 /***********************************************************************
13087 ***********************************************************************/
13089 #ifdef USE_X_TOOLKIT
13090 static XrmOptionDescRec emacs_options
[] = {
13091 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13092 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13094 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13095 XrmoptionSepArg
, NULL
},
13096 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13098 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13099 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13100 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13101 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13102 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13103 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13104 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13106 #endif /* USE_X_TOOLKIT */
13108 static int x_initialized
;
13110 #ifdef MULTI_KBOARD
13111 /* Test whether two display-name strings agree up to the dot that separates
13112 the screen number from the server number. */
13114 same_x_server (name1
, name2
)
13115 char *name1
, *name2
;
13117 int seen_colon
= 0;
13118 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13119 int system_name_length
= strlen (system_name
);
13120 int length_until_period
= 0;
13122 while (system_name
[length_until_period
] != 0
13123 && system_name
[length_until_period
] != '.')
13124 length_until_period
++;
13126 /* Treat `unix' like an empty host name. */
13127 if (! strncmp (name1
, "unix:", 5))
13129 if (! strncmp (name2
, "unix:", 5))
13131 /* Treat this host's name like an empty host name. */
13132 if (! strncmp (name1
, system_name
, system_name_length
)
13133 && name1
[system_name_length
] == ':')
13134 name1
+= system_name_length
;
13135 if (! strncmp (name2
, system_name
, system_name_length
)
13136 && name2
[system_name_length
] == ':')
13137 name2
+= system_name_length
;
13138 /* Treat this host's domainless name like an empty host name. */
13139 if (! strncmp (name1
, system_name
, length_until_period
)
13140 && name1
[length_until_period
] == ':')
13141 name1
+= length_until_period
;
13142 if (! strncmp (name2
, system_name
, length_until_period
)
13143 && name2
[length_until_period
] == ':')
13144 name2
+= length_until_period
;
13146 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13150 if (seen_colon
&& *name1
== '.')
13154 && (*name1
== '.' || *name1
== '\0')
13155 && (*name2
== '.' || *name2
== '\0'));
13159 struct x_display_info
*
13160 x_term_init (display_name
, xrm_option
, resource_name
)
13161 Lisp_Object display_name
;
13163 char *resource_name
;
13167 struct x_display_info
*dpyinfo
;
13172 if (!x_initialized
)
13178 #ifdef USE_X_TOOLKIT
13179 /* weiner@footloose.sps.mot.com reports that this causes
13181 X protocol error: BadAtom (invalid Atom parameter)
13182 on protocol request 18skiloaf.
13183 So let's not use it until R6. */
13184 #ifdef HAVE_X11XTR6
13185 XtSetLanguageProc (NULL
, NULL
, NULL
);
13196 argv
[argc
++] = "-xrm";
13197 argv
[argc
++] = xrm_option
;
13199 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13200 resource_name
, EMACS_CLASS
,
13201 emacs_options
, XtNumber (emacs_options
),
13204 #ifdef HAVE_X11XTR6
13205 /* I think this is to compensate for XtSetLanguageProc. */
13210 #else /* not USE_X_TOOLKIT */
13212 XSetLocaleModifiers ("");
13214 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13215 #endif /* not USE_X_TOOLKIT */
13217 /* Detect failure. */
13224 /* We have definitely succeeded. Record the new connection. */
13226 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13228 #ifdef MULTI_KBOARD
13230 struct x_display_info
*share
;
13233 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13234 share
= share
->next
, tail
= XCDR (tail
))
13235 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13236 XSTRING (display_name
)->data
))
13239 dpyinfo
->kboard
= share
->kboard
;
13242 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13243 init_kboard (dpyinfo
->kboard
);
13244 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13246 char *vendor
= ServerVendor (dpy
);
13248 dpyinfo
->kboard
->Vsystem_key_alist
13249 = call1 (Qvendor_specific_keysyms
,
13250 build_string (vendor
? vendor
: ""));
13254 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13255 all_kboards
= dpyinfo
->kboard
;
13256 /* Don't let the initial kboard remain current longer than necessary.
13257 That would cause problems if a file loaded on startup tries to
13258 prompt in the mini-buffer. */
13259 if (current_kboard
== initial_kboard
)
13260 current_kboard
= dpyinfo
->kboard
;
13262 dpyinfo
->kboard
->reference_count
++;
13266 /* Put this display on the chain. */
13267 dpyinfo
->next
= x_display_list
;
13268 x_display_list
= dpyinfo
;
13270 /* Put it on x_display_name_list as well, to keep them parallel. */
13271 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13272 x_display_name_list
);
13273 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13275 dpyinfo
->display
= dpy
;
13278 XSetAfterFunction (x_current_display
, x_trace_wire
);
13282 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13283 + STRING_BYTES (XSTRING (Vsystem_name
))
13285 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13286 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13288 /* Figure out which modifier bits mean what. */
13289 x_find_modifier_meanings (dpyinfo
);
13291 /* Get the scroll bar cursor. */
13292 dpyinfo
->vertical_scroll_bar_cursor
13293 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13295 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13296 resource_name
, EMACS_CLASS
);
13297 #ifdef HAVE_XRMSETDATABASE
13298 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13300 dpyinfo
->display
->db
= xrdb
;
13302 /* Put the rdb where we can find it in a way that works on
13304 dpyinfo
->xrdb
= xrdb
;
13306 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13307 DefaultScreen (dpyinfo
->display
));
13308 select_visual (dpyinfo
);
13309 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13310 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13311 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13312 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13313 dpyinfo
->grabbed
= 0;
13314 dpyinfo
->reference_count
= 0;
13315 dpyinfo
->icon_bitmap_id
= -1;
13316 dpyinfo
->font_table
= NULL
;
13317 dpyinfo
->n_fonts
= 0;
13318 dpyinfo
->font_table_size
= 0;
13319 dpyinfo
->bitmaps
= 0;
13320 dpyinfo
->bitmaps_size
= 0;
13321 dpyinfo
->bitmaps_last
= 0;
13322 dpyinfo
->scratch_cursor_gc
= 0;
13323 dpyinfo
->mouse_face_mouse_frame
= 0;
13324 dpyinfo
->mouse_face_deferred_gc
= 0;
13325 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13326 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13327 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13328 dpyinfo
->mouse_face_window
= Qnil
;
13329 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13330 dpyinfo
->mouse_face_defer
= 0;
13331 dpyinfo
->x_focus_frame
= 0;
13332 dpyinfo
->x_focus_event_frame
= 0;
13333 dpyinfo
->x_highlight_frame
= 0;
13334 dpyinfo
->image_cache
= make_image_cache ();
13336 /* See if a private colormap is requested. */
13337 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13339 if (dpyinfo
->visual
->class == PseudoColor
)
13342 value
= display_x_get_resource (dpyinfo
,
13343 build_string ("privateColormap"),
13344 build_string ("PrivateColormap"),
13346 if (STRINGP (value
)
13347 && (!strcmp (XSTRING (value
)->data
, "true")
13348 || !strcmp (XSTRING (value
)->data
, "on")))
13349 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13353 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13354 dpyinfo
->visual
, AllocNone
);
13357 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13358 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13359 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13360 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13361 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13362 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13363 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13366 dpyinfo
->Xatom_wm_protocols
13367 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13368 dpyinfo
->Xatom_wm_take_focus
13369 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13370 dpyinfo
->Xatom_wm_save_yourself
13371 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13372 dpyinfo
->Xatom_wm_delete_window
13373 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13374 dpyinfo
->Xatom_wm_change_state
13375 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13376 dpyinfo
->Xatom_wm_configure_denied
13377 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13378 dpyinfo
->Xatom_wm_window_moved
13379 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13380 dpyinfo
->Xatom_editres
13381 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13382 dpyinfo
->Xatom_CLIPBOARD
13383 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13384 dpyinfo
->Xatom_TIMESTAMP
13385 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13386 dpyinfo
->Xatom_TEXT
13387 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13388 dpyinfo
->Xatom_COMPOUND_TEXT
13389 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13390 dpyinfo
->Xatom_DELETE
13391 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13392 dpyinfo
->Xatom_MULTIPLE
13393 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13394 dpyinfo
->Xatom_INCR
13395 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13396 dpyinfo
->Xatom_EMACS_TMP
13397 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13398 dpyinfo
->Xatom_TARGETS
13399 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13400 dpyinfo
->Xatom_NULL
13401 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13402 dpyinfo
->Xatom_ATOM_PAIR
13403 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13404 /* For properties of font. */
13405 dpyinfo
->Xatom_PIXEL_SIZE
13406 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13407 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13408 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13409 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13410 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13411 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13412 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13414 /* Ghostscript support. */
13415 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13416 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13418 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13421 dpyinfo
->cut_buffers_initialized
= 0;
13423 connection
= ConnectionNumber (dpyinfo
->display
);
13424 dpyinfo
->connection
= connection
;
13429 null_bits
[0] = 0x00;
13431 dpyinfo
->null_pixel
13432 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13433 null_bits
, 1, 1, (long) 0, (long) 0,
13438 extern int gray_bitmap_width
, gray_bitmap_height
;
13439 extern unsigned char *gray_bitmap_bits
;
13441 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13443 gray_bitmap_width
, gray_bitmap_height
,
13444 (unsigned long) 1, (unsigned long) 0, 1);
13448 xim_initialize (dpyinfo
, resource_name
);
13451 #ifdef subprocesses
13452 /* This is only needed for distinguishing keyboard and process input. */
13453 if (connection
!= 0)
13454 add_keyboard_wait_descriptor (connection
);
13457 #ifndef F_SETOWN_BUG
13459 #ifdef F_SETOWN_SOCK_NEG
13460 /* stdin is a socket here */
13461 fcntl (connection
, F_SETOWN
, -getpid ());
13462 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13463 fcntl (connection
, F_SETOWN
, getpid ());
13464 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13465 #endif /* ! defined (F_SETOWN) */
13466 #endif /* F_SETOWN_BUG */
13469 if (interrupt_input
)
13470 init_sigio (connection
);
13471 #endif /* ! defined (SIGIO) */
13474 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13475 /* Make sure that we have a valid font for dialog boxes
13476 so that Xt does not crash. */
13478 Display
*dpy
= dpyinfo
->display
;
13479 XrmValue d
, fr
, to
;
13483 d
.addr
= (XPointer
)&dpy
;
13484 d
.size
= sizeof (Display
*);
13485 fr
.addr
= XtDefaultFont
;
13486 fr
.size
= sizeof (XtDefaultFont
);
13487 to
.size
= sizeof (Font
*);
13488 to
.addr
= (XPointer
)&font
;
13489 count
= x_catch_errors (dpy
);
13490 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13492 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13493 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13494 x_uncatch_errors (dpy
, count
);
13499 /* See if we should run in synchronous mode. This is useful
13500 for debugging X code. */
13503 value
= display_x_get_resource (dpyinfo
,
13504 build_string ("synchronous"),
13505 build_string ("Synchronous"),
13507 if (STRINGP (value
)
13508 && (!strcmp (XSTRING (value
)->data
, "true")
13509 || !strcmp (XSTRING (value
)->data
, "on")))
13510 XSynchronize (dpyinfo
->display
, True
);
13518 /* Get rid of display DPYINFO, assuming all frames are already gone,
13519 and without sending any more commands to the X server. */
13522 x_delete_display (dpyinfo
)
13523 struct x_display_info
*dpyinfo
;
13525 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13527 /* Discard this display from x_display_name_list and x_display_list.
13528 We can't use Fdelq because that can quit. */
13529 if (! NILP (x_display_name_list
)
13530 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13531 x_display_name_list
= XCDR (x_display_name_list
);
13536 tail
= x_display_name_list
;
13537 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13539 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13541 XCDR (tail
) = XCDR (XCDR (tail
));
13544 tail
= XCDR (tail
);
13548 if (next_noop_dpyinfo
== dpyinfo
)
13549 next_noop_dpyinfo
= dpyinfo
->next
;
13551 if (x_display_list
== dpyinfo
)
13552 x_display_list
= dpyinfo
->next
;
13555 struct x_display_info
*tail
;
13557 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13558 if (tail
->next
== dpyinfo
)
13559 tail
->next
= tail
->next
->next
;
13562 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13563 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13564 XrmDestroyDatabase (dpyinfo
->xrdb
);
13567 #ifdef MULTI_KBOARD
13568 if (--dpyinfo
->kboard
->reference_count
== 0)
13569 delete_kboard (dpyinfo
->kboard
);
13573 xim_close_dpy (dpyinfo
);
13576 xfree (dpyinfo
->font_table
);
13577 xfree (dpyinfo
->x_id_name
);
13581 /* Set up use of X before we make the first connection. */
13583 static struct redisplay_interface x_redisplay_interface
=
13588 x_clear_end_of_line
,
13590 x_after_update_window_line
,
13591 x_update_window_begin
,
13592 x_update_window_end
,
13595 x_clear_mouse_face
,
13596 x_get_glyph_overhangs
,
13597 x_fix_overlapping_area
13603 rif
= &x_redisplay_interface
;
13605 clear_frame_hook
= x_clear_frame
;
13606 ins_del_lines_hook
= x_ins_del_lines
;
13607 change_line_highlight_hook
= x_change_line_highlight
;
13608 delete_glyphs_hook
= x_delete_glyphs
;
13609 ring_bell_hook
= XTring_bell
;
13610 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13611 set_terminal_modes_hook
= XTset_terminal_modes
;
13612 update_begin_hook
= x_update_begin
;
13613 update_end_hook
= x_update_end
;
13614 set_terminal_window_hook
= XTset_terminal_window
;
13615 read_socket_hook
= XTread_socket
;
13616 frame_up_to_date_hook
= XTframe_up_to_date
;
13617 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13618 mouse_position_hook
= XTmouse_position
;
13619 frame_rehighlight_hook
= XTframe_rehighlight
;
13620 frame_raise_lower_hook
= XTframe_raise_lower
;
13621 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13622 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13623 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13624 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13625 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13627 scroll_region_ok
= 1; /* we'll scroll partial frames */
13628 char_ins_del_ok
= 0; /* just as fast to write the line */
13629 line_ins_del_ok
= 1; /* we'll just blt 'em */
13630 fast_clear_end_of_line
= 1; /* X does this well */
13631 memory_below_frame
= 0; /* we don't remember what scrolls
13636 last_tool_bar_item
= -1;
13637 any_help_event_p
= 0;
13639 /* Try to use interrupt input; if we can't, then start polling. */
13640 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13642 #ifdef USE_X_TOOLKIT
13643 XtToolkitInitialize ();
13644 Xt_app_con
= XtCreateApplicationContext ();
13645 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13647 /* Install an asynchronous timer that processes Xt timeout events
13648 every 0.1s. This is necessary because some widget sets use
13649 timeouts internally, for example the LessTif menu bar, or the
13650 Xaw3d scroll bar. When Xt timouts aren't processed, these
13651 widgets don't behave normally. */
13653 EMACS_TIME interval
;
13654 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13655 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13659 #if USE_TOOLKIT_SCROLL_BARS
13660 xaw3d_arrow_scroll
= False
;
13661 xaw3d_pick_top
= True
;
13664 /* Note that there is no real way portable across R3/R4 to get the
13665 original error handler. */
13666 XSetErrorHandler (x_error_handler
);
13667 XSetIOErrorHandler (x_io_error_quitter
);
13669 /* Disable Window Change signals; they are handled by X events. */
13671 signal (SIGWINCH
, SIG_DFL
);
13672 #endif /* ! defined (SIGWINCH) */
13674 signal (SIGPIPE
, x_connection_signal
);
13681 staticpro (&x_error_message_string
);
13682 x_error_message_string
= Qnil
;
13684 staticpro (&x_display_name_list
);
13685 x_display_name_list
= Qnil
;
13687 staticpro (&last_mouse_scroll_bar
);
13688 last_mouse_scroll_bar
= Qnil
;
13690 staticpro (&Qvendor_specific_keysyms
);
13691 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13693 staticpro (&last_mouse_press_frame
);
13694 last_mouse_press_frame
= Qnil
;
13697 staticpro (&help_echo
);
13698 help_echo_object
= Qnil
;
13699 staticpro (&help_echo_object
);
13700 help_echo_window
= Qnil
;
13701 staticpro (&help_echo_window
);
13702 previous_help_echo
= Qnil
;
13703 staticpro (&previous_help_echo
);
13704 help_echo_pos
= -1;
13706 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13707 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
13708 For example, if a block cursor is over a tab, it will be drawn as\n\
13709 wide as that tab on the display.");
13710 x_stretch_cursor_p
= 0;
13712 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
13713 "If not nil, Emacs uses toolkit scroll bars.");
13714 #if USE_TOOLKIT_SCROLL_BARS
13715 x_toolkit_scroll_bars_p
= 1;
13717 x_toolkit_scroll_bars_p
= 0;
13720 staticpro (&last_mouse_motion_frame
);
13721 last_mouse_motion_frame
= Qnil
;
13724 #endif /* not HAVE_X_WINDOWS */