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>
48 /* Load sys/types.h if not already loaded.
49 In some systems loading it twice is suicidal. */
51 #include <sys/types.h>
56 #include <sys/ioctl.h>
57 #endif /* ! defined (BSD_SYSTEM) */
62 #ifndef INCLUDED_FCNTL
69 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
70 /* #include <sys/param.h> */
75 #include "dispextern.h"
77 #include "termhooks.h"
89 #include "intervals.h"
94 #include <X11/Shell.h>
97 #include <sys/types.h>
98 #ifdef HAVE_SYS_TIME_H
107 extern void free_frame_menubar ();
108 extern FRAME_PTR
x_menubar_window_to_frame ();
110 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
112 extern void _XEditResCheckMessages ();
113 #endif /* not NO_EDITRES */
115 /* Include toolkit specific headers for the scroll bar widget. */
117 #ifdef USE_TOOLKIT_SCROLL_BARS
118 #if defined USE_MOTIF
119 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
120 #include <Xm/ScrollBar.h>
121 #include <Xm/ScrollBarP.h>
122 #else /* !USE_MOTIF i.e. use Xaw */
125 #include <X11/Xaw3d/Simple.h>
126 #include <X11/Xaw3d/Scrollbar.h>
127 #define ARROW_SCROLLBAR
128 #include <X11/Xaw3d/ScrollbarP.h>
129 #else /* !HAVE_XAW3D */
130 #include <X11/Xaw/Simple.h>
131 #include <X11/Xaw/Scrollbar.h>
132 #endif /* !HAVE_XAW3D */
134 #define XtNpickTop "pickTop"
135 #endif /* !XtNpickTop */
136 #endif /* !USE_MOTIF */
137 #endif /* USE_TOOLKIT_SCROLL_BARS */
139 #endif /* USE_X_TOOLKIT */
141 #ifndef USE_X_TOOLKIT
142 #define x_any_window_to_frame x_window_to_frame
143 #define x_top_window_to_frame x_window_to_frame
148 #ifndef XtNinitialState
149 #define XtNinitialState "initialState"
154 /* memmove will be defined as a macro in Xfuncs.h unless
155 <string.h> is included beforehand. The declaration for memmove in
156 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
161 #define min(a,b) ((a) < (b) ? (a) : (b))
164 #define max(a,b) ((a) > (b) ? (a) : (b))
167 #define abs(x) ((x) < 0 ? -(x) : (x))
169 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
172 /* Bitmaps for truncated lines. */
177 LEFT_TRUNCATION_BITMAP
,
178 RIGHT_TRUNCATION_BITMAP
,
179 OVERLAY_ARROW_BITMAP
,
180 CONTINUED_LINE_BITMAP
,
181 CONTINUATION_LINE_BITMAP
,
185 /* Bitmap drawn to indicate lines not displaying text if
186 `indicate-empty-lines' is non-nil. */
190 static unsigned char zv_bits
[] = {
191 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
193 /* An arrow like this: `<-'. */
196 #define left_height 8
197 static unsigned char left_bits
[] = {
198 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
200 /* Right truncation arrow bitmap `->'. */
202 #define right_width 8
203 #define right_height 8
204 static unsigned char right_bits
[] = {
205 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
207 /* Marker for continued lines. */
209 #define continued_width 8
210 #define continued_height 8
211 static unsigned char continued_bits
[] = {
212 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
214 /* Marker for continuation lines. */
216 #define continuation_width 8
217 #define continuation_height 8
218 static unsigned char continuation_bits
[] = {
219 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
221 /* Overlay arrow bitmap. */
227 static unsigned char ov_bits
[] = {
228 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
230 /* A triangular arrow. */
233 static unsigned char ov_bits
[] = {
234 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
238 extern Lisp_Object Qhelp_echo
;
241 /* Non-zero means Emacs uses toolkit scroll bars. */
243 int x_toolkit_scroll_bars_p
;
245 /* If a string, XTread_socket generates an event to display that string.
246 (The display is done in read_char.) */
248 static Lisp_Object help_echo
;
250 /* Temporary variable for XTread_socket. */
252 static Lisp_Object previous_help_echo
;
254 /* Non-zero means that a HELP_EVENT has been generated since Emacs
257 static int any_help_event_p
;
259 /* Non-zero means draw block and hollow cursor as wide as the glyph
260 under it. For example, if a block cursor is over a tab, it will be
261 drawn as wide as that tab on the display. */
263 int x_stretch_cursor_p
;
265 /* This is a chain of structures for all the X displays currently in
268 struct x_display_info
*x_display_list
;
270 /* This is a list of cons cells, each of the form (NAME
271 . FONT-LIST-CACHE), one for each element of x_display_list and in
272 the same order. NAME is the name of the frame. FONT-LIST-CACHE
273 records previous values returned by x-list-fonts. */
275 Lisp_Object x_display_name_list
;
277 /* Frame being updated by update_frame. This is declared in term.c.
278 This is set by update_begin and looked at by all the XT functions.
279 It is zero while not inside an update. In that case, the XT
280 functions assume that `selected_frame' is the frame to apply to. */
282 extern struct frame
*updating_frame
;
284 extern int waiting_for_input
;
286 /* This is a frame waiting to be auto-raised, within XTread_socket. */
288 struct frame
*pending_autoraise_frame
;
291 /* The application context for Xt use. */
292 XtAppContext Xt_app_con
;
293 static String Xt_default_resources
[] = {0};
294 #endif /* USE_X_TOOLKIT */
296 /* Nominal cursor position -- where to draw output.
297 HPOS and VPOS are window relative glyph matrix coordinates.
298 X and Y are window relative pixel coordinates. */
300 struct cursor_pos output_cursor
;
302 /* Non-zero means user is interacting with a toolkit scroll bar. */
304 static int toolkit_scroll_bar_interaction
;
308 Formerly, we used PointerMotionHintMask (in standard_event_mask)
309 so that we would have to call XQueryPointer after each MotionNotify
310 event to ask for another such event. However, this made mouse tracking
311 slow, and there was a bug that made it eventually stop.
313 Simply asking for MotionNotify all the time seems to work better.
315 In order to avoid asking for motion events and then throwing most
316 of them away or busy-polling the server for mouse positions, we ask
317 the server for pointer motion hints. This means that we get only
318 one event per group of mouse movements. "Groups" are delimited by
319 other kinds of events (focus changes and button clicks, for
320 example), or by XQueryPointer calls; when one of these happens, we
321 get another MotionNotify event the next time the mouse moves. This
322 is at least as efficient as getting motion events when mouse
323 tracking is on, and I suspect only negligibly worse when tracking
326 /* Where the mouse was last time we reported a mouse event. */
328 FRAME_PTR last_mouse_frame
;
329 static XRectangle last_mouse_glyph
;
330 static Lisp_Object last_mouse_press_frame
;
332 /* The scroll bar in which the last X motion event occurred.
334 If the last X motion event occurred in a scroll bar, we set this so
335 XTmouse_position can know whether to report a scroll bar motion or
338 If the last X motion event didn't occur in a scroll bar, we set
339 this to Qnil, to tell XTmouse_position to return an ordinary motion
342 static Lisp_Object last_mouse_scroll_bar
;
344 /* This is a hack. We would really prefer that XTmouse_position would
345 return the time associated with the position it returns, but there
346 doesn't seem to be any way to wrest the time-stamp from the server
347 along with the position query. So, we just keep track of the time
348 of the last movement we received, and return that in hopes that
349 it's somewhat accurate. */
351 static Time last_mouse_movement_time
;
353 /* Incremented by XTread_socket whenever it really tries to read
357 static int volatile input_signal_count
;
359 static int input_signal_count
;
362 /* Used locally within XTread_socket. */
364 static int x_noop_count
;
366 /* Initial values of argv and argc. */
368 extern char **initial_argv
;
369 extern int initial_argc
;
371 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
373 /* Tells if a window manager is present or not. */
375 extern Lisp_Object Vx_no_window_manager
;
377 extern Lisp_Object Qface
, Qmouse_face
;
381 /* A mask of extra modifier bits to put into every keyboard char. */
383 extern int extra_keyboard_modifiers
;
385 static Lisp_Object Qvendor_specific_keysyms
;
387 extern XrmDatabase
x_load_resources ();
388 extern Lisp_Object
x_icon_type ();
391 /* Enumeration for overriding/changing the face to use for drawing
392 glyphs in x_draw_glyphs. */
394 enum draw_glyphs_face
404 static void x_update_window_end
P_ ((struct window
*, int));
405 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
406 void x_delete_display
P_ ((struct x_display_info
*));
407 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
409 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
411 static void set_output_cursor
P_ ((struct cursor_pos
*));
412 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
413 int *, int *, int *));
414 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
415 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
416 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
417 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
418 static void show_mouse_face
P_ ((struct x_display_info
*,
419 enum draw_glyphs_face
));
420 static int x_io_error_quitter
P_ ((Display
*));
421 int x_catch_errors
P_ ((Display
*));
422 void x_uncatch_errors
P_ ((Display
*, int));
423 void x_lower_frame
P_ ((struct frame
*));
424 void x_scroll_bar_clear
P_ ((struct frame
*));
425 int x_had_errors_p
P_ ((Display
*));
426 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
427 void x_raise_frame
P_ ((struct frame
*));
428 void x_set_window_size
P_ ((struct frame
*, int, int, int));
429 void x_wm_set_window_state
P_ ((struct frame
*, int));
430 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
431 void x_initialize
P_ ((void));
432 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
433 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
434 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
436 enum draw_glyphs_face
));
437 static void x_update_end
P_ ((struct frame
*));
438 static void XTframe_up_to_date
P_ ((struct frame
*));
439 static void XTreassert_line_highlight
P_ ((int, int));
440 static void x_change_line_highlight
P_ ((int, int, int, int));
441 static void XTset_terminal_modes
P_ ((void));
442 static void XTreset_terminal_modes
P_ ((void));
443 static void XTcursor_to
P_ ((int, int, int, int));
444 static void x_write_glyphs
P_ ((struct glyph
*, int));
445 static void x_clear_end_of_line
P_ ((int));
446 static void x_clear_frame
P_ ((void));
447 static void x_clear_cursor
P_ ((struct window
*));
448 static void frame_highlight
P_ ((struct frame
*));
449 static void frame_unhighlight
P_ ((struct frame
*));
450 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
451 static void XTframe_rehighlight
P_ ((struct frame
*));
452 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
453 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
454 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
455 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
457 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
458 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
459 static void expose_window
P_ ((struct window
*, XRectangle
*));
460 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
461 XRectangle
*, enum glyph_row_area
));
462 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
464 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
465 static void x_update_window_cursor
P_ ((struct window
*, int));
466 static void x_erase_phys_cursor
P_ ((struct window
*));
467 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
468 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
471 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
473 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
474 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
475 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
476 static void x_flush
P_ ((struct frame
*f
));
479 /* Flush display of frame F, or of all frames if F is null. */
488 Lisp_Object rest
, frame
;
489 FOR_EACH_FRAME (rest
, frame
)
490 x_flush (XFRAME (frame
));
492 else if (FRAME_X_P (f
))
493 XFlush (FRAME_X_DISPLAY (f
));
498 /* Remove calls to XFlush by defining XFlush to an empty replacement.
499 Calls to XFlush should be unnecessary because the X output buffer
500 is flushed automatically as needed by calls to XPending,
501 XNextEvent, or XWindowEvent according to the XFlush man page.
502 XTread_socket calls XPending. Removing XFlush improves
505 #define XFlush(DISPLAY) (void) 0
508 /***********************************************************************
510 ***********************************************************************/
514 /* This is a function useful for recording debugging information about
515 the sequence of occurrences in this file. */
523 struct record event_record
[100];
525 int event_record_index
;
527 record_event (locus
, type
)
531 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
532 event_record_index
= 0;
534 event_record
[event_record_index
].locus
= locus
;
535 event_record
[event_record_index
].type
= type
;
536 event_record_index
++;
543 /* Return the struct x_display_info corresponding to DPY. */
545 struct x_display_info
*
546 x_display_info_for_display (dpy
)
549 struct x_display_info
*dpyinfo
;
551 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
552 if (dpyinfo
->display
== dpy
)
560 /***********************************************************************
561 Starting and ending an update
562 ***********************************************************************/
564 /* Start an update of frame F. This function is installed as a hook
565 for update_begin, i.e. it is called when update_begin is called.
566 This function is called prior to calls to x_update_window_begin for
567 each window being updated. Currently, there is nothing to do here
568 because all interesting stuff is done on a window basis. */
578 /* Start update of window W. Set the global variable updated_window
579 to the window being updated and set output_cursor to the cursor
583 x_update_window_begin (w
)
586 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
587 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
590 set_output_cursor (&w
->cursor
);
594 if (f
== display_info
->mouse_face_mouse_frame
)
596 /* Don't do highlighting for mouse motion during the update. */
597 display_info
->mouse_face_defer
= 1;
599 /* If F needs to be redrawn, simply forget about any prior mouse
601 if (FRAME_GARBAGED_P (f
))
602 display_info
->mouse_face_window
= Qnil
;
604 /* Can we tell that this update does not affect the window
605 where the mouse highlight is? If so, no need to turn off.
606 Likewise, don't do anything if the frame is garbaged;
607 in that case, the frame's current matrix that we would use
608 is all wrong, and we will redisplay that line anyway. */
609 if (!NILP (display_info
->mouse_face_window
)
610 && w
== XWINDOW (display_info
->mouse_face_window
))
614 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
615 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
618 if (i
< w
->desired_matrix
->nrows
)
619 clear_mouse_face (display_info
);
627 /* Draw a vertical window border to the right of window W if W doesn't
628 have vertical scroll bars. */
631 x_draw_vertical_border (w
)
634 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
636 /* Redraw borders between horizontally adjacent windows. Don't
637 do it for frames with vertical scroll bars because either the
638 right scroll bar of a window, or the left scroll bar of its
639 neighbor will suffice as a border. */
640 if (!WINDOW_RIGHTMOST_P (w
)
641 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
645 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
646 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
649 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
650 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
655 /* End update of window W (which is equal to updated_window). Draw
656 vertical borders between horizontally adjacent windows, and display
657 W's cursor if CURSOR_ON_P is non-zero. W may be a menu bar
658 pseudo-window in case we don't have X toolkit support. Such
659 windows don't have a cursor, so don't display it here. */
662 x_update_window_end (w
, cursor_on_p
)
666 if (!w
->pseudo_window_p
)
670 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
672 output_cursor
.x
, output_cursor
.y
);
673 x_draw_vertical_border (w
);
677 updated_window
= NULL
;
681 /* End update of frame F. This function is installed as a hook in
688 /* Mouse highlight may be displayed again. */
689 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
692 XFlush (FRAME_X_DISPLAY (f
));
697 /* This function is called from various places in xdisp.c whenever a
698 complete update has been performed. The global variable
699 updated_window is not available here. */
702 XTframe_up_to_date (f
)
707 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
708 if (dpyinfo
->mouse_face_deferred_gc
709 || f
== dpyinfo
->mouse_face_mouse_frame
)
712 if (dpyinfo
->mouse_face_mouse_frame
)
713 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
714 dpyinfo
->mouse_face_mouse_x
,
715 dpyinfo
->mouse_face_mouse_y
);
716 dpyinfo
->mouse_face_deferred_gc
= 0;
723 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
724 arrow bitmaps, or clear the areas where they would be displayed
725 before DESIRED_ROW is made current. The window being updated is
726 found in updated_window. This function It is called from
727 update_window_line only if it is known that there are differences
728 between bitmaps to be drawn between current row and DESIRED_ROW. */
731 x_after_update_window_line (desired_row
)
732 struct glyph_row
*desired_row
;
734 struct window
*w
= updated_window
;
738 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
741 x_draw_row_bitmaps (w
, desired_row
);
743 /* When a window has disappeared, make sure that no rest of
744 full-width rows stays visible in the internal border. */
745 if (windows_or_buffers_changed
)
747 struct frame
*f
= XFRAME (w
->frame
);
748 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
749 int height
= desired_row
->visible_height
;
750 int x
= (window_box_right (w
, -1)
751 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
752 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
754 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
755 x
, y
, width
, height
, False
);
763 /* Draw the bitmap WHICH in one of the areas to the left or right of
764 window W. ROW is the glyph row for which to display the bitmap; it
765 determines the vertical position at which the bitmap has to be
769 x_draw_bitmap (w
, row
, which
)
771 struct glyph_row
*row
;
772 enum bitmap_type which
;
774 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
775 Display
*display
= FRAME_X_DISPLAY (f
);
776 Window window
= FRAME_X_WINDOW (f
);
780 GC gc
= f
->output_data
.x
->normal_gc
;
782 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
784 /* Must clip because of partially visible lines. */
785 x_clip_to_row (w
, row
, gc
, 1);
789 case LEFT_TRUNCATION_BITMAP
:
793 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
795 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
798 case OVERLAY_ARROW_BITMAP
:
802 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
804 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
807 case RIGHT_TRUNCATION_BITMAP
:
811 x
= window_box_right (w
, -1);
812 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
815 case CONTINUED_LINE_BITMAP
:
818 bits
= continued_bits
;
819 x
= window_box_right (w
, -1);
820 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
823 case CONTINUATION_LINE_BITMAP
:
824 wd
= continuation_width
;
825 h
= continuation_height
;
826 bits
= continuation_bits
;
827 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
829 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
836 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
838 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
845 /* Convert to frame coordinates. Set dy to the offset in the row to
846 start drawing the bitmap. */
847 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
848 dy
= (row
->height
- h
) / 2;
850 /* Draw the bitmap. I believe these small pixmaps can be cached
852 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
853 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
855 face
->background
, depth
);
856 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
857 XFreePixmap (display
, pixmap
);
858 XSetClipMask (display
, gc
, None
);
862 /* Draw flags bitmaps for glyph row ROW on window W. Call this
863 function with input blocked. */
866 x_draw_row_bitmaps (w
, row
)
868 struct glyph_row
*row
;
870 struct frame
*f
= XFRAME (w
->frame
);
871 enum bitmap_type bitmap
;
873 int header_line_height
= -1;
875 xassert (interrupt_input_blocked
);
877 /* If row is completely invisible, because of vscrolling, we
878 don't have to draw anything. */
879 if (row
->visible_height
<= 0)
882 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
883 PREPARE_FACE_FOR_DISPLAY (f
, face
);
885 /* Decide which bitmap to draw at the left side. */
886 if (row
->overlay_arrow_p
)
887 bitmap
= OVERLAY_ARROW_BITMAP
;
888 else if (row
->truncated_on_left_p
)
889 bitmap
= LEFT_TRUNCATION_BITMAP
;
890 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
891 bitmap
= CONTINUATION_LINE_BITMAP
;
892 else if (row
->indicate_empty_line_p
)
893 bitmap
= ZV_LINE_BITMAP
;
897 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
899 if (bitmap
== NO_BITMAP
900 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
901 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
903 /* If W has a vertical border to its left, don't draw over it. */
904 int border
= ((XFASTINT (w
->left
) > 0
905 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
907 int left
= window_box_left (w
, -1);
909 if (header_line_height
< 0)
910 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
912 /* In case the same realized face is used for bitmap areas and
913 for something displayed in the text (e.g. face `region' on
914 mono-displays, the fill style may have been changed to
915 FillSolid in x_draw_glyph_string_background. */
917 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
919 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
921 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
924 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
926 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
928 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
929 row
->visible_height
);
931 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
934 /* Draw the left bitmap. */
935 if (bitmap
!= NO_BITMAP
)
936 x_draw_bitmap (w
, row
, bitmap
);
938 /* Decide which bitmap to draw at the right side. */
939 if (row
->truncated_on_right_p
)
940 bitmap
= RIGHT_TRUNCATION_BITMAP
;
941 else if (row
->continued_p
)
942 bitmap
= CONTINUED_LINE_BITMAP
;
946 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
948 if (bitmap
== NO_BITMAP
949 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
950 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
952 int right
= window_box_right (w
, -1);
954 if (header_line_height
< 0)
955 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
957 /* In case the same realized face is used for bitmap areas and
958 for something displayed in the text (e.g. face `region' on
959 mono-displays, the fill style may have been changed to
960 FillSolid in x_draw_glyph_string_background. */
962 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
964 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
965 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
968 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
970 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
971 row
->visible_height
);
973 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
976 /* Draw the right bitmap. */
977 if (bitmap
!= NO_BITMAP
)
978 x_draw_bitmap (w
, row
, bitmap
);
982 /***********************************************************************
984 ***********************************************************************/
986 /* External interface to control of standout mode. Not used for X
987 frames. Aborts when called. */
990 XTreassert_line_highlight (new, vpos
)
997 /* Call this when about to modify line at position VPOS and change
998 whether it is highlighted. Not used for X frames. Aborts when
1002 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1003 int new_highlight
, vpos
, y
, first_unused_hpos
;
1009 /* This is called when starting Emacs and when restarting after
1010 suspend. When starting Emacs, no X window is mapped. And nothing
1011 must be done to Emacs's own window if it is suspended (though that
1015 XTset_terminal_modes ()
1019 /* This is called when exiting or suspending Emacs. Exiting will make
1020 the X-windows go away, and suspending requires no action. */
1023 XTreset_terminal_modes ()
1029 /***********************************************************************
1031 ***********************************************************************/
1033 /* Set the global variable output_cursor to CURSOR. All cursor
1034 positions are relative to updated_window. */
1037 set_output_cursor (cursor
)
1038 struct cursor_pos
*cursor
;
1040 output_cursor
.hpos
= cursor
->hpos
;
1041 output_cursor
.vpos
= cursor
->vpos
;
1042 output_cursor
.x
= cursor
->x
;
1043 output_cursor
.y
= cursor
->y
;
1047 /* Set a nominal cursor position.
1049 HPOS and VPOS are column/row positions in a window glyph matrix. X
1050 and Y are window text area relative pixel positions.
1052 If this is done during an update, updated_window will contain the
1053 window that is being updated and the position is the future output
1054 cursor position for that window. If updated_window is null, use
1055 selected_window and display the cursor at the given position. */
1058 XTcursor_to (vpos
, hpos
, y
, x
)
1059 int vpos
, hpos
, y
, x
;
1063 /* If updated_window is not set, work on selected_window. */
1067 w
= XWINDOW (selected_window
);
1069 /* Set the output cursor. */
1070 output_cursor
.hpos
= hpos
;
1071 output_cursor
.vpos
= vpos
;
1072 output_cursor
.x
= x
;
1073 output_cursor
.y
= y
;
1075 /* If not called as part of an update, really display the cursor.
1076 This will also set the cursor position of W. */
1077 if (updated_window
== NULL
)
1080 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1081 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1088 /***********************************************************************
1090 ***********************************************************************/
1092 /* Function prototypes of this page. */
1094 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1098 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1099 int, XChar2b
*, int));
1100 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1101 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1102 static void x_append_glyph
P_ ((struct it
*));
1103 static void x_append_composite_glyph
P_ ((struct it
*));
1104 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1106 static void x_produce_glyphs
P_ ((struct it
*));
1107 static void x_produce_image_glyph
P_ ((struct it
*it
));
1110 /* Return a pointer to per-char metric information in FONT of a
1111 character pointed by B which is a pointer to an XChar2b. */
1113 #define PER_CHAR_METRIC(font, b) \
1115 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1116 + (((font)->min_byte1 || (font)->max_byte1) \
1117 ? (((b)->byte1 - (font)->min_byte1) \
1118 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1120 : &((font)->max_bounds))
1123 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1124 is not contained in the font. */
1126 static INLINE XCharStruct
*
1127 x_per_char_metric (font
, char2b
)
1131 /* The result metric information. */
1132 XCharStruct
*pcm
= NULL
;
1134 xassert (font
&& char2b
);
1136 if (font
->per_char
!= NULL
)
1138 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1140 /* min_char_or_byte2 specifies the linear character index
1141 corresponding to the first element of the per_char array,
1142 max_char_or_byte2 is the index of the last character. A
1143 character with non-zero CHAR2B->byte1 is not in the font.
1144 A character with byte2 less than min_char_or_byte2 or
1145 greater max_char_or_byte2 is not in the font. */
1146 if (char2b
->byte1
== 0
1147 && char2b
->byte2
>= font
->min_char_or_byte2
1148 && char2b
->byte2
<= font
->max_char_or_byte2
)
1149 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1153 /* If either min_byte1 or max_byte1 are nonzero, both
1154 min_char_or_byte2 and max_char_or_byte2 are less than
1155 256, and the 2-byte character index values corresponding
1156 to the per_char array element N (counting from 0) are:
1158 byte1 = N/D + min_byte1
1159 byte2 = N\D + min_char_or_byte2
1163 D = max_char_or_byte2 - min_char_or_byte2 + 1
1164 / = integer division
1165 \ = integer modulus */
1166 if (char2b
->byte1
>= font
->min_byte1
1167 && char2b
->byte1
<= font
->max_byte1
1168 && char2b
->byte2
>= font
->min_char_or_byte2
1169 && char2b
->byte2
<= font
->max_char_or_byte2
)
1171 pcm
= (font
->per_char
1172 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1173 * (char2b
->byte1
- font
->min_byte1
))
1174 + (char2b
->byte2
- font
->min_char_or_byte2
));
1180 /* If the per_char pointer is null, all glyphs between the first
1181 and last character indexes inclusive have the same
1182 information, as given by both min_bounds and max_bounds. */
1183 if (char2b
->byte2
>= font
->min_char_or_byte2
1184 && char2b
->byte2
<= font
->max_char_or_byte2
)
1185 pcm
= &font
->max_bounds
;
1188 return ((pcm
== NULL
1189 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1194 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1195 the two-byte form of C. Encoding is returned in *CHAR2B. */
1198 x_encode_char (c
, char2b
, font_info
)
1201 struct font_info
*font_info
;
1203 int charset
= CHAR_CHARSET (c
);
1204 XFontStruct
*font
= font_info
->font
;
1206 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1207 This may be either a program in a special encoder language or a
1209 if (font_info
->font_encoder
)
1211 /* It's a program. */
1212 struct ccl_program
*ccl
= font_info
->font_encoder
;
1214 if (CHARSET_DIMENSION (charset
) == 1)
1216 ccl
->reg
[0] = charset
;
1217 ccl
->reg
[1] = char2b
->byte2
;
1221 ccl
->reg
[0] = charset
;
1222 ccl
->reg
[1] = char2b
->byte1
;
1223 ccl
->reg
[2] = char2b
->byte2
;
1226 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1228 /* We assume that MSBs are appropriately set/reset by CCL
1230 if (font
->max_byte1
== 0) /* 1-byte font */
1231 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1233 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1235 else if (font_info
->encoding
[charset
])
1237 /* Fixed encoding scheme. See fontset.h for the meaning of the
1238 encoding numbers. */
1239 int enc
= font_info
->encoding
[charset
];
1241 if ((enc
== 1 || enc
== 2)
1242 && CHARSET_DIMENSION (charset
) == 2)
1243 char2b
->byte1
|= 0x80;
1245 if (enc
== 1 || enc
== 3)
1246 char2b
->byte2
|= 0x80;
1251 /* Get face and two-byte form of character C in face FACE_ID on frame
1252 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1253 means we want to display multibyte text. Value is a pointer to a
1254 realized face that is ready for display. */
1256 static INLINE
struct face
*
1257 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1263 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1267 /* Unibyte case. We don't have to encode, but we have to make
1268 sure to use a face suitable for unibyte. */
1271 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1272 face
= FACE_FROM_ID (f
, face_id
);
1274 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1276 /* Case of ASCII in a face known to fit ASCII. */
1282 int c1
, c2
, charset
;
1284 /* Split characters into bytes. If c2 is -1 afterwards, C is
1285 really a one-byte character so that byte1 is zero. */
1286 SPLIT_CHAR (c
, charset
, c1
, c2
);
1288 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1290 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1292 /* Maybe encode the character in *CHAR2B. */
1293 if (face
->font
!= NULL
)
1295 struct font_info
*font_info
1296 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1298 x_encode_char (c
, char2b
, font_info
);
1302 /* Make sure X resources of the face are allocated. */
1303 xassert (face
!= NULL
);
1304 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1310 /* Get face and two-byte form of character glyph GLYPH on frame F.
1311 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1312 a pointer to a realized face that is ready for display. */
1314 static INLINE
struct face
*
1315 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1317 struct glyph
*glyph
;
1323 xassert (glyph
->type
== CHAR_GLYPH
);
1324 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1329 if (!glyph
->multibyte_p
)
1331 /* Unibyte case. We don't have to encode, but we have to make
1332 sure to use a face suitable for unibyte. */
1334 char2b
->byte2
= glyph
->u
.ch
;
1336 else if (glyph
->u
.ch
< 128
1337 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1339 /* Case of ASCII in a face known to fit ASCII. */
1341 char2b
->byte2
= glyph
->u
.ch
;
1345 int c1
, c2
, charset
;
1347 /* Split characters into bytes. If c2 is -1 afterwards, C is
1348 really a one-byte character so that byte1 is zero. */
1349 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1351 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1353 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1355 /* Maybe encode the character in *CHAR2B. */
1356 if (charset
!= CHARSET_ASCII
)
1358 struct font_info
*font_info
1359 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1362 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1365 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1370 /* Make sure X resources of the face are allocated. */
1371 xassert (face
!= NULL
);
1372 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1377 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1378 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1384 struct glyph
*glyph
;
1385 enum glyph_row_area area
= it
->area
;
1387 xassert (it
->glyph_row
);
1388 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1390 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1391 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1393 /* Play it safe. If sub-structures of the glyph are not all the
1394 same size, it otherwise be that some bits stay set. This
1395 would prevent a comparison with GLYPH_EQUAL_P. */
1398 glyph
->type
= CHAR_GLYPH
;
1399 glyph
->pixel_width
= it
->pixel_width
;
1400 glyph
->u
.ch
= it
->char_to_display
;
1401 glyph
->face_id
= it
->face_id
;
1402 glyph
->charpos
= CHARPOS (it
->position
);
1403 glyph
->object
= it
->object
;
1404 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1405 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1406 glyph
->voffset
= it
->voffset
;
1407 glyph
->multibyte_p
= it
->multibyte_p
;
1408 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1409 || it
->phys_descent
> it
->descent
);
1410 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1411 ++it
->glyph_row
->used
[area
];
1415 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1416 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1419 x_append_composite_glyph (it
)
1422 struct glyph
*glyph
;
1423 enum glyph_row_area area
= it
->area
;
1425 xassert (it
->glyph_row
);
1427 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1428 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1430 /* Play it safe. If sub-structures of the glyph are not all the
1431 same size, it otherwise be that some bits stay set. This
1432 would prevent a comparison with GLYPH_EQUAL_P. */
1435 glyph
->type
= COMPOSITE_GLYPH
;
1436 glyph
->pixel_width
= it
->pixel_width
;
1437 glyph
->u
.cmp_id
= it
->cmp_id
;
1438 glyph
->face_id
= it
->face_id
;
1439 glyph
->charpos
= CHARPOS (it
->position
);
1440 glyph
->object
= it
->object
;
1441 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1442 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1443 glyph
->voffset
= it
->voffset
;
1444 glyph
->multibyte_p
= it
->multibyte_p
;
1445 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1446 || it
->phys_descent
> it
->descent
);
1447 ++it
->glyph_row
->used
[area
];
1452 /* Change IT->ascent and IT->height according to the setting of
1456 take_vertical_position_into_account (it
)
1461 if (it
->voffset
< 0)
1462 /* Increase the ascent so that we can display the text higher
1464 it
->ascent
+= abs (it
->voffset
);
1466 /* Increase the descent so that we can display the text lower
1468 it
->descent
+= it
->voffset
;
1473 /* Produce glyphs/get display metrics for the image IT is loaded with.
1474 See the description of struct display_iterator in dispextern.h for
1475 an overview of struct display_iterator. */
1478 x_produce_image_glyph (it
)
1484 xassert (it
->what
== IT_IMAGE
);
1486 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1487 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1490 /* Make sure X resources of the face and image are loaded. */
1491 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1492 prepare_image_for_display (it
->f
, img
);
1494 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1495 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->margin
- it
->ascent
;
1496 it
->pixel_width
= img
->width
+ 2 * img
->margin
;
1500 if (face
->box
!= FACE_NO_BOX
)
1502 it
->ascent
+= face
->box_line_width
;
1503 it
->descent
+= face
->box_line_width
;
1505 if (it
->start_of_box_run_p
)
1506 it
->pixel_width
+= face
->box_line_width
;
1507 if (it
->end_of_box_run_p
)
1508 it
->pixel_width
+= face
->box_line_width
;
1511 take_vertical_position_into_account (it
);
1515 struct glyph
*glyph
;
1516 enum glyph_row_area area
= it
->area
;
1518 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1519 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1521 glyph
->type
= IMAGE_GLYPH
;
1522 glyph
->u
.img_id
= img
->id
;
1523 glyph
->face_id
= it
->face_id
;
1524 glyph
->pixel_width
= it
->pixel_width
;
1525 glyph
->charpos
= CHARPOS (it
->position
);
1526 glyph
->object
= it
->object
;
1527 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1528 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1529 glyph
->voffset
= it
->voffset
;
1530 glyph
->multibyte_p
= it
->multibyte_p
;
1531 ++it
->glyph_row
->used
[area
];
1537 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1538 of the glyph, WIDTH and HEIGHT are the width and height of the
1539 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1540 ascent of the glyph (0 <= ASCENT <= 1). */
1543 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1549 struct glyph
*glyph
;
1550 enum glyph_row_area area
= it
->area
;
1552 xassert (ascent
>= 0 && ascent
<= 1);
1554 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1555 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1557 glyph
->type
= STRETCH_GLYPH
;
1558 glyph
->u
.stretch
.ascent
= height
* ascent
;
1559 glyph
->u
.stretch
.height
= height
;
1560 glyph
->face_id
= it
->face_id
;
1561 glyph
->pixel_width
= width
;
1562 glyph
->charpos
= CHARPOS (it
->position
);
1563 glyph
->object
= object
;
1564 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1565 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1566 glyph
->voffset
= it
->voffset
;
1567 glyph
->multibyte_p
= it
->multibyte_p
;
1568 ++it
->glyph_row
->used
[area
];
1573 /* Produce a stretch glyph for iterator IT. IT->object is the value
1574 of the glyph property displayed. The value must be a list
1575 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1578 1. `:width WIDTH' specifies that the space should be WIDTH *
1579 canonical char width wide. WIDTH may be an integer or floating
1582 2. `:relative-width FACTOR' specifies that the width of the stretch
1583 should be computed from the width of the first character having the
1584 `glyph' property, and should be FACTOR times that width.
1586 3. `:align-to HPOS' specifies that the space should be wide enough
1587 to reach HPOS, a value in canonical character units.
1589 Exactly one of the above pairs must be present.
1591 4. `:height HEIGHT' specifies that the height of the stretch produced
1592 should be HEIGHT, measured in canonical character units.
1594 5. `:relative-height FACTOR' specifies that the height of the the
1595 stretch should be FACTOR times the height of the characters having
1598 Either none or exactly one of 4 or 5 must be present.
1600 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1601 of the stretch should be used for the ascent of the stretch.
1602 ASCENT must be in the range 0 <= ASCENT <= 100. */
1605 ((INTEGERP (X) || FLOATP (X)) \
1611 x_produce_stretch_glyph (it
)
1614 /* (space :width WIDTH :height HEIGHT. */
1616 extern Lisp_Object Qspace
;
1618 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1619 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1620 extern Lisp_Object QCalign_to
;
1621 Lisp_Object prop
, plist
;
1622 double width
= 0, height
= 0, ascent
= 0;
1623 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1624 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1626 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1628 /* List should start with `space'. */
1629 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1630 plist
= XCDR (it
->object
);
1632 /* Compute the width of the stretch. */
1633 if (prop
= Fplist_get (plist
, QCwidth
),
1635 /* Absolute width `:width WIDTH' specified and valid. */
1636 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1637 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1640 /* Relative width `:relative-width FACTOR' specified and valid.
1641 Compute the width of the characters having the `glyph'
1644 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1647 if (it
->multibyte_p
)
1649 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1650 - IT_BYTEPOS (*it
));
1651 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1654 it2
.c
= *p
, it2
.len
= 1;
1656 it2
.glyph_row
= NULL
;
1657 it2
.what
= IT_CHARACTER
;
1658 x_produce_glyphs (&it2
);
1659 width
= NUMVAL (prop
) * it2
.pixel_width
;
1661 else if (prop
= Fplist_get (plist
, QCalign_to
),
1663 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1665 /* Nothing specified -> width defaults to canonical char width. */
1666 width
= CANON_X_UNIT (it
->f
);
1668 /* Compute height. */
1669 if (prop
= Fplist_get (plist
, QCheight
),
1671 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1672 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1674 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1676 height
= FONT_HEIGHT (font
);
1678 /* Compute percentage of height used for ascent. If
1679 `:ascent ASCENT' is present and valid, use that. Otherwise,
1680 derive the ascent from the font in use. */
1681 if (prop
= Fplist_get (plist
, QCascent
),
1682 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1683 ascent
= NUMVAL (prop
) / 100.0;
1685 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1694 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1695 if (!STRINGP (object
))
1696 object
= it
->w
->buffer
;
1697 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1700 it
->pixel_width
= width
;
1701 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1702 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1705 if (face
->box
!= FACE_NO_BOX
)
1707 it
->ascent
+= face
->box_line_width
;
1708 it
->descent
+= face
->box_line_width
;
1710 if (it
->start_of_box_run_p
)
1711 it
->pixel_width
+= face
->box_line_width
;
1712 if (it
->end_of_box_run_p
)
1713 it
->pixel_width
+= face
->box_line_width
;
1716 take_vertical_position_into_account (it
);
1719 /* Return proper value to be used as baseline offset of font that has
1720 ASCENT and DESCENT to draw characters by the font at the vertical
1721 center of the line of frame F.
1723 Here, out task is to find the value of BOFF in the following figure;
1725 -------------------------+-----------+-
1726 -+-+---------+-+ | |
1728 | | | | F_ASCENT F_HEIGHT
1731 | | |-|-+------+-----------|------- baseline
1733 | |---------|-+-+ | |
1735 -+-+---------+-+ F_DESCENT |
1736 -------------------------+-----------+-
1738 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1739 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1740 DESCENT = FONT->descent
1741 HEIGHT = FONT_HEIGHT (FONT)
1742 F_DESCENT = (F->output_data.x->font->descent
1743 - F->output_data.x->baseline_offset)
1744 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1747 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1749 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT))) / 2 \
1750 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1752 /* Produce glyphs/get display metrics for the display element IT is
1753 loaded with. See the description of struct display_iterator in
1754 dispextern.h for an overview of struct display_iterator. */
1757 x_produce_glyphs (it
)
1760 it
->glyph_not_available_p
= 0;
1762 if (it
->what
== IT_CHARACTER
)
1766 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1768 int font_not_found_p
;
1769 struct font_info
*font_info
;
1770 int boff
; /* baseline offset */
1772 /* Maybe translate single-byte characters to multibyte, or the
1774 it
->char_to_display
= it
->c
;
1775 if (!ASCII_BYTE_P (it
->c
))
1777 if (unibyte_display_via_language_environment
1778 && SINGLE_BYTE_CHAR_P (it
->c
)
1780 || !NILP (Vnonascii_translation_table
)))
1782 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1783 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1784 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1786 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1787 && !it
->multibyte_p
)
1789 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1790 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1791 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1795 /* Get font to use. Encode IT->char_to_display. */
1796 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1797 it
->face_id
, &char2b
,
1801 /* When no suitable font found, use the default font. */
1802 font_not_found_p
= font
== NULL
;
1803 if (font_not_found_p
)
1805 font
= FRAME_FONT (it
->f
);
1806 boff
= it
->f
->output_data
.x
->baseline_offset
;
1811 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1812 boff
= font_info
->baseline_offset
;
1813 if (font_info
->vertical_centering
)
1814 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1817 if (it
->char_to_display
>= ' '
1818 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1820 /* Either unibyte or ASCII. */
1825 pcm
= x_per_char_metric (font
, &char2b
);
1826 it
->ascent
= font
->ascent
+ boff
;
1827 it
->descent
= font
->descent
- boff
;
1831 it
->phys_ascent
= pcm
->ascent
+ boff
;
1832 it
->phys_descent
= pcm
->descent
- boff
;
1833 it
->pixel_width
= pcm
->width
;
1837 it
->glyph_not_available_p
= 1;
1838 it
->phys_ascent
= font
->ascent
+ boff
;
1839 it
->phys_descent
= font
->descent
- boff
;
1840 it
->pixel_width
= FONT_WIDTH (font
);
1843 /* If this is a space inside a region of text with
1844 `space-width' property, change its width. */
1845 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1847 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1849 /* If face has a box, add the box thickness to the character
1850 height. If character has a box line to the left and/or
1851 right, add the box line width to the character's width. */
1852 if (face
->box
!= FACE_NO_BOX
)
1854 int thick
= face
->box_line_width
;
1856 it
->ascent
+= thick
;
1857 it
->descent
+= thick
;
1859 if (it
->start_of_box_run_p
)
1860 it
->pixel_width
+= thick
;
1861 if (it
->end_of_box_run_p
)
1862 it
->pixel_width
+= thick
;
1865 /* If face has an overline, add the height of the overline
1866 (1 pixel) and a 1 pixel margin to the character height. */
1867 if (face
->overline_p
)
1870 take_vertical_position_into_account (it
);
1872 /* If we have to actually produce glyphs, do it. */
1877 /* Translate a space with a `space-width' property
1878 into a stretch glyph. */
1879 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1880 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1881 it
->ascent
+ it
->descent
, ascent
);
1884 x_append_glyph (it
);
1886 /* If characters with lbearing or rbearing are displayed
1887 in this line, record that fact in a flag of the
1888 glyph row. This is used to optimize X output code. */
1889 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1890 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1893 else if (it
->char_to_display
== '\n')
1895 /* A newline has no width but we need the height of the line. */
1896 it
->pixel_width
= 0;
1898 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1899 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1901 if (face
->box
!= FACE_NO_BOX
)
1903 int thick
= face
->box_line_width
;
1904 it
->ascent
+= thick
;
1905 it
->descent
+= thick
;
1908 else if (it
->char_to_display
== '\t')
1910 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1911 int x
= it
->current_x
+ it
->continuation_lines_width
;
1912 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1914 it
->pixel_width
= next_tab_x
- x
;
1916 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1917 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1921 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1922 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1923 it
->ascent
+ it
->descent
, ascent
);
1928 /* A multi-byte character. Assume that the display width of the
1929 character is the width of the character multiplied by the
1930 width of the font. */
1932 /* If we found a font, this font should give us the right
1933 metrics. If we didn't find a font, use the frame's
1934 default font and calculate the width of the character
1935 from the charset width; this is what old redisplay code
1937 pcm
= x_per_char_metric (font
, &char2b
);
1938 if (font_not_found_p
|| !pcm
)
1940 int charset
= CHAR_CHARSET (it
->char_to_display
);
1942 it
->glyph_not_available_p
= 1;
1943 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1944 * CHARSET_WIDTH (charset
));
1945 it
->phys_ascent
= font
->ascent
+ boff
;
1946 it
->phys_descent
= font
->descent
- boff
;
1950 it
->pixel_width
= pcm
->width
;
1951 it
->phys_ascent
= pcm
->ascent
+ boff
;
1952 it
->phys_descent
= pcm
->descent
- boff
;
1954 && (pcm
->lbearing
< 0
1955 || pcm
->rbearing
> pcm
->width
))
1956 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1959 it
->ascent
= font
->ascent
+ boff
;
1960 it
->descent
= font
->descent
- boff
;
1961 if (face
->box
!= FACE_NO_BOX
)
1963 int thick
= face
->box_line_width
;
1964 it
->ascent
+= thick
;
1965 it
->descent
+= thick
;
1967 if (it
->start_of_box_run_p
)
1968 it
->pixel_width
+= thick
;
1969 if (it
->end_of_box_run_p
)
1970 it
->pixel_width
+= thick
;
1973 /* If face has an overline, add the height of the overline
1974 (1 pixel) and a 1 pixel margin to the character height. */
1975 if (face
->overline_p
)
1978 take_vertical_position_into_account (it
);
1981 x_append_glyph (it
);
1984 else if (it
->what
== IT_COMPOSITION
)
1986 /* Note: A composition is represented as one glyph in the
1987 glyph matrix. There are no padding glyphs. */
1990 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1992 int font_not_found_p
;
1993 struct font_info
*font_info
;
1994 int boff
; /* baseline offset */
1995 struct composition
*cmp
= composition_table
[it
->cmp_id
];
1997 /* Maybe translate single-byte characters to multibyte. */
1998 it
->char_to_display
= it
->c
;
1999 if (unibyte_display_via_language_environment
2000 && SINGLE_BYTE_CHAR_P (it
->c
)
2003 && !NILP (Vnonascii_translation_table
))))
2005 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2008 /* Get face and font to use. Encode IT->char_to_display. */
2009 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2010 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2011 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2012 it
->face_id
, &char2b
, it
->multibyte_p
);
2015 /* When no suitable font found, use the default font. */
2016 font_not_found_p
= font
== NULL
;
2017 if (font_not_found_p
)
2019 font
= FRAME_FONT (it
->f
);
2020 boff
= it
->f
->output_data
.x
->baseline_offset
;
2025 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2026 boff
= font_info
->baseline_offset
;
2027 if (font_info
->vertical_centering
)
2028 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2031 /* There are no padding glyphs, so there is only one glyph to
2032 produce for the composition. Important is that pixel_width,
2033 ascent and descent are the values of what is drawn by
2034 draw_glyphs (i.e. the values of the overall glyphs composed). */
2037 /* If we have not yet calculated pixel size data of glyphs of
2038 the composition for the current face font, calculate them
2039 now. Theoretically, we have to check all fonts for the
2040 glyphs, but that requires much time and memory space. So,
2041 here we check only the font of the first glyph. This leads
2042 to incorrect display very rarely, and C-l (recenter) can
2043 correct the display anyway. */
2044 if (cmp
->font
!= (void *) font
)
2046 /* Ascent and descent of the font of the first character of
2047 this composition (adjusted by baseline offset). Ascent
2048 and descent of overall glyphs should not be less than
2049 them respectively. */
2050 int font_ascent
= font
->ascent
+ boff
;
2051 int font_descent
= font
->descent
- boff
;
2052 /* Bounding box of the overall glyphs. */
2053 int leftmost
, rightmost
, lowest
, highest
;
2054 int i
, width
, ascent
, descent
;
2056 cmp
->font
= (void *) font
;
2058 /* Initialize the bounding box. */
2059 pcm
= x_per_char_metric (font
, &char2b
);
2063 ascent
= pcm
->ascent
;
2064 descent
= pcm
->descent
;
2068 width
= FONT_WIDTH (font
);
2069 ascent
= font
->ascent
;
2070 descent
= font
->descent
;
2074 lowest
= - descent
+ boff
;
2075 highest
= ascent
+ boff
;
2079 && font_info
->default_ascent
2080 && CHAR_TABLE_P (Vuse_default_ascent
)
2081 && !NILP (Faref (Vuse_default_ascent
,
2082 make_number (it
->char_to_display
))))
2083 highest
= font_info
->default_ascent
+ boff
;
2085 /* Draw the first glyph at the normal position. It may be
2086 shifted to right later if some other glyphs are drawn at
2088 cmp
->offsets
[0] = 0;
2089 cmp
->offsets
[1] = boff
;
2091 /* Set cmp->offsets for the remaining glyphs. */
2092 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2094 int left
, right
, btm
, top
;
2095 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2096 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2098 face
= FACE_FROM_ID (it
->f
, face_id
);
2099 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2104 font
= FRAME_FONT (it
->f
);
2105 boff
= it
->f
->output_data
.x
->baseline_offset
;
2111 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2112 boff
= font_info
->baseline_offset
;
2113 if (font_info
->vertical_centering
)
2114 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2117 pcm
= x_per_char_metric (font
, &char2b
);
2121 ascent
= pcm
->ascent
;
2122 descent
= pcm
->descent
;
2126 width
= FONT_WIDTH (font
);
2127 ascent
= font
->ascent
;
2128 descent
= font
->descent
;
2131 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2133 /* Relative composition with or without
2135 left
= (leftmost
+ rightmost
- width
) / 2;
2136 btm
= - descent
+ boff
;
2137 if (font_info
&& font_info
->relative_compose
2138 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2139 || NILP (Faref (Vignore_relative_composition
,
2140 make_number (ch
)))))
2143 if (- descent
>= font_info
->relative_compose
)
2144 /* One extra pixel between two glyphs. */
2146 else if (ascent
<= 0)
2147 /* One extra pixel between two glyphs. */
2148 btm
= lowest
- 1 - ascent
- descent
;
2153 /* A composition rule is specified by an integer
2154 value that encodes global and new reference
2155 points (GREF and NREF). GREF and NREF are
2156 specified by numbers as below:
2164 ---3---4---5--- baseline
2166 6---7---8 -- descent
2168 int rule
= COMPOSITION_RULE (cmp
, i
);
2169 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2171 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2172 grefx
= gref
% 3, nrefx
= nref
% 3;
2173 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2176 + grefx
* (rightmost
- leftmost
) / 2
2177 - nrefx
* width
/ 2);
2178 btm
= ((grefy
== 0 ? highest
2180 : grefy
== 2 ? lowest
2181 : (highest
+ lowest
) / 2)
2182 - (nrefy
== 0 ? ascent
+ descent
2183 : nrefy
== 1 ? descent
- boff
2185 : (ascent
+ descent
) / 2));
2188 cmp
->offsets
[i
* 2] = left
;
2189 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2191 /* Update the bounding box of the overall glyphs. */
2192 right
= left
+ width
;
2193 top
= btm
+ descent
+ ascent
;
2194 if (left
< leftmost
)
2196 if (right
> rightmost
)
2204 /* If there are glyphs whose x-offsets are negative,
2205 shift all glyphs to the right and make all x-offsets
2209 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2210 cmp
->offsets
[i
* 2] -= leftmost
;
2211 rightmost
-= leftmost
;
2214 cmp
->pixel_width
= rightmost
;
2215 cmp
->ascent
= highest
;
2216 cmp
->descent
= - lowest
;
2217 if (cmp
->ascent
< font_ascent
)
2218 cmp
->ascent
= font_ascent
;
2219 if (cmp
->descent
< font_descent
)
2220 cmp
->descent
= font_descent
;
2223 it
->pixel_width
= cmp
->pixel_width
;
2224 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2225 it
->descent
= it
->phys_descent
= cmp
->descent
;
2227 if (face
->box
!= FACE_NO_BOX
)
2229 int thick
= face
->box_line_width
;
2230 it
->ascent
+= thick
;
2231 it
->descent
+= thick
;
2233 if (it
->start_of_box_run_p
)
2234 it
->pixel_width
+= thick
;
2235 if (it
->end_of_box_run_p
)
2236 it
->pixel_width
+= thick
;
2239 /* If face has an overline, add the height of the overline
2240 (1 pixel) and a 1 pixel margin to the character height. */
2241 if (face
->overline_p
)
2244 take_vertical_position_into_account (it
);
2247 x_append_composite_glyph (it
);
2249 else if (it
->what
== IT_IMAGE
)
2250 x_produce_image_glyph (it
);
2251 else if (it
->what
== IT_STRETCH
)
2252 x_produce_stretch_glyph (it
);
2254 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2255 because this isn't true for images with `:ascent 100'. */
2256 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2257 if (it
->area
== TEXT_AREA
)
2258 it
->current_x
+= it
->pixel_width
;
2260 it
->descent
+= it
->extra_line_spacing
;
2262 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2263 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2264 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2265 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2269 /* Estimate the pixel height of the mode or top line on frame F.
2270 FACE_ID specifies what line's height to estimate. */
2273 x_estimate_mode_line_height (f
, face_id
)
2275 enum face_id face_id
;
2279 /* This function is called so early when Emacs starts that the face
2280 cache and mode line face are not yet initialized. */
2281 if (FRAME_FACE_CACHE (f
))
2283 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2285 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
2292 /***********************************************************************
2294 ***********************************************************************/
2296 /* A sequence of glyphs to be drawn in the same face.
2298 This data structure is not really completely X specific, so it
2299 could possibly, at least partially, be useful for other systems. It
2300 is currently not part of the external redisplay interface because
2301 it's not clear what other systems will need. */
2305 /* X-origin of the string. */
2308 /* Y-origin and y-position of the base line of this string. */
2311 /* The width of the string, not including a face extension. */
2314 /* The width of the string, including a face extension. */
2315 int background_width
;
2317 /* The height of this string. This is the height of the line this
2318 string is drawn in, and can be different from the height of the
2319 font the string is drawn in. */
2322 /* Number of pixels this string overwrites in front of its x-origin.
2323 This number is zero if the string has an lbearing >= 0; it is
2324 -lbearing, if the string has an lbearing < 0. */
2327 /* Number of pixels this string overwrites past its right-most
2328 nominal x-position, i.e. x + width. Zero if the string's
2329 rbearing is <= its nominal width, rbearing - width otherwise. */
2332 /* The frame on which the glyph string is drawn. */
2335 /* The window on which the glyph string is drawn. */
2338 /* X display and window for convenience. */
2342 /* The glyph row for which this string was built. It determines the
2343 y-origin and height of the string. */
2344 struct glyph_row
*row
;
2346 /* The area within row. */
2347 enum glyph_row_area area
;
2349 /* Characters to be drawn, and number of characters. */
2353 /* A face-override for drawing cursors, mouse face and similar. */
2354 enum draw_glyphs_face hl
;
2356 /* Face in which this string is to be drawn. */
2359 /* Font in which this string is to be drawn. */
2362 /* Font info for this string. */
2363 struct font_info
*font_info
;
2365 /* Non-null means this string describes (part of) a composition.
2366 All characters from char2b are drawn composed. */
2367 struct composition
*cmp
;
2369 /* Index of this glyph string's first character in the glyph
2370 definition of CMP. If this is zero, this glyph string describes
2371 the first character of a composition. */
2374 /* 1 means this glyph strings face has to be drawn to the right end
2375 of the window's drawing area. */
2376 unsigned extends_to_end_of_line_p
: 1;
2378 /* 1 means the background of this string has been drawn. */
2379 unsigned background_filled_p
: 1;
2381 /* 1 means glyph string must be drawn with 16-bit functions. */
2382 unsigned two_byte_p
: 1;
2384 /* 1 means that the original font determined for drawing this glyph
2385 string could not be loaded. The member `font' has been set to
2386 the frame's default font in this case. */
2387 unsigned font_not_found_p
: 1;
2389 /* 1 means that the face in which this glyph string is drawn has a
2391 unsigned stippled_p
: 1;
2393 /* 1 means only the foreground of this glyph string must be drawn,
2394 and we should use the physical height of the line this glyph
2395 string appears in as clip rect. */
2396 unsigned for_overlaps_p
: 1;
2398 /* The GC to use for drawing this glyph string. */
2401 /* A pointer to the first glyph in the string. This glyph
2402 corresponds to char2b[0]. Needed to draw rectangles if
2403 font_not_found_p is 1. */
2404 struct glyph
*first_glyph
;
2406 /* Image, if any. */
2409 struct glyph_string
*next
, *prev
;
2416 x_dump_glyph_string (s
)
2417 struct glyph_string
*s
;
2419 fprintf (stderr
, "glyph string\n");
2420 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2421 s
->x
, s
->y
, s
->width
, s
->height
);
2422 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2423 fprintf (stderr
, " hl = %d\n", s
->hl
);
2424 fprintf (stderr
, " left overhang = %d, right = %d\n",
2425 s
->left_overhang
, s
->right_overhang
);
2426 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2427 fprintf (stderr
, " extends to end of line = %d\n",
2428 s
->extends_to_end_of_line_p
);
2429 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2430 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2433 #endif /* GLYPH_DEBUG */
2437 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2438 struct glyph_string
**,
2439 struct glyph_string
*,
2440 struct glyph_string
*));
2441 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2442 struct glyph_string
**,
2443 struct glyph_string
*,
2444 struct glyph_string
*));
2445 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2446 struct glyph_string
**,
2447 struct glyph_string
*));
2448 static int x_left_overwritten
P_ ((struct glyph_string
*));
2449 static int x_left_overwriting
P_ ((struct glyph_string
*));
2450 static int x_right_overwritten
P_ ((struct glyph_string
*));
2451 static int x_right_overwriting
P_ ((struct glyph_string
*));
2452 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2454 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2455 XChar2b
*, struct window
*,
2457 enum glyph_row_area
, int,
2458 enum draw_glyphs_face
));
2459 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2460 enum glyph_row_area
, int, int,
2461 enum draw_glyphs_face
, int *, int *, int));
2462 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2463 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2464 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2466 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2467 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2468 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2469 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2470 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2471 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2472 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2473 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2474 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2476 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2477 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2478 unsigned long *, double, int));
2479 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2480 double, int, unsigned long));
2481 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2482 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2483 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2484 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2485 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2486 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2487 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2489 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2490 int, int, int, int, XRectangle
*));
2491 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2492 int, int, int, XRectangle
*));
2493 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2494 enum glyph_row_area
));
2497 /* Append the list of glyph strings with head H and tail T to the list
2498 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2501 x_append_glyph_string_lists (head
, tail
, h
, t
)
2502 struct glyph_string
**head
, **tail
;
2503 struct glyph_string
*h
, *t
;
2517 /* Prepend the list of glyph strings with head H and tail T to the
2518 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2522 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2523 struct glyph_string
**head
, **tail
;
2524 struct glyph_string
*h
, *t
;
2538 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2539 Set *HEAD and *TAIL to the resulting list. */
2542 x_append_glyph_string (head
, tail
, s
)
2543 struct glyph_string
**head
, **tail
;
2544 struct glyph_string
*s
;
2546 s
->next
= s
->prev
= NULL
;
2547 x_append_glyph_string_lists (head
, tail
, s
, s
);
2551 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2556 struct glyph_string
*s
;
2558 if (s
->font
== FRAME_FONT (s
->f
)
2559 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2560 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2562 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2565 /* Cursor on non-default face: must merge. */
2569 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2570 xgcv
.foreground
= s
->face
->background
;
2572 /* If the glyph would be invisible, try a different foreground. */
2573 if (xgcv
.foreground
== xgcv
.background
)
2574 xgcv
.foreground
= s
->face
->foreground
;
2575 if (xgcv
.foreground
== xgcv
.background
)
2576 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2577 if (xgcv
.foreground
== xgcv
.background
)
2578 xgcv
.foreground
= s
->face
->foreground
;
2580 /* Make sure the cursor is distinct from text in this face. */
2581 if (xgcv
.background
== s
->face
->background
2582 && xgcv
.foreground
== s
->face
->foreground
)
2584 xgcv
.background
= s
->face
->foreground
;
2585 xgcv
.foreground
= s
->face
->background
;
2588 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2589 xgcv
.font
= s
->font
->fid
;
2590 xgcv
.graphics_exposures
= False
;
2591 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2593 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2594 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2597 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2598 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2600 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2605 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2608 x_set_mouse_face_gc (s
)
2609 struct glyph_string
*s
;
2614 /* What face has to be used for the mouse face? */
2615 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2616 face
= FACE_FROM_ID (s
->f
, face_id
);
2617 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2618 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2620 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2621 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2622 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2624 /* If font in this face is same as S->font, use it. */
2625 if (s
->font
== s
->face
->font
)
2626 s
->gc
= s
->face
->gc
;
2629 /* Otherwise construct scratch_cursor_gc with values from FACE
2634 xgcv
.background
= s
->face
->background
;
2635 xgcv
.foreground
= s
->face
->foreground
;
2636 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2637 xgcv
.font
= s
->font
->fid
;
2638 xgcv
.graphics_exposures
= False
;
2639 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2641 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2642 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2645 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2646 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2648 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2651 xassert (s
->gc
!= 0);
2655 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2656 Faces to use in the mode line have already been computed when the
2657 matrix was built, so there isn't much to do, here. */
2660 x_set_mode_line_face_gc (s
)
2661 struct glyph_string
*s
;
2663 s
->gc
= s
->face
->gc
;
2664 xassert (s
->gc
!= 0);
2668 /* Set S->gc of glyph string S for drawing that glyph string. Set
2669 S->stippled_p to a non-zero value if the face of S has a stipple
2673 x_set_glyph_string_gc (s
)
2674 struct glyph_string
*s
;
2676 if (s
->hl
== DRAW_NORMAL_TEXT
)
2678 s
->gc
= s
->face
->gc
;
2679 s
->stippled_p
= s
->face
->stipple
!= 0;
2681 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2683 x_set_mode_line_face_gc (s
);
2684 s
->stippled_p
= s
->face
->stipple
!= 0;
2686 else if (s
->hl
== DRAW_CURSOR
)
2688 x_set_cursor_gc (s
);
2691 else if (s
->hl
== DRAW_MOUSE_FACE
)
2693 x_set_mouse_face_gc (s
);
2694 s
->stippled_p
= s
->face
->stipple
!= 0;
2696 else if (s
->hl
== DRAW_IMAGE_RAISED
2697 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2699 s
->gc
= s
->face
->gc
;
2700 s
->stippled_p
= s
->face
->stipple
!= 0;
2704 s
->gc
= s
->face
->gc
;
2705 s
->stippled_p
= s
->face
->stipple
!= 0;
2708 /* GC must have been set. */
2709 xassert (s
->gc
!= 0);
2713 /* Return in *R the clipping rectangle for glyph string S. */
2716 x_get_glyph_string_clip_rect (s
, r
)
2717 struct glyph_string
*s
;
2720 if (s
->row
->full_width_p
)
2722 /* Draw full-width. X coordinates are relative to S->w->left. */
2723 int canon_x
= CANON_X_UNIT (s
->f
);
2725 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2726 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2728 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2730 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2731 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2735 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2737 /* Unless displaying a mode or menu bar line, which are always
2738 fully visible, clip to the visible part of the row. */
2739 if (s
->w
->pseudo_window_p
)
2740 r
->height
= s
->row
->visible_height
;
2742 r
->height
= s
->height
;
2746 /* This is a text line that may be partially visible. */
2747 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2748 r
->width
= window_box_width (s
->w
, s
->area
);
2749 r
->height
= s
->row
->visible_height
;
2752 /* Don't use S->y for clipping because it doesn't take partially
2753 visible lines into account. For example, it can be negative for
2754 partially visible lines at the top of a window. */
2755 if (!s
->row
->full_width_p
2756 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2757 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2759 r
->y
= max (0, s
->row
->y
);
2761 /* If drawing a tool-bar window, draw it over the internal border
2762 at the top of the window. */
2763 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2764 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2766 /* If S draws overlapping rows, it's sufficient to use the top and
2767 bottom of the window for clipping because this glyph string
2768 intentionally draws over other lines. */
2769 if (s
->for_overlaps_p
)
2771 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2772 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2775 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2779 /* Set clipping for output of glyph string S. S may be part of a mode
2780 line or menu if we don't have X toolkit support. */
2783 x_set_glyph_string_clipping (s
)
2784 struct glyph_string
*s
;
2787 x_get_glyph_string_clip_rect (s
, &r
);
2788 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2792 /* Compute left and right overhang of glyph string S. If S is a glyph
2793 string for a composition, assume overhangs don't exist. */
2796 x_compute_glyph_string_overhangs (s
)
2797 struct glyph_string
*s
;
2800 && s
->first_glyph
->type
== CHAR_GLYPH
)
2803 int direction
, font_ascent
, font_descent
;
2804 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2805 &font_ascent
, &font_descent
, &cs
);
2806 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2807 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2812 /* Compute overhangs and x-positions for glyph string S and its
2813 predecessors, or successors. X is the starting x-position for S.
2814 BACKWARD_P non-zero means process predecessors. */
2817 x_compute_overhangs_and_x (s
, x
, backward_p
)
2818 struct glyph_string
*s
;
2826 x_compute_glyph_string_overhangs (s
);
2836 x_compute_glyph_string_overhangs (s
);
2845 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2846 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2847 assumed to be zero. */
2850 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2851 struct glyph
*glyph
;
2857 if (glyph
->type
== CHAR_GLYPH
)
2861 struct font_info
*font_info
;
2865 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2867 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2869 && (pcm
= x_per_char_metric (font
, &char2b
)))
2871 if (pcm
->rbearing
> pcm
->width
)
2872 *right
= pcm
->rbearing
- pcm
->width
;
2873 if (pcm
->lbearing
< 0)
2874 *left
= -pcm
->lbearing
;
2880 /* Return the index of the first glyph preceding glyph string S that
2881 is overwritten by S because of S's left overhang. Value is -1
2882 if no glyphs are overwritten. */
2885 x_left_overwritten (s
)
2886 struct glyph_string
*s
;
2890 if (s
->left_overhang
)
2893 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2894 int first
= s
->first_glyph
- glyphs
;
2896 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2897 x
-= glyphs
[i
].pixel_width
;
2908 /* Return the index of the first glyph preceding glyph string S that
2909 is overwriting S because of its right overhang. Value is -1 if no
2910 glyph in front of S overwrites S. */
2913 x_left_overwriting (s
)
2914 struct glyph_string
*s
;
2917 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2918 int first
= s
->first_glyph
- glyphs
;
2922 for (i
= first
- 1; i
>= 0; --i
)
2925 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2928 x
-= glyphs
[i
].pixel_width
;
2935 /* Return the index of the last glyph following glyph string S that is
2936 not overwritten by S because of S's right overhang. Value is -1 if
2937 no such glyph is found. */
2940 x_right_overwritten (s
)
2941 struct glyph_string
*s
;
2945 if (s
->right_overhang
)
2948 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2949 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2950 int end
= s
->row
->used
[s
->area
];
2952 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
2953 x
+= glyphs
[i
].pixel_width
;
2962 /* Return the index of the last glyph following glyph string S that
2963 overwrites S because of its left overhang. Value is negative
2964 if no such glyph is found. */
2967 x_right_overwriting (s
)
2968 struct glyph_string
*s
;
2971 int end
= s
->row
->used
[s
->area
];
2972 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2973 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2977 for (i
= first
; i
< end
; ++i
)
2980 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2983 x
+= glyphs
[i
].pixel_width
;
2990 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2993 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2994 struct glyph_string
*s
;
2998 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
2999 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3000 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3001 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3005 /* Draw the background of glyph_string S. If S->background_filled_p
3006 is non-zero don't draw it. FORCE_P non-zero means draw the
3007 background even if it wouldn't be drawn normally. This is used
3008 when a string preceding S draws into the background of S, or S
3009 contains the first component of a composition. */
3012 x_draw_glyph_string_background (s
, force_p
)
3013 struct glyph_string
*s
;
3016 /* Nothing to do if background has already been drawn or if it
3017 shouldn't be drawn in the first place. */
3018 if (!s
->background_filled_p
)
3022 /* Fill background with a stipple pattern. */
3023 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3024 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3025 s
->y
+ s
->face
->box_line_width
,
3026 s
->background_width
,
3027 s
->height
- 2 * s
->face
->box_line_width
);
3028 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3029 s
->background_filled_p
= 1;
3031 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
3032 || s
->font_not_found_p
3033 || s
->extends_to_end_of_line_p
3036 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
3037 s
->background_width
,
3038 s
->height
- 2 * s
->face
->box_line_width
);
3039 s
->background_filled_p
= 1;
3045 /* Draw the foreground of glyph string S. */
3048 x_draw_glyph_string_foreground (s
)
3049 struct glyph_string
*s
;
3053 /* If first glyph of S has a left box line, start drawing the text
3054 of S to the right of that box line. */
3055 if (s
->face
->box
!= FACE_NO_BOX
3056 && s
->first_glyph
->left_box_line_p
)
3057 x
= s
->x
+ s
->face
->box_line_width
;
3061 /* Draw characters of S as rectangles if S's font could not be
3063 if (s
->font_not_found_p
)
3065 for (i
= 0; i
< s
->nchars
; ++i
)
3067 struct glyph
*g
= s
->first_glyph
+ i
;
3068 XDrawRectangle (s
->display
, s
->window
,
3069 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3071 x
+= g
->pixel_width
;
3076 char *char1b
= (char *) s
->char2b
;
3077 int boff
= s
->font_info
->baseline_offset
;
3079 if (s
->font_info
->vertical_centering
)
3080 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3082 /* If we can use 8-bit functions, condense S->char2b. */
3084 for (i
= 0; i
< s
->nchars
; ++i
)
3085 char1b
[i
] = s
->char2b
[i
].byte2
;
3087 /* Draw text with XDrawString if background has already been
3088 filled. Otherwise, use XDrawImageString. (Note that
3089 XDrawImageString is usually faster than XDrawString.) Always
3090 use XDrawImageString when drawing the cursor so that there is
3091 no chance that characters under a box cursor are invisible. */
3092 if (s
->for_overlaps_p
3093 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3095 /* Draw characters with 16-bit or 8-bit functions. */
3097 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3098 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3100 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3101 s
->ybase
- boff
, char1b
, s
->nchars
);
3106 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3107 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3109 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3110 s
->ybase
- boff
, char1b
, s
->nchars
);
3115 /* Draw the foreground of composite glyph string S. */
3118 x_draw_composite_glyph_string_foreground (s
)
3119 struct glyph_string
*s
;
3123 /* If first glyph of S has a left box line, start drawing the text
3124 of S to the right of that box line. */
3125 if (s
->face
->box
!= FACE_NO_BOX
3126 && s
->first_glyph
->left_box_line_p
)
3127 x
= s
->x
+ s
->face
->box_line_width
;
3131 /* S is a glyph string for a composition. S->gidx is the index of
3132 the first character drawn for glyphs of this composition.
3133 S->gidx == 0 means we are drawing the very first character of
3134 this composition. */
3136 /* Draw a rectangle for the composition if the font for the very
3137 first character of the composition could not be loaded. */
3138 if (s
->font_not_found_p
)
3141 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3142 s
->width
- 1, s
->height
- 1);
3146 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3147 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3148 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3149 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3155 #ifdef USE_X_TOOLKIT
3157 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3160 /* Return the frame on which widget WIDGET is used.. Abort if frame
3161 cannot be determined. */
3164 x_frame_of_widget (widget
)
3167 struct x_display_info
*dpyinfo
;
3171 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3173 /* Find the top-level shell of the widget. Note that this function
3174 can be called when the widget is not yet realized, so XtWindow
3175 (widget) == 0. That's the reason we can't simply use
3176 x_any_window_to_frame. */
3177 while (!XtIsTopLevelShell (widget
))
3178 widget
= XtParent (widget
);
3180 /* Look for a frame with that top-level widget. Allocate the color
3181 on that frame to get the right gamma correction value. */
3182 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3183 if (GC_FRAMEP (XCAR (tail
))
3184 && (f
= XFRAME (XCAR (tail
)),
3185 (f
->output_data
.nothing
!= 1
3186 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3187 && f
->output_data
.x
->widget
== widget
)
3194 /* Allocate the color COLOR->pixel on the screen and display of
3195 widget WIDGET in colormap CMAP. If an exact match cannot be
3196 allocated, try the nearest color available. Value is non-zero
3197 if successful. This is called from lwlib. */
3200 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3205 struct frame
*f
= x_frame_of_widget (widget
);
3206 return x_alloc_nearest_color (f
, cmap
, color
);
3210 #endif /* USE_X_TOOLKIT */
3213 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3214 CMAP. If an exact match can't be allocated, try the nearest color
3215 available. Value is non-zero if successful. Set *COLOR to the
3219 x_alloc_nearest_color (f
, cmap
, color
)
3224 Display
*display
= FRAME_X_DISPLAY (f
);
3225 Screen
*screen
= FRAME_X_SCREEN (f
);
3228 gamma_correct (f
, color
);
3229 rc
= XAllocColor (display
, cmap
, color
);
3232 /* If we got to this point, the colormap is full, so we're going
3233 to try to get the next closest color. The algorithm used is
3234 a least-squares matching, which is what X uses for closest
3235 color matching with StaticColor visuals. */
3237 unsigned long nearest_delta
= ~0;
3238 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3239 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3241 for (i
= 0; i
< ncells
; ++i
)
3243 XQueryColors (display
, cmap
, cells
, ncells
);
3245 for (nearest
= i
= 0; i
< ncells
; ++i
)
3247 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3248 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3249 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3250 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3252 if (delta
< nearest_delta
)
3255 nearest_delta
= delta
;
3259 color
->red
= cells
[nearest
].red
;
3260 color
->green
= cells
[nearest
].green
;
3261 color
->blue
= cells
[nearest
].blue
;
3262 rc
= XAllocColor (display
, cmap
, color
);
3265 #ifdef DEBUG_X_COLORS
3267 register_color (color
->pixel
);
3268 #endif /* DEBUG_X_COLORS */
3274 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3275 It's necessary to do this instead of just using PIXEL directly to
3276 get color reference counts right. */
3279 x_copy_color (f
, pixel
)
3281 unsigned long pixel
;
3285 color
.pixel
= pixel
;
3287 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3288 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3290 #ifdef DEBUG_X_COLORS
3291 register_color (pixel
);
3297 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3298 It's necessary to do this instead of just using PIXEL directly to
3299 get color reference counts right. */
3302 x_copy_dpy_color (dpy
, cmap
, pixel
)
3305 unsigned long pixel
;
3309 color
.pixel
= pixel
;
3311 XQueryColor (dpy
, cmap
, &color
);
3312 XAllocColor (dpy
, cmap
, &color
);
3314 #ifdef DEBUG_X_COLORS
3315 register_color (pixel
);
3321 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3322 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3323 If this produces the same color as PIXEL, try a color where all RGB
3324 values have DELTA added. Return the allocated color in *PIXEL.
3325 DISPLAY is the X display, CMAP is the colormap to operate on.
3326 Value is non-zero if successful. */
3329 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3333 unsigned long *pixel
;
3340 /* Get RGB color values. */
3341 color
.pixel
= *pixel
;
3342 XQueryColor (display
, cmap
, &color
);
3344 /* Change RGB values by specified FACTOR. Avoid overflow! */
3345 xassert (factor
>= 0);
3346 new.red
= min (0xffff, factor
* color
.red
);
3347 new.green
= min (0xffff, factor
* color
.green
);
3348 new.blue
= min (0xffff, factor
* color
.blue
);
3350 /* Try to allocate the color. */
3351 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3354 if (new.pixel
== *pixel
)
3356 /* If we end up with the same color as before, try adding
3357 delta to the RGB values. */
3358 x_free_colors (f
, &new.pixel
, 1);
3360 new.red
= min (0xffff, delta
+ color
.red
);
3361 new.green
= min (0xffff, delta
+ color
.green
);
3362 new.blue
= min (0xffff, delta
+ color
.blue
);
3363 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3374 /* Set up the foreground color for drawing relief lines of glyph
3375 string S. RELIEF is a pointer to a struct relief containing the GC
3376 with which lines will be drawn. Use a color that is FACTOR or
3377 DELTA lighter or darker than the relief's background which is found
3378 in S->f->output_data.x->relief_background. If such a color cannot
3379 be allocated, use DEFAULT_PIXEL, instead. */
3382 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3384 struct relief
*relief
;
3387 unsigned long default_pixel
;
3390 struct x_output
*di
= f
->output_data
.x
;
3391 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3392 unsigned long pixel
;
3393 unsigned long background
= di
->relief_background
;
3394 Colormap cmap
= FRAME_X_COLORMAP (f
);
3395 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3396 Display
*dpy
= FRAME_X_DISPLAY (f
);
3398 xgcv
.graphics_exposures
= False
;
3399 xgcv
.line_width
= 1;
3401 /* Free previously allocated color. The color cell will be reused
3402 when it has been freed as many times as it was allocated, so this
3403 doesn't affect faces using the same colors. */
3405 && relief
->allocated_p
)
3407 x_free_colors (f
, &relief
->pixel
, 1);
3408 relief
->allocated_p
= 0;
3411 /* Allocate new color. */
3412 xgcv
.foreground
= default_pixel
;
3414 if (dpyinfo
->n_planes
!= 1
3415 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3417 relief
->allocated_p
= 1;
3418 xgcv
.foreground
= relief
->pixel
= pixel
;
3421 if (relief
->gc
== 0)
3423 xgcv
.stipple
= dpyinfo
->gray
;
3425 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3428 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3432 /* Set up colors for the relief lines around glyph string S. */
3435 x_setup_relief_colors (s
)
3436 struct glyph_string
*s
;
3438 struct x_output
*di
= s
->f
->output_data
.x
;
3439 unsigned long color
;
3441 if (s
->face
->use_box_color_for_shadows_p
)
3442 color
= s
->face
->box_color
;
3447 /* Get the background color of the face. */
3448 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3449 color
= xgcv
.background
;
3452 if (di
->white_relief
.gc
== 0
3453 || color
!= di
->relief_background
)
3455 di
->relief_background
= color
;
3456 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3457 WHITE_PIX_DEFAULT (s
->f
));
3458 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3459 BLACK_PIX_DEFAULT (s
->f
));
3464 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3465 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3466 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3467 relief. LEFT_P non-zero means draw a relief on the left side of
3468 the rectangle. RIGHT_P non-zero means draw a relief on the right
3469 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3473 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3474 raised_p
, left_p
, right_p
, clip_rect
)
3476 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3477 XRectangle
*clip_rect
;
3483 gc
= f
->output_data
.x
->white_relief
.gc
;
3485 gc
= f
->output_data
.x
->black_relief
.gc
;
3486 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3489 for (i
= 0; i
< width
; ++i
)
3490 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3491 left_x
+ i
* left_p
, top_y
+ i
,
3492 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3496 for (i
= 0; i
< width
; ++i
)
3497 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3498 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3500 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3502 gc
= f
->output_data
.x
->black_relief
.gc
;
3504 gc
= f
->output_data
.x
->white_relief
.gc
;
3505 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3508 for (i
= 0; i
< width
; ++i
)
3509 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3510 left_x
+ i
* left_p
, bottom_y
- i
,
3511 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3515 for (i
= 0; i
< width
; ++i
)
3516 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3517 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3519 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3523 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3524 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3525 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3526 left side of the rectangle. RIGHT_P non-zero means draw a line
3527 on the right side of the rectangle. CLIP_RECT is the clipping
3528 rectangle to use when drawing. */
3531 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3532 left_p
, right_p
, clip_rect
)
3533 struct glyph_string
*s
;
3534 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3535 XRectangle
*clip_rect
;
3539 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3540 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3541 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3544 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3545 left_x
, top_y
, right_x
- left_x
, width
);
3549 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3550 left_x
, top_y
, width
, bottom_y
- top_y
);
3553 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3554 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3558 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3559 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3561 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3562 XSetClipMask (s
->display
, s
->gc
, None
);
3566 /* Draw a box around glyph string S. */
3569 x_draw_glyph_string_box (s
)
3570 struct glyph_string
*s
;
3572 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3573 int left_p
, right_p
;
3574 struct glyph
*last_glyph
;
3575 XRectangle clip_rect
;
3577 last_x
= window_box_right (s
->w
, s
->area
);
3578 if (s
->row
->full_width_p
3579 && !s
->w
->pseudo_window_p
)
3581 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3582 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3583 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3586 /* The glyph that may have a right box line. */
3587 last_glyph
= (s
->cmp
|| s
->img
3589 : s
->first_glyph
+ s
->nchars
- 1);
3591 width
= s
->face
->box_line_width
;
3592 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3594 right_x
= ((s
->row
->full_width_p
3596 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3598 bottom_y
= top_y
+ s
->height
- 1;
3600 left_p
= (s
->first_glyph
->left_box_line_p
3601 || (s
->hl
== DRAW_MOUSE_FACE
3603 || s
->prev
->hl
!= s
->hl
)));
3604 right_p
= (last_glyph
->right_box_line_p
3605 || (s
->hl
== DRAW_MOUSE_FACE
3607 || s
->next
->hl
!= s
->hl
)));
3609 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3611 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3612 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3613 left_p
, right_p
, &clip_rect
);
3616 x_setup_relief_colors (s
);
3617 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3618 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3623 /* Draw foreground of image glyph string S. */
3626 x_draw_image_foreground (s
)
3627 struct glyph_string
*s
;
3630 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3632 /* If first glyph of S has a left box line, start drawing it to the
3633 right of that line. */
3634 if (s
->face
->box
!= FACE_NO_BOX
3635 && s
->first_glyph
->left_box_line_p
)
3636 x
= s
->x
+ s
->face
->box_line_width
;
3640 /* If there is a margin around the image, adjust x- and y-position
3644 x
+= s
->img
->margin
;
3645 y
+= s
->img
->margin
;
3652 /* We can't set both a clip mask and use XSetClipRectangles
3653 because the latter also sets a clip mask. We also can't
3654 trust on the shape extension to be available
3655 (XShapeCombineRegion). So, compute the rectangle to draw
3657 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3660 XRectangle clip_rect
, image_rect
, r
;
3662 xgcv
.clip_mask
= s
->img
->mask
;
3663 xgcv
.clip_x_origin
= x
;
3664 xgcv
.clip_y_origin
= y
;
3665 xgcv
.function
= GXcopy
;
3666 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3668 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3671 image_rect
.width
= s
->img
->width
;
3672 image_rect
.height
= s
->img
->height
;
3673 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3674 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3675 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3679 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3680 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3682 /* When the image has a mask, we can expect that at
3683 least part of a mouse highlight or a block cursor will
3684 be visible. If the image doesn't have a mask, make
3685 a block cursor visible by drawing a rectangle around
3686 the image. I believe it's looking better if we do
3687 nothing here for mouse-face. */
3688 if (s
->hl
== DRAW_CURSOR
)
3689 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3690 s
->img
->width
- 1, s
->img
->height
- 1);
3694 /* Draw a rectangle if image could not be loaded. */
3695 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3696 s
->img
->width
- 1, s
->img
->height
- 1);
3700 /* Draw a relief around the image glyph string S. */
3703 x_draw_image_relief (s
)
3704 struct glyph_string
*s
;
3706 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3709 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3711 /* If first glyph of S has a left box line, start drawing it to the
3712 right of that line. */
3713 if (s
->face
->box
!= FACE_NO_BOX
3714 && s
->first_glyph
->left_box_line_p
)
3715 x
= s
->x
+ s
->face
->box_line_width
;
3719 /* If there is a margin around the image, adjust x- and y-position
3723 x
+= s
->img
->margin
;
3724 y
+= s
->img
->margin
;
3727 if (s
->hl
== DRAW_IMAGE_SUNKEN
3728 || s
->hl
== DRAW_IMAGE_RAISED
)
3730 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3731 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3735 thick
= abs (s
->img
->relief
);
3736 raised_p
= s
->img
->relief
> 0;
3741 x1
= x
+ s
->img
->width
+ thick
- 1;
3742 y1
= y
+ s
->img
->height
+ thick
- 1;
3744 x_setup_relief_colors (s
);
3745 x_get_glyph_string_clip_rect (s
, &r
);
3746 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3750 /* Draw the foreground of image glyph string S to PIXMAP. */
3753 x_draw_image_foreground_1 (s
, pixmap
)
3754 struct glyph_string
*s
;
3758 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3760 /* If first glyph of S has a left box line, start drawing it to the
3761 right of that line. */
3762 if (s
->face
->box
!= FACE_NO_BOX
3763 && s
->first_glyph
->left_box_line_p
)
3764 x
= s
->face
->box_line_width
;
3768 /* If there is a margin around the image, adjust x- and y-position
3772 x
+= s
->img
->margin
;
3773 y
+= s
->img
->margin
;
3780 /* We can't set both a clip mask and use XSetClipRectangles
3781 because the latter also sets a clip mask. We also can't
3782 trust on the shape extension to be available
3783 (XShapeCombineRegion). So, compute the rectangle to draw
3785 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3789 xgcv
.clip_mask
= s
->img
->mask
;
3790 xgcv
.clip_x_origin
= x
;
3791 xgcv
.clip_y_origin
= y
;
3792 xgcv
.function
= GXcopy
;
3793 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3795 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3796 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3797 XSetClipMask (s
->display
, s
->gc
, None
);
3801 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3802 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3804 /* When the image has a mask, we can expect that at
3805 least part of a mouse highlight or a block cursor will
3806 be visible. If the image doesn't have a mask, make
3807 a block cursor visible by drawing a rectangle around
3808 the image. I believe it's looking better if we do
3809 nothing here for mouse-face. */
3810 if (s
->hl
== DRAW_CURSOR
)
3811 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3812 s
->img
->width
- 1, s
->img
->height
- 1);
3816 /* Draw a rectangle if image could not be loaded. */
3817 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3818 s
->img
->width
- 1, s
->img
->height
- 1);
3822 /* Draw part of the background of glyph string S. X, Y, W, and H
3823 give the rectangle to draw. */
3826 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3827 struct glyph_string
*s
;
3832 /* Fill background with a stipple pattern. */
3833 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3834 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3835 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3838 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3842 /* Draw image glyph string S.
3845 s->x +-------------------------
3848 | +-------------------------
3851 | | +-------------------
3857 x_draw_image_glyph_string (s
)
3858 struct glyph_string
*s
;
3861 int box_line_width
= s
->face
->box_line_width
;
3862 int margin
= s
->img
->margin
;
3864 Pixmap pixmap
= None
;
3866 height
= s
->height
- 2 * box_line_width
;
3868 /* Fill background with face under the image. Do it only if row is
3869 taller than image or if image has a clip mask to reduce
3871 s
->stippled_p
= s
->face
->stipple
!= 0;
3872 if (height
> s
->img
->height
3875 || s
->img
->pixmap
== 0
3876 || s
->width
!= s
->background_width
)
3878 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3879 x
= s
->x
+ box_line_width
;
3883 y
= s
->y
+ box_line_width
;
3887 /* Create a pixmap as large as the glyph string Fill it with
3888 the background color. Copy the image to it, using its
3889 mask. Copy the temporary pixmap to the display. */
3890 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3891 int depth
= DefaultDepthOfScreen (screen
);
3893 /* Create a pixmap as large as the glyph string. */
3894 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3895 s
->background_width
,
3898 /* Don't clip in the following because we're working on the
3900 XSetClipMask (s
->display
, s
->gc
, None
);
3902 /* Fill the pixmap with the background color/stipple. */
3905 /* Fill background with a stipple pattern. */
3906 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3907 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3908 0, 0, s
->background_width
, s
->height
);
3909 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3914 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3916 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3917 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3918 0, 0, s
->background_width
, s
->height
);
3919 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3923 /* Implementation idea: Is it possible to construct a mask?
3924 We could look at the color at the margins of the image, and
3925 say that this color is probably the background color of the
3927 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3929 s
->background_filled_p
= 1;
3932 /* Draw the foreground. */
3935 x_draw_image_foreground_1 (s
, pixmap
);
3936 x_set_glyph_string_clipping (s
);
3937 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
3938 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3939 XFreePixmap (s
->display
, pixmap
);
3942 x_draw_image_foreground (s
);
3944 /* If we must draw a relief around the image, do it. */
3946 || s
->hl
== DRAW_IMAGE_RAISED
3947 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3948 x_draw_image_relief (s
);
3952 /* Draw stretch glyph string S. */
3955 x_draw_stretch_glyph_string (s
)
3956 struct glyph_string
*s
;
3958 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3959 s
->stippled_p
= s
->face
->stipple
!= 0;
3961 if (s
->hl
== DRAW_CURSOR
3962 && !x_stretch_cursor_p
)
3964 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3965 as wide as the stretch glyph. */
3966 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
3969 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3971 /* Clear rest using the GC of the original non-cursor face. */
3972 if (width
< s
->background_width
)
3974 GC gc
= s
->face
->gc
;
3975 int x
= s
->x
+ width
, y
= s
->y
;
3976 int w
= s
->background_width
- width
, h
= s
->height
;
3979 x_get_glyph_string_clip_rect (s
, &r
);
3980 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
3982 if (s
->face
->stipple
)
3984 /* Fill background with a stipple pattern. */
3985 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3986 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3987 XSetFillStyle (s
->display
, gc
, FillSolid
);
3992 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
3993 XSetForeground (s
->display
, gc
, xgcv
.background
);
3994 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3995 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4000 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4003 s
->background_filled_p
= 1;
4007 /* Draw glyph string S. */
4010 x_draw_glyph_string (s
)
4011 struct glyph_string
*s
;
4013 /* If S draws into the background of its successor, draw the
4014 background of the successor first so that S can draw into it.
4015 This makes S->next use XDrawString instead of XDrawImageString. */
4016 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4018 xassert (s
->next
->img
== NULL
);
4019 x_set_glyph_string_gc (s
->next
);
4020 x_set_glyph_string_clipping (s
->next
);
4021 x_draw_glyph_string_background (s
->next
, 1);
4024 /* Set up S->gc, set clipping and draw S. */
4025 x_set_glyph_string_gc (s
);
4026 x_set_glyph_string_clipping (s
);
4028 switch (s
->first_glyph
->type
)
4031 x_draw_image_glyph_string (s
);
4035 x_draw_stretch_glyph_string (s
);
4039 if (s
->for_overlaps_p
)
4040 s
->background_filled_p
= 1;
4042 x_draw_glyph_string_background (s
, 0);
4043 x_draw_glyph_string_foreground (s
);
4046 case COMPOSITE_GLYPH
:
4047 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4048 s
->background_filled_p
= 1;
4050 x_draw_glyph_string_background (s
, 1);
4051 x_draw_composite_glyph_string_foreground (s
);
4058 if (!s
->for_overlaps_p
)
4060 /* Draw underline. */
4061 if (s
->face
->underline_p
)
4063 unsigned long dy
, h
;
4065 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4067 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
4070 if (s
->face
->underline_defaulted_p
)
4071 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4076 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4077 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4078 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4080 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4084 /* Draw overline. */
4085 if (s
->face
->overline_p
)
4087 unsigned long dy
= 0, h
= 1;
4089 if (s
->face
->overline_color_defaulted_p
)
4090 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4095 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4096 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4097 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4099 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4103 /* Draw strike-through. */
4104 if (s
->face
->strike_through_p
)
4106 unsigned long h
= 1;
4107 unsigned long dy
= (s
->height
- h
) / 2;
4109 if (s
->face
->strike_through_color_defaulted_p
)
4110 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4115 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4116 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4117 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4119 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4124 if (s
->face
->box
!= FACE_NO_BOX
)
4125 x_draw_glyph_string_box (s
);
4128 /* Reset clipping. */
4129 XSetClipMask (s
->display
, s
->gc
, None
);
4133 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4134 struct face
**, int));
4137 /* Load glyph string S with a composition components specified by S->cmp.
4138 FACES is an array of faces for all components of this composition.
4139 S->gidx is the index of the first component for S.
4140 OVERLAPS_P non-zero means S should draw the foreground only, and
4141 use its lines physical height for clipping.
4143 Value is the index of a component not in S. */
4146 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4147 struct glyph_string
*s
;
4148 struct face
**faces
;
4155 s
->for_overlaps_p
= overlaps_p
;
4157 s
->face
= faces
[s
->gidx
];
4158 s
->font
= s
->face
->font
;
4159 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4161 /* For all glyphs of this composition, starting at the offset
4162 S->gidx, until we reach the end of the definition or encounter a
4163 glyph that requires the different face, add it to S. */
4165 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4168 /* All glyph strings for the same composition has the same width,
4169 i.e. the width set for the first component of the composition. */
4171 s
->width
= s
->first_glyph
->pixel_width
;
4173 /* If the specified font could not be loaded, use the frame's
4174 default font, but record the fact that we couldn't load it in
4175 the glyph string so that we can draw rectangles for the
4176 characters of the glyph string. */
4177 if (s
->font
== NULL
)
4179 s
->font_not_found_p
= 1;
4180 s
->font
= FRAME_FONT (s
->f
);
4183 /* Adjust base line for subscript/superscript text. */
4184 s
->ybase
+= s
->first_glyph
->voffset
;
4186 xassert (s
->face
&& s
->face
->gc
);
4188 /* This glyph string must always be drawn with 16-bit functions. */
4191 return s
->gidx
+ s
->nchars
;
4195 /* Load glyph string S with a sequence characters.
4196 FACE_ID is the face id of the string. START is the index of the
4197 first glyph to consider, END is the index of the last + 1.
4198 OVERLAPS_P non-zero means S should draw the foreground only, and
4199 use its lines physical height for clipping.
4201 Value is the index of the first glyph not in S. */
4204 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4205 struct glyph_string
*s
;
4207 int start
, end
, overlaps_p
;
4209 struct glyph
*glyph
, *last
;
4211 int glyph_not_available_p
;
4213 xassert (s
->f
== XFRAME (s
->w
->frame
));
4214 xassert (s
->nchars
== 0);
4215 xassert (start
>= 0 && end
> start
);
4217 s
->for_overlaps_p
= overlaps_p
,
4218 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4219 last
= s
->row
->glyphs
[s
->area
] + end
;
4220 voffset
= glyph
->voffset
;
4222 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4225 && glyph
->type
== CHAR_GLYPH
4226 && glyph
->voffset
== voffset
4227 /* Same face id implies same font, nowadays. */
4228 && glyph
->face_id
== face_id
4229 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4233 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4234 s
->char2b
+ s
->nchars
,
4236 s
->two_byte_p
= two_byte_p
;
4238 xassert (s
->nchars
<= end
- start
);
4239 s
->width
+= glyph
->pixel_width
;
4243 s
->font
= s
->face
->font
;
4244 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4246 /* If the specified font could not be loaded, use the frame's font,
4247 but record the fact that we couldn't load it in
4248 S->font_not_found_p so that we can draw rectangles for the
4249 characters of the glyph string. */
4250 if (s
->font
== NULL
|| glyph_not_available_p
)
4252 s
->font_not_found_p
= 1;
4253 s
->font
= FRAME_FONT (s
->f
);
4256 /* Adjust base line for subscript/superscript text. */
4257 s
->ybase
+= voffset
;
4259 xassert (s
->face
&& s
->face
->gc
);
4260 return glyph
- s
->row
->glyphs
[s
->area
];
4264 /* Fill glyph string S from image glyph S->first_glyph. */
4267 x_fill_image_glyph_string (s
)
4268 struct glyph_string
*s
;
4270 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4271 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4273 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4274 s
->font
= s
->face
->font
;
4275 s
->width
= s
->first_glyph
->pixel_width
;
4277 /* Adjust base line for subscript/superscript text. */
4278 s
->ybase
+= s
->first_glyph
->voffset
;
4282 /* Fill glyph string S from stretch glyph S->first_glyph. */
4285 x_fill_stretch_glyph_string (s
)
4286 struct glyph_string
*s
;
4288 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4289 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4290 s
->font
= s
->face
->font
;
4291 s
->width
= s
->first_glyph
->pixel_width
;
4293 /* Adjust base line for subscript/superscript text. */
4294 s
->ybase
+= s
->first_glyph
->voffset
;
4298 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4299 of XChar2b structures for S; it can't be allocated in
4300 x_init_glyph_string because it must be allocated via `alloca'. W
4301 is the window on which S is drawn. ROW and AREA are the glyph row
4302 and area within the row from which S is constructed. START is the
4303 index of the first glyph structure covered by S. HL is a
4304 face-override for drawing S. */
4307 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4308 struct glyph_string
*s
;
4311 struct glyph_row
*row
;
4312 enum glyph_row_area area
;
4314 enum draw_glyphs_face hl
;
4316 bzero (s
, sizeof *s
);
4318 s
->f
= XFRAME (w
->frame
);
4319 s
->display
= FRAME_X_DISPLAY (s
->f
);
4320 s
->window
= FRAME_X_WINDOW (s
->f
);
4325 s
->first_glyph
= row
->glyphs
[area
] + start
;
4326 s
->height
= row
->height
;
4327 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4329 /* Display the internal border below the tool-bar window. */
4330 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4331 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4333 s
->ybase
= s
->y
+ row
->ascent
;
4337 /* Set background width of glyph string S. START is the index of the
4338 first glyph following S. LAST_X is the right-most x-position + 1
4339 in the drawing area. */
4342 x_set_glyph_string_background_width (s
, start
, last_x
)
4343 struct glyph_string
*s
;
4347 /* If the face of this glyph string has to be drawn to the end of
4348 the drawing area, set S->extends_to_end_of_line_p. */
4349 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4351 if (start
== s
->row
->used
[s
->area
]
4352 && s
->hl
== DRAW_NORMAL_TEXT
4353 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4354 || s
->face
->background
!= default_face
->background
4355 || s
->face
->stipple
!= default_face
->stipple
))
4356 s
->extends_to_end_of_line_p
= 1;
4358 /* If S extends its face to the end of the line, set its
4359 background_width to the distance to the right edge of the drawing
4361 if (s
->extends_to_end_of_line_p
)
4362 s
->background_width
= last_x
- s
->x
+ 1;
4364 s
->background_width
= s
->width
;
4368 /* Add a glyph string for a stretch glyph to the list of strings
4369 between HEAD and TAIL. START is the index of the stretch glyph in
4370 row area AREA of glyph row ROW. END is the index of the last glyph
4371 in that glyph row area. X is the current output position assigned
4372 to the new glyph string constructed. HL overrides that face of the
4373 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4374 is the right-most x-position of the drawing area. */
4376 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4377 and below -- keep them on one line. */
4378 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4381 s = (struct glyph_string *) alloca (sizeof *s); \
4382 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4383 x_fill_stretch_glyph_string (s); \
4384 x_append_glyph_string (&HEAD, &TAIL, s); \
4391 /* Add a glyph string for an image glyph to the list of strings
4392 between HEAD and TAIL. START is the index of the image glyph in
4393 row area AREA of glyph row ROW. END is the index of the last glyph
4394 in that glyph row area. X is the current output position assigned
4395 to the new glyph string constructed. HL overrides that face of the
4396 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4397 is the right-most x-position of the drawing area. */
4399 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4402 s = (struct glyph_string *) alloca (sizeof *s); \
4403 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4404 x_fill_image_glyph_string (s); \
4405 x_append_glyph_string (&HEAD, &TAIL, s); \
4412 /* Add a glyph string for a sequence of character glyphs to the list
4413 of strings between HEAD and TAIL. START is the index of the first
4414 glyph in row area AREA of glyph row ROW that is part of the new
4415 glyph string. END is the index of the last glyph in that glyph row
4416 area. X is the current output position assigned to the new glyph
4417 string constructed. HL overrides that face of the glyph; e.g. it
4418 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4419 right-most x-position of the drawing area. */
4421 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4427 c = (ROW)->glyphs[AREA][START].u.ch; \
4428 face_id = (ROW)->glyphs[AREA][START].face_id; \
4430 s = (struct glyph_string *) alloca (sizeof *s); \
4431 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4432 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4433 x_append_glyph_string (&HEAD, &TAIL, s); \
4435 START = x_fill_glyph_string (s, face_id, START, END, \
4441 /* Add a glyph string for a composite sequence to the list of strings
4442 between HEAD and TAIL. START is the index of the first glyph in
4443 row area AREA of glyph row ROW that is part of the new glyph
4444 string. END is the index of the last glyph in that glyph row area.
4445 X is the current output position assigned to the new glyph string
4446 constructed. HL overrides that face of the glyph; e.g. it is
4447 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4448 x-position of the drawing area. */
4450 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4452 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4453 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4454 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4455 struct composition *cmp = composition_table[cmp_id]; \
4456 int glyph_len = cmp->glyph_len; \
4458 struct face **faces; \
4459 struct glyph_string *first_s = NULL; \
4462 base_face = base_face->ascii_face; \
4463 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4464 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4465 /* At first, fill in `char2b' and `faces'. */ \
4466 for (n = 0; n < glyph_len; n++) \
4468 int c = COMPOSITION_GLYPH (cmp, n); \
4469 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4470 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4471 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4472 this_face_id, char2b + n, 1); \
4475 /* Make glyph_strings for each glyph sequence that is drawable by \
4476 the same face, and append them to HEAD/TAIL. */ \
4477 for (n = 0; n < cmp->glyph_len;) \
4479 s = (struct glyph_string *) alloca (sizeof *s); \
4480 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4481 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4489 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4497 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4498 of AREA of glyph row ROW on window W between indices START and END.
4499 HL overrides the face for drawing glyph strings, e.g. it is
4500 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4501 x-positions of the drawing area.
4503 This is an ugly monster macro construct because we must use alloca
4504 to allocate glyph strings (because x_draw_glyphs can be called
4507 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4510 HEAD = TAIL = NULL; \
4511 while (START < END) \
4513 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4514 switch (first_glyph->type) \
4517 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4518 TAIL, HL, X, LAST_X, \
4522 case COMPOSITE_GLYPH: \
4523 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4524 HEAD, TAIL, HL, X, LAST_X,\
4528 case STRETCH_GLYPH: \
4529 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4530 HEAD, TAIL, HL, X, LAST_X); \
4534 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4535 TAIL, HL, X, LAST_X); \
4542 x_set_glyph_string_background_width (s, START, LAST_X); \
4549 /* Draw glyphs between START and END in AREA of ROW on window W,
4550 starting at x-position X. X is relative to AREA in W. HL is a
4551 face-override with the following meaning:
4553 DRAW_NORMAL_TEXT draw normally
4554 DRAW_CURSOR draw in cursor face
4555 DRAW_MOUSE_FACE draw in mouse face.
4556 DRAW_INVERSE_VIDEO draw in mode line face
4557 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4558 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4560 If REAL_START is non-null, return in *REAL_START the real starting
4561 position for display. This can be different from START in case
4562 overlapping glyphs must be displayed. If REAL_END is non-null,
4563 return in *REAL_END the real end position for display. This can be
4564 different from END in case overlapping glyphs must be displayed.
4566 If OVERLAPS_P is non-zero, draw only the foreground of characters
4567 and clip to the physical height of ROW.
4569 Value is the x-position reached, relative to AREA of W. */
4572 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4576 struct glyph_row
*row
;
4577 enum glyph_row_area area
;
4579 enum draw_glyphs_face hl
;
4580 int *real_start
, *real_end
;
4583 struct glyph_string
*head
, *tail
;
4584 struct glyph_string
*s
;
4585 int last_x
, area_width
;
4589 /* Let's rather be paranoid than getting a SEGV. */
4590 start
= max (0, start
);
4591 end
= min (end
, row
->used
[area
]);
4593 *real_start
= start
;
4597 /* Translate X to frame coordinates. Set last_x to the right
4598 end of the drawing area. */
4599 if (row
->full_width_p
)
4601 /* X is relative to the left edge of W, without scroll bars
4603 struct frame
*f
= XFRAME (w
->frame
);
4604 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4605 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4608 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4609 last_x
= window_left_x
+ area_width
;
4611 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4613 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4614 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4620 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4621 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4625 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4626 area_width
= window_box_width (w
, area
);
4627 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4630 /* Build a doubly-linked list of glyph_string structures between
4631 head and tail from what we have to draw. Note that the macro
4632 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4633 the reason we use a separate variable `i'. */
4635 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4638 x_reached
= tail
->x
+ tail
->background_width
;
4642 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4643 the row, redraw some glyphs in front or following the glyph
4644 strings built above. */
4645 if (!overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4648 struct glyph_string
*h
, *t
;
4650 /* Compute overhangs for all glyph strings. */
4651 for (s
= head
; s
; s
= s
->next
)
4652 x_compute_glyph_string_overhangs (s
);
4654 /* Prepend glyph strings for glyphs in front of the first glyph
4655 string that are overwritten because of the first glyph
4656 string's left overhang. The background of all strings
4657 prepended must be drawn because the first glyph string
4659 i
= x_left_overwritten (head
);
4663 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4664 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4668 *real_start
= start
;
4669 x_compute_overhangs_and_x (t
, head
->x
, 1);
4670 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4673 /* Prepend glyph strings for glyphs in front of the first glyph
4674 string that overwrite that glyph string because of their
4675 right overhang. For these strings, only the foreground must
4676 be drawn, because it draws over the glyph string at `head'.
4677 The background must not be drawn because this would overwrite
4678 right overhangs of preceding glyphs for which no glyph
4680 i
= x_left_overwriting (head
);
4683 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4684 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4686 for (s
= h
; s
; s
= s
->next
)
4687 s
->background_filled_p
= 1;
4690 x_compute_overhangs_and_x (t
, head
->x
, 1);
4691 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4694 /* Append glyphs strings for glyphs following the last glyph
4695 string tail that are overwritten by tail. The background of
4696 these strings has to be drawn because tail's foreground draws
4698 i
= x_right_overwritten (tail
);
4701 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4702 DRAW_NORMAL_TEXT
, x
, last_x
,
4704 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4705 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4710 /* Append glyph strings for glyphs following the last glyph
4711 string tail that overwrite tail. The foreground of such
4712 glyphs has to be drawn because it writes into the background
4713 of tail. The background must not be drawn because it could
4714 paint over the foreground of following glyphs. */
4715 i
= x_right_overwriting (tail
);
4718 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4719 DRAW_NORMAL_TEXT
, x
, last_x
,
4721 for (s
= h
; s
; s
= s
->next
)
4722 s
->background_filled_p
= 1;
4723 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4724 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4730 /* Draw all strings. */
4731 for (s
= head
; s
; s
= s
->next
)
4732 x_draw_glyph_string (s
);
4734 /* Value is the x-position up to which drawn, relative to AREA of W.
4735 This doesn't include parts drawn because of overhangs. */
4736 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4737 if (!row
->full_width_p
)
4739 if (area
> LEFT_MARGIN_AREA
)
4740 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4741 if (area
> TEXT_AREA
)
4742 x_reached
-= window_box_width (w
, TEXT_AREA
);
4748 /* Fix the display of area AREA of overlapping row ROW in window W. */
4751 x_fix_overlapping_area (w
, row
, area
)
4753 struct glyph_row
*row
;
4754 enum glyph_row_area area
;
4760 if (area
== LEFT_MARGIN_AREA
)
4762 else if (area
== TEXT_AREA
)
4763 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4765 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4766 + window_box_width (w
, TEXT_AREA
));
4768 for (i
= 0; i
< row
->used
[area
];)
4770 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4772 int start
= i
, start_x
= x
;
4776 x
+= row
->glyphs
[area
][i
].pixel_width
;
4779 while (i
< row
->used
[area
]
4780 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4782 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4784 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4789 x
+= row
->glyphs
[area
][i
].pixel_width
;
4798 /* Output LEN glyphs starting at START at the nominal cursor position.
4799 Advance the nominal cursor over the text. The global variable
4800 updated_window contains the window being updated, updated_row is
4801 the glyph row being updated, and updated_area is the area of that
4802 row being updated. */
4805 x_write_glyphs (start
, len
)
4806 struct glyph
*start
;
4809 int x
, hpos
, real_start
, real_end
;
4811 xassert (updated_window
&& updated_row
);
4816 hpos
= start
- updated_row
->glyphs
[updated_area
];
4817 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4818 updated_row
, updated_area
,
4820 (updated_row
->inverse_p
4821 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4822 &real_start
, &real_end
, 0);
4824 /* If we drew over the cursor, note that it is not visible any more. */
4825 note_overwritten_text_cursor (updated_window
, real_start
,
4826 real_end
- real_start
);
4830 /* Advance the output cursor. */
4831 output_cursor
.hpos
+= len
;
4832 output_cursor
.x
= x
;
4836 /* Insert LEN glyphs from START at the nominal cursor position. */
4839 x_insert_glyphs (start
, len
)
4840 struct glyph
*start
;
4845 int line_height
, shift_by_width
, shifted_region_width
;
4846 struct glyph_row
*row
;
4847 struct glyph
*glyph
;
4848 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4850 xassert (updated_window
&& updated_row
);
4853 f
= XFRAME (WINDOW_FRAME (w
));
4855 /* Get the height of the line we are in. */
4857 line_height
= row
->height
;
4859 /* Get the width of the glyphs to insert. */
4861 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4862 shift_by_width
+= glyph
->pixel_width
;
4864 /* Get the width of the region to shift right. */
4865 shifted_region_width
= (window_box_width (w
, updated_area
)
4870 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4871 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4872 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4873 f
->output_data
.x
->normal_gc
,
4875 shifted_region_width
, line_height
,
4876 frame_x
+ shift_by_width
, frame_y
);
4878 /* Write the glyphs. */
4879 hpos
= start
- row
->glyphs
[updated_area
];
4880 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4881 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4882 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4884 /* Advance the output cursor. */
4885 output_cursor
.hpos
+= len
;
4886 output_cursor
.x
+= shift_by_width
;
4891 /* Delete N glyphs at the nominal cursor position. Not implemented
4902 /* Erase the current text line from the nominal cursor position
4903 (inclusive) to pixel column TO_X (exclusive). The idea is that
4904 everything from TO_X onward is already erased.
4906 TO_X is a pixel position relative to updated_area of
4907 updated_window. TO_X == -1 means clear to the end of this area. */
4910 x_clear_end_of_line (to_x
)
4914 struct window
*w
= updated_window
;
4915 int max_x
, min_y
, max_y
;
4916 int from_x
, from_y
, to_y
;
4918 xassert (updated_window
&& updated_row
);
4919 f
= XFRAME (w
->frame
);
4921 if (updated_row
->full_width_p
)
4923 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4924 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4925 && !w
->pseudo_window_p
)
4926 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4929 max_x
= window_box_width (w
, updated_area
);
4930 max_y
= window_text_bottom_y (w
);
4932 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
4933 of window. For TO_X > 0, truncate to end of drawing area. */
4939 to_x
= min (to_x
, max_x
);
4941 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
4943 /* Notice if the cursor will be cleared by this operation. */
4944 if (!updated_row
->full_width_p
)
4945 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
4947 from_x
= output_cursor
.x
;
4949 /* Translate to frame coordinates. */
4950 if (updated_row
->full_width_p
)
4952 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
4953 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
4957 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
4958 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
4961 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
4962 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
4963 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
4965 /* Prevent inadvertently clearing to end of the X window. */
4966 if (to_x
> from_x
&& to_y
> from_y
)
4969 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4970 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
4977 /* Clear entire frame. If updating_frame is non-null, clear that
4978 frame. Otherwise clear the selected frame. */
4988 f
= SELECTED_FRAME ();
4990 /* Clearing the frame will erase any cursor, so mark them all as no
4992 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4993 output_cursor
.hpos
= output_cursor
.vpos
= 0;
4994 output_cursor
.x
= -1;
4996 /* We don't set the output cursor here because there will always
4997 follow an explicit cursor_to. */
4999 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5001 /* We have to clear the scroll bars, too. If we have changed
5002 colors or something like that, then they should be notified. */
5003 x_scroll_bar_clear (f
);
5005 XFlush (FRAME_X_DISPLAY (f
));
5011 /* Invert the middle quarter of the frame for .15 sec. */
5013 /* We use the select system call to do the waiting, so we have to make
5014 sure it's available. If it isn't, we just won't do visual bells. */
5016 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5019 /* Subtract the `struct timeval' values X and Y, storing the result in
5020 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5023 timeval_subtract (result
, x
, y
)
5024 struct timeval
*result
, x
, y
;
5026 /* Perform the carry for the later subtraction by updating y. This
5027 is safer because on some systems the tv_sec member is unsigned. */
5028 if (x
.tv_usec
< y
.tv_usec
)
5030 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5031 y
.tv_usec
-= 1000000 * nsec
;
5035 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5037 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5038 y
.tv_usec
+= 1000000 * nsec
;
5042 /* Compute the time remaining to wait. tv_usec is certainly
5044 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5045 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5047 /* Return indication of whether the result should be considered
5049 return x
.tv_sec
< y
.tv_sec
;
5061 /* Create a GC that will use the GXxor function to flip foreground
5062 pixels into background pixels. */
5066 values
.function
= GXxor
;
5067 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5068 ^ f
->output_data
.x
->background_pixel
);
5070 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5071 GCFunction
| GCForeground
, &values
);
5075 /* Get the height not including a menu bar widget. */
5076 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5077 /* Height of each line to flash. */
5078 int flash_height
= FRAME_LINE_HEIGHT (f
);
5079 /* These will be the left and right margins of the rectangles. */
5080 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5081 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5085 /* Don't flash the area between a scroll bar and the frame
5086 edge it is next to. */
5087 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5089 case vertical_scroll_bar_left
:
5090 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5093 case vertical_scroll_bar_right
:
5094 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5101 width
= flash_right
- flash_left
;
5103 /* If window is tall, flash top and bottom line. */
5104 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5106 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5108 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5109 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5110 width
, flash_height
);
5111 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5113 (height
- flash_height
5114 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5115 width
, flash_height
);
5118 /* If it is short, flash it all. */
5119 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5120 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5121 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5126 struct timeval wakeup
;
5128 EMACS_GET_TIME (wakeup
);
5130 /* Compute time to wait until, propagating carry from usecs. */
5131 wakeup
.tv_usec
+= 150000;
5132 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5133 wakeup
.tv_usec
%= 1000000;
5135 /* Keep waiting until past the time wakeup. */
5138 struct timeval timeout
;
5140 EMACS_GET_TIME (timeout
);
5142 /* In effect, timeout = wakeup - timeout.
5143 Break if result would be negative. */
5144 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5147 /* Try to wait that long--but we might wake up sooner. */
5148 select (0, NULL
, NULL
, NULL
, &timeout
);
5152 /* If window is tall, flash top and bottom line. */
5153 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5155 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5157 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5158 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5159 width
, flash_height
);
5160 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5162 (height
- flash_height
5163 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5164 width
, flash_height
);
5167 /* If it is short, flash it all. */
5168 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5169 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5170 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5172 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5180 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5183 /* Make audible bell. */
5188 struct frame
*f
= SELECTED_FRAME ();
5190 if (FRAME_X_DISPLAY (f
))
5192 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5199 XBell (FRAME_X_DISPLAY (f
), 0);
5200 XFlush (FRAME_X_DISPLAY (f
));
5207 /* Specify how many text lines, from the top of the window,
5208 should be affected by insert-lines and delete-lines operations.
5209 This, and those operations, are used only within an update
5210 that is bounded by calls to x_update_begin and x_update_end. */
5213 XTset_terminal_window (n
)
5216 /* This function intentionally left blank. */
5221 /***********************************************************************
5223 ***********************************************************************/
5225 /* Perform an insert-lines or delete-lines operation, inserting N
5226 lines or deleting -N lines at vertical position VPOS. */
5229 x_ins_del_lines (vpos
, n
)
5236 /* Scroll part of the display as described by RUN. */
5239 x_scroll_run (w
, run
)
5243 struct frame
*f
= XFRAME (w
->frame
);
5244 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5246 /* Get frame-relative bounding box of the text display area of W,
5247 without mode lines. Include in this box the flags areas to the
5248 left and right of W. */
5249 window_box (w
, -1, &x
, &y
, &width
, &height
);
5250 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5251 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5253 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5254 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5255 bottom_y
= y
+ height
;
5259 /* Scrolling up. Make sure we don't copy part of the mode
5260 line at the bottom. */
5261 if (from_y
+ run
->height
> bottom_y
)
5262 height
= bottom_y
- from_y
;
5264 height
= run
->height
;
5268 /* Scolling down. Make sure we don't copy over the mode line.
5270 if (to_y
+ run
->height
> bottom_y
)
5271 height
= bottom_y
- to_y
;
5273 height
= run
->height
;
5278 /* Cursor off. Will be switched on again in x_update_window_end. */
5282 XCopyArea (FRAME_X_DISPLAY (f
),
5283 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5284 f
->output_data
.x
->normal_gc
,
5294 /***********************************************************************
5296 ***********************************************************************/
5298 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5299 corner of the exposed rectangle. W and H are width and height of
5300 the exposed area. All are pixel values. W or H zero means redraw
5301 the entire frame. */
5304 expose_frame (f
, x
, y
, w
, h
)
5310 TRACE ((stderr
, "expose_frame "));
5312 /* No need to redraw if frame will be redrawn soon. */
5313 if (FRAME_GARBAGED_P (f
))
5315 TRACE ((stderr
, " garbaged\n"));
5319 /* If basic faces haven't been realized yet, there is no point in
5320 trying to redraw anything. This can happen when we get an expose
5321 event while Emacs is starting, e.g. by moving another window. */
5322 if (FRAME_FACE_CACHE (f
) == NULL
5323 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5325 TRACE ((stderr
, " no faces\n"));
5329 if (w
== 0 || h
== 0)
5332 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5333 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5343 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5344 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5346 if (WINDOWP (f
->tool_bar_window
))
5348 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5349 XRectangle window_rect
;
5350 XRectangle intersection_rect
;
5351 int window_x
, window_y
, window_width
, window_height
;
5354 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5355 window_rect
.x
= window_x
;
5356 window_rect
.y
= window_y
;
5357 window_rect
.width
= window_width
;
5358 window_rect
.height
= window_height
;
5360 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5361 expose_window (w
, &intersection_rect
);
5364 #ifndef USE_X_TOOLKIT
5365 if (WINDOWP (f
->menu_bar_window
))
5367 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5368 XRectangle window_rect
;
5369 XRectangle intersection_rect
;
5370 int window_x
, window_y
, window_width
, window_height
;
5373 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5374 window_rect
.x
= window_x
;
5375 window_rect
.y
= window_y
;
5376 window_rect
.width
= window_width
;
5377 window_rect
.height
= window_height
;
5379 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5380 expose_window (w
, &intersection_rect
);
5382 #endif /* not USE_X_TOOLKIT */
5386 /* Redraw (parts) of all windows in the window tree rooted at W that
5387 intersect R. R contains frame pixel coordinates. */
5390 expose_window_tree (w
, r
)
5396 if (!NILP (w
->hchild
))
5397 expose_window_tree (XWINDOW (w
->hchild
), r
);
5398 else if (!NILP (w
->vchild
))
5399 expose_window_tree (XWINDOW (w
->vchild
), r
);
5402 XRectangle window_rect
;
5403 XRectangle intersection_rect
;
5404 struct frame
*f
= XFRAME (w
->frame
);
5405 int window_x
, window_y
, window_width
, window_height
;
5407 /* Frame-relative pixel rectangle of W. */
5408 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5412 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5413 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5414 window_rect
.y
= window_y
;
5417 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5418 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5420 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5422 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5423 expose_window (w
, &intersection_rect
);
5426 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5431 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5432 which intersects rectangle R. R is in window-relative coordinates. */
5435 expose_area (w
, row
, r
, area
)
5437 struct glyph_row
*row
;
5439 enum glyph_row_area area
;
5442 struct glyph
*first
= row
->glyphs
[area
];
5443 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5447 /* Set x to the window-relative start position for drawing glyphs of
5448 AREA. The first glyph of the text area can be partially visible.
5449 The first glyphs of other areas cannot. */
5450 if (area
== LEFT_MARGIN_AREA
)
5452 else if (area
== TEXT_AREA
)
5453 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5455 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5456 + window_box_width (w
, TEXT_AREA
));
5458 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5459 /* If row extends face to end of line write the whole line. */
5460 x_draw_glyphs (w
, x
, row
, area
,
5462 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5466 /* Find the first glyph that must be redrawn. */
5468 && x
+ first
->pixel_width
< r
->x
)
5470 x
+= first
->pixel_width
;
5474 /* Find the last one. */
5478 && x
< r
->x
+ r
->width
)
5480 x
+= last
->pixel_width
;
5486 x_draw_glyphs (w
, first_x
, row
, area
,
5487 first
- row
->glyphs
[area
],
5488 last
- row
->glyphs
[area
],
5489 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5495 /* Redraw the parts of the glyph row ROW on window W intersecting
5496 rectangle R. R is in window-relative coordinates. */
5499 expose_line (w
, row
, r
)
5501 struct glyph_row
*row
;
5504 xassert (row
->enabled_p
);
5506 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5507 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5508 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5512 if (row
->used
[LEFT_MARGIN_AREA
])
5513 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5514 if (row
->used
[TEXT_AREA
])
5515 expose_area (w
, row
, r
, TEXT_AREA
);
5516 if (row
->used
[RIGHT_MARGIN_AREA
])
5517 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5518 x_draw_row_bitmaps (w
, row
);
5523 /* Return non-zero if W's cursor intersects rectangle R. */
5526 x_phys_cursor_in_rect_p (w
, r
)
5530 XRectangle cr
, result
;
5531 struct glyph
*cursor_glyph
;
5533 cursor_glyph
= get_phys_cursor_glyph (w
);
5536 cr
.x
= w
->phys_cursor
.x
;
5537 cr
.y
= w
->phys_cursor
.y
;
5538 cr
.width
= cursor_glyph
->pixel_width
;
5539 cr
.height
= w
->phys_cursor_height
;
5540 return x_intersect_rectangles (&cr
, r
, &result
);
5547 /* Redraw a rectangle of window W. R is a rectangle in window
5548 relative coordinates. Call this function with input blocked. */
5551 expose_window (w
, r
)
5555 struct glyph_row
*row
;
5557 int yb
= window_text_bottom_y (w
);
5558 int cursor_cleared_p
;
5560 /* If window is not yet fully initialized, do nothing. This can
5561 happen when toolkit scroll bars are used and a window is split.
5562 Reconfiguring the scroll bar will generate an expose for a newly
5564 if (w
->current_matrix
== NULL
)
5567 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5568 r
->x
, r
->y
, r
->width
, r
->height
));
5570 /* Convert to window coordinates. */
5571 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5572 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5574 /* Turn off the cursor. */
5575 if (!w
->pseudo_window_p
5576 && x_phys_cursor_in_rect_p (w
, r
))
5579 cursor_cleared_p
= 1;
5582 cursor_cleared_p
= 0;
5584 /* Find the first row intersecting the rectangle R. */
5585 row
= w
->current_matrix
->rows
;
5587 while (row
->enabled_p
5589 && y
+ row
->height
< r
->y
)
5595 /* Display the text in the rectangle, one text line at a time. */
5596 while (row
->enabled_p
5598 && y
< r
->y
+ r
->height
)
5600 expose_line (w
, row
, r
);
5605 /* Display the mode line if there is one. */
5606 if (WINDOW_WANTS_MODELINE_P (w
)
5607 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5609 && row
->y
< r
->y
+ r
->height
)
5610 expose_line (w
, row
, r
);
5612 if (!w
->pseudo_window_p
)
5614 /* Draw border between windows. */
5615 x_draw_vertical_border (w
);
5617 /* Turn the cursor on again. */
5618 if (cursor_cleared_p
)
5619 x_update_window_cursor (w
, 1);
5624 /* Determine the intersection of two rectangles R1 and R2. Return
5625 the intersection in *RESULT. Value is non-zero if RESULT is not
5629 x_intersect_rectangles (r1
, r2
, result
)
5630 XRectangle
*r1
, *r2
, *result
;
5632 XRectangle
*left
, *right
;
5633 XRectangle
*upper
, *lower
;
5634 int intersection_p
= 0;
5636 /* Rearrange so that R1 is the left-most rectangle. */
5638 left
= r1
, right
= r2
;
5640 left
= r2
, right
= r1
;
5642 /* X0 of the intersection is right.x0, if this is inside R1,
5643 otherwise there is no intersection. */
5644 if (right
->x
<= left
->x
+ left
->width
)
5646 result
->x
= right
->x
;
5648 /* The right end of the intersection is the minimum of the
5649 the right ends of left and right. */
5650 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5653 /* Same game for Y. */
5655 upper
= r1
, lower
= r2
;
5657 upper
= r2
, lower
= r1
;
5659 /* The upper end of the intersection is lower.y0, if this is inside
5660 of upper. Otherwise, there is no intersection. */
5661 if (lower
->y
<= upper
->y
+ upper
->height
)
5663 result
->y
= lower
->y
;
5665 /* The lower end of the intersection is the minimum of the lower
5666 ends of upper and lower. */
5667 result
->height
= (min (lower
->y
+ lower
->height
,
5668 upper
->y
+ upper
->height
)
5674 return intersection_p
;
5685 /* We used to only do this if Vx_no_window_manager was non-nil, but
5686 the ICCCM (section 4.1.6) says that the window's border pixmap
5687 and border pixel are window attributes which are "private to the
5688 client", so we can always change it to whatever we want. */
5690 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5691 f
->output_data
.x
->border_pixel
);
5693 x_update_cursor (f
, 1);
5697 frame_unhighlight (f
)
5700 /* We used to only do this if Vx_no_window_manager was non-nil, but
5701 the ICCCM (section 4.1.6) says that the window's border pixmap
5702 and border pixel are window attributes which are "private to the
5703 client", so we can always change it to whatever we want. */
5705 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5706 f
->output_data
.x
->border_tile
);
5708 x_update_cursor (f
, 1);
5711 /* The focus has changed. Update the frames as necessary to reflect
5712 the new situation. Note that we can't change the selected frame
5713 here, because the Lisp code we are interrupting might become confused.
5714 Each event gets marked with the frame in which it occurred, so the
5715 Lisp code can tell when the switch took place by examining the events. */
5718 x_new_focus_frame (dpyinfo
, frame
)
5719 struct x_display_info
*dpyinfo
;
5720 struct frame
*frame
;
5722 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5724 if (frame
!= dpyinfo
->x_focus_frame
)
5726 /* Set this before calling other routines, so that they see
5727 the correct value of x_focus_frame. */
5728 dpyinfo
->x_focus_frame
= frame
;
5730 if (old_focus
&& old_focus
->auto_lower
)
5731 x_lower_frame (old_focus
);
5734 selected_frame
= frame
;
5735 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5737 Fselect_window (selected_frame
->selected_window
);
5738 choose_minibuf_frame ();
5741 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5742 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5744 pending_autoraise_frame
= 0;
5747 x_frame_rehighlight (dpyinfo
);
5750 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5753 x_mouse_leave (dpyinfo
)
5754 struct x_display_info
*dpyinfo
;
5756 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5759 /* The focus has changed, or we have redirected a frame's focus to
5760 another frame (this happens when a frame uses a surrogate
5761 mini-buffer frame). Shift the highlight as appropriate.
5763 The FRAME argument doesn't necessarily have anything to do with which
5764 frame is being highlighted or un-highlighted; we only use it to find
5765 the appropriate X display info. */
5768 XTframe_rehighlight (frame
)
5769 struct frame
*frame
;
5771 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5775 x_frame_rehighlight (dpyinfo
)
5776 struct x_display_info
*dpyinfo
;
5778 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5780 if (dpyinfo
->x_focus_frame
)
5782 dpyinfo
->x_highlight_frame
5783 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5784 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5785 : dpyinfo
->x_focus_frame
);
5786 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5788 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5789 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5793 dpyinfo
->x_highlight_frame
= 0;
5795 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5798 frame_unhighlight (old_highlight
);
5799 if (dpyinfo
->x_highlight_frame
)
5800 frame_highlight (dpyinfo
->x_highlight_frame
);
5806 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5808 /* Initialize mode_switch_bit and modifier_meaning. */
5810 x_find_modifier_meanings (dpyinfo
)
5811 struct x_display_info
*dpyinfo
;
5813 int min_code
, max_code
;
5816 XModifierKeymap
*mods
;
5818 dpyinfo
->meta_mod_mask
= 0;
5819 dpyinfo
->shift_lock_mask
= 0;
5820 dpyinfo
->alt_mod_mask
= 0;
5821 dpyinfo
->super_mod_mask
= 0;
5822 dpyinfo
->hyper_mod_mask
= 0;
5825 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5827 min_code
= dpyinfo
->display
->min_keycode
;
5828 max_code
= dpyinfo
->display
->max_keycode
;
5831 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5832 min_code
, max_code
- min_code
+ 1,
5834 mods
= XGetModifierMapping (dpyinfo
->display
);
5836 /* Scan the modifier table to see which modifier bits the Meta and
5837 Alt keysyms are on. */
5839 int row
, col
; /* The row and column in the modifier table. */
5841 for (row
= 3; row
< 8; row
++)
5842 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5845 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5847 /* Zeroes are used for filler. Skip them. */
5851 /* Are any of this keycode's keysyms a meta key? */
5855 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5857 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5863 dpyinfo
->meta_mod_mask
|= (1 << row
);
5868 dpyinfo
->alt_mod_mask
|= (1 << row
);
5873 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5878 dpyinfo
->super_mod_mask
|= (1 << row
);
5882 /* Ignore this if it's not on the lock modifier. */
5883 if ((1 << row
) == LockMask
)
5884 dpyinfo
->shift_lock_mask
= LockMask
;
5892 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5893 if (! dpyinfo
->meta_mod_mask
)
5895 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
5896 dpyinfo
->alt_mod_mask
= 0;
5899 /* If some keys are both alt and meta,
5900 make them just meta, not alt. */
5901 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
5903 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
5906 XFree ((char *) syms
);
5907 XFreeModifiermap (mods
);
5910 /* Convert between the modifier bits X uses and the modifier bits
5914 x_x_to_emacs_modifiers (dpyinfo
, state
)
5915 struct x_display_info
*dpyinfo
;
5918 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
5919 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
5920 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
5921 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
5922 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
5923 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
5927 x_emacs_to_x_modifiers (dpyinfo
, state
)
5928 struct x_display_info
*dpyinfo
;
5931 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
5932 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
5933 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
5934 | ((state
& shift_modifier
) ? ShiftMask
: 0)
5935 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
5936 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
5939 /* Convert a keysym to its name. */
5942 x_get_keysym_name (keysym
)
5948 value
= XKeysymToString (keysym
);
5956 /* Mouse clicks and mouse movement. Rah. */
5958 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5959 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5960 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5961 not force the value into range. */
5964 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5966 register int pix_x
, pix_y
;
5967 register int *x
, *y
;
5971 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5972 even for negative values. */
5974 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
5976 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
5978 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5979 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5983 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
5984 bounds
->height
= f
->output_data
.x
->line_height
;
5985 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5986 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5993 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5994 pix_x
= FRAME_WINDOW_WIDTH (f
);
5998 else if (pix_y
> f
->height
)
6007 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6008 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6009 can't tell the positions because W's display is not up to date,
6013 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6016 int *frame_x
, *frame_y
;
6020 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6021 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6023 if (display_completed
)
6025 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6026 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6027 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6033 *frame_x
+= glyph
->pixel_width
;
6041 *frame_y
= *frame_x
= 0;
6045 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6046 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6051 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6053 If the event is a button press, then note that we have grabbed
6057 construct_mouse_click (result
, event
, f
)
6058 struct input_event
*result
;
6059 XButtonEvent
*event
;
6062 /* Make the event type no_event; we'll change that when we decide
6064 result
->kind
= mouse_click
;
6065 result
->code
= event
->button
- Button1
;
6066 result
->timestamp
= event
->time
;
6067 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6069 | (event
->type
== ButtonRelease
6073 XSETINT (result
->x
, event
->x
);
6074 XSETINT (result
->y
, event
->y
);
6075 XSETFRAME (result
->frame_or_window
, f
);
6079 #if 0 /* This function isn't called. --gerd */
6081 /* Prepare a menu-event in *RESULT for placement in the input queue. */
6084 construct_menu_click (result
, event
, f
)
6085 struct input_event
*result
;
6086 XButtonEvent
*event
;
6089 /* Make the event type no_event; we'll change that when we decide
6091 result
->kind
= mouse_click
;
6092 result
->code
= event
->button
- Button1
;
6093 result
->timestamp
= event
->time
;
6094 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6096 | (event
->type
== ButtonRelease
6100 XSETINT (result
->x
, event
->x
);
6101 XSETINT (result
->y
, -1);
6102 XSETFRAME (result
->frame_or_window
, f
);
6108 /* Function to report a mouse movement to the mainstream Emacs code.
6109 The input handler calls this.
6111 We have received a mouse movement event, which is given in *event.
6112 If the mouse is over a different glyph than it was last time, tell
6113 the mainstream emacs code by setting mouse_moved. If not, ask for
6114 another motion event, so we can check again the next time it moves. */
6116 static XMotionEvent last_mouse_motion_event
;
6117 static Lisp_Object last_mouse_motion_frame
;
6120 note_mouse_movement (frame
, event
)
6122 XMotionEvent
*event
;
6124 last_mouse_movement_time
= event
->time
;
6125 last_mouse_motion_event
= *event
;
6126 XSETFRAME (last_mouse_motion_frame
, frame
);
6128 if (event
->window
!= FRAME_X_WINDOW (frame
))
6130 frame
->mouse_moved
= 1;
6131 last_mouse_scroll_bar
= Qnil
;
6132 note_mouse_highlight (frame
, -1, -1);
6135 /* Has the mouse moved off the glyph it was on at the last sighting? */
6136 else if (event
->x
< last_mouse_glyph
.x
6137 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6138 || event
->y
< last_mouse_glyph
.y
6139 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6141 frame
->mouse_moved
= 1;
6142 last_mouse_scroll_bar
= Qnil
;
6143 note_mouse_highlight (frame
, event
->x
, event
->y
);
6147 /* This is used for debugging, to turn off note_mouse_highlight. */
6149 int disable_mouse_highlight
;
6153 /************************************************************************
6155 ************************************************************************/
6157 /* Find the glyph under window-relative coordinates X/Y in window W.
6158 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6159 strings. Return in *HPOS and *VPOS the row and column number of
6160 the glyph found. Return in *AREA the glyph area containing X.
6161 Value is a pointer to the glyph found or null if X/Y is not on
6162 text, or we can't tell because W's current matrix is not up to
6165 static struct glyph
*
6166 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6169 int *hpos
, *vpos
, *area
;
6171 struct glyph
*glyph
, *end
;
6172 struct glyph_row
*row
= NULL
;
6173 int x0
, i
, left_area_width
;
6175 /* Find row containing Y. Give up if some row is not enabled. */
6176 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6178 row
= MATRIX_ROW (w
->current_matrix
, i
);
6179 if (!row
->enabled_p
)
6181 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6188 /* Give up if Y is not in the window. */
6189 if (i
== w
->current_matrix
->nrows
)
6192 /* Get the glyph area containing X. */
6193 if (w
->pseudo_window_p
)
6200 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6201 if (x
< left_area_width
)
6203 *area
= LEFT_MARGIN_AREA
;
6206 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6209 x0
= row
->x
+ left_area_width
;
6213 *area
= RIGHT_MARGIN_AREA
;
6214 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6218 /* Find glyph containing X. */
6219 glyph
= row
->glyphs
[*area
];
6220 end
= glyph
+ row
->used
[*area
];
6223 if (x
< x0
+ glyph
->pixel_width
)
6225 if (w
->pseudo_window_p
)
6227 else if (BUFFERP (glyph
->object
))
6231 x0
+= glyph
->pixel_width
;
6238 *hpos
= glyph
- row
->glyphs
[*area
];
6243 /* Convert frame-relative x/y to coordinates relative to window W.
6244 Takes pseudo-windows into account. */
6247 frame_to_window_pixel_xy (w
, x
, y
)
6251 if (w
->pseudo_window_p
)
6253 /* A pseudo-window is always full-width, and starts at the
6254 left edge of the frame, plus a frame border. */
6255 struct frame
*f
= XFRAME (w
->frame
);
6256 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6257 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6261 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6262 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6267 /* Take proper action when mouse has moved to the mode or top line of
6268 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6269 mode line. X is relative to the start of the text display area of
6270 W, so the width of bitmap areas and scroll bars must be subtracted
6271 to get a position relative to the start of the mode line. */
6274 note_mode_line_highlight (w
, x
, mode_line_p
)
6278 struct frame
*f
= XFRAME (w
->frame
);
6279 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6280 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6281 struct glyph_row
*row
;
6284 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6286 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6290 struct glyph
*glyph
, *end
;
6291 Lisp_Object help
, map
;
6294 /* Find the glyph under X. */
6295 glyph
= row
->glyphs
[TEXT_AREA
];
6296 end
= glyph
+ row
->used
[TEXT_AREA
];
6297 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6298 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6300 && x
>= x0
+ glyph
->pixel_width
)
6302 x0
+= glyph
->pixel_width
;
6307 && STRINGP (glyph
->object
)
6308 && XSTRING (glyph
->object
)->intervals
6309 && glyph
->charpos
>= 0
6310 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6312 /* If we're on a string with `help-echo' text property,
6313 arrange for the help to be displayed. This is done by
6314 setting the global variable help_echo to the help string. */
6315 help
= Fget_text_property (make_number (glyph
->charpos
),
6316 Qhelp_echo
, glyph
->object
);
6320 /* Change the mouse pointer according to what is under X/Y. */
6321 map
= Fget_text_property (make_number (glyph
->charpos
),
6322 Qlocal_map
, glyph
->object
);
6323 if (!NILP (Fkeymapp (map
)))
6324 cursor
= f
->output_data
.x
->nontext_cursor
;
6328 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6332 /* Take proper action when the mouse has moved to position X, Y on
6333 frame F as regards highlighting characters that have mouse-face
6334 properties. Also de-highlighting chars where the mouse was before.
6335 X and Y can be negative or out of range. */
6338 note_mouse_highlight (f
, x
, y
)
6342 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6347 /* When a menu is active, don't highlight because this looks odd. */
6348 #ifdef USE_X_TOOLKIT
6349 if (popup_activated ())
6353 if (disable_mouse_highlight
6354 || !f
->glyphs_initialized_p
)
6357 dpyinfo
->mouse_face_mouse_x
= x
;
6358 dpyinfo
->mouse_face_mouse_y
= y
;
6359 dpyinfo
->mouse_face_mouse_frame
= f
;
6361 if (dpyinfo
->mouse_face_defer
)
6366 dpyinfo
->mouse_face_deferred_gc
= 1;
6370 /* Which window is that in? */
6371 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6373 /* If we were displaying active text in another window, clear that. */
6374 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6375 clear_mouse_face (dpyinfo
);
6377 /* Not on a window -> return. */
6378 if (!WINDOWP (window
))
6381 /* Convert to window-relative pixel coordinates. */
6382 w
= XWINDOW (window
);
6383 frame_to_window_pixel_xy (w
, &x
, &y
);
6385 /* Handle tool-bar window differently since it doesn't display a
6387 if (EQ (window
, f
->tool_bar_window
))
6389 note_tool_bar_highlight (f
, x
, y
);
6393 if (portion
== 1 || portion
== 3)
6395 /* Mouse is on the mode or top line. */
6396 note_mode_line_highlight (w
, x
, portion
== 1);
6400 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6401 f
->output_data
.x
->text_cursor
);
6403 /* Are we in a window whose display is up to date?
6404 And verify the buffer's text has not changed. */
6405 if (/* Within text portion of the window. */
6407 && EQ (w
->window_end_valid
, w
->buffer
)
6408 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6409 && (XFASTINT (w
->last_overlay_modified
)
6410 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6412 int hpos
, vpos
, pos
, i
, area
;
6413 struct glyph
*glyph
;
6415 /* Find the glyph under X/Y. */
6416 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6418 /* Clear mouse face if X/Y not over text. */
6420 || area
!= TEXT_AREA
6421 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6423 clear_mouse_face (dpyinfo
);
6427 pos
= glyph
->charpos
;
6428 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6430 /* Check for mouse-face and help-echo. */
6432 Lisp_Object mouse_face
, overlay
, position
;
6433 Lisp_Object
*overlay_vec
;
6435 struct buffer
*obuf
;
6438 /* If we get an out-of-range value, return now; avoid an error. */
6439 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6442 /* Make the window's buffer temporarily current for
6443 overlays_at and compute_char_face. */
6444 obuf
= current_buffer
;
6445 current_buffer
= XBUFFER (w
->buffer
);
6451 /* Is this char mouse-active or does it have help-echo? */
6452 XSETINT (position
, pos
);
6454 /* Put all the overlays we want in a vector in overlay_vec.
6455 Store the length in len. If there are more than 10, make
6456 enough space for all, and try again. */
6458 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6459 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6460 if (noverlays
> len
)
6463 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6464 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6467 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6469 /* Check mouse-face highlighting. */
6470 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6471 && vpos
>= dpyinfo
->mouse_face_beg_row
6472 && vpos
<= dpyinfo
->mouse_face_end_row
6473 && (vpos
> dpyinfo
->mouse_face_beg_row
6474 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6475 && (vpos
< dpyinfo
->mouse_face_end_row
6476 || hpos
< dpyinfo
->mouse_face_end_col
6477 || dpyinfo
->mouse_face_past_end
)))
6479 /* Clear the display of the old active region, if any. */
6480 clear_mouse_face (dpyinfo
);
6482 /* Find the highest priority overlay that has a mouse-face prop. */
6484 for (i
= 0; i
< noverlays
; i
++)
6486 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6487 if (!NILP (mouse_face
))
6489 overlay
= overlay_vec
[i
];
6494 /* If no overlay applies, get a text property. */
6496 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6498 /* Handle the overlay case. */
6499 if (! NILP (overlay
))
6501 /* Find the range of text around this char that
6502 should be active. */
6503 Lisp_Object before
, after
;
6506 before
= Foverlay_start (overlay
);
6507 after
= Foverlay_end (overlay
);
6508 /* Record this as the current active region. */
6509 fast_find_position (w
, XFASTINT (before
),
6510 &dpyinfo
->mouse_face_beg_col
,
6511 &dpyinfo
->mouse_face_beg_row
,
6512 &dpyinfo
->mouse_face_beg_x
,
6513 &dpyinfo
->mouse_face_beg_y
);
6514 dpyinfo
->mouse_face_past_end
6515 = !fast_find_position (w
, XFASTINT (after
),
6516 &dpyinfo
->mouse_face_end_col
,
6517 &dpyinfo
->mouse_face_end_row
,
6518 &dpyinfo
->mouse_face_end_x
,
6519 &dpyinfo
->mouse_face_end_y
);
6520 dpyinfo
->mouse_face_window
= window
;
6521 dpyinfo
->mouse_face_face_id
6522 = face_at_buffer_position (w
, pos
, 0, 0,
6523 &ignore
, pos
+ 1, 1);
6525 /* Display it as active. */
6526 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6528 /* Handle the text property case. */
6529 else if (! NILP (mouse_face
))
6531 /* Find the range of text around this char that
6532 should be active. */
6533 Lisp_Object before
, after
, beginning
, end
;
6536 beginning
= Fmarker_position (w
->start
);
6537 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6538 - XFASTINT (w
->window_end_pos
)));
6540 = Fprevious_single_property_change (make_number (pos
+ 1),
6542 w
->buffer
, beginning
);
6544 = Fnext_single_property_change (position
, Qmouse_face
,
6546 /* Record this as the current active region. */
6547 fast_find_position (w
, XFASTINT (before
),
6548 &dpyinfo
->mouse_face_beg_col
,
6549 &dpyinfo
->mouse_face_beg_row
,
6550 &dpyinfo
->mouse_face_beg_x
,
6551 &dpyinfo
->mouse_face_beg_y
);
6552 dpyinfo
->mouse_face_past_end
6553 = !fast_find_position (w
, XFASTINT (after
),
6554 &dpyinfo
->mouse_face_end_col
,
6555 &dpyinfo
->mouse_face_end_row
,
6556 &dpyinfo
->mouse_face_end_x
,
6557 &dpyinfo
->mouse_face_end_y
);
6558 dpyinfo
->mouse_face_window
= window
;
6559 dpyinfo
->mouse_face_face_id
6560 = face_at_buffer_position (w
, pos
, 0, 0,
6561 &ignore
, pos
+ 1, 1);
6563 /* Display it as active. */
6564 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6568 /* Look for a `help-echo' property. */
6572 /* Check overlays first. */
6574 for (i
= 0; i
< noverlays
&& !STRINGP (help
); ++i
)
6575 help
= Foverlay_get (overlay_vec
[i
], Qhelp_echo
);
6577 /* Try text properties. */
6579 && ((STRINGP (glyph
->object
)
6580 && glyph
->charpos
>= 0
6581 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6582 || (BUFFERP (glyph
->object
)
6583 && glyph
->charpos
>= BEGV
6584 && glyph
->charpos
< ZV
)))
6585 help
= Fget_text_property (make_number (glyph
->charpos
),
6586 Qhelp_echo
, glyph
->object
);
6594 current_buffer
= obuf
;
6600 redo_mouse_highlight ()
6602 if (!NILP (last_mouse_motion_frame
)
6603 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6604 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6605 last_mouse_motion_event
.x
,
6606 last_mouse_motion_event
.y
);
6611 /***********************************************************************
6613 ***********************************************************************/
6615 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6616 struct glyph
**, int *, int *, int *));
6618 /* Tool-bar item index of the item on which a mouse button was pressed
6621 static int last_tool_bar_item
;
6624 /* Get information about the tool-bar item at position X/Y on frame F.
6625 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6626 the current matrix of the tool-bar window of F, or NULL if not
6627 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6628 item in F->current_tool_bar_items. Value is
6630 -1 if X/Y is not on a tool-bar item
6631 0 if X/Y is on the same item that was highlighted before.
6635 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6638 struct glyph
**glyph
;
6639 int *hpos
, *vpos
, *prop_idx
;
6641 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6642 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6645 /* Find the glyph under X/Y. */
6646 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6650 /* Get the start of this tool-bar item's properties in
6651 f->current_tool_bar_items. */
6652 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6655 /* Is mouse on the highlighted item? */
6656 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6657 && *vpos
>= dpyinfo
->mouse_face_beg_row
6658 && *vpos
<= dpyinfo
->mouse_face_end_row
6659 && (*vpos
> dpyinfo
->mouse_face_beg_row
6660 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6661 && (*vpos
< dpyinfo
->mouse_face_end_row
6662 || *hpos
< dpyinfo
->mouse_face_end_col
6663 || dpyinfo
->mouse_face_past_end
))
6670 /* Handle mouse button event on the tool-bar of frame F, at
6671 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6675 x_handle_tool_bar_click (f
, button_event
)
6677 XButtonEvent
*button_event
;
6679 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6680 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6681 int hpos
, vpos
, prop_idx
;
6682 struct glyph
*glyph
;
6683 Lisp_Object enabled_p
;
6684 int x
= button_event
->x
;
6685 int y
= button_event
->y
;
6687 /* If not on the highlighted tool-bar item, return. */
6688 frame_to_window_pixel_xy (w
, &x
, &y
);
6689 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6692 /* If item is disabled, do nothing. */
6693 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6694 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6695 if (NILP (enabled_p
))
6698 if (button_event
->type
== ButtonPress
)
6700 /* Show item in pressed state. */
6701 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6702 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6703 last_tool_bar_item
= prop_idx
;
6707 Lisp_Object key
, frame
;
6708 struct input_event event
;
6710 /* Show item in released state. */
6711 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6712 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6714 key
= (XVECTOR (f
->current_tool_bar_items
)
6715 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6717 XSETFRAME (frame
, f
);
6718 event
.kind
= TOOL_BAR_EVENT
;
6719 event
.frame_or_window
= Fcons (frame
, Fcons (Qtool_bar
, Qnil
));
6720 kbd_buffer_store_event (&event
);
6722 event
.kind
= TOOL_BAR_EVENT
;
6723 event
.frame_or_window
= Fcons (frame
, key
);
6724 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6725 button_event
->state
);
6726 kbd_buffer_store_event (&event
);
6727 last_tool_bar_item
= -1;
6732 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6733 tool-bar window-relative coordinates X/Y. Called from
6734 note_mouse_highlight. */
6737 note_tool_bar_highlight (f
, x
, y
)
6741 Lisp_Object window
= f
->tool_bar_window
;
6742 struct window
*w
= XWINDOW (window
);
6743 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6745 struct glyph
*glyph
;
6746 struct glyph_row
*row
;
6748 Lisp_Object enabled_p
;
6750 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6751 int mouse_down_p
, rc
;
6753 /* Function note_mouse_highlight is called with negative x(y
6754 values when mouse moves outside of the frame. */
6755 if (x
<= 0 || y
<= 0)
6757 clear_mouse_face (dpyinfo
);
6761 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6764 /* Not on tool-bar item. */
6765 clear_mouse_face (dpyinfo
);
6769 /* On same tool-bar item as before. */
6772 clear_mouse_face (dpyinfo
);
6774 /* Mouse is down, but on different tool-bar item? */
6775 mouse_down_p
= (dpyinfo
->grabbed
6776 && f
== last_mouse_frame
6777 && FRAME_LIVE_P (f
));
6779 && last_tool_bar_item
!= prop_idx
)
6782 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6783 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6785 /* If tool-bar item is not enabled, don't highlight it. */
6786 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6787 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6788 if (!NILP (enabled_p
))
6790 /* Compute the x-position of the glyph. In front and past the
6791 image is a space. We include this is the highlighted area. */
6792 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6793 for (i
= x
= 0; i
< hpos
; ++i
)
6794 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6796 /* Record this as the current active region. */
6797 dpyinfo
->mouse_face_beg_col
= hpos
;
6798 dpyinfo
->mouse_face_beg_row
= vpos
;
6799 dpyinfo
->mouse_face_beg_x
= x
;
6800 dpyinfo
->mouse_face_beg_y
= row
->y
;
6801 dpyinfo
->mouse_face_past_end
= 0;
6803 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6804 dpyinfo
->mouse_face_end_row
= vpos
;
6805 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6806 dpyinfo
->mouse_face_end_y
= row
->y
;
6807 dpyinfo
->mouse_face_window
= window
;
6808 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6810 /* Display it as active. */
6811 show_mouse_face (dpyinfo
, draw
);
6812 dpyinfo
->mouse_face_image_state
= draw
;
6817 /* Set help_echo to a help string.to display for this tool-bar item.
6818 XTread_socket does the rest. */
6819 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6820 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6821 if (!STRINGP (help_echo
))
6822 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6823 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6828 /* Find the glyph matrix position of buffer position POS in window W.
6829 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6830 current glyphs must be up to date. If POS is above window start
6831 return (0, 0, 0, 0). If POS is after end of W, return end of
6835 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6838 int *hpos
, *vpos
, *x
, *y
;
6842 int maybe_next_line_p
= 0;
6843 int line_start_position
;
6844 int yb
= window_text_bottom_y (w
);
6845 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6846 struct glyph_row
*best_row
= row
;
6847 int row_vpos
= 0, best_row_vpos
= 0;
6852 if (row
->used
[TEXT_AREA
])
6853 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6855 line_start_position
= 0;
6857 if (line_start_position
> pos
)
6859 /* If the position sought is the end of the buffer,
6860 don't include the blank lines at the bottom of the window. */
6861 else if (line_start_position
== pos
6862 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6864 maybe_next_line_p
= 1;
6867 else if (line_start_position
> 0)
6870 best_row_vpos
= row_vpos
;
6873 if (row
->y
+ row
->height
>= yb
)
6880 /* Find the right column within BEST_ROW. */
6882 current_x
= best_row
->x
;
6883 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6885 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6888 charpos
= glyph
->charpos
;
6892 *vpos
= best_row_vpos
;
6897 else if (charpos
> pos
)
6899 else if (charpos
> 0)
6902 current_x
+= glyph
->pixel_width
;
6905 /* If we're looking for the end of the buffer,
6906 and we didn't find it in the line we scanned,
6907 use the start of the following line. */
6908 if (maybe_next_line_p
)
6913 current_x
= best_row
->x
;
6916 *vpos
= best_row_vpos
;
6917 *hpos
= lastcol
+ 1;
6924 /* Display the active region described by mouse_face_*
6925 in its mouse-face if HL > 0, in its normal face if HL = 0. */
6928 show_mouse_face (dpyinfo
, draw
)
6929 struct x_display_info
*dpyinfo
;
6930 enum draw_glyphs_face draw
;
6932 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
6933 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6935 int cursor_off_p
= 0;
6936 struct cursor_pos saved_cursor
;
6938 saved_cursor
= output_cursor
;
6940 /* If window is in the process of being destroyed, don't bother
6942 if (w
->current_matrix
== NULL
)
6945 /* Recognize when we are called to operate on rows that don't exist
6946 anymore. This can happen when a window is split. */
6947 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
6950 set_output_cursor (&w
->phys_cursor
);
6952 /* Note that mouse_face_beg_row etc. are window relative. */
6953 for (i
= dpyinfo
->mouse_face_beg_row
;
6954 i
<= dpyinfo
->mouse_face_end_row
;
6957 int start_hpos
, end_hpos
, start_x
;
6958 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
6960 /* Don't do anything if row doesn't have valid contents. */
6961 if (!row
->enabled_p
)
6964 /* For all but the first row, the highlight starts at column 0. */
6965 if (i
== dpyinfo
->mouse_face_beg_row
)
6967 start_hpos
= dpyinfo
->mouse_face_beg_col
;
6968 start_x
= dpyinfo
->mouse_face_beg_x
;
6976 if (i
== dpyinfo
->mouse_face_end_row
)
6977 end_hpos
= dpyinfo
->mouse_face_end_col
;
6979 end_hpos
= row
->used
[TEXT_AREA
];
6981 /* If the cursor's in the text we are about to rewrite, turn the
6983 if (!w
->pseudo_window_p
6984 && i
== output_cursor
.vpos
6985 && output_cursor
.hpos
>= start_hpos
- 1
6986 && output_cursor
.hpos
<= end_hpos
)
6988 x_update_window_cursor (w
, 0);
6992 if (end_hpos
> start_hpos
)
6993 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
6994 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
6997 /* If we turned the cursor off, turn it back on. */
6999 x_display_cursor (w
, 1,
7000 output_cursor
.hpos
, output_cursor
.vpos
,
7001 output_cursor
.x
, output_cursor
.y
);
7003 output_cursor
= saved_cursor
;
7007 /* Change the mouse cursor. */
7008 if (draw
== DRAW_NORMAL_TEXT
)
7009 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7010 f
->output_data
.x
->text_cursor
);
7011 else if (draw
== DRAW_MOUSE_FACE
)
7012 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7013 f
->output_data
.x
->cross_cursor
);
7015 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7016 f
->output_data
.x
->nontext_cursor
);
7019 /* Clear out the mouse-highlighted active region.
7020 Redraw it un-highlighted first. */
7023 clear_mouse_face (dpyinfo
)
7024 struct x_display_info
*dpyinfo
;
7029 if (! NILP (dpyinfo
->mouse_face_window
))
7030 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7032 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7033 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7034 dpyinfo
->mouse_face_window
= Qnil
;
7037 /* Just discard the mouse face information for frame F, if any.
7038 This is used when the size of F is changed. */
7041 cancel_mouse_face (f
)
7045 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7047 window
= dpyinfo
->mouse_face_window
;
7048 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7050 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7051 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7052 dpyinfo
->mouse_face_window
= Qnil
;
7056 static struct scroll_bar
*x_window_to_scroll_bar ();
7057 static void x_scroll_bar_report_motion ();
7059 /* Return the current position of the mouse.
7060 *fp should be a frame which indicates which display to ask about.
7062 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7063 and *part to the frame, window, and scroll bar part that the mouse
7064 is over. Set *x and *y to the portion and whole of the mouse's
7065 position on the scroll bar.
7067 If the mouse movement started elsewhere, set *fp to the frame the
7068 mouse is on, *bar_window to nil, and *x and *y to the character cell
7071 Set *time to the server time-stamp for the time at which the mouse
7072 was at this position.
7074 Don't store anything if we don't have a valid set of values to report.
7076 This clears the mouse_moved flag, so we can wait for the next mouse
7080 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7083 Lisp_Object
*bar_window
;
7084 enum scroll_bar_part
*part
;
7086 unsigned long *time
;
7092 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7093 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7099 Window dummy_window
;
7102 Lisp_Object frame
, tail
;
7104 /* Clear the mouse-moved flag for every frame on this display. */
7105 FOR_EACH_FRAME (tail
, frame
)
7106 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7107 XFRAME (frame
)->mouse_moved
= 0;
7109 last_mouse_scroll_bar
= Qnil
;
7111 /* Figure out which root window we're on. */
7112 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7113 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7115 /* The root window which contains the pointer. */
7118 /* Trash which we can't trust if the pointer is on
7119 a different screen. */
7122 /* The position on that root window. */
7125 /* More trash we can't trust. */
7128 /* Modifier keys and pointer buttons, about which
7130 (unsigned int *) &dummy
);
7132 /* Now we have a position on the root; find the innermost window
7133 containing the pointer. */
7137 int parent_x
= 0, parent_y
= 0;
7142 /* XTranslateCoordinates can get errors if the window
7143 structure is changing at the same time this function
7144 is running. So at least we must not crash from them. */
7146 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7148 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7149 && FRAME_LIVE_P (last_mouse_frame
))
7151 /* If mouse was grabbed on a frame, give coords for that frame
7152 even if the mouse is now outside it. */
7153 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7155 /* From-window, to-window. */
7156 root
, FRAME_X_WINDOW (last_mouse_frame
),
7158 /* From-position, to-position. */
7159 root_x
, root_y
, &win_x
, &win_y
,
7163 f1
= last_mouse_frame
;
7169 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7171 /* From-window, to-window. */
7174 /* From-position, to-position. */
7175 root_x
, root_y
, &win_x
, &win_y
,
7180 if (child
== None
|| child
== win
)
7188 /* Now we know that:
7189 win is the innermost window containing the pointer
7190 (XTC says it has no child containing the pointer),
7191 win_x and win_y are the pointer's position in it
7192 (XTC did this the last time through), and
7193 parent_x and parent_y are the pointer's position in win's parent.
7194 (They are what win_x and win_y were when win was child.
7195 If win is the root window, it has no parent, and
7196 parent_{x,y} are invalid, but that's okay, because we'll
7197 never use them in that case.) */
7199 /* Is win one of our frames? */
7200 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7203 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7206 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7208 /* If not, is it one of our scroll bars? */
7211 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7215 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7221 if (f1
== 0 && insist
> 0)
7222 f1
= SELECTED_FRAME ();
7226 /* Ok, we found a frame. Store all the values.
7227 last_mouse_glyph is a rectangle used to reduce the
7228 generation of mouse events. To not miss any motion
7229 events, we must divide the frame into rectangles of the
7230 size of the smallest character that could be displayed
7231 on it, i.e. into the same rectangles that matrices on
7232 the frame are divided into. */
7234 #if OLD_REDISPLAY_CODE
7235 int ignore1
, ignore2
;
7236 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7238 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7242 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7243 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7247 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7248 round down even for negative values. */
7254 last_mouse_glyph
.width
= width
;
7255 last_mouse_glyph
.height
= height
;
7256 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7257 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7264 XSETINT (*x
, win_x
);
7265 XSETINT (*y
, win_y
);
7266 *time
= last_mouse_movement_time
;
7275 #ifdef USE_X_TOOLKIT
7277 /* Atimer callback function for TIMER. Called every 0.1s to process
7278 Xt timeouts, if needed. We must avoid calling XtAppPending as
7279 much as possible because that function does an implicit XFlush
7280 that slows us down. */
7283 x_process_timeouts (timer
)
7284 struct atimer
*timer
;
7286 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7289 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7290 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7295 #endif /* USE_X_TOOLKIT */
7298 /* Scroll bar support. */
7300 /* Given an X window ID, find the struct scroll_bar which manages it.
7301 This can be called in GC, so we have to make sure to strip off mark
7304 static struct scroll_bar
*
7305 x_window_to_scroll_bar (window_id
)
7310 for (tail
= Vframe_list
;
7311 XGCTYPE (tail
) == Lisp_Cons
;
7314 Lisp_Object frame
, bar
, condemned
;
7316 frame
= XCAR (tail
);
7317 /* All elements of Vframe_list should be frames. */
7318 if (! GC_FRAMEP (frame
))
7321 /* Scan this frame's scroll bar list for a scroll bar with the
7323 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7324 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7325 /* This trick allows us to search both the ordinary and
7326 condemned scroll bar lists with one loop. */
7327 ! GC_NILP (bar
) || (bar
= condemned
,
7330 bar
= XSCROLL_BAR (bar
)->next
)
7331 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7332 return XSCROLL_BAR (bar
);
7340 /************************************************************************
7342 ************************************************************************/
7344 #if USE_TOOLKIT_SCROLL_BARS
7346 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7347 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7348 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7349 struct scroll_bar
*));
7350 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7354 /* Id of action hook installed for scroll bars. */
7356 static XtActionHookId action_hook_id
;
7358 /* Lisp window being scrolled. Set when starting to interact with
7359 a toolkit scroll bar, reset to nil when ending the interaction. */
7361 static Lisp_Object window_being_scrolled
;
7363 /* Last scroll bar part sent in xm_scroll_callback. */
7365 static int last_scroll_bar_part
;
7367 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7368 that movements of 1/20 of the screen size are mapped to up/down. */
7370 static Boolean xaw3d_arrow_scroll
;
7372 /* Whether the drag scrolling maintains the mouse at the top of the
7373 thumb. If not, resizing the thumb needs to be done more carefully
7374 to avoid jerkyness. */
7376 static Boolean xaw3d_pick_top
;
7379 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7380 bars are used.. The hook is responsible for detecting when
7381 the user ends an interaction with the scroll bar, and generates
7382 a `end-scroll' scroll_bar_click' event if so. */
7385 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7388 XtPointer client_data
;
7392 Cardinal
*num_params
;
7398 scroll_bar_p
= XmIsScrollBar (widget
);
7399 end_action
= "Release";
7400 #else /* !USE_MOTIF i.e. use Xaw */
7401 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7402 end_action
= "EndScroll";
7403 #endif /* USE_MOTIF */
7406 && strcmp (action_name
, end_action
) == 0
7407 && WINDOWP (window_being_scrolled
))
7411 x_send_scroll_bar_event (window_being_scrolled
,
7412 scroll_bar_end_scroll
, 0, 0);
7413 w
= XWINDOW (window_being_scrolled
);
7414 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7415 window_being_scrolled
= Qnil
;
7416 last_scroll_bar_part
= -1;
7418 /* Xt timeouts no longer needed. */
7419 toolkit_scroll_bar_interaction
= 0;
7424 /* Send a client message with message type Xatom_Scrollbar for a
7425 scroll action to the frame of WINDOW. PART is a value identifying
7426 the part of the scroll bar that was clicked on. PORTION is the
7427 amount to scroll of a whole of WHOLE. */
7430 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7432 int part
, portion
, whole
;
7435 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7436 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7438 /* Construct a ClientMessage event to send to the frame. */
7439 ev
->type
= ClientMessage
;
7440 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7441 ev
->display
= FRAME_X_DISPLAY (f
);
7442 ev
->window
= FRAME_X_WINDOW (f
);
7444 ev
->data
.l
[0] = (long) window
;
7445 ev
->data
.l
[1] = (long) part
;
7446 ev
->data
.l
[2] = (long) 0;
7447 ev
->data
.l
[3] = (long) portion
;
7448 ev
->data
.l
[4] = (long) whole
;
7450 /* Make Xt timeouts work while the scroll bar is active. */
7451 toolkit_scroll_bar_interaction
= 1;
7453 /* Setting the event mask to zero means that the message will
7454 be sent to the client that created the window, and if that
7455 window no longer exists, no event will be sent. */
7457 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7462 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7466 x_scroll_bar_to_input_event (event
, ievent
)
7468 struct input_event
*ievent
;
7470 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7471 Lisp_Object window
= (Lisp_Object
) ev
->data
.l
[0];
7472 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7474 ievent
->kind
= scroll_bar_click
;
7475 ievent
->frame_or_window
= window
;
7476 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7477 ievent
->part
= ev
->data
.l
[1];
7478 ievent
->code
= ev
->data
.l
[2];
7479 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7480 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7481 ievent
->modifiers
= 0;
7487 /* Minimum and maximum values used for Motif scroll bars. */
7490 #define XM_SB_MAX 10000000
7491 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7494 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7495 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7496 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7499 xm_scroll_callback (widget
, client_data
, call_data
)
7501 XtPointer client_data
, call_data
;
7503 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7504 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7506 int part
= -1, whole
= 0, portion
= 0;
7510 case XmCR_DECREMENT
:
7511 bar
->dragging
= Qnil
;
7512 part
= scroll_bar_up_arrow
;
7515 case XmCR_INCREMENT
:
7516 bar
->dragging
= Qnil
;
7517 part
= scroll_bar_down_arrow
;
7520 case XmCR_PAGE_DECREMENT
:
7521 bar
->dragging
= Qnil
;
7522 part
= scroll_bar_above_handle
;
7525 case XmCR_PAGE_INCREMENT
:
7526 bar
->dragging
= Qnil
;
7527 part
= scroll_bar_below_handle
;
7531 bar
->dragging
= Qnil
;
7532 part
= scroll_bar_to_top
;
7535 case XmCR_TO_BOTTOM
:
7536 bar
->dragging
= Qnil
;
7537 part
= scroll_bar_to_bottom
;
7543 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7544 && XINT (bar
->dragging
) <= cs
->value
);
7546 /* Get the slider size. */
7548 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7551 /* At the max position of the scroll bar, do a line-wise
7552 movement. Without doing anything, the LessTif scroll bar
7553 calls us with the same cs->value again and again. If we
7554 want to make sure that we can reach the end of the buffer,
7555 we have to do something.
7557 Implementation note: setting bar->dragging always to
7558 cs->value gives a smoother movement at the max position.
7559 Setting it to nil when doing line-wise movement gives
7560 a better slider behavior. */
7562 if (cs
->value
+ slider_size
== XM_SB_MAX
7564 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7566 part
= scroll_bar_down_arrow
;
7567 bar
->dragging
= Qnil
;
7571 whole
= XM_SB_RANGE
;
7572 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7573 part
= scroll_bar_handle
;
7574 bar
->dragging
= make_number (cs
->value
);
7579 case XmCR_VALUE_CHANGED
:
7585 window_being_scrolled
= bar
->window
;
7586 last_scroll_bar_part
= part
;
7587 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7592 #else /* !USE_MOTIF, i.e. Xaw. */
7595 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7596 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7597 scroll bar struct. CALL_DATA is a pointer to a float saying where
7601 xaw_jump_callback (widget
, client_data
, call_data
)
7603 XtPointer client_data
, call_data
;
7605 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7606 float top
= *(float *) call_data
;
7608 int whole
, portion
, height
;
7611 /* Get the size of the thumb, a value between 0 and 1. */
7613 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7617 portion
= shown
< 1 ? top
* whole
: 0;
7619 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7620 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7621 the bottom, so we force the scrolling whenever we see that we're
7622 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7623 we try to ensure that we always stay two pixels away from the
7625 part
= scroll_bar_down_arrow
;
7627 part
= scroll_bar_handle
;
7629 window_being_scrolled
= bar
->window
;
7630 bar
->dragging
= make_number (portion
);
7631 last_scroll_bar_part
= part
;
7632 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7636 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7637 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7638 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7639 the scroll bar. CALL_DATA is an integer specifying the action that
7640 has taken place. It's magnitude is in the range 0..height of the
7641 scroll bar. Negative values mean scroll towards buffer start.
7642 Values < height of scroll bar mean line-wise movement. */
7645 xaw_scroll_callback (widget
, client_data
, call_data
)
7647 XtPointer client_data
, call_data
;
7649 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7650 int position
= (int) call_data
;
7654 /* Get the height of the scroll bar. */
7656 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7659 if (abs (position
) >= height
)
7660 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
7662 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
7663 it maps line-movement to call_data = max(5, height/20). */
7664 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
7665 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
7667 part
= scroll_bar_move_ratio
;
7669 window_being_scrolled
= bar
->window
;
7670 bar
->dragging
= Qnil
;
7671 last_scroll_bar_part
= part
;
7672 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
7676 #endif /* not USE_MOTIF */
7679 /* Create the widget for scroll bar BAR on frame F. Record the widget
7680 and X window of the scroll bar in BAR. */
7683 x_create_toolkit_scroll_bar (f
, bar
)
7685 struct scroll_bar
*bar
;
7691 char *scroll_bar_name
= "verticalScrollBar";
7692 unsigned long pixel
;
7697 /* LessTif 0.85, problems:
7699 1. When the mouse if over the scroll bar, the scroll bar will
7700 get keyboard events. I didn't find a way to turn this off.
7702 2. Do we have to explicitly set the cursor to get an arrow
7703 cursor (see below)? */
7705 /* Set resources. Create the widget. */
7706 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7707 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7708 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7709 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7710 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7711 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7712 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7714 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7717 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7721 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7724 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7728 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7729 scroll_bar_name
, av
, ac
);
7731 /* Add one callback for everything that can happen. */
7732 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7734 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7736 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7738 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7740 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7742 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7744 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7747 /* Realize the widget. Only after that is the X window created. */
7748 XtRealizeWidget (widget
);
7750 /* Set the cursor to an arrow. I didn't find a resource to do that.
7751 And I'm wondering why it hasn't an arrow cursor by default. */
7752 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7753 f
->output_data
.x
->nontext_cursor
);
7755 #else /* !USE_MOTIF i.e. use Xaw */
7757 /* Set resources. Create the widget. The background of the
7758 Xaw3d scroll bar widget is a little bit light for my taste.
7759 We don't alter it here to let users change it according
7760 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7761 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7762 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7763 /* For smoother scrolling with Xaw3d -sm */
7764 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
7765 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
7767 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7770 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7774 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7777 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7781 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7782 f
->output_data
.x
->edit_widget
, av
, ac
);
7786 char *val
= initial
;
7787 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
7788 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
7790 { /* ARROW_SCROLL */
7791 xaw3d_arrow_scroll
= True
;
7792 /* Isn't that just a personal preference ? -sm */
7793 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
7797 /* Define callbacks. */
7798 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
7799 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
7802 /* Realize the widget. Only after that is the X window created. */
7803 XtRealizeWidget (widget
);
7805 #endif /* !USE_MOTIF */
7807 /* Install an action hook that let's us detect when the user
7808 finishes interacting with a scroll bar. */
7809 if (action_hook_id
== 0)
7810 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7812 /* Remember X window and widget in the scroll bar vector. */
7813 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7814 xwindow
= XtWindow (widget
);
7815 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7821 /* Set the thumb size and position of scroll bar BAR. We are currently
7822 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7825 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7826 struct scroll_bar
*bar
;
7827 int portion
, position
, whole
;
7830 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7836 top
= (float) position
/ whole
;
7837 shown
= (float) portion
/ whole
;
7845 Boolean arrow1_selected
, arrow2_selected
;
7846 unsigned char flags
;
7847 XmScrollBarWidget sb
;
7849 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
7850 is the scroll bar's maximum and MIN is the scroll bar's minimum
7852 size
= shown
* XM_SB_RANGE
;
7853 size
= min (size
, XM_SB_RANGE
);
7854 size
= max (size
, 1);
7856 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7857 value
= top
* XM_SB_RANGE
;
7858 value
= min (value
, XM_SB_MAX
- size
);
7859 value
= max (value
, XM_SB_MIN
);
7861 /* LessTif: Calling XmScrollBarSetValues after an increment or
7862 decrement turns off auto-repeat LessTif-internally. This can
7863 be seen in ScrollBar.c which resets Arrow1Selected and
7864 Arrow2Selected. It also sets internal flags so that LessTif
7865 believes the mouse is in the slider. We either have to change
7866 our code, or work around that by accessing private data. */
7868 sb
= (XmScrollBarWidget
) widget
;
7869 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
7870 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
7871 flags
= sb
->scrollBar
.flags
;
7873 if (NILP (bar
->dragging
))
7874 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
7875 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7876 /* This has the negative side effect that the slider value is
7877 not what it would be if we scrolled here using line-wise or
7878 page-wise movement. */
7879 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
7882 /* If currently dragging, only update the slider size.
7883 This reduces flicker effects. */
7884 int old_value
, old_size
, increment
, page_increment
;
7886 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
7887 &increment
, &page_increment
);
7888 XmScrollBarSetValues (widget
, old_value
,
7889 min (size
, XM_SB_RANGE
- old_value
),
7893 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
7894 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
7895 sb
->scrollBar
.flags
= flags
;
7897 #else /* !USE_MOTIF i.e. use Xaw */
7899 float old_top
, old_shown
;
7901 XtVaGetValues (widget
,
7902 XtNtopOfThumb
, &old_top
,
7903 XtNshown
, &old_shown
,
7907 /* Massage the top+shown values. */
7908 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
7909 top
= max (0, min (1, top
));
7912 /* Keep two pixels available for moving the thumb down. */
7913 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
7915 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
7916 check that your system's configuration file contains a define
7917 for `NARROWPROTO'. See s/freebsd.h for an example. */
7918 if (top
!= old_top
|| shown
!= old_shown
)
7920 if (NILP (bar
->dragging
))
7921 XawScrollbarSetThumb (widget
, top
, shown
);
7925 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
7926 int scroll_mode
= 0;
7928 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
7929 if (xaw3d_arrow_scroll
)
7931 /* Xaw3d stupidly ignores resize requests while dragging
7932 so we have to make it believe it's not in dragging mode. */
7933 scroll_mode
= sb
->scrollbar
.scroll_mode
;
7934 if (scroll_mode
== 2)
7935 sb
->scrollbar
.scroll_mode
= 0;
7938 /* Try to make the scrolling a tad smoother. */
7939 if (!xaw3d_pick_top
)
7940 shown
= min (shown
, old_shown
);
7942 XawScrollbarSetThumb (widget
, top
, shown
);
7945 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
7946 sb
->scrollbar
.scroll_mode
= scroll_mode
;
7951 #endif /* !USE_MOTIF */
7956 #endif /* USE_TOOLKIT_SCROLL_BARS */
7960 /************************************************************************
7961 Scroll bars, general
7962 ************************************************************************/
7964 /* Create a scroll bar and return the scroll bar vector for it. W is
7965 the Emacs window on which to create the scroll bar. TOP, LEFT,
7966 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7969 static struct scroll_bar
*
7970 x_scroll_bar_create (w
, top
, left
, width
, height
)
7972 int top
, left
, width
, height
;
7974 struct frame
*f
= XFRAME (w
->frame
);
7975 struct scroll_bar
*bar
7976 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7980 #if USE_TOOLKIT_SCROLL_BARS
7981 x_create_toolkit_scroll_bar (f
, bar
);
7982 #else /* not USE_TOOLKIT_SCROLL_BARS */
7984 XSetWindowAttributes a
;
7988 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7989 if (a
.background_pixel
== -1)
7990 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
7992 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
7993 | ButtonMotionMask
| PointerMotionHintMask
7995 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
7997 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
7999 /* Clear the area of W that will serve as a scroll bar. This is
8000 for the case that a window has been split horizontally. In
8001 this case, no clear_frame is generated to reduce flickering. */
8002 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8004 window_box_height (w
), False
);
8006 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8007 /* Position and size of scroll bar. */
8008 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8010 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8012 /* Border width, depth, class, and visual. */
8019 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8021 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8023 XSETWINDOW (bar
->window
, w
);
8024 XSETINT (bar
->top
, top
);
8025 XSETINT (bar
->left
, left
);
8026 XSETINT (bar
->width
, width
);
8027 XSETINT (bar
->height
, height
);
8028 XSETINT (bar
->start
, 0);
8029 XSETINT (bar
->end
, 0);
8030 bar
->dragging
= Qnil
;
8032 /* Add bar to its frame's list of scroll bars. */
8033 bar
->next
= FRAME_SCROLL_BARS (f
);
8035 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8036 if (!NILP (bar
->next
))
8037 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8039 /* Map the window/widget. */
8040 #if USE_TOOLKIT_SCROLL_BARS
8041 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
8042 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8043 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8045 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8047 #else /* not USE_TOOLKIT_SCROLL_BARS */
8048 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8049 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8056 /* Draw BAR's handle in the proper position.
8058 If the handle is already drawn from START to END, don't bother
8059 redrawing it, unless REBUILD is non-zero; in that case, always
8060 redraw it. (REBUILD is handy for drawing the handle after expose
8063 Normally, we want to constrain the start and end of the handle to
8064 fit inside its rectangle, but if the user is dragging the scroll
8065 bar handle, we want to let them drag it down all the way, so that
8066 the bar's top is as far down as it goes; otherwise, there's no way
8067 to move to the very end of the buffer. */
8069 #ifndef USE_TOOLKIT_SCROLL_BARS
8072 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8073 struct scroll_bar
*bar
;
8077 int dragging
= ! NILP (bar
->dragging
);
8078 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8079 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8080 GC gc
= f
->output_data
.x
->normal_gc
;
8082 /* If the display is already accurate, do nothing. */
8084 && start
== XINT (bar
->start
)
8085 && end
== XINT (bar
->end
))
8091 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8092 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8093 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8095 /* Make sure the values are reasonable, and try to preserve
8096 the distance between start and end. */
8098 int length
= end
- start
;
8102 else if (start
> top_range
)
8104 end
= start
+ length
;
8108 else if (end
> top_range
&& ! dragging
)
8112 /* Store the adjusted setting in the scroll bar. */
8113 XSETINT (bar
->start
, start
);
8114 XSETINT (bar
->end
, end
);
8116 /* Clip the end position, just for display. */
8117 if (end
> top_range
)
8120 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8121 below top positions, to make sure the handle is always at least
8122 that many pixels tall. */
8123 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8125 /* Draw the empty space above the handle. Note that we can't clear
8126 zero-height areas; that means "clear to end of window." */
8128 XClearArea (FRAME_X_DISPLAY (f
), w
,
8130 /* x, y, width, height, and exposures. */
8131 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8132 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8133 inside_width
, start
,
8136 /* Change to proper foreground color if one is specified. */
8137 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8138 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8139 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8141 /* Draw the handle itself. */
8142 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8144 /* x, y, width, height */
8145 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8146 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8147 inside_width
, end
- start
);
8149 /* Restore the foreground color of the GC if we changed it above. */
8150 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8151 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8152 f
->output_data
.x
->foreground_pixel
);
8154 /* Draw the empty space below the handle. Note that we can't
8155 clear zero-height areas; that means "clear to end of window." */
8156 if (end
< inside_height
)
8157 XClearArea (FRAME_X_DISPLAY (f
), w
,
8159 /* x, y, width, height, and exposures. */
8160 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8161 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8162 inside_width
, inside_height
- end
,
8170 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8172 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8176 x_scroll_bar_remove (bar
)
8177 struct scroll_bar
*bar
;
8181 #if USE_TOOLKIT_SCROLL_BARS
8182 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
8183 #else /* not USE_TOOLKIT_SCROLL_BARS */
8185 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8186 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8188 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8190 /* Disassociate this scroll bar from its window. */
8191 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8197 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8198 that we are displaying PORTION characters out of a total of WHOLE
8199 characters, starting at POSITION. If WINDOW has no scroll bar,
8203 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8205 int portion
, whole
, position
;
8207 struct frame
*f
= XFRAME (w
->frame
);
8208 struct scroll_bar
*bar
;
8209 int top
, height
, left
, sb_left
, width
, sb_width
;
8210 int window_x
, window_y
, window_width
, window_height
;
8212 /* Get window dimensions. */
8213 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8215 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8216 height
= window_height
;
8218 /* Compute the left edge of the scroll bar area. */
8219 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8220 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8222 left
= XFASTINT (w
->left
);
8223 left
*= CANON_X_UNIT (f
);
8224 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8226 /* Compute the width of the scroll bar which might be less than
8227 the width of the area reserved for the scroll bar. */
8228 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8229 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8233 /* Compute the left edge of the scroll bar. */
8234 #ifdef USE_TOOLKIT_SCROLL_BARS
8235 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8236 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8238 sb_left
= left
+ (width
- sb_width
) / 2;
8240 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8241 sb_left
= left
+ width
- sb_width
;
8246 /* Does the scroll bar exist yet? */
8247 if (NILP (w
->vertical_scroll_bar
))
8250 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8251 left
, top
, width
, height
, False
);
8253 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8257 /* It may just need to be moved and resized. */
8258 unsigned int mask
= 0;
8260 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8264 if (sb_left
!= XINT (bar
->left
))
8266 if (top
!= XINT (bar
->top
))
8268 if (sb_width
!= XINT (bar
->width
))
8270 if (height
!= XINT (bar
->height
))
8273 #ifdef USE_TOOLKIT_SCROLL_BARS
8275 /* Since toolkit scroll bars are smaller than the space reserved
8276 for them on the frame, we have to clear "under" them. */
8277 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8278 left
, top
, width
, height
, False
);
8280 /* Move/size the scroll bar widget. */
8282 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8283 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8285 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8288 #else /* not USE_TOOLKIT_SCROLL_BARS */
8290 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8292 /* Clear areas not covered by the scroll bar. This makes sure a
8293 previous mode line display is cleared after C-x 2 C-x 1, for
8294 example. Non-toolkit scroll bars are as wide as the area
8295 reserved for scroll bars - trim at both sides. */
8296 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8297 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8299 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8300 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8301 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8305 /* Move/size the scroll bar window. */
8310 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8312 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8314 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8318 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8320 /* Remember new settings. */
8321 XSETINT (bar
->left
, sb_left
);
8322 XSETINT (bar
->top
, top
);
8323 XSETINT (bar
->width
, sb_width
);
8324 XSETINT (bar
->height
, height
);
8329 #if USE_TOOLKIT_SCROLL_BARS
8330 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8331 #else /* not USE_TOOLKIT_SCROLL_BARS */
8332 /* Set the scroll bar's current state, unless we're currently being
8334 if (NILP (bar
->dragging
))
8336 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8339 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8342 int start
= ((double) position
* top_range
) / whole
;
8343 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8344 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8347 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8349 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8353 /* The following three hooks are used when we're doing a thorough
8354 redisplay of the frame. We don't explicitly know which scroll bars
8355 are going to be deleted, because keeping track of when windows go
8356 away is a real pain - "Can you say set-window-configuration, boys
8357 and girls?" Instead, we just assert at the beginning of redisplay
8358 that *all* scroll bars are to be removed, and then save a scroll bar
8359 from the fiery pit when we actually redisplay its window. */
8361 /* Arrange for all scroll bars on FRAME to be removed at the next call
8362 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8363 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8366 XTcondemn_scroll_bars (frame
)
8369 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8370 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8373 bar
= FRAME_SCROLL_BARS (frame
);
8374 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8375 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8376 XSCROLL_BAR (bar
)->prev
= Qnil
;
8377 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8378 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8379 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8383 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8384 Note that WINDOW isn't necessarily condemned at all. */
8386 XTredeem_scroll_bar (window
)
8387 struct window
*window
;
8389 struct scroll_bar
*bar
;
8391 /* We can't redeem this window's scroll bar if it doesn't have one. */
8392 if (NILP (window
->vertical_scroll_bar
))
8395 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8397 /* Unlink it from the condemned list. */
8399 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8401 if (NILP (bar
->prev
))
8403 /* If the prev pointer is nil, it must be the first in one of
8405 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8406 /* It's not condemned. Everything's fine. */
8408 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8409 window
->vertical_scroll_bar
))
8410 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8412 /* If its prev pointer is nil, it must be at the front of
8413 one or the other! */
8417 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8419 if (! NILP (bar
->next
))
8420 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8422 bar
->next
= FRAME_SCROLL_BARS (f
);
8424 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8425 if (! NILP (bar
->next
))
8426 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8430 /* Remove all scroll bars on FRAME that haven't been saved since the
8431 last call to `*condemn_scroll_bars_hook'. */
8434 XTjudge_scroll_bars (f
)
8437 Lisp_Object bar
, next
;
8439 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8441 /* Clear out the condemned list now so we won't try to process any
8442 more events on the hapless scroll bars. */
8443 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8445 for (; ! NILP (bar
); bar
= next
)
8447 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8449 x_scroll_bar_remove (b
);
8452 b
->next
= b
->prev
= Qnil
;
8455 /* Now there should be no references to the condemned scroll bars,
8456 and they should get garbage-collected. */
8460 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8461 is a no-op when using toolkit scroll bars.
8463 This may be called from a signal handler, so we have to ignore GC
8467 x_scroll_bar_expose (bar
, event
)
8468 struct scroll_bar
*bar
;
8471 #ifndef USE_TOOLKIT_SCROLL_BARS
8473 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8474 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8475 GC gc
= f
->output_data
.x
->normal_gc
;
8476 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8480 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8482 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8483 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8485 /* x, y, width, height */
8487 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8488 XINT (bar
->height
) - 1);
8492 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8495 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8496 is set to something other than no_event, it is enqueued.
8498 This may be called from a signal handler, so we have to ignore GC
8501 #ifndef USE_TOOLKIT_SCROLL_BARS
8504 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8505 struct scroll_bar
*bar
;
8507 struct input_event
*emacs_event
;
8509 if (! GC_WINDOWP (bar
->window
))
8512 emacs_event
->kind
= scroll_bar_click
;
8513 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8514 emacs_event
->modifiers
8515 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8516 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8517 event
->xbutton
.state
)
8518 | (event
->type
== ButtonRelease
8521 emacs_event
->frame_or_window
= bar
->window
;
8522 emacs_event
->timestamp
= event
->xbutton
.time
;
8525 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8527 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8530 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8531 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8534 if (y
> top_range
) y
= top_range
;
8536 if (y
< XINT (bar
->start
))
8537 emacs_event
->part
= scroll_bar_above_handle
;
8538 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8539 emacs_event
->part
= scroll_bar_handle
;
8541 emacs_event
->part
= scroll_bar_below_handle
;
8543 /* Just because the user has clicked on the handle doesn't mean
8544 they want to drag it. Lisp code needs to be able to decide
8545 whether or not we're dragging. */
8547 /* If the user has just clicked on the handle, record where they're
8549 if (event
->type
== ButtonPress
8550 && emacs_event
->part
== scroll_bar_handle
)
8551 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8554 /* If the user has released the handle, set it to its final position. */
8555 if (event
->type
== ButtonRelease
8556 && ! NILP (bar
->dragging
))
8558 int new_start
= y
- XINT (bar
->dragging
);
8559 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8561 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8562 bar
->dragging
= Qnil
;
8565 /* Same deal here as the other #if 0. */
8567 /* Clicks on the handle are always reported as occurring at the top of
8569 if (emacs_event
->part
== scroll_bar_handle
)
8570 emacs_event
->x
= bar
->start
;
8572 XSETINT (emacs_event
->x
, y
);
8574 XSETINT (emacs_event
->x
, y
);
8577 XSETINT (emacs_event
->y
, top_range
);
8581 /* Handle some mouse motion while someone is dragging the scroll bar.
8583 This may be called from a signal handler, so we have to ignore GC
8587 x_scroll_bar_note_movement (bar
, event
)
8588 struct scroll_bar
*bar
;
8591 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8593 last_mouse_movement_time
= event
->xmotion
.time
;
8596 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8598 /* If we're dragging the bar, display it. */
8599 if (! GC_NILP (bar
->dragging
))
8601 /* Where should the handle be now? */
8602 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8604 if (new_start
!= XINT (bar
->start
))
8606 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8608 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8613 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8615 /* Return information to the user about the current position of the mouse
8616 on the scroll bar. */
8619 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8621 Lisp_Object
*bar_window
;
8622 enum scroll_bar_part
*part
;
8624 unsigned long *time
;
8626 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8627 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8628 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8630 Window dummy_window
;
8632 unsigned int dummy_mask
;
8636 /* Get the mouse's position relative to the scroll bar window, and
8638 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8640 /* Root, child, root x and root y. */
8641 &dummy_window
, &dummy_window
,
8642 &dummy_coord
, &dummy_coord
,
8644 /* Position relative to scroll bar. */
8647 /* Mouse buttons and modifier keys. */
8654 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8657 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8659 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8661 if (! NILP (bar
->dragging
))
8662 win_y
-= XINT (bar
->dragging
);
8666 if (win_y
> top_range
)
8670 *bar_window
= bar
->window
;
8672 if (! NILP (bar
->dragging
))
8673 *part
= scroll_bar_handle
;
8674 else if (win_y
< XINT (bar
->start
))
8675 *part
= scroll_bar_above_handle
;
8676 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8677 *part
= scroll_bar_handle
;
8679 *part
= scroll_bar_below_handle
;
8681 XSETINT (*x
, win_y
);
8682 XSETINT (*y
, top_range
);
8685 last_mouse_scroll_bar
= Qnil
;
8688 *time
= last_mouse_movement_time
;
8694 /* The screen has been cleared so we may have changed foreground or
8695 background colors, and the scroll bars may need to be redrawn.
8696 Clear out the scroll bars, and ask for expose events, so we can
8700 x_scroll_bar_clear (f
)
8703 #ifndef USE_TOOLKIT_SCROLL_BARS
8706 /* We can have scroll bars even if this is 0,
8707 if we just turned off scroll bar mode.
8708 But in that case we should not clear them. */
8709 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8710 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8711 bar
= XSCROLL_BAR (bar
)->next
)
8712 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8714 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8717 /* This processes Expose events from the menu-bar specific X event
8718 loop in xmenu.c. This allows to redisplay the frame if necessary
8719 when handling menu-bar or pop-up items. */
8722 process_expose_from_menu (event
)
8726 struct x_display_info
*dpyinfo
;
8727 int frame_exposed_p
= 0;
8731 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8732 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8735 if (f
->async_visible
== 0)
8737 f
->async_visible
= 1;
8738 f
->async_iconified
= 0;
8739 f
->output_data
.x
->has_been_visible
= 1;
8740 SET_FRAME_GARBAGED (f
);
8744 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8745 event
.xexpose
.x
, event
.xexpose
.y
,
8746 event
.xexpose
.width
, event
.xexpose
.height
);
8747 frame_exposed_p
= 1;
8752 struct scroll_bar
*bar
8753 = x_window_to_scroll_bar (event
.xexpose
.window
);
8756 x_scroll_bar_expose (bar
, &event
);
8760 return frame_exposed_p
;
8763 /* Define a queue to save up SelectionRequest events for later handling. */
8765 struct selection_event_queue
8768 struct selection_event_queue
*next
;
8771 static struct selection_event_queue
*queue
;
8773 /* Nonzero means queue up certain events--don't process them yet. */
8775 static int x_queue_selection_requests
;
8777 /* Queue up an X event *EVENT, to be processed later. */
8780 x_queue_event (f
, event
)
8784 struct selection_event_queue
*queue_tmp
8785 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8787 if (queue_tmp
!= NULL
)
8789 queue_tmp
->event
= *event
;
8790 queue_tmp
->next
= queue
;
8795 /* Take all the queued events and put them back
8796 so that they get processed afresh. */
8799 x_unqueue_events (display
)
8802 while (queue
!= NULL
)
8804 struct selection_event_queue
*queue_tmp
= queue
;
8805 XPutBackEvent (display
, &queue_tmp
->event
);
8806 queue
= queue_tmp
->next
;
8807 xfree ((char *)queue_tmp
);
8811 /* Start queuing SelectionRequest events. */
8814 x_start_queuing_selection_requests (display
)
8817 x_queue_selection_requests
++;
8820 /* Stop queuing SelectionRequest events. */
8823 x_stop_queuing_selection_requests (display
)
8826 x_queue_selection_requests
--;
8827 x_unqueue_events (display
);
8830 /* The main X event-reading loop - XTread_socket. */
8832 /* Time stamp of enter window event. This is only used by XTread_socket,
8833 but we have to put it out here, since static variables within functions
8834 sometimes don't work. */
8836 static Time enter_timestamp
;
8838 /* This holds the state XLookupString needs to implement dead keys
8839 and other tricks known as "compose processing". _X Window System_
8840 says that a portable program can't use this, but Stephen Gildea assures
8841 me that letting the compiler initialize it to zeros will work okay.
8843 This must be defined outside of XTread_socket, for the same reasons
8844 given for enter_time stamp, above. */
8846 static XComposeStatus compose_status
;
8848 /* Record the last 100 characters stored
8849 to help debug the loss-of-chars-during-GC problem. */
8851 static int temp_index
;
8852 static short temp_buffer
[100];
8854 /* Set this to nonzero to fake an "X I/O error"
8855 on a particular display. */
8857 struct x_display_info
*XTread_socket_fake_io_error
;
8859 /* When we find no input here, we occasionally do a no-op command
8860 to verify that the X server is still running and we can still talk with it.
8861 We try all the open displays, one by one.
8862 This variable is used for cycling thru the displays. */
8864 static struct x_display_info
*next_noop_dpyinfo
;
8866 #define SET_SAVED_MENU_EVENT(size) \
8869 if (f->output_data.x->saved_menu_event == 0) \
8870 f->output_data.x->saved_menu_event \
8871 = (XEvent *) xmalloc (sizeof (XEvent)); \
8872 bcopy (&event, f->output_data.x->saved_menu_event, size); \
8873 if (numchars >= 1) \
8875 bufp->kind = menu_bar_activate_event; \
8876 XSETFRAME (bufp->frame_or_window, f); \
8884 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
8885 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
8887 /* Read events coming from the X server.
8888 This routine is called by the SIGIO handler.
8889 We return as soon as there are no more events to be read.
8891 Events representing keys are stored in buffer BUFP,
8892 which can hold up to NUMCHARS characters.
8893 We return the number of characters stored into the buffer,
8894 thus pretending to be `read'.
8896 EXPECTED is nonzero if the caller knows input is available. */
8899 XTread_socket (sd
, bufp
, numchars
, expected
)
8901 /* register */ struct input_event
*bufp
;
8902 /* register */ int numchars
;
8909 int event_found
= 0;
8910 struct x_display_info
*dpyinfo
;
8912 if (interrupt_input_blocked
)
8914 interrupt_input_pending
= 1;
8918 interrupt_input_pending
= 0;
8921 /* So people can tell when we have read the available input. */
8922 input_signal_count
++;
8925 abort (); /* Don't think this happens. */
8927 /* Find the display we are supposed to read input for.
8928 It's the one communicating on descriptor SD. */
8929 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
8931 #if 0 /* This ought to be unnecessary; let's verify it. */
8933 /* If available, Xlib uses FIOSNBIO to make the socket
8934 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
8935 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
8936 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
8937 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
8938 #endif /* ! defined (FIOSNBIO) */
8941 #if 0 /* This code can't be made to work, with multiple displays,
8942 and appears not to be used on any system any more.
8943 Also keyboard.c doesn't turn O_NDELAY on and off
8944 for X connections. */
8947 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
8949 extern int read_alarm_should_throw
;
8950 read_alarm_should_throw
= 1;
8951 XPeekEvent (dpyinfo
->display
, &event
);
8952 read_alarm_should_throw
= 0;
8954 #endif /* HAVE_SELECT */
8958 /* For debugging, this gives a way to fake an I/O error. */
8959 if (dpyinfo
== XTread_socket_fake_io_error
)
8961 XTread_socket_fake_io_error
= 0;
8962 x_io_error_quitter (dpyinfo
->display
);
8965 while (XPending (dpyinfo
->display
))
8967 XNextEvent (dpyinfo
->display
, &event
);
8971 /* Filter events for the current X input method.
8972 XFilterEvent returns non-zero if the input method has
8973 consumed the event. We pass the frame's X window to
8974 XFilterEvent because that's the one for which the IC
8976 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
8977 event
.xclient
.window
);
8978 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
8988 if (event
.xclient
.message_type
8989 == dpyinfo
->Xatom_wm_protocols
8990 && event
.xclient
.format
== 32)
8992 if (event
.xclient
.data
.l
[0]
8993 == dpyinfo
->Xatom_wm_take_focus
)
8995 /* Use x_any_window_to_frame because this
8996 could be the shell widget window
8997 if the frame has no title bar. */
8998 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9000 /* Not quite sure this is needed -pd */
9001 if (f
&& FRAME_XIC (f
))
9002 XSetICFocus (FRAME_XIC (f
));
9004 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9005 instructs the WM to set the input focus automatically for
9006 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9007 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9008 it has set the focus. So, XSetInputFocus below is not
9011 The call to XSetInputFocus below has also caused trouble. In
9012 cases where the XSetInputFocus done by the WM and the one
9013 below are temporally close (on a fast machine), the call
9014 below can generate additional FocusIn events which confuse
9017 /* Since we set WM_TAKE_FOCUS, we must call
9018 XSetInputFocus explicitly. But not if f is null,
9019 since that might be an event for a deleted frame. */
9022 Display
*d
= event
.xclient
.display
;
9023 /* Catch and ignore errors, in case window has been
9024 iconified by a window manager such as GWM. */
9025 int count
= x_catch_errors (d
);
9026 XSetInputFocus (d
, event
.xclient
.window
,
9027 /* The ICCCM says this is
9028 the only valid choice. */
9030 event
.xclient
.data
.l
[1]);
9031 /* This is needed to detect the error
9032 if there is an error. */
9034 x_uncatch_errors (d
, count
);
9036 /* Not certain about handling scroll bars here */
9039 else if (event
.xclient
.data
.l
[0]
9040 == dpyinfo
->Xatom_wm_save_yourself
)
9042 /* Save state modify the WM_COMMAND property to
9043 something which can reinstate us. This notifies
9044 the session manager, who's looking for such a
9045 PropertyNotify. Can restart processing when
9046 a keyboard or mouse event arrives. */
9049 f
= x_top_window_to_frame (dpyinfo
,
9050 event
.xclient
.window
);
9052 /* This is just so we only give real data once
9053 for a single Emacs process. */
9054 if (f
== SELECTED_FRAME ())
9055 XSetCommand (FRAME_X_DISPLAY (f
),
9056 event
.xclient
.window
,
9057 initial_argv
, initial_argc
);
9059 XSetCommand (FRAME_X_DISPLAY (f
),
9060 event
.xclient
.window
,
9064 else if (event
.xclient
.data
.l
[0]
9065 == dpyinfo
->Xatom_wm_delete_window
)
9068 = x_any_window_to_frame (dpyinfo
,
9069 event
.xclient
.window
);
9076 bufp
->kind
= delete_window_event
;
9077 XSETFRAME (bufp
->frame_or_window
, f
);
9085 else if (event
.xclient
.message_type
9086 == dpyinfo
->Xatom_wm_configure_denied
)
9089 else if (event
.xclient
.message_type
9090 == dpyinfo
->Xatom_wm_window_moved
)
9094 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9096 new_x
= event
.xclient
.data
.s
[0];
9097 new_y
= event
.xclient
.data
.s
[1];
9101 f
->output_data
.x
->left_pos
= new_x
;
9102 f
->output_data
.x
->top_pos
= new_y
;
9106 else if (event
.xclient
.message_type
9107 == dpyinfo
->Xatom_editres
)
9110 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9111 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9114 #endif /* HACK_EDITRES */
9115 else if ((event
.xclient
.message_type
9116 == dpyinfo
->Xatom_DONE
)
9117 || (event
.xclient
.message_type
9118 == dpyinfo
->Xatom_PAGE
))
9120 /* Ghostview job completed. Kill it. We could
9121 reply with "Next" if we received "Page", but we
9122 currently never do because we are interested in
9123 images, only, which should have 1 page. */
9124 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9126 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9127 x_kill_gs_process (pixmap
, f
);
9128 expose_frame (f
, 0, 0, 0, 0);
9130 #ifdef USE_TOOLKIT_SCROLL_BARS
9131 /* Scroll bar callbacks send a ClientMessage from which
9132 we construct an input_event. */
9133 else if (event
.xclient
.message_type
9134 == dpyinfo
->Xatom_Scrollbar
)
9136 x_scroll_bar_to_input_event (&event
, bufp
);
9137 ++bufp
, ++count
, --numchars
;
9140 #endif /* USE_TOOLKIT_SCROLL_BARS */
9146 case SelectionNotify
:
9147 #ifdef USE_X_TOOLKIT
9148 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9150 #endif /* not USE_X_TOOLKIT */
9151 x_handle_selection_notify (&event
.xselection
);
9154 case SelectionClear
: /* Someone has grabbed ownership. */
9155 #ifdef USE_X_TOOLKIT
9156 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9158 #endif /* USE_X_TOOLKIT */
9160 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9165 bufp
->kind
= selection_clear_event
;
9166 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9167 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9168 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9169 bufp
->frame_or_window
= Qnil
;
9177 case SelectionRequest
: /* Someone wants our selection. */
9178 #ifdef USE_X_TOOLKIT
9179 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9181 #endif /* USE_X_TOOLKIT */
9182 if (x_queue_selection_requests
)
9183 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9187 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9192 bufp
->kind
= selection_request_event
;
9193 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9194 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9195 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9196 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9197 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9198 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9199 bufp
->frame_or_window
= Qnil
;
9207 case PropertyNotify
:
9208 #ifdef USE_X_TOOLKIT
9209 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9211 #endif /* not USE_X_TOOLKIT */
9212 x_handle_property_notify (&event
.xproperty
);
9215 case ReparentNotify
:
9216 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9220 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9221 x_real_positions (f
, &x
, &y
);
9222 f
->output_data
.x
->left_pos
= x
;
9223 f
->output_data
.x
->top_pos
= y
;
9228 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9231 if (f
->async_visible
== 0)
9233 f
->async_visible
= 1;
9234 f
->async_iconified
= 0;
9235 f
->output_data
.x
->has_been_visible
= 1;
9236 SET_FRAME_GARBAGED (f
);
9239 expose_frame (x_window_to_frame (dpyinfo
,
9240 event
.xexpose
.window
),
9241 event
.xexpose
.x
, event
.xexpose
.y
,
9242 event
.xexpose
.width
, event
.xexpose
.height
);
9246 #ifdef USE_TOOLKIT_SCROLL_BARS
9247 /* Dispatch event to the widget. */
9249 #else /* not USE_TOOLKIT_SCROLL_BARS */
9250 struct scroll_bar
*bar
9251 = x_window_to_scroll_bar (event
.xexpose
.window
);
9254 x_scroll_bar_expose (bar
, &event
);
9255 #ifdef USE_X_TOOLKIT
9258 #endif /* USE_X_TOOLKIT */
9259 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9263 case GraphicsExpose
: /* This occurs when an XCopyArea's
9264 source area was obscured or not
9266 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9270 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9271 event
.xgraphicsexpose
.width
,
9272 event
.xgraphicsexpose
.height
);
9274 #ifdef USE_X_TOOLKIT
9277 #endif /* USE_X_TOOLKIT */
9280 case NoExpose
: /* This occurs when an XCopyArea's
9281 source area was completely
9286 /* Redo the mouse-highlight after the tooltip has gone. */
9287 if (event
.xmap
.window
== tip_window
)
9290 redo_mouse_highlight ();
9293 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9294 if (f
) /* F may no longer exist if
9295 the frame was deleted. */
9297 /* While a frame is unmapped, display generation is
9298 disabled; you don't want to spend time updating a
9299 display that won't ever be seen. */
9300 f
->async_visible
= 0;
9301 /* We can't distinguish, from the event, whether the window
9302 has become iconified or invisible. So assume, if it
9303 was previously visible, than now it is iconified.
9304 But x_make_frame_invisible clears both
9305 the visible flag and the iconified flag;
9306 and that way, we know the window is not iconified now. */
9307 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9309 f
->async_iconified
= 1;
9311 bufp
->kind
= iconify_event
;
9312 XSETFRAME (bufp
->frame_or_window
, f
);
9321 if (event
.xmap
.window
== tip_window
)
9322 /* The tooltip has been drawn already. Avoid
9323 the SET_FRAME_GARBAGED below. */
9326 /* We use x_top_window_to_frame because map events can
9327 come for sub-windows and they don't mean that the
9328 frame is visible. */
9329 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9332 f
->async_visible
= 1;
9333 f
->async_iconified
= 0;
9334 f
->output_data
.x
->has_been_visible
= 1;
9336 /* wait_reading_process_input will notice this and update
9337 the frame's display structures. */
9338 SET_FRAME_GARBAGED (f
);
9342 bufp
->kind
= deiconify_event
;
9343 XSETFRAME (bufp
->frame_or_window
, f
);
9348 else if (! NILP (Vframe_list
)
9349 && ! NILP (XCDR (Vframe_list
)))
9350 /* Force a redisplay sooner or later
9351 to update the frame titles
9352 in case this is the second frame. */
9353 record_asynch_buffer_change ();
9358 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9361 /* I couldn't find a way to prevent LessTif scroll bars
9362 from consuming key events. */
9365 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9367 if (widget
&& XmIsScrollBar (widget
))
9369 widget
= XtParent (widget
);
9370 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9373 #endif /* USE_MOTIF */
9377 KeySym keysym
, orig_keysym
;
9378 /* al%imercury@uunet.uu.net says that making this 81 instead of
9379 80 fixed a bug whereby meta chars made his Emacs hang. */
9380 unsigned char copy_buffer
[81];
9384 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9385 extra_keyboard_modifiers
);
9386 modifiers
= event
.xkey
.state
;
9388 /* This will have to go some day... */
9390 /* make_lispy_event turns chars into control chars.
9391 Don't do it here because XLookupString is too eager. */
9392 event
.xkey
.state
&= ~ControlMask
;
9393 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9394 | dpyinfo
->super_mod_mask
9395 | dpyinfo
->hyper_mod_mask
9396 | dpyinfo
->alt_mod_mask
);
9398 /* In case Meta is ComposeCharacter,
9399 clear its status. According to Markus Ehrnsperger
9400 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9401 this enables ComposeCharacter to work whether or
9402 not it is combined with Meta. */
9403 if (modifiers
& dpyinfo
->meta_mod_mask
)
9404 bzero (&compose_status
, sizeof (compose_status
));
9409 unsigned char *copy_bufptr
= copy_buffer
;
9410 int copy_bufsiz
= sizeof (copy_buffer
);
9411 Status status_return
;
9413 nbytes
= XmbLookupString (FRAME_XIC (f
),
9414 &event
.xkey
, copy_bufptr
,
9415 copy_bufsiz
, &keysym
,
9417 if (status_return
== XBufferOverflow
)
9419 copy_bufsiz
= nbytes
+ 1;
9420 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9421 nbytes
= XmbLookupString (FRAME_XIC (f
),
9422 &event
.xkey
, copy_bufptr
,
9423 copy_bufsiz
, &keysym
,
9427 if (status_return
== XLookupNone
)
9429 else if (status_return
== XLookupChars
)
9431 else if (status_return
!= XLookupKeySym
9432 && status_return
!= XLookupBoth
)
9436 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9437 80, &keysym
, &compose_status
);
9439 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9440 80, &keysym
, &compose_status
);
9443 orig_keysym
= keysym
;
9447 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9448 || keysym
== XK_Delete
9449 #ifdef XK_ISO_Left_Tab
9450 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9452 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9453 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9454 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9456 /* This recognizes the "extended function keys".
9457 It seems there's no cleaner way.
9458 Test IsModifierKey to avoid handling mode_switch
9460 || ((unsigned) (keysym
) >= XK_Select
9461 && (unsigned)(keysym
) < XK_KP_Space
)
9463 #ifdef XK_dead_circumflex
9464 || orig_keysym
== XK_dead_circumflex
9466 #ifdef XK_dead_grave
9467 || orig_keysym
== XK_dead_grave
9469 #ifdef XK_dead_tilde
9470 || orig_keysym
== XK_dead_tilde
9472 #ifdef XK_dead_diaeresis
9473 || orig_keysym
== XK_dead_diaeresis
9475 #ifdef XK_dead_macron
9476 || orig_keysym
== XK_dead_macron
9478 #ifdef XK_dead_degree
9479 || orig_keysym
== XK_dead_degree
9481 #ifdef XK_dead_acute
9482 || orig_keysym
== XK_dead_acute
9484 #ifdef XK_dead_cedilla
9485 || orig_keysym
== XK_dead_cedilla
9487 #ifdef XK_dead_breve
9488 || orig_keysym
== XK_dead_breve
9490 #ifdef XK_dead_ogonek
9491 || orig_keysym
== XK_dead_ogonek
9493 #ifdef XK_dead_caron
9494 || orig_keysym
== XK_dead_caron
9496 #ifdef XK_dead_doubleacute
9497 || orig_keysym
== XK_dead_doubleacute
9499 #ifdef XK_dead_abovedot
9500 || orig_keysym
== XK_dead_abovedot
9502 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9503 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9504 /* Any "vendor-specific" key is ok. */
9505 || (orig_keysym
& (1 << 28)))
9506 && ! (IsModifierKey (orig_keysym
)
9508 #ifdef XK_Mode_switch
9509 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9512 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9514 #endif /* not HAVE_X11R5 */
9517 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9519 temp_buffer
[temp_index
++] = keysym
;
9520 bufp
->kind
= non_ascii_keystroke
;
9521 bufp
->code
= keysym
;
9522 XSETFRAME (bufp
->frame_or_window
, f
);
9524 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9526 bufp
->timestamp
= event
.xkey
.time
;
9531 else if (numchars
> nbytes
)
9535 for (i
= 0; i
< nbytes
; i
++)
9537 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9539 temp_buffer
[temp_index
++] = copy_buffer
[i
];
9540 bufp
->kind
= ascii_keystroke
;
9541 bufp
->code
= copy_buffer
[i
];
9542 XSETFRAME (bufp
->frame_or_window
, f
);
9544 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9546 bufp
->timestamp
= event
.xkey
.time
;
9553 if (keysym
== NoSymbol
)
9563 /* Don't dispatch this event since XtDispatchEvent calls
9564 XFilterEvent, and two calls in a row may freeze the
9573 /* Don't dispatch this event since XtDispatchEvent calls
9574 XFilterEvent, and two calls in a row may freeze the
9581 /* Here's a possible interpretation of the whole
9582 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9583 you get a FocusIn event, you have to get a FocusOut
9584 event before you relinquish the focus. If you
9585 haven't received a FocusIn event, then a mere
9586 LeaveNotify is enough to free you. */
9590 int from_menu_bar_p
= 0;
9592 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9594 #ifdef LESSTIF_VERSION
9595 /* When clicking outside of a menu bar popup to close
9596 it, we get a FocusIn/ EnterNotify sequence of
9597 events. The flag event.xcrossing.focus is not set
9598 in the EnterNotify event of that sequence because
9599 the focus is in the menu bar,
9600 event.xcrossing.window is the frame's X window.
9601 Unconditionally setting the focus frame to null in
9602 this case is not the right thing, because no event
9603 follows that could set the focus frame to the right
9606 This could be a LessTif bug, but I wasn't able to
9607 reproduce the behavior in a simple test program.
9609 (gerd, LessTif 0.88.1). */
9611 if (!event
.xcrossing
.focus
9613 && f
->output_data
.x
->menubar_widget
)
9618 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9619 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9620 from_menu_bar_p
= 1;
9622 #endif /* LESSTIF_VERSION */
9624 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9626 /* Avoid nasty pop/raise loops. */
9627 if (f
&& (!(f
->auto_raise
)
9629 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9631 x_new_focus_frame (dpyinfo
, f
);
9632 enter_timestamp
= event
.xcrossing
.time
;
9635 else if (f
== dpyinfo
->x_focus_frame
)
9636 x_new_focus_frame (dpyinfo
, 0);
9638 /* EnterNotify counts as mouse movement,
9639 so update things that depend on mouse position. */
9640 if (f
&& !f
->output_data
.x
->busy_p
)
9641 note_mouse_movement (f
, &event
.xmotion
);
9646 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9647 if (event
.xfocus
.detail
!= NotifyPointer
)
9648 dpyinfo
->x_focus_event_frame
= f
;
9651 x_new_focus_frame (dpyinfo
, f
);
9653 /* Don't stop displaying the initial startup message
9654 for a switch-frame event we don't need. */
9655 if (GC_NILP (Vterminal_frame
)
9656 && GC_CONSP (Vframe_list
)
9657 && !GC_NILP (XCDR (Vframe_list
)))
9659 bufp
->kind
= FOCUS_IN_EVENT
;
9660 XSETFRAME (bufp
->frame_or_window
, f
);
9661 ++bufp
, ++count
, --numchars
;
9666 if (f
&& FRAME_XIC (f
))
9667 XSetICFocus (FRAME_XIC (f
));
9673 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9677 int from_menu_bar_p
= 0;
9679 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9681 /* If we move outside the frame, then we're
9682 certainly no longer on any text in the frame. */
9683 clear_mouse_face (dpyinfo
);
9684 dpyinfo
->mouse_face_mouse_frame
= 0;
9687 /* Generate a nil HELP_EVENT to cancel a help-echo.
9688 Do it only if there's something to cancel.
9689 Otherwise, the startup message is cleared when
9690 the mouse leaves the frame. */
9691 if (any_help_event_p
)
9693 XSETFRAME (frame
, f
);
9694 bufp
->kind
= HELP_EVENT
;
9695 bufp
->frame_or_window
= Fcons (frame
, Qnil
);
9696 ++bufp
, ++count
, --numchars
;
9699 #ifdef LESSTIF_VERSION
9700 /* Please see the comment at the start of the
9701 EnterNotify case. */
9702 if (!event
.xcrossing
.focus
9703 && f
->output_data
.x
->menubar_widget
)
9707 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9708 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9709 from_menu_bar_p
= 1;
9711 #endif /* LESSTIF_VERSION */
9713 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9714 x_mouse_leave (dpyinfo
);
9717 if (f
== dpyinfo
->x_focus_event_frame
)
9718 dpyinfo
->x_focus_event_frame
= 0;
9719 if (f
== dpyinfo
->x_focus_frame
)
9720 x_new_focus_frame (dpyinfo
, 0);
9726 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9727 if (event
.xfocus
.detail
!= NotifyPointer
9728 && f
== dpyinfo
->x_focus_event_frame
)
9729 dpyinfo
->x_focus_event_frame
= 0;
9730 if (f
&& f
== dpyinfo
->x_focus_frame
)
9731 x_new_focus_frame (dpyinfo
, 0);
9734 if (f
&& FRAME_XIC (f
))
9735 XUnsetICFocus (FRAME_XIC (f
));
9742 previous_help_echo
= help_echo
;
9745 if (dpyinfo
->grabbed
&& last_mouse_frame
9746 && FRAME_LIVE_P (last_mouse_frame
))
9747 f
= last_mouse_frame
;
9749 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9752 note_mouse_movement (f
, &event
.xmotion
);
9755 #ifndef USE_TOOLKIT_SCROLL_BARS
9756 struct scroll_bar
*bar
9757 = x_window_to_scroll_bar (event
.xmotion
.window
);
9760 x_scroll_bar_note_movement (bar
, &event
);
9761 #endif /* USE_TOOLKIT_SCROLL_BARS */
9763 /* If we move outside the frame, then we're
9764 certainly no longer on any text in the frame. */
9765 clear_mouse_face (dpyinfo
);
9768 /* If the contents of the global variable help_echo
9769 has changed, generate a HELP_EVENT. */
9770 if (STRINGP (help_echo
)
9771 || STRINGP (previous_help_echo
))
9776 XSETFRAME (frame
, f
);
9780 any_help_event_p
= 1;
9781 bufp
->kind
= HELP_EVENT
;
9782 bufp
->frame_or_window
= Fcons (frame
, help_echo
);
9783 ++bufp
, ++count
, --numchars
;
9789 case ConfigureNotify
:
9790 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
9793 #ifndef USE_X_TOOLKIT
9794 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
9795 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
9797 /* In the toolkit version, change_frame_size
9798 is called by the code that handles resizing
9799 of the EmacsFrame widget. */
9801 /* Even if the number of character rows and columns has
9802 not changed, the font size may have changed, so we need
9803 to check the pixel dimensions as well. */
9804 if (columns
!= f
->width
9805 || rows
!= f
->height
9806 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
9807 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
9809 change_frame_size (f
, rows
, columns
, 0, 1, 0);
9810 SET_FRAME_GARBAGED (f
);
9811 cancel_mouse_face (f
);
9815 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
9816 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
9818 /* What we have now is the position of Emacs's own window.
9819 Convert that to the position of the window manager window. */
9820 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
9821 &f
->output_data
.x
->top_pos
);
9824 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
9825 xic_set_statusarea (f
);
9828 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
9830 /* Since the WM decorations come below top_pos now,
9831 we must put them below top_pos in the future. */
9832 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
9833 x_wm_set_size_hint (f
, (long) 0, 0);
9836 /* Some window managers pass (0,0) as the location of
9837 the window, and the Motif event handler stores it
9838 in the emacs widget, which messes up Motif menus. */
9839 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
9841 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
9842 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
9844 #endif /* USE_MOTIF */
9851 /* If we decide we want to generate an event to be seen
9852 by the rest of Emacs, we put it here. */
9853 struct input_event emacs_event
;
9856 emacs_event
.kind
= no_event
;
9857 bzero (&compose_status
, sizeof (compose_status
));
9859 if (dpyinfo
->grabbed
9861 && FRAME_LIVE_P (last_mouse_frame
))
9862 f
= last_mouse_frame
;
9864 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9868 /* Is this in the tool-bar? */
9869 if (WINDOWP (f
->tool_bar_window
)
9870 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
9875 x
= event
.xbutton
.x
;
9876 y
= event
.xbutton
.y
;
9879 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
9880 if (EQ (window
, f
->tool_bar_window
))
9882 x_handle_tool_bar_click (f
, &event
.xbutton
);
9888 if (!dpyinfo
->x_focus_frame
9889 || f
== dpyinfo
->x_focus_frame
)
9890 construct_mouse_click (&emacs_event
, &event
, f
);
9894 #ifndef USE_TOOLKIT_SCROLL_BARS
9895 struct scroll_bar
*bar
9896 = x_window_to_scroll_bar (event
.xbutton
.window
);
9899 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
9900 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9903 if (event
.type
== ButtonPress
)
9905 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
9906 last_mouse_frame
= f
;
9907 /* Ignore any mouse motion that happened
9908 before this event; any subsequent mouse-movement
9909 Emacs events should reflect only motion after
9915 last_tool_bar_item
= -1;
9919 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
9922 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
9924 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
9930 #ifdef USE_X_TOOLKIT
9931 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9932 /* For a down-event in the menu bar,
9933 don't pass it to Xt right now.
9934 Instead, save it away
9935 and we will pass it to Xt from kbd_buffer_get_event.
9936 That way, we can run some Lisp code first. */
9937 if (f
&& event
.type
== ButtonPress
9938 /* Verify the event is really within the menu bar
9939 and not just sent to it due to grabbing. */
9940 && event
.xbutton
.x
>= 0
9941 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
9942 && event
.xbutton
.y
>= 0
9943 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
9944 && event
.xbutton
.same_screen
)
9946 SET_SAVED_BUTTON_EVENT
;
9947 XSETFRAME (last_mouse_press_frame
, f
);
9949 else if (event
.type
== ButtonPress
)
9951 last_mouse_press_frame
= Qnil
;
9955 #ifdef USE_MOTIF /* This should do not harm for Lucid,
9956 but I am trying to be cautious. */
9957 else if (event
.type
== ButtonRelease
)
9959 if (!NILP (last_mouse_press_frame
))
9961 f
= XFRAME (last_mouse_press_frame
);
9962 if (f
->output_data
.x
)
9963 SET_SAVED_BUTTON_EVENT
;
9968 #endif /* USE_MOTIF */
9971 #endif /* USE_X_TOOLKIT */
9975 case CirculateNotify
:
9978 case CirculateRequest
:
9981 case VisibilityNotify
:
9985 /* Someone has changed the keyboard mapping - update the
9987 switch (event
.xmapping
.request
)
9989 case MappingModifier
:
9990 x_find_modifier_meanings (dpyinfo
);
9991 /* This is meant to fall through. */
9992 case MappingKeyboard
:
9993 XRefreshKeyboardMapping (&event
.xmapping
);
9999 #ifdef USE_X_TOOLKIT
10001 XtDispatchEvent (&event
);
10003 #endif /* USE_X_TOOLKIT */
10011 /* On some systems, an X bug causes Emacs to get no more events
10012 when the window is destroyed. Detect that. (1994.) */
10015 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10016 One XNOOP in 100 loops will make Emacs terminate.
10017 B. Bretthauer, 1994 */
10019 if (x_noop_count
>= 100)
10023 if (next_noop_dpyinfo
== 0)
10024 next_noop_dpyinfo
= x_display_list
;
10026 XNoOp (next_noop_dpyinfo
->display
);
10028 /* Each time we get here, cycle through the displays now open. */
10029 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10033 /* If the focus was just given to an auto-raising frame,
10035 /* ??? This ought to be able to handle more than one such frame. */
10036 if (pending_autoraise_frame
)
10038 x_raise_frame (pending_autoraise_frame
);
10039 pending_autoraise_frame
= 0;
10049 /***********************************************************************
10051 ***********************************************************************/
10053 /* Note if the text cursor of window W has been overwritten by a
10054 drawing operation that outputs N glyphs starting at HPOS in the
10055 line given by output_cursor.vpos. N < 0 means all the rest of the
10056 line after HPOS has been written. */
10059 note_overwritten_text_cursor (w
, hpos
, n
)
10063 if (updated_area
== TEXT_AREA
10064 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10065 && hpos
<= w
->phys_cursor
.hpos
10067 || hpos
+ n
> w
->phys_cursor
.hpos
))
10068 w
->phys_cursor_on_p
= 0;
10072 /* Set clipping for output in glyph row ROW. W is the window in which
10073 we operate. GC is the graphics context to set clipping in.
10074 WHOLE_LINE_P non-zero means include the areas used for truncation
10075 mark display and alike in the clipping rectangle.
10077 ROW may be a text row or, e.g., a mode line. Text rows must be
10078 clipped to the interior of the window dedicated to text display,
10079 mode lines must be clipped to the whole window. */
10082 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10084 struct glyph_row
*row
;
10088 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10089 XRectangle clip_rect
;
10090 int window_x
, window_y
, window_width
, window_height
;
10092 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10094 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10095 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10096 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10097 clip_rect
.width
= window_width
;
10098 clip_rect
.height
= row
->visible_height
;
10100 /* If clipping to the whole line, including trunc marks, extend
10101 the rectangle to the left and increase its width. */
10104 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10105 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10108 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10112 /* Draw a hollow box cursor on window W in glyph row ROW. */
10115 x_draw_hollow_cursor (w
, row
)
10117 struct glyph_row
*row
;
10119 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10120 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10121 Display
*dpy
= FRAME_X_DISPLAY (f
);
10124 struct glyph
*cursor_glyph
;
10127 /* Compute frame-relative coordinates from window-relative
10129 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10130 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10131 + row
->ascent
- w
->phys_cursor_ascent
);
10132 h
= row
->height
- 1;
10134 /* Get the glyph the cursor is on. If we can't tell because
10135 the current matrix is invalid or such, give up. */
10136 cursor_glyph
= get_phys_cursor_glyph (w
);
10137 if (cursor_glyph
== NULL
)
10140 /* Compute the width of the rectangle to draw. If on a stretch
10141 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10142 rectangle as wide as the glyph, but use a canonical character
10144 wd
= cursor_glyph
->pixel_width
- 1;
10145 if (cursor_glyph
->type
== STRETCH_GLYPH
10146 && !x_stretch_cursor_p
)
10147 wd
= min (CANON_X_UNIT (f
), wd
);
10149 /* The foreground of cursor_gc is typically the same as the normal
10150 background color, which can cause the cursor box to be invisible. */
10151 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10152 if (dpyinfo
->scratch_cursor_gc
)
10153 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10155 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10156 GCForeground
, &xgcv
);
10157 gc
= dpyinfo
->scratch_cursor_gc
;
10159 /* Set clipping, draw the rectangle, and reset clipping again. */
10160 x_clip_to_row (w
, row
, gc
, 0);
10161 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10162 XSetClipMask (dpy
, gc
, None
);
10166 /* Draw a bar cursor on window W in glyph row ROW.
10168 Implementation note: One would like to draw a bar cursor with an
10169 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10170 Unfortunately, I didn't find a font yet that has this property set.
10174 x_draw_bar_cursor (w
, row
, width
)
10176 struct glyph_row
*row
;
10179 /* If cursor hpos is out of bounds, don't draw garbage. This can
10180 happen in mini-buffer windows when switching between echo area
10181 glyphs and mini-buffer. */
10182 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10184 struct frame
*f
= XFRAME (w
->frame
);
10185 struct glyph
*cursor_glyph
;
10188 unsigned long mask
;
10193 cursor_glyph
= get_phys_cursor_glyph (w
);
10194 if (cursor_glyph
== NULL
)
10197 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10198 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10199 xgcv
.graphics_exposures
= 0;
10200 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10201 dpy
= FRAME_X_DISPLAY (f
);
10202 window
= FRAME_X_WINDOW (f
);
10203 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10206 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10209 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10210 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10214 width
= f
->output_data
.x
->cursor_width
;
10216 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10217 x_clip_to_row (w
, row
, gc
, 0);
10218 XFillRectangle (dpy
, window
, gc
,
10220 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10221 min (cursor_glyph
->pixel_width
, width
),
10223 XSetClipMask (dpy
, gc
, None
);
10228 /* Clear the cursor of window W to background color, and mark the
10229 cursor as not shown. This is used when the text where the cursor
10230 is is about to be rewritten. */
10236 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10237 x_update_window_cursor (w
, 0);
10241 /* Draw the cursor glyph of window W in glyph row ROW. See the
10242 comment of x_draw_glyphs for the meaning of HL. */
10245 x_draw_phys_cursor_glyph (w
, row
, hl
)
10247 struct glyph_row
*row
;
10248 enum draw_glyphs_face hl
;
10250 /* If cursor hpos is out of bounds, don't draw garbage. This can
10251 happen in mini-buffer windows when switching between echo area
10252 glyphs and mini-buffer. */
10253 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10255 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10256 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10259 /* When we erase the cursor, and ROW is overlapped by other
10260 rows, make sure that these overlapping parts of other rows
10262 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10264 if (row
> w
->current_matrix
->rows
10265 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10266 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10268 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10269 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10270 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10276 /* Erase the image of a cursor of window W from the screen. */
10279 x_erase_phys_cursor (w
)
10282 struct frame
*f
= XFRAME (w
->frame
);
10283 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10284 int hpos
= w
->phys_cursor
.hpos
;
10285 int vpos
= w
->phys_cursor
.vpos
;
10286 int mouse_face_here_p
= 0;
10287 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10288 struct glyph_row
*cursor_row
;
10289 struct glyph
*cursor_glyph
;
10290 enum draw_glyphs_face hl
;
10292 /* No cursor displayed or row invalidated => nothing to do on the
10294 if (w
->phys_cursor_type
== NO_CURSOR
)
10295 goto mark_cursor_off
;
10297 /* VPOS >= active_glyphs->nrows means that window has been resized.
10298 Don't bother to erase the cursor. */
10299 if (vpos
>= active_glyphs
->nrows
)
10300 goto mark_cursor_off
;
10302 /* If row containing cursor is marked invalid, there is nothing we
10304 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10305 if (!cursor_row
->enabled_p
)
10306 goto mark_cursor_off
;
10308 /* This can happen when the new row is shorter than the old one.
10309 In this case, either x_draw_glyphs or clear_end_of_line
10310 should have cleared the cursor. Note that we wouldn't be
10311 able to erase the cursor in this case because we don't have a
10312 cursor glyph at hand. */
10313 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10314 goto mark_cursor_off
;
10316 /* If the cursor is in the mouse face area, redisplay that when
10317 we clear the cursor. */
10318 if (! NILP (dpyinfo
->mouse_face_window
)
10319 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10320 && (vpos
> dpyinfo
->mouse_face_beg_row
10321 || (vpos
== dpyinfo
->mouse_face_beg_row
10322 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10323 && (vpos
< dpyinfo
->mouse_face_end_row
10324 || (vpos
== dpyinfo
->mouse_face_end_row
10325 && hpos
< dpyinfo
->mouse_face_end_col
))
10326 /* Don't redraw the cursor's spot in mouse face if it is at the
10327 end of a line (on a newline). The cursor appears there, but
10328 mouse highlighting does not. */
10329 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10330 mouse_face_here_p
= 1;
10332 /* Maybe clear the display under the cursor. */
10333 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10336 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10338 cursor_glyph
= get_phys_cursor_glyph (w
);
10339 if (cursor_glyph
== NULL
)
10340 goto mark_cursor_off
;
10342 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10344 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10346 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10348 cursor_glyph
->pixel_width
,
10349 cursor_row
->visible_height
,
10353 /* Erase the cursor by redrawing the character underneath it. */
10354 if (mouse_face_here_p
)
10355 hl
= DRAW_MOUSE_FACE
;
10356 else if (cursor_row
->inverse_p
)
10357 hl
= DRAW_INVERSE_VIDEO
;
10359 hl
= DRAW_NORMAL_TEXT
;
10360 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10363 w
->phys_cursor_on_p
= 0;
10364 w
->phys_cursor_type
= NO_CURSOR
;
10368 /* Display or clear cursor of window W. If ON is zero, clear the
10369 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10370 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10373 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10375 int on
, hpos
, vpos
, x
, y
;
10377 struct frame
*f
= XFRAME (w
->frame
);
10378 int new_cursor_type
;
10379 int new_cursor_width
;
10380 struct glyph_matrix
*current_glyphs
;
10381 struct glyph_row
*glyph_row
;
10382 struct glyph
*glyph
;
10384 /* This is pointless on invisible frames, and dangerous on garbaged
10385 windows and frames; in the latter case, the frame or window may
10386 be in the midst of changing its size, and x and y may be off the
10388 if (! FRAME_VISIBLE_P (f
)
10389 || FRAME_GARBAGED_P (f
)
10390 || vpos
>= w
->current_matrix
->nrows
10391 || hpos
>= w
->current_matrix
->matrix_w
)
10394 /* If cursor is off and we want it off, return quickly. */
10395 if (!on
&& !w
->phys_cursor_on_p
)
10398 current_glyphs
= w
->current_matrix
;
10399 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10400 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10402 /* If cursor row is not enabled, we don't really know where to
10403 display the cursor. */
10404 if (!glyph_row
->enabled_p
)
10406 w
->phys_cursor_on_p
= 0;
10410 xassert (interrupt_input_blocked
);
10412 /* Set new_cursor_type to the cursor we want to be displayed. In a
10413 mini-buffer window, we want the cursor only to appear if we are
10414 reading input from this window. For the selected window, we want
10415 the cursor type given by the frame parameter. If explicitly
10416 marked off, draw no cursor. In all other cases, we want a hollow
10418 new_cursor_width
= -1;
10419 if (cursor_in_echo_area
10420 && FRAME_HAS_MINIBUF_P (f
)
10421 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10423 if (w
== XWINDOW (echo_area_window
))
10424 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10426 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10430 if (w
!= XWINDOW (selected_window
)
10431 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10433 extern int cursor_in_non_selected_windows
;
10435 if (MINI_WINDOW_P (w
) || !cursor_in_non_selected_windows
)
10436 new_cursor_type
= NO_CURSOR
;
10438 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10440 else if (w
->cursor_off_p
)
10441 new_cursor_type
= NO_CURSOR
;
10444 struct buffer
*b
= XBUFFER (w
->buffer
);
10446 if (EQ (b
->cursor_type
, Qt
))
10447 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10449 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10450 &new_cursor_width
);
10454 /* If cursor is currently being shown and we don't want it to be or
10455 it is in the wrong place, or the cursor type is not what we want,
10457 if (w
->phys_cursor_on_p
10459 || w
->phys_cursor
.x
!= x
10460 || w
->phys_cursor
.y
!= y
10461 || new_cursor_type
!= w
->phys_cursor_type
))
10462 x_erase_phys_cursor (w
);
10464 /* If the cursor is now invisible and we want it to be visible,
10466 if (on
&& !w
->phys_cursor_on_p
)
10468 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10469 w
->phys_cursor_height
= glyph_row
->height
;
10471 /* Set phys_cursor_.* before x_draw_.* is called because some
10472 of them may need the information. */
10473 w
->phys_cursor
.x
= x
;
10474 w
->phys_cursor
.y
= glyph_row
->y
;
10475 w
->phys_cursor
.hpos
= hpos
;
10476 w
->phys_cursor
.vpos
= vpos
;
10477 w
->phys_cursor_type
= new_cursor_type
;
10478 w
->phys_cursor_on_p
= 1;
10480 switch (new_cursor_type
)
10482 case HOLLOW_BOX_CURSOR
:
10483 x_draw_hollow_cursor (w
, glyph_row
);
10486 case FILLED_BOX_CURSOR
:
10487 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10491 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10502 if (w
== XWINDOW (f
->selected_window
))
10503 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10504 xic_set_preeditarea (w
, x
, y
);
10509 if (updating_frame
!= f
)
10510 XFlush (FRAME_X_DISPLAY (f
));
10515 /* Display the cursor on window W, or clear it. X and Y are window
10516 relative pixel coordinates. HPOS and VPOS are glyph matrix
10517 positions. If W is not the selected window, display a hollow
10518 cursor. ON non-zero means display the cursor at X, Y which
10519 correspond to HPOS, VPOS, otherwise it is cleared. */
10522 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10524 int on
, hpos
, vpos
, x
, y
;
10527 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10532 /* Display the cursor on window W, or clear it, according to ON_P.
10533 Don't change the cursor's position. */
10536 x_update_cursor (f
, on_p
)
10539 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10543 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10544 in the window tree rooted at W. */
10547 x_update_cursor_in_window_tree (w
, on_p
)
10553 if (!NILP (w
->hchild
))
10554 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10555 else if (!NILP (w
->vchild
))
10556 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10558 x_update_window_cursor (w
, on_p
);
10560 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10565 /* Switch the display of W's cursor on or off, according to the value
10569 x_update_window_cursor (w
, on
)
10573 /* Don't update cursor in windows whose frame is in the process
10574 of being deleted. */
10575 if (w
->current_matrix
)
10578 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10579 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10589 /* Refresh bitmap kitchen sink icon for frame F
10590 when we get an expose event for it. */
10596 /* Normally, the window manager handles this function. */
10599 /* Make the x-window of frame F use the gnu icon bitmap. */
10602 x_bitmap_icon (f
, file
)
10608 if (FRAME_X_WINDOW (f
) == 0)
10611 /* Free up our existing icon bitmap if any. */
10612 if (f
->output_data
.x
->icon_bitmap
> 0)
10613 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10614 f
->output_data
.x
->icon_bitmap
= 0;
10616 if (STRINGP (file
))
10617 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10620 /* Create the GNU bitmap if necessary. */
10621 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10622 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10623 = x_create_bitmap_from_data (f
, gnu_bits
,
10624 gnu_width
, gnu_height
);
10626 /* The first time we create the GNU bitmap,
10627 this increments the ref-count one extra time.
10628 As a result, the GNU bitmap is never freed.
10629 That way, we don't have to worry about allocating it again. */
10630 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10632 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10635 x_wm_set_icon_pixmap (f
, bitmap_id
);
10636 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10642 /* Make the x-window of frame F use a rectangle with text.
10643 Use ICON_NAME as the text. */
10646 x_text_icon (f
, icon_name
)
10650 if (FRAME_X_WINDOW (f
) == 0)
10655 XTextProperty text
;
10656 text
.value
= (unsigned char *) icon_name
;
10657 text
.encoding
= XA_STRING
;
10659 text
.nitems
= strlen (icon_name
);
10660 #ifdef USE_X_TOOLKIT
10661 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10663 #else /* not USE_X_TOOLKIT */
10664 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10665 #endif /* not USE_X_TOOLKIT */
10667 #else /* not HAVE_X11R4 */
10668 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10669 #endif /* not HAVE_X11R4 */
10671 if (f
->output_data
.x
->icon_bitmap
> 0)
10672 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10673 f
->output_data
.x
->icon_bitmap
= 0;
10674 x_wm_set_icon_pixmap (f
, 0);
10679 #define X_ERROR_MESSAGE_SIZE 200
10681 /* If non-nil, this should be a string.
10682 It means catch X errors and store the error message in this string. */
10684 static Lisp_Object x_error_message_string
;
10686 /* An X error handler which stores the error message in
10687 x_error_message_string. This is called from x_error_handler if
10688 x_catch_errors is in effect. */
10691 x_error_catcher (display
, error
)
10693 XErrorEvent
*error
;
10695 XGetErrorText (display
, error
->error_code
,
10696 XSTRING (x_error_message_string
)->data
,
10697 X_ERROR_MESSAGE_SIZE
);
10700 /* Begin trapping X errors for display DPY. Actually we trap X errors
10701 for all displays, but DPY should be the display you are actually
10704 After calling this function, X protocol errors no longer cause
10705 Emacs to exit; instead, they are recorded in the string
10706 stored in x_error_message_string.
10708 Calling x_check_errors signals an Emacs error if an X error has
10709 occurred since the last call to x_catch_errors or x_check_errors.
10711 Calling x_uncatch_errors resumes the normal error handling. */
10713 void x_check_errors ();
10714 static Lisp_Object
x_catch_errors_unwind ();
10717 x_catch_errors (dpy
)
10720 int count
= specpdl_ptr
- specpdl
;
10722 /* Make sure any errors from previous requests have been dealt with. */
10723 XSync (dpy
, False
);
10725 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10727 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10728 XSTRING (x_error_message_string
)->data
[0] = 0;
10733 /* Unbind the binding that we made to check for X errors. */
10736 x_catch_errors_unwind (old_val
)
10737 Lisp_Object old_val
;
10739 x_error_message_string
= old_val
;
10743 /* If any X protocol errors have arrived since the last call to
10744 x_catch_errors or x_check_errors, signal an Emacs error using
10745 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10748 x_check_errors (dpy
, format
)
10752 /* Make sure to catch any errors incurred so far. */
10753 XSync (dpy
, False
);
10755 if (XSTRING (x_error_message_string
)->data
[0])
10756 error (format
, XSTRING (x_error_message_string
)->data
);
10759 /* Nonzero if we had any X protocol errors
10760 since we did x_catch_errors on DPY. */
10763 x_had_errors_p (dpy
)
10766 /* Make sure to catch any errors incurred so far. */
10767 XSync (dpy
, False
);
10769 return XSTRING (x_error_message_string
)->data
[0] != 0;
10772 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
10775 x_clear_errors (dpy
)
10778 XSTRING (x_error_message_string
)->data
[0] = 0;
10781 /* Stop catching X protocol errors and let them make Emacs die.
10782 DPY should be the display that was passed to x_catch_errors.
10783 COUNT should be the value that was returned by
10784 the corresponding call to x_catch_errors. */
10787 x_uncatch_errors (dpy
, count
)
10791 unbind_to (count
, Qnil
);
10795 static unsigned int x_wire_count
;
10798 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
10803 /* Handle SIGPIPE, which can happen when the connection to a server
10804 simply goes away. SIGPIPE is handled by x_connection_signal.
10805 Don't need to do anything, because the write which caused the
10806 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
10807 which will do the appropriate cleanup for us. */
10810 x_connection_signal (signalnum
) /* If we don't have an argument, */
10811 int signalnum
; /* some compilers complain in signal calls. */
10814 /* USG systems forget handlers when they are used;
10815 must reestablish each time */
10816 signal (signalnum
, x_connection_signal
);
10820 /* Handling X errors. */
10822 /* Handle the loss of connection to display DISPLAY. */
10825 x_connection_closed (display
, error_message
)
10827 char *error_message
;
10829 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
10830 Lisp_Object frame
, tail
;
10832 /* Indicate that this display is dead. */
10834 #if 0 /* Closing the display caused a bus error on OpenWindows. */
10835 #ifdef USE_X_TOOLKIT
10836 XtCloseDisplay (display
);
10841 dpyinfo
->display
= 0;
10843 /* First delete frames whose mini-buffers are on frames
10844 that are on the dead display. */
10845 FOR_EACH_FRAME (tail
, frame
)
10847 Lisp_Object minibuf_frame
;
10849 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
10850 if (FRAME_X_P (XFRAME (frame
))
10851 && FRAME_X_P (XFRAME (minibuf_frame
))
10852 && ! EQ (frame
, minibuf_frame
)
10853 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
10854 Fdelete_frame (frame
, Qt
);
10857 /* Now delete all remaining frames on the dead display.
10858 We are now sure none of these is used as the mini-buffer
10859 for another frame that we need to delete. */
10860 FOR_EACH_FRAME (tail
, frame
)
10861 if (FRAME_X_P (XFRAME (frame
))
10862 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
10864 /* Set this to t so that Fdelete_frame won't get confused
10865 trying to find a replacement. */
10866 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
10867 Fdelete_frame (frame
, Qt
);
10871 x_delete_display (dpyinfo
);
10873 if (x_display_list
== 0)
10875 fprintf (stderr
, "%s\n", error_message
);
10876 shut_down_emacs (0, 0, Qnil
);
10880 /* Ordinary stack unwind doesn't deal with these. */
10882 sigunblock (sigmask (SIGIO
));
10884 sigunblock (sigmask (SIGALRM
));
10885 TOTALLY_UNBLOCK_INPUT
;
10887 clear_waiting_for_input ();
10888 error ("%s", error_message
);
10891 /* This is the usual handler for X protocol errors.
10892 It kills all frames on the display that we got the error for.
10893 If that was the only one, it prints an error message and kills Emacs. */
10896 x_error_quitter (display
, error
)
10898 XErrorEvent
*error
;
10900 char buf
[256], buf1
[356];
10902 /* Note that there is no real way portable across R3/R4 to get the
10903 original error handler. */
10905 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
10906 sprintf (buf1
, "X protocol error: %s on protocol request %d",
10907 buf
, error
->request_code
);
10908 x_connection_closed (display
, buf1
);
10911 /* This is the first-level handler for X protocol errors.
10912 It calls x_error_quitter or x_error_catcher. */
10915 x_error_handler (display
, error
)
10917 XErrorEvent
*error
;
10919 if (! NILP (x_error_message_string
))
10920 x_error_catcher (display
, error
);
10922 x_error_quitter (display
, error
);
10926 /* This is the handler for X IO errors, always.
10927 It kills all frames on the display that we lost touch with.
10928 If that was the only one, it prints an error message and kills Emacs. */
10931 x_io_error_quitter (display
)
10936 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
10937 x_connection_closed (display
, buf
);
10941 /* Changing the font of the frame. */
10943 /* Give frame F the font named FONTNAME as its default font, and
10944 return the full name of that font. FONTNAME may be a wildcard
10945 pattern; in that case, we choose some font that fits the pattern.
10946 The return value shows which font we chose. */
10949 x_new_font (f
, fontname
)
10951 register char *fontname
;
10953 struct font_info
*fontp
10954 = FS_LOAD_FONT (f
, 0, fontname
, -1);
10959 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
10960 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
10961 f
->output_data
.x
->fontset
= -1;
10963 /* Compute the scroll bar width in character columns. */
10964 if (f
->scroll_bar_pixel_width
> 0)
10966 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10967 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
10971 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10972 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
10975 /* Now make the frame display the given font. */
10976 if (FRAME_X_WINDOW (f
) != 0)
10978 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
10979 f
->output_data
.x
->font
->fid
);
10980 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
10981 f
->output_data
.x
->font
->fid
);
10982 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
10983 f
->output_data
.x
->font
->fid
);
10985 frame_update_line_height (f
);
10986 x_set_window_size (f
, 0, f
->width
, f
->height
);
10989 /* If we are setting a new frame's font for the first time,
10990 there are no faces yet, so this font's height is the line height. */
10991 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
10993 return build_string (fontp
->full_name
);
10996 /* Give frame F the fontset named FONTSETNAME as its default font, and
10997 return the full name of that fontset. FONTSETNAME may be a wildcard
10998 pattern; in that case, we choose some fontset that fits the pattern.
10999 The return value shows which fontset we chose. */
11002 x_new_fontset (f
, fontsetname
)
11006 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11007 Lisp_Object result
;
11012 if (f
->output_data
.x
->fontset
== fontset
)
11013 /* This fontset is already set in frame F. There's nothing more
11015 return fontset_name (fontset
);
11017 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11019 if (!STRINGP (result
))
11020 /* Can't load ASCII font. */
11023 /* Since x_new_font doesn't update any fontset information, do it now. */
11024 f
->output_data
.x
->fontset
= fontset
;
11028 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11029 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11032 return build_string (fontsetname
);
11036 /***********************************************************************
11038 ***********************************************************************/
11044 /* XIM destroy callback function, which is called whenever the
11045 connection to input method XIM dies. CLIENT_DATA contains a
11046 pointer to the x_display_info structure corresponding to XIM. */
11049 xim_destroy_callback (xim
, client_data
, call_data
)
11051 XPointer client_data
;
11052 XPointer call_data
;
11054 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11055 Lisp_Object frame
, tail
;
11059 /* No need to call XDestroyIC.. */
11060 FOR_EACH_FRAME (tail
, frame
)
11062 struct frame
*f
= XFRAME (frame
);
11063 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11065 FRAME_XIC (f
) = NULL
;
11066 if (FRAME_XIC_FONTSET (f
))
11068 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11069 FRAME_XIC_FONTSET (f
) = NULL
;
11074 /* No need to call XCloseIM. */
11075 dpyinfo
->xim
= NULL
;
11076 XFree (dpyinfo
->xim_styles
);
11080 #endif /* HAVE_X11R6 */
11082 /* Open the connection to the XIM server on display DPYINFO.
11083 RESOURCE_NAME is the resource name Emacs uses. */
11086 xim_open_dpy (dpyinfo
, resource_name
)
11087 struct x_display_info
*dpyinfo
;
11088 char *resource_name
;
11092 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11093 dpyinfo
->xim
= xim
;
11098 XIMCallback destroy
;
11101 /* Get supported styles and XIM values. */
11102 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11105 destroy
.callback
= xim_destroy_callback
;
11106 destroy
.client_data
= (XPointer
)dpyinfo
;
11107 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11113 #ifdef HAVE_X11R6_XIM
11117 struct x_display_info
*dpyinfo
;
11118 char *resource_name
;
11121 /* XIM instantiate callback function, which is called whenever an XIM
11122 server is available. DISPLAY is teh display of the XIM.
11123 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11124 when the callback was registered. */
11127 xim_instantiate_callback (display
, client_data
, call_data
)
11129 XPointer client_data
;
11130 XPointer call_data
;
11132 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11133 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11135 /* We don't support multiple XIM connections. */
11139 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11141 /* Create XIC for the existing frames on the same display, as long
11142 as they have no XIC. */
11143 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11145 Lisp_Object tail
, frame
;
11148 FOR_EACH_FRAME (tail
, frame
)
11150 struct frame
*f
= XFRAME (frame
);
11152 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11153 if (FRAME_XIC (f
) == NULL
)
11155 create_frame_xic (f
);
11156 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11157 xic_set_statusarea (f
);
11158 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11160 struct window
*w
= XWINDOW (f
->selected_window
);
11161 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11170 #endif /* HAVE_X11R6_XIM */
11173 /* Open a connection to the XIM server on display DPYINFO.
11174 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11175 connection only at the first time. On X11R6, open the connection
11176 in the XIM instantiate callback function. */
11179 xim_initialize (dpyinfo
, resource_name
)
11180 struct x_display_info
*dpyinfo
;
11181 char *resource_name
;
11183 #ifdef HAVE_X11R6_XIM
11184 struct xim_inst_t
*xim_inst
;
11187 dpyinfo
->xim
= NULL
;
11188 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11189 xim_inst
->dpyinfo
= dpyinfo
;
11190 len
= strlen (resource_name
);
11191 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11192 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11193 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11194 resource_name
, EMACS_CLASS
,
11195 xim_instantiate_callback
,
11196 /* Fixme: This is XPointer in
11197 XFree86 but (XPointer *) on
11198 Tru64, at least. */
11199 (XPointer
) xim_inst
);
11200 #else /* not HAVE_X11R6_XIM */
11201 dpyinfo
->xim
= NULL
;
11202 xim_open_dpy (dpyinfo
, resource_name
);
11203 #endif /* not HAVE_X11R6_XIM */
11207 /* Close the connection to the XIM server on display DPYINFO. */
11210 xim_close_dpy (dpyinfo
)
11211 struct x_display_info
*dpyinfo
;
11213 #ifdef HAVE_X11R6_XIM
11214 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11216 xim_instantiate_callback
, NULL
);
11217 #endif /* not HAVE_X11R6_XIM */
11218 XCloseIM (dpyinfo
->xim
);
11219 dpyinfo
->xim
= NULL
;
11220 XFree (dpyinfo
->xim_styles
);
11223 #endif /* not HAVE_X11R6_XIM */
11227 /* Calculate the absolute position in frame F
11228 from its current recorded position values and gravity. */
11231 x_calc_absolute_position (f
)
11235 int win_x
= 0, win_y
= 0;
11236 int flags
= f
->output_data
.x
->size_hint_flags
;
11239 /* We have nothing to do if the current position
11240 is already for the top-left corner. */
11241 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11244 #ifdef USE_X_TOOLKIT
11245 this_window
= XtWindow (f
->output_data
.x
->widget
);
11247 this_window
= FRAME_X_WINDOW (f
);
11250 /* Find the position of the outside upper-left corner of
11251 the inner window, with respect to the outer window.
11252 But do this only if we will need the results. */
11253 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11258 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11261 x_clear_errors (FRAME_X_DISPLAY (f
));
11262 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11264 /* From-window, to-window. */
11266 f
->output_data
.x
->parent_desc
,
11268 /* From-position, to-position. */
11269 0, 0, &win_x
, &win_y
,
11271 /* Child of win. */
11273 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11275 Window newroot
, newparent
= 0xdeadbeef;
11276 Window
*newchildren
;
11277 unsigned int nchildren
;
11279 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11280 &newparent
, &newchildren
, &nchildren
))
11283 XFree ((char *) newchildren
);
11285 f
->output_data
.x
->parent_desc
= newparent
;
11291 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11295 /* Treat negative positions as relative to the leftmost bottommost
11296 position that fits on the screen. */
11297 if (flags
& XNegative
)
11298 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11299 - 2 * f
->output_data
.x
->border_width
- win_x
11301 + f
->output_data
.x
->left_pos
);
11303 if (flags
& YNegative
)
11305 int menubar_height
= 0;
11307 #ifdef USE_X_TOOLKIT
11308 if (f
->output_data
.x
->menubar_widget
)
11310 = (f
->output_data
.x
->menubar_widget
->core
.height
11311 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
11314 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11315 - 2 * f
->output_data
.x
->border_width
11319 + f
->output_data
.x
->top_pos
);
11322 /* The left_pos and top_pos
11323 are now relative to the top and left screen edges,
11324 so the flags should correspond. */
11325 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11328 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11329 to really change the position, and 0 when calling from
11330 x_make_frame_visible (in that case, XOFF and YOFF are the current
11331 position values). It is -1 when calling from x_set_frame_parameters,
11332 which means, do adjust for borders but don't change the gravity. */
11335 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11337 register int xoff
, yoff
;
11338 int change_gravity
;
11340 int modified_top
, modified_left
;
11342 if (change_gravity
> 0)
11344 f
->output_data
.x
->top_pos
= yoff
;
11345 f
->output_data
.x
->left_pos
= xoff
;
11346 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11348 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11350 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11351 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11353 x_calc_absolute_position (f
);
11356 x_wm_set_size_hint (f
, (long) 0, 0);
11358 modified_left
= f
->output_data
.x
->left_pos
;
11359 modified_top
= f
->output_data
.x
->top_pos
;
11360 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11361 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11362 /* It is a mystery why we need to add the border_width here
11363 when the frame is already visible, but experiment says we do. */
11364 if (change_gravity
!= 0)
11366 modified_left
+= f
->output_data
.x
->border_width
;
11367 modified_top
+= f
->output_data
.x
->border_width
;
11371 #ifdef USE_X_TOOLKIT
11372 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11373 modified_left
, modified_top
);
11374 #else /* not USE_X_TOOLKIT */
11375 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11376 modified_left
, modified_top
);
11377 #endif /* not USE_X_TOOLKIT */
11381 /* Call this to change the size of frame F's x-window.
11382 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11383 for this size change and subsequent size changes.
11384 Otherwise we leave the window gravity unchanged. */
11387 x_set_window_size (f
, change_gravity
, cols
, rows
)
11389 int change_gravity
;
11392 #ifndef USE_X_TOOLKIT
11393 int pixelwidth
, pixelheight
;
11398 #ifdef USE_X_TOOLKIT
11400 /* The x and y position of the widget is clobbered by the
11401 call to XtSetValues within EmacsFrameSetCharSize.
11402 This is a real kludge, but I don't understand Xt so I can't
11403 figure out a correct fix. Can anyone else tell me? -- rms. */
11404 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11405 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11406 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11407 f
->output_data
.x
->widget
->core
.x
= xpos
;
11408 f
->output_data
.x
->widget
->core
.y
= ypos
;
11411 #else /* not USE_X_TOOLKIT */
11413 check_frame_size (f
, &rows
, &cols
);
11414 f
->output_data
.x
->vertical_scroll_bar_extra
11415 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11417 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11418 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11419 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11420 f
->output_data
.x
->flags_areas_extra
11421 = FRAME_FLAGS_AREA_WIDTH (f
);
11422 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11423 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11425 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11426 x_wm_set_size_hint (f
, (long) 0, 0);
11428 XSync (FRAME_X_DISPLAY (f
), False
);
11429 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11430 pixelwidth
, pixelheight
);
11432 /* Now, strictly speaking, we can't be sure that this is accurate,
11433 but the window manager will get around to dealing with the size
11434 change request eventually, and we'll hear how it went when the
11435 ConfigureNotify event gets here.
11437 We could just not bother storing any of this information here,
11438 and let the ConfigureNotify event set everything up, but that
11439 might be kind of confusing to the Lisp code, since size changes
11440 wouldn't be reported in the frame parameters until some random
11441 point in the future when the ConfigureNotify event arrives.
11443 We pass 1 for DELAY since we can't run Lisp code inside of
11445 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11446 PIXEL_WIDTH (f
) = pixelwidth
;
11447 PIXEL_HEIGHT (f
) = pixelheight
;
11449 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11450 receive in the ConfigureNotify event; if we get what we asked
11451 for, then the event won't cause the screen to become garbaged, so
11452 we have to make sure to do it here. */
11453 SET_FRAME_GARBAGED (f
);
11455 XFlush (FRAME_X_DISPLAY (f
));
11457 #endif /* not USE_X_TOOLKIT */
11459 /* If cursor was outside the new size, mark it as off. */
11460 mark_window_cursors_off (XWINDOW (f
->root_window
));
11462 /* Clear out any recollection of where the mouse highlighting was,
11463 since it might be in a place that's outside the new frame size.
11464 Actually checking whether it is outside is a pain in the neck,
11465 so don't try--just let the highlighting be done afresh with new size. */
11466 cancel_mouse_face (f
);
11471 /* Mouse warping. */
11474 x_set_mouse_position (f
, x
, y
)
11480 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11481 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11483 if (pix_x
< 0) pix_x
= 0;
11484 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11486 if (pix_y
< 0) pix_y
= 0;
11487 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11491 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11492 0, 0, 0, 0, pix_x
, pix_y
);
11496 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11499 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11505 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11506 0, 0, 0, 0, pix_x
, pix_y
);
11510 /* focus shifting, raising and lowering. */
11513 x_focus_on_frame (f
)
11516 #if 0 /* This proves to be unpleasant. */
11520 /* I don't think that the ICCCM allows programs to do things like this
11521 without the interaction of the window manager. Whatever you end up
11522 doing with this code, do it to x_unfocus_frame too. */
11523 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11524 RevertToPointerRoot
, CurrentTime
);
11529 x_unfocus_frame (f
)
11533 /* Look at the remarks in x_focus_on_frame. */
11534 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11535 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11536 RevertToPointerRoot
, CurrentTime
);
11540 /* Raise frame F. */
11546 if (f
->async_visible
)
11549 #ifdef USE_X_TOOLKIT
11550 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11551 #else /* not USE_X_TOOLKIT */
11552 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11553 #endif /* not USE_X_TOOLKIT */
11554 XFlush (FRAME_X_DISPLAY (f
));
11559 /* Lower frame F. */
11565 if (f
->async_visible
)
11568 #ifdef USE_X_TOOLKIT
11569 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11570 #else /* not USE_X_TOOLKIT */
11571 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11572 #endif /* not USE_X_TOOLKIT */
11573 XFlush (FRAME_X_DISPLAY (f
));
11579 XTframe_raise_lower (f
, raise_flag
)
11589 /* Change of visibility. */
11591 /* This tries to wait until the frame is really visible.
11592 However, if the window manager asks the user where to position
11593 the frame, this will return before the user finishes doing that.
11594 The frame will not actually be visible at that time,
11595 but it will become visible later when the window manager
11596 finishes with it. */
11599 x_make_frame_visible (f
)
11603 int original_top
, original_left
;
11607 type
= x_icon_type (f
);
11609 x_bitmap_icon (f
, type
);
11611 if (! FRAME_VISIBLE_P (f
))
11613 /* We test FRAME_GARBAGED_P here to make sure we don't
11614 call x_set_offset a second time
11615 if we get to x_make_frame_visible a second time
11616 before the window gets really visible. */
11617 if (! FRAME_ICONIFIED_P (f
)
11618 && ! f
->output_data
.x
->asked_for_visible
)
11619 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11621 f
->output_data
.x
->asked_for_visible
= 1;
11623 if (! EQ (Vx_no_window_manager
, Qt
))
11624 x_wm_set_window_state (f
, NormalState
);
11625 #ifdef USE_X_TOOLKIT
11626 /* This was XtPopup, but that did nothing for an iconified frame. */
11627 XtMapWidget (f
->output_data
.x
->widget
);
11628 #else /* not USE_X_TOOLKIT */
11629 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11630 #endif /* not USE_X_TOOLKIT */
11631 #if 0 /* This seems to bring back scroll bars in the wrong places
11632 if the window configuration has changed. They seem
11633 to come back ok without this. */
11634 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11635 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11639 XFlush (FRAME_X_DISPLAY (f
));
11641 /* Synchronize to ensure Emacs knows the frame is visible
11642 before we do anything else. We do this loop with input not blocked
11643 so that incoming events are handled. */
11647 /* This must be before UNBLOCK_INPUT
11648 since events that arrive in response to the actions above
11649 will set it when they are handled. */
11650 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11652 original_left
= f
->output_data
.x
->left_pos
;
11653 original_top
= f
->output_data
.x
->top_pos
;
11655 /* This must come after we set COUNT. */
11658 /* We unblock here so that arriving X events are processed. */
11660 /* Now move the window back to where it was "supposed to be".
11661 But don't do it if the gravity is negative.
11662 When the gravity is negative, this uses a position
11663 that is 3 pixels too low. Perhaps that's really the border width.
11665 Don't do this if the window has never been visible before,
11666 because the window manager may choose the position
11667 and we don't want to override it. */
11669 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11670 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11671 && previously_visible
)
11675 unsigned int width
, height
, border
, depth
;
11679 /* On some window managers (such as FVWM) moving an existing
11680 window, even to the same place, causes the window manager
11681 to introduce an offset. This can cause the window to move
11682 to an unexpected location. Check the geometry (a little
11683 slow here) and then verify that the window is in the right
11684 place. If the window is not in the right place, move it
11685 there, and take the potential window manager hit. */
11686 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11687 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11689 if (original_left
!= x
|| original_top
!= y
)
11690 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11691 original_left
, original_top
);
11696 XSETFRAME (frame
, f
);
11698 /* Wait until the frame is visible. Process X events until a
11699 MapNotify event has been seen, or until we think we won't get a
11700 MapNotify at all.. */
11701 for (count
= input_signal_count
+ 10;
11702 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
11704 /* Force processing of queued events. */
11707 /* Machines that do polling rather than SIGIO have been
11708 observed to go into a busy-wait here. So we'll fake an
11709 alarm signal to let the handler know that there's something
11710 to be read. We used to raise a real alarm, but it seems
11711 that the handler isn't always enabled here. This is
11713 if (input_polling_used ())
11715 /* It could be confusing if a real alarm arrives while
11716 processing the fake one. Turn it off and let the
11717 handler reset it. */
11718 extern void poll_for_input_1
P_ ((void));
11719 int old_poll_suppress_count
= poll_suppress_count
;
11720 poll_suppress_count
= 1;
11721 poll_for_input_1 ();
11722 poll_suppress_count
= old_poll_suppress_count
;
11725 /* See if a MapNotify event has been processed. */
11726 FRAME_SAMPLE_VISIBILITY (f
);
11731 /* Change from mapped state to withdrawn state. */
11733 /* Make the frame visible (mapped and not iconified). */
11736 x_make_frame_invisible (f
)
11741 #ifdef USE_X_TOOLKIT
11742 /* Use the frame's outermost window, not the one we normally draw on. */
11743 window
= XtWindow (f
->output_data
.x
->widget
);
11744 #else /* not USE_X_TOOLKIT */
11745 window
= FRAME_X_WINDOW (f
);
11746 #endif /* not USE_X_TOOLKIT */
11748 /* Don't keep the highlight on an invisible frame. */
11749 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11750 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11752 #if 0/* This might add unreliability; I don't trust it -- rms. */
11753 if (! f
->async_visible
&& ! f
->async_iconified
)
11759 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11760 that the current position of the window is user-specified, rather than
11761 program-specified, so that when the window is mapped again, it will be
11762 placed at the same location, without forcing the user to position it
11763 by hand again (they have already done that once for this window.) */
11764 x_wm_set_size_hint (f
, (long) 0, 1);
11768 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11769 DefaultScreen (FRAME_X_DISPLAY (f
))))
11771 UNBLOCK_INPUT_RESIGNAL
;
11772 error ("Can't notify window manager of window withdrawal");
11774 #else /* ! defined (HAVE_X11R4) */
11776 /* Tell the window manager what we're going to do. */
11777 if (! EQ (Vx_no_window_manager
, Qt
))
11781 unmap
.xunmap
.type
= UnmapNotify
;
11782 unmap
.xunmap
.window
= window
;
11783 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
11784 unmap
.xunmap
.from_configure
= False
;
11785 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11786 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11788 SubstructureRedirectMaskSubstructureNotifyMask
,
11791 UNBLOCK_INPUT_RESIGNAL
;
11792 error ("Can't notify window manager of withdrawal");
11796 /* Unmap the window ourselves. Cheeky! */
11797 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
11798 #endif /* ! defined (HAVE_X11R4) */
11800 /* We can't distinguish this from iconification
11801 just by the event that we get from the server.
11802 So we can't win using the usual strategy of letting
11803 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11804 and synchronize with the server to make sure we agree. */
11806 FRAME_ICONIFIED_P (f
) = 0;
11807 f
->async_visible
= 0;
11808 f
->async_iconified
= 0;
11815 /* Change window state from mapped to iconified. */
11818 x_iconify_frame (f
)
11824 /* Don't keep the highlight on an invisible frame. */
11825 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11826 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11828 if (f
->async_iconified
)
11833 FRAME_SAMPLE_VISIBILITY (f
);
11835 type
= x_icon_type (f
);
11837 x_bitmap_icon (f
, type
);
11839 #ifdef USE_X_TOOLKIT
11841 if (! FRAME_VISIBLE_P (f
))
11843 if (! EQ (Vx_no_window_manager
, Qt
))
11844 x_wm_set_window_state (f
, IconicState
);
11845 /* This was XtPopup, but that did nothing for an iconified frame. */
11846 XtMapWidget (f
->output_data
.x
->widget
);
11847 /* The server won't give us any event to indicate
11848 that an invisible frame was changed to an icon,
11849 so we have to record it here. */
11852 f
->async_iconified
= 1;
11853 f
->async_visible
= 0;
11858 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11859 XtWindow (f
->output_data
.x
->widget
),
11860 DefaultScreen (FRAME_X_DISPLAY (f
)));
11864 error ("Can't notify window manager of iconification");
11866 f
->async_iconified
= 1;
11867 f
->async_visible
= 0;
11871 XFlush (FRAME_X_DISPLAY (f
));
11873 #else /* not USE_X_TOOLKIT */
11875 /* Make sure the X server knows where the window should be positioned,
11876 in case the user deiconifies with the window manager. */
11877 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
11878 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11880 /* Since we don't know which revision of X we're running, we'll use both
11881 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11883 /* X11R4: send a ClientMessage to the window manager using the
11884 WM_CHANGE_STATE type. */
11888 message
.xclient
.window
= FRAME_X_WINDOW (f
);
11889 message
.xclient
.type
= ClientMessage
;
11890 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11891 message
.xclient
.format
= 32;
11892 message
.xclient
.data
.l
[0] = IconicState
;
11894 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11895 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11897 SubstructureRedirectMask
| SubstructureNotifyMask
,
11900 UNBLOCK_INPUT_RESIGNAL
;
11901 error ("Can't notify window manager of iconification");
11905 /* X11R3: set the initial_state field of the window manager hints to
11907 x_wm_set_window_state (f
, IconicState
);
11909 if (!FRAME_VISIBLE_P (f
))
11911 /* If the frame was withdrawn, before, we must map it. */
11912 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11915 f
->async_iconified
= 1;
11916 f
->async_visible
= 0;
11918 XFlush (FRAME_X_DISPLAY (f
));
11920 #endif /* not USE_X_TOOLKIT */
11923 /* Destroy the X window of frame F. */
11926 x_destroy_window (f
)
11929 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11933 /* If a display connection is dead, don't try sending more
11934 commands to the X server. */
11935 if (dpyinfo
->display
!= 0)
11937 if (f
->output_data
.x
->icon_desc
!= 0)
11938 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
11941 free_frame_xic (f
);
11943 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
11944 #ifdef USE_X_TOOLKIT
11945 if (f
->output_data
.x
->widget
)
11946 XtDestroyWidget (f
->output_data
.x
->widget
);
11947 free_frame_menubar (f
);
11948 #endif /* USE_X_TOOLKIT */
11950 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
11951 unload_color (f
, f
->output_data
.x
->background_pixel
);
11952 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
11953 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
11954 unload_color (f
, f
->output_data
.x
->border_pixel
);
11955 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
11956 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
11957 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
11958 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
11959 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
11960 if (f
->output_data
.x
->white_relief
.allocated_p
)
11961 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
11962 if (f
->output_data
.x
->black_relief
.allocated_p
)
11963 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
11965 free_frame_faces (f
);
11966 XFlush (FRAME_X_DISPLAY (f
));
11969 if (f
->output_data
.x
->saved_menu_event
)
11970 xfree (f
->output_data
.x
->saved_menu_event
);
11972 xfree (f
->output_data
.x
);
11973 f
->output_data
.x
= 0;
11974 if (f
== dpyinfo
->x_focus_frame
)
11975 dpyinfo
->x_focus_frame
= 0;
11976 if (f
== dpyinfo
->x_focus_event_frame
)
11977 dpyinfo
->x_focus_event_frame
= 0;
11978 if (f
== dpyinfo
->x_highlight_frame
)
11979 dpyinfo
->x_highlight_frame
= 0;
11981 dpyinfo
->reference_count
--;
11983 if (f
== dpyinfo
->mouse_face_mouse_frame
)
11985 dpyinfo
->mouse_face_beg_row
11986 = dpyinfo
->mouse_face_beg_col
= -1;
11987 dpyinfo
->mouse_face_end_row
11988 = dpyinfo
->mouse_face_end_col
= -1;
11989 dpyinfo
->mouse_face_window
= Qnil
;
11990 dpyinfo
->mouse_face_deferred_gc
= 0;
11991 dpyinfo
->mouse_face_mouse_frame
= 0;
11997 /* Setting window manager hints. */
11999 /* Set the normal size hints for the window manager, for frame F.
12000 FLAGS is the flags word to use--or 0 meaning preserve the flags
12001 that the window now has.
12002 If USER_POSITION is nonzero, we set the USPosition
12003 flag (this is useful when FLAGS is 0). */
12006 x_wm_set_size_hint (f
, flags
, user_position
)
12011 XSizeHints size_hints
;
12013 #ifdef USE_X_TOOLKIT
12016 Dimension widget_width
, widget_height
;
12017 Window window
= XtWindow (f
->output_data
.x
->widget
);
12018 #else /* not USE_X_TOOLKIT */
12019 Window window
= FRAME_X_WINDOW (f
);
12020 #endif /* not USE_X_TOOLKIT */
12022 /* Setting PMaxSize caused various problems. */
12023 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12025 size_hints
.x
= f
->output_data
.x
->left_pos
;
12026 size_hints
.y
= f
->output_data
.x
->top_pos
;
12028 #ifdef USE_X_TOOLKIT
12029 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12030 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12031 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12032 size_hints
.height
= widget_height
;
12033 size_hints
.width
= widget_width
;
12034 #else /* not USE_X_TOOLKIT */
12035 size_hints
.height
= PIXEL_HEIGHT (f
);
12036 size_hints
.width
= PIXEL_WIDTH (f
);
12037 #endif /* not USE_X_TOOLKIT */
12039 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12040 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12041 size_hints
.max_width
12042 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12043 size_hints
.max_height
12044 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12046 /* Calculate the base and minimum sizes.
12048 (When we use the X toolkit, we don't do it here.
12049 Instead we copy the values that the widgets are using, below.) */
12050 #ifndef USE_X_TOOLKIT
12052 int base_width
, base_height
;
12053 int min_rows
= 0, min_cols
= 0;
12055 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12056 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12058 check_frame_size (f
, &min_rows
, &min_cols
);
12060 /* The window manager uses the base width hints to calculate the
12061 current number of rows and columns in the frame while
12062 resizing; min_width and min_height aren't useful for this
12063 purpose, since they might not give the dimensions for a
12064 zero-row, zero-column frame.
12066 We use the base_width and base_height members if we have
12067 them; otherwise, we set the min_width and min_height members
12068 to the size for a zero x zero frame. */
12071 size_hints
.flags
|= PBaseSize
;
12072 size_hints
.base_width
= base_width
;
12073 size_hints
.base_height
= base_height
;
12074 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12075 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12077 size_hints
.min_width
= base_width
;
12078 size_hints
.min_height
= base_height
;
12082 /* If we don't need the old flags, we don't need the old hint at all. */
12085 size_hints
.flags
|= flags
;
12088 #endif /* not USE_X_TOOLKIT */
12091 XSizeHints hints
; /* Sometimes I hate X Windows... */
12092 long supplied_return
;
12096 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12099 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12102 #ifdef USE_X_TOOLKIT
12103 size_hints
.base_height
= hints
.base_height
;
12104 size_hints
.base_width
= hints
.base_width
;
12105 size_hints
.min_height
= hints
.min_height
;
12106 size_hints
.min_width
= hints
.min_width
;
12110 size_hints
.flags
|= flags
;
12115 if (hints
.flags
& PSize
)
12116 size_hints
.flags
|= PSize
;
12117 if (hints
.flags
& PPosition
)
12118 size_hints
.flags
|= PPosition
;
12119 if (hints
.flags
& USPosition
)
12120 size_hints
.flags
|= USPosition
;
12121 if (hints
.flags
& USSize
)
12122 size_hints
.flags
|= USSize
;
12126 #ifndef USE_X_TOOLKIT
12131 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12132 size_hints
.flags
|= PWinGravity
;
12136 size_hints
.flags
&= ~ PPosition
;
12137 size_hints
.flags
|= USPosition
;
12139 #endif /* PWinGravity */
12142 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12144 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12148 /* Used for IconicState or NormalState */
12151 x_wm_set_window_state (f
, state
)
12155 #ifdef USE_X_TOOLKIT
12158 XtSetArg (al
[0], XtNinitialState
, state
);
12159 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12160 #else /* not USE_X_TOOLKIT */
12161 Window window
= FRAME_X_WINDOW (f
);
12163 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12164 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12166 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12167 #endif /* not USE_X_TOOLKIT */
12171 x_wm_set_icon_pixmap (f
, pixmap_id
)
12175 Pixmap icon_pixmap
;
12177 #ifndef USE_X_TOOLKIT
12178 Window window
= FRAME_X_WINDOW (f
);
12183 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12184 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12188 /* It seems there is no way to turn off use of an icon pixmap.
12189 The following line does it, only if no icon has yet been created,
12190 for some window managers. But with mwm it crashes.
12191 Some people say it should clear the IconPixmapHint bit in this case,
12192 but that doesn't work, and the X consortium said it isn't the
12193 right thing at all. Since there is no way to win,
12194 best to explicitly give up. */
12196 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12202 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12206 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12207 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12210 #else /* not USE_X_TOOLKIT */
12212 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12213 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12215 #endif /* not USE_X_TOOLKIT */
12219 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12221 int icon_x
, icon_y
;
12223 #ifdef USE_X_TOOLKIT
12224 Window window
= XtWindow (f
->output_data
.x
->widget
);
12226 Window window
= FRAME_X_WINDOW (f
);
12229 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12230 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12231 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12233 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12237 /***********************************************************************
12239 ***********************************************************************/
12241 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12244 x_get_font_info (f
, font_idx
)
12248 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12252 /* Return a list of names of available fonts matching PATTERN on frame
12253 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
12254 to be listed. Frame F NULL means we have not yet created any
12255 frame on X, and consult the first display in x_display_list.
12256 MAXNAMES sets a limit on how many fonts to match. */
12259 x_list_fonts (f
, pattern
, size
, maxnames
)
12261 Lisp_Object pattern
;
12265 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12266 Lisp_Object tem
, second_best
;
12267 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
12268 int try_XLoadQueryFont
= 0;
12271 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12272 if (NILP (patterns
))
12273 patterns
= Fcons (pattern
, Qnil
);
12275 if (maxnames
== 1 && !size
)
12276 /* We can return any single font matching PATTERN. */
12277 try_XLoadQueryFont
= 1;
12279 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12282 char **names
= NULL
;
12284 pattern
= XCAR (patterns
);
12285 /* See if we cached the result for this particular query.
12286 The cache is an alist of the form:
12287 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
12289 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
12290 key
= Fcons (pattern
, make_number (maxnames
)),
12291 !NILP (list
= Fassoc (key
, tem
))))
12293 list
= Fcdr_safe (list
);
12294 /* We have a cashed list. Don't have to get the list again. */
12298 /* At first, put PATTERN in the cache. */
12301 count
= x_catch_errors (dpy
);
12303 if (try_XLoadQueryFont
)
12306 unsigned long value
;
12308 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12309 if (x_had_errors_p (dpy
))
12311 /* This error is perhaps due to insufficient memory on X
12312 server. Let's just ignore it. */
12314 x_clear_errors (dpy
);
12318 && XGetFontProperty (font
, XA_FONT
, &value
))
12320 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12321 int len
= strlen (name
);
12324 /* If DXPC (a Differential X Protocol Compressor)
12325 Ver.3.7 is running, XGetAtomName will return null
12326 string. We must avoid such a name. */
12328 try_XLoadQueryFont
= 0;
12332 names
= (char **) alloca (sizeof (char *));
12333 /* Some systems only allow alloca assigned to a
12335 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12336 bcopy (name
, names
[0], len
+ 1);
12341 try_XLoadQueryFont
= 0;
12344 XFreeFont (dpy
, font
);
12347 if (!try_XLoadQueryFont
)
12349 /* We try at least 10 fonts because XListFonts will return
12350 auto-scaled fonts at the head. */
12351 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12353 if (x_had_errors_p (dpy
))
12355 /* This error is perhaps due to insufficient memory on X
12356 server. Let's just ignore it. */
12358 x_clear_errors (dpy
);
12362 x_uncatch_errors (dpy
, count
);
12369 /* Make a list of all the fonts we got back.
12370 Store that in the font cache for the display. */
12371 for (i
= 0; i
< num_fonts
; i
++)
12374 char *p
= names
[i
];
12375 int average_width
= -1, dashes
= 0;
12377 /* Count the number of dashes in NAMES[I]. If there are
12378 14 dashes, and the field value following 12th dash
12379 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12380 is usually too ugly to be used for editing. Let's
12386 if (dashes
== 7) /* PIXEL_SIZE field */
12388 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12389 average_width
= atoi (p
);
12391 if (dashes
< 14 || average_width
!= 0)
12393 tem
= build_string (names
[i
]);
12394 if (NILP (Fassoc (tem
, list
)))
12396 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12397 && ((fast_c_string_match_ignore_case
12398 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12400 /* We can set the value of PIXEL_SIZE to the
12401 width of this font. */
12402 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12404 /* For the moment, width is not known. */
12405 list
= Fcons (Fcons (tem
, Qnil
), list
);
12409 if (!try_XLoadQueryFont
)
12410 XFreeFontNames (names
);
12413 /* Now store the result in the cache. */
12415 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
12416 = Fcons (Fcons (key
, list
),
12417 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
12420 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12422 newlist
= second_best
= Qnil
;
12423 /* Make a list of the fonts that have the right width. */
12424 for (; CONSP (list
); list
= XCDR (list
))
12430 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12434 newlist
= Fcons (XCAR (tem
), newlist
);
12438 if (!INTEGERP (XCDR (tem
)))
12440 /* Since we have not yet known the size of this font, we
12441 must try slow function call XLoadQueryFont. */
12442 XFontStruct
*thisinfo
;
12445 count
= x_catch_errors (dpy
);
12446 thisinfo
= XLoadQueryFont (dpy
,
12447 XSTRING (XCAR (tem
))->data
);
12448 if (x_had_errors_p (dpy
))
12450 /* This error is perhaps due to insufficient memory on X
12451 server. Let's just ignore it. */
12453 x_clear_errors (dpy
);
12455 x_uncatch_errors (dpy
, count
);
12461 = (thisinfo
->min_bounds
.width
== 0
12463 : make_number (thisinfo
->max_bounds
.width
));
12464 XFreeFont (dpy
, thisinfo
);
12467 /* For unknown reason, the previous call of XListFont had
12468 returned a font which can't be opened. Record the size
12469 as 0 not to try to open it again. */
12470 XCDR (tem
) = make_number (0);
12473 found_size
= XINT (XCDR (tem
));
12474 if (found_size
== size
)
12475 newlist
= Fcons (XCAR (tem
), newlist
);
12476 else if (found_size
> 0)
12478 if (NILP (second_best
))
12480 else if (found_size
< size
)
12482 if (XINT (XCDR (second_best
)) > size
12483 || XINT (XCDR (second_best
)) < found_size
)
12488 if (XINT (XCDR (second_best
)) > size
12489 && XINT (XCDR (second_best
)) > found_size
)
12494 if (!NILP (newlist
))
12496 else if (!NILP (second_best
))
12498 newlist
= Fcons (XCAR (second_best
), Qnil
);
12509 /* Check that FONT is valid on frame F. It is if it can be found in F's
12513 x_check_font (f
, font
)
12518 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12520 xassert (font
!= NULL
);
12522 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12523 if (dpyinfo
->font_table
[i
].name
12524 && font
== dpyinfo
->font_table
[i
].font
)
12527 xassert (i
< dpyinfo
->n_fonts
);
12530 #endif /* GLYPH_DEBUG != 0 */
12532 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12533 Note: There are (broken) X fonts out there with invalid XFontStruct
12534 min_bounds contents. For example, handa@etl.go.jp reports that
12535 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
12536 have font->min_bounds.width == 0. */
12539 x_font_min_bounds (font
, w
, h
)
12543 *h
= FONT_HEIGHT (font
);
12544 *w
= font
->min_bounds
.width
;
12546 /* Try to handle the case where FONT->min_bounds has invalid
12547 contents. Since the only font known to have invalid min_bounds
12548 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12550 *w
= font
->max_bounds
.width
;
12554 /* Compute the smallest character width and smallest font height over
12555 all fonts available on frame F. Set the members smallest_char_width
12556 and smallest_font_height in F's x_display_info structure to
12557 the values computed. Value is non-zero if smallest_font_height or
12558 smallest_char_width become smaller than they were before. */
12561 x_compute_min_glyph_bounds (f
)
12565 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12567 int old_width
= dpyinfo
->smallest_char_width
;
12568 int old_height
= dpyinfo
->smallest_font_height
;
12570 dpyinfo
->smallest_font_height
= 100000;
12571 dpyinfo
->smallest_char_width
= 100000;
12573 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12574 if (dpyinfo
->font_table
[i
].name
)
12576 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12579 font
= (XFontStruct
*) fontp
->font
;
12580 xassert (font
!= (XFontStruct
*) ~0);
12581 x_font_min_bounds (font
, &w
, &h
);
12583 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12584 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12587 xassert (dpyinfo
->smallest_char_width
> 0
12588 && dpyinfo
->smallest_font_height
> 0);
12590 return (dpyinfo
->n_fonts
== 1
12591 || dpyinfo
->smallest_char_width
< old_width
12592 || dpyinfo
->smallest_font_height
< old_height
);
12596 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12597 pointer to the structure font_info while allocating it dynamically.
12598 If SIZE is 0, load any size of font.
12599 If loading is failed, return NULL. */
12602 x_load_font (f
, fontname
, size
)
12604 register char *fontname
;
12607 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12608 Lisp_Object font_names
;
12611 /* Get a list of all the fonts that match this name. Once we
12612 have a list of matching fonts, we compare them against the fonts
12613 we already have by comparing names. */
12614 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12616 if (!NILP (font_names
))
12621 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12622 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12623 if (dpyinfo
->font_table
[i
].name
12624 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12625 XSTRING (XCAR (tail
))->data
)
12626 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12627 XSTRING (XCAR (tail
))->data
)))
12628 return (dpyinfo
->font_table
+ i
);
12631 /* Load the font and add it to the table. */
12635 struct font_info
*fontp
;
12636 unsigned long value
;
12639 /* If we have found fonts by x_list_font, load one of them. If
12640 not, we still try to load a font by the name given as FONTNAME
12641 because XListFonts (called in x_list_font) of some X server has
12642 a bug of not finding a font even if the font surely exists and
12643 is loadable by XLoadQueryFont. */
12644 if (size
> 0 && !NILP (font_names
))
12645 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12648 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12649 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12650 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12652 /* This error is perhaps due to insufficient memory on X
12653 server. Let's just ignore it. */
12655 x_clear_errors (FRAME_X_DISPLAY (f
));
12657 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12662 /* Find a free slot in the font table. */
12663 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12664 if (dpyinfo
->font_table
[i
].name
== NULL
)
12667 /* If no free slot found, maybe enlarge the font table. */
12668 if (i
== dpyinfo
->n_fonts
12669 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12672 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12673 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12674 dpyinfo
->font_table
12675 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12678 fontp
= dpyinfo
->font_table
+ i
;
12679 if (i
== dpyinfo
->n_fonts
)
12680 ++dpyinfo
->n_fonts
;
12682 /* Now fill in the slots of *FONTP. */
12684 fontp
->font
= font
;
12685 fontp
->font_idx
= i
;
12686 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12687 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12689 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12691 if (XGetFontProperty (font
, XA_FONT
, &value
))
12693 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12697 /* Count the number of dashes in the "full name".
12698 If it is too few, this isn't really the font's full name,
12700 In X11R4, the fonts did not come with their canonical names
12711 full_name
= (char *) xmalloc (p
- name
+ 1);
12712 bcopy (name
, full_name
, p
- name
+ 1);
12718 if (full_name
!= 0)
12719 fontp
->full_name
= full_name
;
12721 fontp
->full_name
= fontp
->name
;
12723 fontp
->size
= font
->max_bounds
.width
;
12724 fontp
->height
= FONT_HEIGHT (font
);
12726 /* For some font, ascent and descent in max_bounds field is
12727 larger than the above value. */
12728 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12729 if (max_height
> fontp
->height
)
12730 fontp
->height
= max_height
;
12733 if (NILP (font_names
))
12735 /* We come here because of a bug of XListFonts mentioned at
12736 the head of this block. Let's store this information in
12737 the cache for x_list_fonts. */
12738 Lisp_Object lispy_name
= build_string (fontname
);
12739 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12741 XCDR (dpyinfo
->name_list_element
)
12742 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
12743 Fcons (Fcons (lispy_full_name
,
12744 make_number (fontp
->size
)),
12746 XCDR (dpyinfo
->name_list_element
));
12748 XCDR (dpyinfo
->name_list_element
)
12749 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
12750 Fcons (Fcons (lispy_full_name
,
12751 make_number (fontp
->size
)),
12753 XCDR (dpyinfo
->name_list_element
));
12756 /* The slot `encoding' specifies how to map a character
12757 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
12758 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
12759 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
12760 2:0xA020..0xFF7F). For the moment, we don't know which charset
12761 uses this font. So, we set information in fontp->encoding[1]
12762 which is never used by any charset. If mapping can't be
12763 decided, set FONT_ENCODING_NOT_DECIDED. */
12765 = (font
->max_byte1
== 0
12767 ? (font
->min_char_or_byte2
< 0x80
12768 ? (font
->max_char_or_byte2
< 0x80
12769 ? 0 /* 0x20..0x7F */
12770 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
12771 : 1) /* 0xA0..0xFF */
12773 : (font
->min_byte1
< 0x80
12774 ? (font
->max_byte1
< 0x80
12775 ? (font
->min_char_or_byte2
< 0x80
12776 ? (font
->max_char_or_byte2
< 0x80
12777 ? 0 /* 0x2020..0x7F7F */
12778 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
12779 : 3) /* 0x20A0..0x7FFF */
12780 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
12781 : (font
->min_char_or_byte2
< 0x80
12782 ? (font
->max_char_or_byte2
< 0x80
12783 ? 2 /* 0xA020..0xFF7F */
12784 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
12785 : 1))); /* 0xA0A0..0xFFFF */
12787 fontp
->baseline_offset
12788 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
12789 ? (long) value
: 0);
12790 fontp
->relative_compose
12791 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
12792 ? (long) value
: 0);
12793 fontp
->default_ascent
12794 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
12795 ? (long) value
: 0);
12797 /* Set global flag fonts_changed_p to non-zero if the font loaded
12798 has a character with a smaller width than any other character
12799 before, or if the font loaded has a smalle>r height than any
12800 other font loaded before. If this happens, it will make a
12801 glyph matrix reallocation necessary. */
12802 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
12809 /* Return a pointer to struct font_info of a font named FONTNAME for
12810 frame F. If no such font is loaded, return NULL. */
12813 x_query_font (f
, fontname
)
12815 register char *fontname
;
12817 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12820 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12821 if (dpyinfo
->font_table
[i
].name
12822 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
12823 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
12824 return (dpyinfo
->font_table
+ i
);
12829 /* Find a CCL program for a font specified by FONTP, and set the member
12830 `encoder' of the structure. */
12833 x_find_ccl_program (fontp
)
12834 struct font_info
*fontp
;
12836 Lisp_Object list
, elt
;
12838 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
12842 && STRINGP (XCAR (elt
))
12843 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
12849 struct ccl_program
*ccl
12850 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
12852 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
12855 fontp
->font_encoder
= ccl
;
12861 /***********************************************************************
12863 ***********************************************************************/
12865 #ifdef USE_X_TOOLKIT
12866 static XrmOptionDescRec emacs_options
[] = {
12867 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
12868 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
12870 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
12871 XrmoptionSepArg
, NULL
},
12872 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
12874 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12875 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12876 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12877 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12878 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12879 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
12880 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
12882 #endif /* USE_X_TOOLKIT */
12884 static int x_initialized
;
12886 #ifdef MULTI_KBOARD
12887 /* Test whether two display-name strings agree up to the dot that separates
12888 the screen number from the server number. */
12890 same_x_server (name1
, name2
)
12891 char *name1
, *name2
;
12893 int seen_colon
= 0;
12894 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
12895 int system_name_length
= strlen (system_name
);
12896 int length_until_period
= 0;
12898 while (system_name
[length_until_period
] != 0
12899 && system_name
[length_until_period
] != '.')
12900 length_until_period
++;
12902 /* Treat `unix' like an empty host name. */
12903 if (! strncmp (name1
, "unix:", 5))
12905 if (! strncmp (name2
, "unix:", 5))
12907 /* Treat this host's name like an empty host name. */
12908 if (! strncmp (name1
, system_name
, system_name_length
)
12909 && name1
[system_name_length
] == ':')
12910 name1
+= system_name_length
;
12911 if (! strncmp (name2
, system_name
, system_name_length
)
12912 && name2
[system_name_length
] == ':')
12913 name2
+= system_name_length
;
12914 /* Treat this host's domainless name like an empty host name. */
12915 if (! strncmp (name1
, system_name
, length_until_period
)
12916 && name1
[length_until_period
] == ':')
12917 name1
+= length_until_period
;
12918 if (! strncmp (name2
, system_name
, length_until_period
)
12919 && name2
[length_until_period
] == ':')
12920 name2
+= length_until_period
;
12922 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
12926 if (seen_colon
&& *name1
== '.')
12930 && (*name1
== '.' || *name1
== '\0')
12931 && (*name2
== '.' || *name2
== '\0'));
12935 struct x_display_info
*
12936 x_term_init (display_name
, xrm_option
, resource_name
)
12937 Lisp_Object display_name
;
12939 char *resource_name
;
12943 struct x_display_info
*dpyinfo
;
12948 if (!x_initialized
)
12954 #ifdef USE_X_TOOLKIT
12955 /* weiner@footloose.sps.mot.com reports that this causes
12957 X protocol error: BadAtom (invalid Atom parameter)
12958 on protocol request 18skiloaf.
12959 So let's not use it until R6. */
12960 #ifdef HAVE_X11XTR6
12961 XtSetLanguageProc (NULL
, NULL
, NULL
);
12972 argv
[argc
++] = "-xrm";
12973 argv
[argc
++] = xrm_option
;
12975 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
12976 resource_name
, EMACS_CLASS
,
12977 emacs_options
, XtNumber (emacs_options
),
12980 #ifdef HAVE_X11XTR6
12981 /* I think this is to compensate for XtSetLanguageProc. */
12986 #else /* not USE_X_TOOLKIT */
12988 XSetLocaleModifiers ("");
12990 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
12991 #endif /* not USE_X_TOOLKIT */
12993 /* Detect failure. */
13000 /* We have definitely succeeded. Record the new connection. */
13002 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13004 #ifdef MULTI_KBOARD
13006 struct x_display_info
*share
;
13009 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13010 share
= share
->next
, tail
= XCDR (tail
))
13011 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13012 XSTRING (display_name
)->data
))
13015 dpyinfo
->kboard
= share
->kboard
;
13018 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13019 init_kboard (dpyinfo
->kboard
);
13020 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13022 char *vendor
= ServerVendor (dpy
);
13024 dpyinfo
->kboard
->Vsystem_key_alist
13025 = call1 (Qvendor_specific_keysyms
,
13026 build_string (vendor
? vendor
: ""));
13030 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13031 all_kboards
= dpyinfo
->kboard
;
13032 /* Don't let the initial kboard remain current longer than necessary.
13033 That would cause problems if a file loaded on startup tries to
13034 prompt in the mini-buffer. */
13035 if (current_kboard
== initial_kboard
)
13036 current_kboard
= dpyinfo
->kboard
;
13038 dpyinfo
->kboard
->reference_count
++;
13042 /* Put this display on the chain. */
13043 dpyinfo
->next
= x_display_list
;
13044 x_display_list
= dpyinfo
;
13046 /* Put it on x_display_name_list as well, to keep them parallel. */
13047 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13048 x_display_name_list
);
13049 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13051 dpyinfo
->display
= dpy
;
13054 XSetAfterFunction (x_current_display
, x_trace_wire
);
13058 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13059 + STRING_BYTES (XSTRING (Vsystem_name
))
13061 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13062 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13064 /* Figure out which modifier bits mean what. */
13065 x_find_modifier_meanings (dpyinfo
);
13067 /* Get the scroll bar cursor. */
13068 dpyinfo
->vertical_scroll_bar_cursor
13069 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13071 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13072 resource_name
, EMACS_CLASS
);
13073 #ifdef HAVE_XRMSETDATABASE
13074 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13076 dpyinfo
->display
->db
= xrdb
;
13078 /* Put the rdb where we can find it in a way that works on
13080 dpyinfo
->xrdb
= xrdb
;
13082 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13083 DefaultScreen (dpyinfo
->display
));
13084 select_visual (dpyinfo
);
13085 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13086 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13087 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13088 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13089 dpyinfo
->grabbed
= 0;
13090 dpyinfo
->reference_count
= 0;
13091 dpyinfo
->icon_bitmap_id
= -1;
13092 dpyinfo
->font_table
= NULL
;
13093 dpyinfo
->n_fonts
= 0;
13094 dpyinfo
->font_table_size
= 0;
13095 dpyinfo
->bitmaps
= 0;
13096 dpyinfo
->bitmaps_size
= 0;
13097 dpyinfo
->bitmaps_last
= 0;
13098 dpyinfo
->scratch_cursor_gc
= 0;
13099 dpyinfo
->mouse_face_mouse_frame
= 0;
13100 dpyinfo
->mouse_face_deferred_gc
= 0;
13101 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13102 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13103 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13104 dpyinfo
->mouse_face_window
= Qnil
;
13105 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13106 dpyinfo
->mouse_face_defer
= 0;
13107 dpyinfo
->x_focus_frame
= 0;
13108 dpyinfo
->x_focus_event_frame
= 0;
13109 dpyinfo
->x_highlight_frame
= 0;
13110 dpyinfo
->image_cache
= make_image_cache ();
13112 /* See if a private colormap is requested. */
13113 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13115 if (dpyinfo
->visual
->class == PseudoColor
)
13118 value
= display_x_get_resource (dpyinfo
,
13119 build_string ("privateColormap"),
13120 build_string ("PrivateColormap"),
13122 if (STRINGP (value
)
13123 && (!strcmp (XSTRING (value
)->data
, "true")
13124 || !strcmp (XSTRING (value
)->data
, "on")))
13125 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13129 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13130 dpyinfo
->visual
, AllocNone
);
13133 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13134 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13135 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13136 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13137 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13138 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13139 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13142 dpyinfo
->Xatom_wm_protocols
13143 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13144 dpyinfo
->Xatom_wm_take_focus
13145 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13146 dpyinfo
->Xatom_wm_save_yourself
13147 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13148 dpyinfo
->Xatom_wm_delete_window
13149 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13150 dpyinfo
->Xatom_wm_change_state
13151 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13152 dpyinfo
->Xatom_wm_configure_denied
13153 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13154 dpyinfo
->Xatom_wm_window_moved
13155 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13156 dpyinfo
->Xatom_editres
13157 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13158 dpyinfo
->Xatom_CLIPBOARD
13159 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13160 dpyinfo
->Xatom_TIMESTAMP
13161 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13162 dpyinfo
->Xatom_TEXT
13163 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13164 dpyinfo
->Xatom_COMPOUND_TEXT
13165 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13166 dpyinfo
->Xatom_DELETE
13167 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13168 dpyinfo
->Xatom_MULTIPLE
13169 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13170 dpyinfo
->Xatom_INCR
13171 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13172 dpyinfo
->Xatom_EMACS_TMP
13173 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13174 dpyinfo
->Xatom_TARGETS
13175 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13176 dpyinfo
->Xatom_NULL
13177 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13178 dpyinfo
->Xatom_ATOM_PAIR
13179 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13180 /* For properties of font. */
13181 dpyinfo
->Xatom_PIXEL_SIZE
13182 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13183 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13184 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13185 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13186 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13187 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13188 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13190 /* Ghostscript support. */
13191 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13192 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13194 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13197 dpyinfo
->cut_buffers_initialized
= 0;
13199 connection
= ConnectionNumber (dpyinfo
->display
);
13200 dpyinfo
->connection
= connection
;
13205 null_bits
[0] = 0x00;
13207 dpyinfo
->null_pixel
13208 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13209 null_bits
, 1, 1, (long) 0, (long) 0,
13214 extern int gray_bitmap_width
, gray_bitmap_height
;
13215 extern unsigned char *gray_bitmap_bits
;
13217 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13219 gray_bitmap_width
, gray_bitmap_height
,
13220 (unsigned long) 1, (unsigned long) 0, 1);
13224 xim_initialize (dpyinfo
, resource_name
);
13227 #ifdef subprocesses
13228 /* This is only needed for distinguishing keyboard and process input. */
13229 if (connection
!= 0)
13230 add_keyboard_wait_descriptor (connection
);
13233 #ifndef F_SETOWN_BUG
13235 #ifdef F_SETOWN_SOCK_NEG
13236 /* stdin is a socket here */
13237 fcntl (connection
, F_SETOWN
, -getpid ());
13238 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13239 fcntl (connection
, F_SETOWN
, getpid ());
13240 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13241 #endif /* ! defined (F_SETOWN) */
13242 #endif /* F_SETOWN_BUG */
13245 if (interrupt_input
)
13246 init_sigio (connection
);
13247 #endif /* ! defined (SIGIO) */
13250 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13251 /* Make sure that we have a valid font for dialog boxes
13252 so that Xt does not crash. */
13254 Display
*dpy
= dpyinfo
->display
;
13255 XrmValue d
, fr
, to
;
13259 d
.addr
= (XPointer
)&dpy
;
13260 d
.size
= sizeof (Display
*);
13261 fr
.addr
= XtDefaultFont
;
13262 fr
.size
= sizeof (XtDefaultFont
);
13263 to
.size
= sizeof (Font
*);
13264 to
.addr
= (XPointer
)&font
;
13265 count
= x_catch_errors (dpy
);
13266 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13268 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13269 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13270 x_uncatch_errors (dpy
, count
);
13275 /* See if we should run in synchronous mode. This is useful
13276 for debugging X code. */
13279 value
= display_x_get_resource (dpyinfo
,
13280 build_string ("synchronous"),
13281 build_string ("Synchronous"),
13283 if (STRINGP (value
)
13284 && (!strcmp (XSTRING (value
)->data
, "true")
13285 || !strcmp (XSTRING (value
)->data
, "on")))
13286 XSynchronize (dpyinfo
->display
, True
);
13294 /* Get rid of display DPYINFO, assuming all frames are already gone,
13295 and without sending any more commands to the X server. */
13298 x_delete_display (dpyinfo
)
13299 struct x_display_info
*dpyinfo
;
13301 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13303 /* Discard this display from x_display_name_list and x_display_list.
13304 We can't use Fdelq because that can quit. */
13305 if (! NILP (x_display_name_list
)
13306 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13307 x_display_name_list
= XCDR (x_display_name_list
);
13312 tail
= x_display_name_list
;
13313 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13315 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13317 XCDR (tail
) = XCDR (XCDR (tail
));
13320 tail
= XCDR (tail
);
13324 if (next_noop_dpyinfo
== dpyinfo
)
13325 next_noop_dpyinfo
= dpyinfo
->next
;
13327 if (x_display_list
== dpyinfo
)
13328 x_display_list
= dpyinfo
->next
;
13331 struct x_display_info
*tail
;
13333 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13334 if (tail
->next
== dpyinfo
)
13335 tail
->next
= tail
->next
->next
;
13338 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13339 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13340 XrmDestroyDatabase (dpyinfo
->xrdb
);
13343 #ifdef MULTI_KBOARD
13344 if (--dpyinfo
->kboard
->reference_count
== 0)
13345 delete_kboard (dpyinfo
->kboard
);
13349 xim_close_dpy (dpyinfo
);
13352 xfree (dpyinfo
->font_table
);
13353 xfree (dpyinfo
->x_id_name
);
13357 /* Set up use of X before we make the first connection. */
13359 static struct redisplay_interface x_redisplay_interface
=
13364 x_clear_end_of_line
,
13366 x_after_update_window_line
,
13367 x_update_window_begin
,
13368 x_update_window_end
,
13371 x_get_glyph_overhangs
,
13372 x_fix_overlapping_area
13378 rif
= &x_redisplay_interface
;
13380 clear_frame_hook
= x_clear_frame
;
13381 ins_del_lines_hook
= x_ins_del_lines
;
13382 change_line_highlight_hook
= x_change_line_highlight
;
13383 delete_glyphs_hook
= x_delete_glyphs
;
13384 ring_bell_hook
= XTring_bell
;
13385 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13386 set_terminal_modes_hook
= XTset_terminal_modes
;
13387 update_begin_hook
= x_update_begin
;
13388 update_end_hook
= x_update_end
;
13389 set_terminal_window_hook
= XTset_terminal_window
;
13390 read_socket_hook
= XTread_socket
;
13391 frame_up_to_date_hook
= XTframe_up_to_date
;
13392 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13393 mouse_position_hook
= XTmouse_position
;
13394 frame_rehighlight_hook
= XTframe_rehighlight
;
13395 frame_raise_lower_hook
= XTframe_raise_lower
;
13396 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13397 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13398 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13399 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13400 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13402 scroll_region_ok
= 1; /* we'll scroll partial frames */
13403 char_ins_del_ok
= 0; /* just as fast to write the line */
13404 line_ins_del_ok
= 1; /* we'll just blt 'em */
13405 fast_clear_end_of_line
= 1; /* X does this well */
13406 memory_below_frame
= 0; /* we don't remember what scrolls
13411 last_tool_bar_item
= -1;
13412 any_help_event_p
= 0;
13414 /* Try to use interrupt input; if we can't, then start polling. */
13415 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13417 #ifdef USE_X_TOOLKIT
13418 XtToolkitInitialize ();
13419 Xt_app_con
= XtCreateApplicationContext ();
13420 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13422 /* Install an asynchronous timer that processes Xt timeout events
13423 every 0.1s. This is necessary because some widget sets use
13424 timeouts internally, for example the LessTif menu bar, or the
13425 Xaw3d scroll bar. When Xt timouts aren't processed, these
13426 widgets don't behave normally. */
13428 EMACS_TIME interval
;
13429 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13430 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13434 #if USE_TOOLKIT_SCROLL_BARS
13435 xaw3d_arrow_scroll
= False
;
13436 xaw3d_pick_top
= True
;
13439 /* Note that there is no real way portable across R3/R4 to get the
13440 original error handler. */
13441 XSetErrorHandler (x_error_handler
);
13442 XSetIOErrorHandler (x_io_error_quitter
);
13444 /* Disable Window Change signals; they are handled by X events. */
13446 signal (SIGWINCH
, SIG_DFL
);
13447 #endif /* ! defined (SIGWINCH) */
13449 signal (SIGPIPE
, x_connection_signal
);
13456 staticpro (&x_error_message_string
);
13457 x_error_message_string
= Qnil
;
13459 staticpro (&x_display_name_list
);
13460 x_display_name_list
= Qnil
;
13462 staticpro (&last_mouse_scroll_bar
);
13463 last_mouse_scroll_bar
= Qnil
;
13465 staticpro (&Qvendor_specific_keysyms
);
13466 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13468 staticpro (&last_mouse_press_frame
);
13469 last_mouse_press_frame
= Qnil
;
13471 staticpro (&help_echo
);
13473 staticpro (&previous_help_echo
);
13474 previous_help_echo
= Qnil
;
13476 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13477 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
13478 For example, if a block cursor is over a tab, it will be drawn as\n\
13479 wide as that tab on the display.");
13480 x_stretch_cursor_p
= 0;
13482 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
13483 "If not nil, Emacs uses toolkit scroll bars.");
13484 #if USE_TOOLKIT_SCROLL_BARS
13485 x_toolkit_scroll_bars_p
= 1;
13487 x_toolkit_scroll_bars_p
= 0;
13490 staticpro (&last_mouse_motion_frame
);
13491 last_mouse_motion_frame
= Qnil
;
13494 #endif /* not HAVE_X_WINDOWS */