1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
73 #include "dispextern.h"
75 #include "termhooks.h"
87 #include "intervals.h"
92 #include <X11/Shell.h>
95 #ifdef HAVE_SYS_TIME_H
104 extern void free_frame_menubar ();
105 extern FRAME_PTR
x_menubar_window_to_frame ();
107 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
109 extern void _XEditResCheckMessages ();
110 #endif /* not NO_EDITRES */
112 /* Include toolkit specific headers for the scroll bar widget. */
114 #ifdef USE_TOOLKIT_SCROLL_BARS
115 #if defined USE_MOTIF
116 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
117 #include <Xm/ScrollBar.h>
118 #include <Xm/ScrollBarP.h>
119 #else /* !USE_MOTIF i.e. use Xaw */
122 #include <X11/Xaw3d/Simple.h>
123 #include <X11/Xaw3d/Scrollbar.h>
124 #define ARROW_SCROLLBAR
125 #include <X11/Xaw3d/ScrollbarP.h>
126 #else /* !HAVE_XAW3D */
127 #include <X11/Xaw/Simple.h>
128 #include <X11/Xaw/Scrollbar.h>
129 #endif /* !HAVE_XAW3D */
131 #define XtNpickTop "pickTop"
132 #endif /* !XtNpickTop */
133 #endif /* !USE_MOTIF */
134 #endif /* USE_TOOLKIT_SCROLL_BARS */
136 #endif /* USE_X_TOOLKIT */
138 #ifndef USE_X_TOOLKIT
139 #define x_any_window_to_frame x_window_to_frame
140 #define x_top_window_to_frame x_window_to_frame
145 #ifndef XtNinitialState
146 #define XtNinitialState "initialState"
151 /* memmove will be defined as a macro in Xfuncs.h unless
152 <string.h> is included beforehand. The declaration for memmove in
153 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
158 #define min(a,b) ((a) < (b) ? (a) : (b))
161 #define max(a,b) ((a) > (b) ? (a) : (b))
164 #define abs(x) ((x) < 0 ? -(x) : (x))
166 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
169 /* Bitmaps for truncated lines. */
174 LEFT_TRUNCATION_BITMAP
,
175 RIGHT_TRUNCATION_BITMAP
,
176 OVERLAY_ARROW_BITMAP
,
177 CONTINUED_LINE_BITMAP
,
178 CONTINUATION_LINE_BITMAP
,
182 /* Bitmap drawn to indicate lines not displaying text if
183 `indicate-empty-lines' is non-nil. */
187 static unsigned char zv_bits
[] = {
188 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
190 /* An arrow like this: `<-'. */
193 #define left_height 8
194 static unsigned char left_bits
[] = {
195 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
197 /* Right truncation arrow bitmap `->'. */
199 #define right_width 8
200 #define right_height 8
201 static unsigned char right_bits
[] = {
202 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
204 /* Marker for continued lines. */
206 #define continued_width 8
207 #define continued_height 8
208 static unsigned char continued_bits
[] = {
209 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
211 /* Marker for continuation lines. */
213 #define continuation_width 8
214 #define continuation_height 8
215 static unsigned char continuation_bits
[] = {
216 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
218 /* Overlay arrow bitmap. */
224 static unsigned char ov_bits
[] = {
225 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
227 /* A triangular arrow. */
230 static unsigned char ov_bits
[] = {
231 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
235 extern Lisp_Object Qhelp_echo
;
238 /* Non-zero means Emacs uses toolkit scroll bars. */
240 int x_toolkit_scroll_bars_p
;
242 /* If a string, XTread_socket generates an event to display that string.
243 (The display is done in read_char.) */
245 static Lisp_Object help_echo
;
247 /* Temporary variable for XTread_socket. */
249 static Lisp_Object previous_help_echo
;
251 /* Non-zero means that a HELP_EVENT has been generated since Emacs
254 static int any_help_event_p
;
256 /* Non-zero means draw block and hollow cursor as wide as the glyph
257 under it. For example, if a block cursor is over a tab, it will be
258 drawn as wide as that tab on the display. */
260 int x_stretch_cursor_p
;
262 /* This is a chain of structures for all the X displays currently in
265 struct x_display_info
*x_display_list
;
267 /* This is a list of cons cells, each of the form (NAME
268 . FONT-LIST-CACHE), one for each element of x_display_list and in
269 the same order. NAME is the name of the frame. FONT-LIST-CACHE
270 records previous values returned by x-list-fonts. */
272 Lisp_Object x_display_name_list
;
274 /* Frame being updated by update_frame. This is declared in term.c.
275 This is set by update_begin and looked at by all the XT functions.
276 It is zero while not inside an update. In that case, the XT
277 functions assume that `selected_frame' is the frame to apply to. */
279 extern struct frame
*updating_frame
;
281 extern int waiting_for_input
;
283 /* This is a frame waiting to be auto-raised, within XTread_socket. */
285 struct frame
*pending_autoraise_frame
;
288 /* The application context for Xt use. */
289 XtAppContext Xt_app_con
;
290 static String Xt_default_resources
[] = {0};
291 #endif /* USE_X_TOOLKIT */
293 /* Nominal cursor position -- where to draw output.
294 HPOS and VPOS are window relative glyph matrix coordinates.
295 X and Y are window relative pixel coordinates. */
297 struct cursor_pos output_cursor
;
299 /* Non-zero means user is interacting with a toolkit scroll bar. */
301 static int toolkit_scroll_bar_interaction
;
305 Formerly, we used PointerMotionHintMask (in standard_event_mask)
306 so that we would have to call XQueryPointer after each MotionNotify
307 event to ask for another such event. However, this made mouse tracking
308 slow, and there was a bug that made it eventually stop.
310 Simply asking for MotionNotify all the time seems to work better.
312 In order to avoid asking for motion events and then throwing most
313 of them away or busy-polling the server for mouse positions, we ask
314 the server for pointer motion hints. This means that we get only
315 one event per group of mouse movements. "Groups" are delimited by
316 other kinds of events (focus changes and button clicks, for
317 example), or by XQueryPointer calls; when one of these happens, we
318 get another MotionNotify event the next time the mouse moves. This
319 is at least as efficient as getting motion events when mouse
320 tracking is on, and I suspect only negligibly worse when tracking
323 /* Where the mouse was last time we reported a mouse event. */
325 FRAME_PTR last_mouse_frame
;
326 static XRectangle last_mouse_glyph
;
327 static Lisp_Object last_mouse_press_frame
;
329 /* The scroll bar in which the last X motion event occurred.
331 If the last X motion event occurred in a scroll bar, we set this so
332 XTmouse_position can know whether to report a scroll bar motion or
335 If the last X motion event didn't occur in a scroll bar, we set
336 this to Qnil, to tell XTmouse_position to return an ordinary motion
339 static Lisp_Object last_mouse_scroll_bar
;
341 /* This is a hack. We would really prefer that XTmouse_position would
342 return the time associated with the position it returns, but there
343 doesn't seem to be any way to wrest the time-stamp from the server
344 along with the position query. So, we just keep track of the time
345 of the last movement we received, and return that in hopes that
346 it's somewhat accurate. */
348 static Time last_mouse_movement_time
;
350 /* Incremented by XTread_socket whenever it really tries to read
354 static int volatile input_signal_count
;
356 static int input_signal_count
;
359 /* Used locally within XTread_socket. */
361 static int x_noop_count
;
363 /* Initial values of argv and argc. */
365 extern char **initial_argv
;
366 extern int initial_argc
;
368 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
370 /* Tells if a window manager is present or not. */
372 extern Lisp_Object Vx_no_window_manager
;
374 extern Lisp_Object Qface
, Qmouse_face
;
378 /* A mask of extra modifier bits to put into every keyboard char. */
380 extern int extra_keyboard_modifiers
;
382 static Lisp_Object Qvendor_specific_keysyms
;
384 extern XrmDatabase
x_load_resources ();
385 extern Lisp_Object
x_icon_type ();
388 /* Enumeration for overriding/changing the face to use for drawing
389 glyphs in x_draw_glyphs. */
391 enum draw_glyphs_face
401 static void x_update_window_end
P_ ((struct window
*, int));
402 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
403 void x_delete_display
P_ ((struct x_display_info
*));
404 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
406 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
408 static void set_output_cursor
P_ ((struct cursor_pos
*));
409 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
410 int *, int *, int *));
411 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
412 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
413 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
414 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
415 static void show_mouse_face
P_ ((struct x_display_info
*,
416 enum draw_glyphs_face
));
417 static int x_io_error_quitter
P_ ((Display
*));
418 int x_catch_errors
P_ ((Display
*));
419 void x_uncatch_errors
P_ ((Display
*, int));
420 void x_lower_frame
P_ ((struct frame
*));
421 void x_scroll_bar_clear
P_ ((struct frame
*));
422 int x_had_errors_p
P_ ((Display
*));
423 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
424 void x_raise_frame
P_ ((struct frame
*));
425 void x_set_window_size
P_ ((struct frame
*, int, int, int));
426 void x_wm_set_window_state
P_ ((struct frame
*, int));
427 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
428 void x_initialize
P_ ((void));
429 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
430 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
431 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
433 enum draw_glyphs_face
));
434 static void x_update_end
P_ ((struct frame
*));
435 static void XTframe_up_to_date
P_ ((struct frame
*));
436 static void XTreassert_line_highlight
P_ ((int, int));
437 static void x_change_line_highlight
P_ ((int, int, int, int));
438 static void XTset_terminal_modes
P_ ((void));
439 static void XTreset_terminal_modes
P_ ((void));
440 static void XTcursor_to
P_ ((int, int, int, int));
441 static void x_write_glyphs
P_ ((struct glyph
*, int));
442 static void x_clear_end_of_line
P_ ((int));
443 static void x_clear_frame
P_ ((void));
444 static void x_clear_cursor
P_ ((struct window
*));
445 static void frame_highlight
P_ ((struct frame
*));
446 static void frame_unhighlight
P_ ((struct frame
*));
447 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
448 static void XTframe_rehighlight
P_ ((struct frame
*));
449 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
450 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
451 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
452 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
454 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
455 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
456 static void expose_window
P_ ((struct window
*, XRectangle
*));
457 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
458 XRectangle
*, enum glyph_row_area
));
459 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
461 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
462 static void x_update_window_cursor
P_ ((struct window
*, int));
463 static void x_erase_phys_cursor
P_ ((struct window
*));
464 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
465 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
468 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
470 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
471 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
472 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
473 static void x_flush
P_ ((struct frame
*f
));
476 /* Flush display of frame F, or of all frames if F is null. */
485 Lisp_Object rest
, frame
;
486 FOR_EACH_FRAME (rest
, frame
)
487 x_flush (XFRAME (frame
));
489 else if (FRAME_X_P (f
))
490 XFlush (FRAME_X_DISPLAY (f
));
495 /* Remove calls to XFlush by defining XFlush to an empty replacement.
496 Calls to XFlush should be unnecessary because the X output buffer
497 is flushed automatically as needed by calls to XPending,
498 XNextEvent, or XWindowEvent according to the XFlush man page.
499 XTread_socket calls XPending. Removing XFlush improves
502 #define XFlush(DISPLAY) (void) 0
505 /***********************************************************************
507 ***********************************************************************/
511 /* This is a function useful for recording debugging information about
512 the sequence of occurrences in this file. */
520 struct record event_record
[100];
522 int event_record_index
;
524 record_event (locus
, type
)
528 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
529 event_record_index
= 0;
531 event_record
[event_record_index
].locus
= locus
;
532 event_record
[event_record_index
].type
= type
;
533 event_record_index
++;
540 /* Return the struct x_display_info corresponding to DPY. */
542 struct x_display_info
*
543 x_display_info_for_display (dpy
)
546 struct x_display_info
*dpyinfo
;
548 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
549 if (dpyinfo
->display
== dpy
)
557 /***********************************************************************
558 Starting and ending an update
559 ***********************************************************************/
561 /* Start an update of frame F. This function is installed as a hook
562 for update_begin, i.e. it is called when update_begin is called.
563 This function is called prior to calls to x_update_window_begin for
564 each window being updated. Currently, there is nothing to do here
565 because all interesting stuff is done on a window basis. */
575 /* Start update of window W. Set the global variable updated_window
576 to the window being updated and set output_cursor to the cursor
580 x_update_window_begin (w
)
583 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
584 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
587 set_output_cursor (&w
->cursor
);
591 if (f
== display_info
->mouse_face_mouse_frame
)
593 /* Don't do highlighting for mouse motion during the update. */
594 display_info
->mouse_face_defer
= 1;
596 /* If F needs to be redrawn, simply forget about any prior mouse
598 if (FRAME_GARBAGED_P (f
))
599 display_info
->mouse_face_window
= Qnil
;
601 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
602 their mouse_face_p flag set, which means that they are always
603 unequal to rows in a desired matrix which never have that
604 flag set. So, rows containing mouse-face glyphs are never
605 scrolled, and we don't have to switch the mouse highlight off
606 here to prevent it from being scrolled. */
608 /* Can we tell that this update does not affect the window
609 where the mouse highlight is? If so, no need to turn off.
610 Likewise, don't do anything if the frame is garbaged;
611 in that case, the frame's current matrix that we would use
612 is all wrong, and we will redisplay that line anyway. */
613 if (!NILP (display_info
->mouse_face_window
)
614 && w
== XWINDOW (display_info
->mouse_face_window
))
618 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
619 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
622 if (i
< w
->desired_matrix
->nrows
)
623 clear_mouse_face (display_info
);
632 /* Draw a vertical window border to the right of window W if W doesn't
633 have vertical scroll bars. */
636 x_draw_vertical_border (w
)
639 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
641 /* Redraw borders between horizontally adjacent windows. Don't
642 do it for frames with vertical scroll bars because either the
643 right scroll bar of a window, or the left scroll bar of its
644 neighbor will suffice as a border. */
645 if (!WINDOW_RIGHTMOST_P (w
)
646 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
650 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
651 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
654 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
655 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
660 /* End update of window W (which is equal to updated_window). Draw
661 vertical borders between horizontally adjacent windows, and display
662 W's cursor if CURSOR_ON_P is non-zero. W may be a menu bar
663 pseudo-window in case we don't have X toolkit support. Such
664 windows don't have a cursor, so don't display it here. */
667 x_update_window_end (w
, cursor_on_p
)
671 if (!w
->pseudo_window_p
)
675 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
677 output_cursor
.x
, output_cursor
.y
);
678 x_draw_vertical_border (w
);
682 updated_window
= NULL
;
686 /* End update of frame F. This function is installed as a hook in
693 /* Mouse highlight may be displayed again. */
694 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
697 XFlush (FRAME_X_DISPLAY (f
));
702 /* This function is called from various places in xdisp.c whenever a
703 complete update has been performed. The global variable
704 updated_window is not available here. */
707 XTframe_up_to_date (f
)
712 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
713 if (dpyinfo
->mouse_face_deferred_gc
714 || f
== dpyinfo
->mouse_face_mouse_frame
)
717 if (dpyinfo
->mouse_face_mouse_frame
)
718 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
719 dpyinfo
->mouse_face_mouse_x
,
720 dpyinfo
->mouse_face_mouse_y
);
721 dpyinfo
->mouse_face_deferred_gc
= 0;
728 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
729 arrow bitmaps, or clear the areas where they would be displayed
730 before DESIRED_ROW is made current. The window being updated is
731 found in updated_window. This function It is called from
732 update_window_line only if it is known that there are differences
733 between bitmaps to be drawn between current row and DESIRED_ROW. */
736 x_after_update_window_line (desired_row
)
737 struct glyph_row
*desired_row
;
739 struct window
*w
= updated_window
;
743 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
746 x_draw_row_bitmaps (w
, desired_row
);
748 /* When a window has disappeared, make sure that no rest of
749 full-width rows stays visible in the internal border. */
750 if (windows_or_buffers_changed
)
752 struct frame
*f
= XFRAME (w
->frame
);
753 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
754 int height
= desired_row
->visible_height
;
755 int x
= (window_box_right (w
, -1)
756 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
757 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
759 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
760 x
, y
, width
, height
, False
);
768 /* Draw the bitmap WHICH in one of the areas to the left or right of
769 window W. ROW is the glyph row for which to display the bitmap; it
770 determines the vertical position at which the bitmap has to be
774 x_draw_bitmap (w
, row
, which
)
776 struct glyph_row
*row
;
777 enum bitmap_type which
;
779 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
780 Display
*display
= FRAME_X_DISPLAY (f
);
781 Window window
= FRAME_X_WINDOW (f
);
785 GC gc
= f
->output_data
.x
->normal_gc
;
787 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
789 /* Must clip because of partially visible lines. */
790 x_clip_to_row (w
, row
, gc
, 1);
794 case LEFT_TRUNCATION_BITMAP
:
798 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
800 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
803 case OVERLAY_ARROW_BITMAP
:
807 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
809 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
812 case RIGHT_TRUNCATION_BITMAP
:
816 x
= window_box_right (w
, -1);
817 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
820 case CONTINUED_LINE_BITMAP
:
823 bits
= continued_bits
;
824 x
= window_box_right (w
, -1);
825 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
828 case CONTINUATION_LINE_BITMAP
:
829 wd
= continuation_width
;
830 h
= continuation_height
;
831 bits
= continuation_bits
;
832 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
834 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
841 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
843 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
850 /* Convert to frame coordinates. Set dy to the offset in the row to
851 start drawing the bitmap. */
852 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
853 dy
= (row
->height
- h
) / 2;
855 /* Draw the bitmap. I believe these small pixmaps can be cached
857 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
858 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
860 face
->background
, depth
);
861 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
862 XFreePixmap (display
, pixmap
);
863 XSetClipMask (display
, gc
, None
);
867 /* Draw flags bitmaps for glyph row ROW on window W. Call this
868 function with input blocked. */
871 x_draw_row_bitmaps (w
, row
)
873 struct glyph_row
*row
;
875 struct frame
*f
= XFRAME (w
->frame
);
876 enum bitmap_type bitmap
;
878 int header_line_height
= -1;
880 xassert (interrupt_input_blocked
);
882 /* If row is completely invisible, because of vscrolling, we
883 don't have to draw anything. */
884 if (row
->visible_height
<= 0)
887 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
888 PREPARE_FACE_FOR_DISPLAY (f
, face
);
890 /* Decide which bitmap to draw at the left side. */
891 if (row
->overlay_arrow_p
)
892 bitmap
= OVERLAY_ARROW_BITMAP
;
893 else if (row
->truncated_on_left_p
)
894 bitmap
= LEFT_TRUNCATION_BITMAP
;
895 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
896 bitmap
= CONTINUATION_LINE_BITMAP
;
897 else if (row
->indicate_empty_line_p
)
898 bitmap
= ZV_LINE_BITMAP
;
902 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
904 if (bitmap
== NO_BITMAP
905 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
906 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
908 /* If W has a vertical border to its left, don't draw over it. */
909 int border
= ((XFASTINT (w
->left
) > 0
910 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
912 int left
= window_box_left (w
, -1);
914 if (header_line_height
< 0)
915 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
917 /* In case the same realized face is used for bitmap areas and
918 for something displayed in the text (e.g. face `region' on
919 mono-displays, the fill style may have been changed to
920 FillSolid in x_draw_glyph_string_background. */
922 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
924 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
926 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
929 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
931 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
933 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
934 row
->visible_height
);
936 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
939 /* Draw the left bitmap. */
940 if (bitmap
!= NO_BITMAP
)
941 x_draw_bitmap (w
, row
, bitmap
);
943 /* Decide which bitmap to draw at the right side. */
944 if (row
->truncated_on_right_p
)
945 bitmap
= RIGHT_TRUNCATION_BITMAP
;
946 else if (row
->continued_p
)
947 bitmap
= CONTINUED_LINE_BITMAP
;
951 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
953 if (bitmap
== NO_BITMAP
954 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
955 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
957 int right
= window_box_right (w
, -1);
959 if (header_line_height
< 0)
960 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
962 /* In case the same realized face is used for bitmap areas and
963 for something displayed in the text (e.g. face `region' on
964 mono-displays, the fill style may have been changed to
965 FillSolid in x_draw_glyph_string_background. */
967 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
969 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
970 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
973 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
975 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
976 row
->visible_height
);
978 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
981 /* Draw the right bitmap. */
982 if (bitmap
!= NO_BITMAP
)
983 x_draw_bitmap (w
, row
, bitmap
);
987 /***********************************************************************
989 ***********************************************************************/
991 /* External interface to control of standout mode. Not used for X
992 frames. Aborts when called. */
995 XTreassert_line_highlight (new, vpos
)
1002 /* Call this when about to modify line at position VPOS and change
1003 whether it is highlighted. Not used for X frames. Aborts when
1007 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1008 int new_highlight
, vpos
, y
, first_unused_hpos
;
1014 /* This is called when starting Emacs and when restarting after
1015 suspend. When starting Emacs, no X window is mapped. And nothing
1016 must be done to Emacs's own window if it is suspended (though that
1020 XTset_terminal_modes ()
1024 /* This is called when exiting or suspending Emacs. Exiting will make
1025 the X-windows go away, and suspending requires no action. */
1028 XTreset_terminal_modes ()
1034 /***********************************************************************
1036 ***********************************************************************/
1038 /* Set the global variable output_cursor to CURSOR. All cursor
1039 positions are relative to updated_window. */
1042 set_output_cursor (cursor
)
1043 struct cursor_pos
*cursor
;
1045 output_cursor
.hpos
= cursor
->hpos
;
1046 output_cursor
.vpos
= cursor
->vpos
;
1047 output_cursor
.x
= cursor
->x
;
1048 output_cursor
.y
= cursor
->y
;
1052 /* Set a nominal cursor position.
1054 HPOS and VPOS are column/row positions in a window glyph matrix. X
1055 and Y are window text area relative pixel positions.
1057 If this is done during an update, updated_window will contain the
1058 window that is being updated and the position is the future output
1059 cursor position for that window. If updated_window is null, use
1060 selected_window and display the cursor at the given position. */
1063 XTcursor_to (vpos
, hpos
, y
, x
)
1064 int vpos
, hpos
, y
, x
;
1068 /* If updated_window is not set, work on selected_window. */
1072 w
= XWINDOW (selected_window
);
1074 /* Set the output cursor. */
1075 output_cursor
.hpos
= hpos
;
1076 output_cursor
.vpos
= vpos
;
1077 output_cursor
.x
= x
;
1078 output_cursor
.y
= y
;
1080 /* If not called as part of an update, really display the cursor.
1081 This will also set the cursor position of W. */
1082 if (updated_window
== NULL
)
1085 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1086 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1093 /***********************************************************************
1095 ***********************************************************************/
1097 /* Function prototypes of this page. */
1099 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1103 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1104 int, XChar2b
*, int));
1105 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1106 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1107 static void x_append_glyph
P_ ((struct it
*));
1108 static void x_append_composite_glyph
P_ ((struct it
*));
1109 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1111 static void x_produce_glyphs
P_ ((struct it
*));
1112 static void x_produce_image_glyph
P_ ((struct it
*it
));
1115 /* Return a pointer to per-char metric information in FONT of a
1116 character pointed by B which is a pointer to an XChar2b. */
1118 #define PER_CHAR_METRIC(font, b) \
1120 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1121 + (((font)->min_byte1 || (font)->max_byte1) \
1122 ? (((b)->byte1 - (font)->min_byte1) \
1123 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1125 : &((font)->max_bounds))
1128 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1129 is not contained in the font. */
1131 static INLINE XCharStruct
*
1132 x_per_char_metric (font
, char2b
)
1136 /* The result metric information. */
1137 XCharStruct
*pcm
= NULL
;
1139 xassert (font
&& char2b
);
1141 if (font
->per_char
!= NULL
)
1143 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1145 /* min_char_or_byte2 specifies the linear character index
1146 corresponding to the first element of the per_char array,
1147 max_char_or_byte2 is the index of the last character. A
1148 character with non-zero CHAR2B->byte1 is not in the font.
1149 A character with byte2 less than min_char_or_byte2 or
1150 greater max_char_or_byte2 is not in the font. */
1151 if (char2b
->byte1
== 0
1152 && char2b
->byte2
>= font
->min_char_or_byte2
1153 && char2b
->byte2
<= font
->max_char_or_byte2
)
1154 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1158 /* If either min_byte1 or max_byte1 are nonzero, both
1159 min_char_or_byte2 and max_char_or_byte2 are less than
1160 256, and the 2-byte character index values corresponding
1161 to the per_char array element N (counting from 0) are:
1163 byte1 = N/D + min_byte1
1164 byte2 = N\D + min_char_or_byte2
1168 D = max_char_or_byte2 - min_char_or_byte2 + 1
1169 / = integer division
1170 \ = integer modulus */
1171 if (char2b
->byte1
>= font
->min_byte1
1172 && char2b
->byte1
<= font
->max_byte1
1173 && char2b
->byte2
>= font
->min_char_or_byte2
1174 && char2b
->byte2
<= font
->max_char_or_byte2
)
1176 pcm
= (font
->per_char
1177 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1178 * (char2b
->byte1
- font
->min_byte1
))
1179 + (char2b
->byte2
- font
->min_char_or_byte2
));
1185 /* If the per_char pointer is null, all glyphs between the first
1186 and last character indexes inclusive have the same
1187 information, as given by both min_bounds and max_bounds. */
1188 if (char2b
->byte2
>= font
->min_char_or_byte2
1189 && char2b
->byte2
<= font
->max_char_or_byte2
)
1190 pcm
= &font
->max_bounds
;
1193 return ((pcm
== NULL
1194 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1199 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1200 the two-byte form of C. Encoding is returned in *CHAR2B. */
1203 x_encode_char (c
, char2b
, font_info
)
1206 struct font_info
*font_info
;
1208 int charset
= CHAR_CHARSET (c
);
1209 XFontStruct
*font
= font_info
->font
;
1211 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1212 This may be either a program in a special encoder language or a
1214 if (font_info
->font_encoder
)
1216 /* It's a program. */
1217 struct ccl_program
*ccl
= font_info
->font_encoder
;
1219 if (CHARSET_DIMENSION (charset
) == 1)
1221 ccl
->reg
[0] = charset
;
1222 ccl
->reg
[1] = char2b
->byte2
;
1226 ccl
->reg
[0] = charset
;
1227 ccl
->reg
[1] = char2b
->byte1
;
1228 ccl
->reg
[2] = char2b
->byte2
;
1231 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1233 /* We assume that MSBs are appropriately set/reset by CCL
1235 if (font
->max_byte1
== 0) /* 1-byte font */
1236 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1238 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1240 else if (font_info
->encoding
[charset
])
1242 /* Fixed encoding scheme. See fontset.h for the meaning of the
1243 encoding numbers. */
1244 int enc
= font_info
->encoding
[charset
];
1246 if ((enc
== 1 || enc
== 2)
1247 && CHARSET_DIMENSION (charset
) == 2)
1248 char2b
->byte1
|= 0x80;
1250 if (enc
== 1 || enc
== 3)
1251 char2b
->byte2
|= 0x80;
1256 /* Get face and two-byte form of character C in face FACE_ID on frame
1257 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1258 means we want to display multibyte text. Value is a pointer to a
1259 realized face that is ready for display. */
1261 static INLINE
struct face
*
1262 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1268 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1272 /* Unibyte case. We don't have to encode, but we have to make
1273 sure to use a face suitable for unibyte. */
1276 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1277 face
= FACE_FROM_ID (f
, face_id
);
1279 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1281 /* Case of ASCII in a face known to fit ASCII. */
1287 int c1
, c2
, charset
;
1289 /* Split characters into bytes. If c2 is -1 afterwards, C is
1290 really a one-byte character so that byte1 is zero. */
1291 SPLIT_CHAR (c
, charset
, c1
, c2
);
1293 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1295 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1297 /* Maybe encode the character in *CHAR2B. */
1298 if (face
->font
!= NULL
)
1300 struct font_info
*font_info
1301 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1303 x_encode_char (c
, char2b
, font_info
);
1307 /* Make sure X resources of the face are allocated. */
1308 xassert (face
!= NULL
);
1309 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1315 /* Get face and two-byte form of character glyph GLYPH on frame F.
1316 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1317 a pointer to a realized face that is ready for display. */
1319 static INLINE
struct face
*
1320 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1322 struct glyph
*glyph
;
1328 xassert (glyph
->type
== CHAR_GLYPH
);
1329 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1334 if (!glyph
->multibyte_p
)
1336 /* Unibyte case. We don't have to encode, but we have to make
1337 sure to use a face suitable for unibyte. */
1339 char2b
->byte2
= glyph
->u
.ch
;
1341 else if (glyph
->u
.ch
< 128
1342 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1344 /* Case of ASCII in a face known to fit ASCII. */
1346 char2b
->byte2
= glyph
->u
.ch
;
1350 int c1
, c2
, charset
;
1352 /* Split characters into bytes. If c2 is -1 afterwards, C is
1353 really a one-byte character so that byte1 is zero. */
1354 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1356 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1358 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1360 /* Maybe encode the character in *CHAR2B. */
1361 if (charset
!= CHARSET_ASCII
)
1363 struct font_info
*font_info
1364 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1367 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1370 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1375 /* Make sure X resources of the face are allocated. */
1376 xassert (face
!= NULL
);
1377 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1382 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1383 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1389 struct glyph
*glyph
;
1390 enum glyph_row_area area
= it
->area
;
1392 xassert (it
->glyph_row
);
1393 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1395 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1396 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1398 glyph
->charpos
= CHARPOS (it
->position
);
1399 glyph
->object
= it
->object
;
1400 glyph
->pixel_width
= it
->pixel_width
;
1401 glyph
->voffset
= it
->voffset
;
1402 glyph
->type
= CHAR_GLYPH
;
1403 glyph
->multibyte_p
= it
->multibyte_p
;
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
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1407 || it
->phys_descent
> it
->descent
);
1408 glyph
->padding_p
= 0;
1409 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1410 glyph
->face_id
= it
->face_id
;
1411 glyph
->u
.ch
= it
->char_to_display
;
1412 ++it
->glyph_row
->used
[area
];
1416 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1417 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1420 x_append_composite_glyph (it
)
1423 struct glyph
*glyph
;
1424 enum glyph_row_area area
= it
->area
;
1426 xassert (it
->glyph_row
);
1428 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1429 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1431 glyph
->charpos
= CHARPOS (it
->position
);
1432 glyph
->object
= it
->object
;
1433 glyph
->pixel_width
= it
->pixel_width
;
1434 glyph
->voffset
= it
->voffset
;
1435 glyph
->type
= COMPOSITE_GLYPH
;
1436 glyph
->multibyte_p
= it
->multibyte_p
;
1437 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1438 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1439 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1440 || it
->phys_descent
> it
->descent
);
1441 glyph
->padding_p
= 0;
1442 glyph
->glyph_not_available_p
= 0;
1443 glyph
->face_id
= it
->face_id
;
1444 glyph
->u
.cmp_id
= it
->cmp_id
;
1445 ++it
->glyph_row
->used
[area
];
1450 /* Change IT->ascent and IT->height according to the setting of
1454 take_vertical_position_into_account (it
)
1459 if (it
->voffset
< 0)
1460 /* Increase the ascent so that we can display the text higher
1462 it
->ascent
+= abs (it
->voffset
);
1464 /* Increase the descent so that we can display the text lower
1466 it
->descent
+= it
->voffset
;
1471 /* Produce glyphs/get display metrics for the image IT is loaded with.
1472 See the description of struct display_iterator in dispextern.h for
1473 an overview of struct display_iterator. */
1476 x_produce_image_glyph (it
)
1482 xassert (it
->what
== IT_IMAGE
);
1484 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1485 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1488 /* Make sure X resources of the face and image are loaded. */
1489 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1490 prepare_image_for_display (it
->f
, img
);
1492 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1493 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->margin
- it
->ascent
;
1494 it
->pixel_width
= img
->width
+ 2 * img
->margin
;
1498 if (face
->box
!= FACE_NO_BOX
)
1500 it
->ascent
+= face
->box_line_width
;
1501 it
->descent
+= face
->box_line_width
;
1503 if (it
->start_of_box_run_p
)
1504 it
->pixel_width
+= face
->box_line_width
;
1505 if (it
->end_of_box_run_p
)
1506 it
->pixel_width
+= face
->box_line_width
;
1509 take_vertical_position_into_account (it
);
1513 struct glyph
*glyph
;
1514 enum glyph_row_area area
= it
->area
;
1516 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1517 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1519 glyph
->charpos
= CHARPOS (it
->position
);
1520 glyph
->object
= it
->object
;
1521 glyph
->pixel_width
= it
->pixel_width
;
1522 glyph
->voffset
= it
->voffset
;
1523 glyph
->type
= IMAGE_GLYPH
;
1524 glyph
->multibyte_p
= it
->multibyte_p
;
1525 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1526 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1527 glyph
->overlaps_vertically_p
= 0;
1528 glyph
->padding_p
= 0;
1529 glyph
->glyph_not_available_p
= 0;
1530 glyph
->face_id
= it
->face_id
;
1531 glyph
->u
.img_id
= img
->id
;
1532 ++it
->glyph_row
->used
[area
];
1538 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1539 of the glyph, WIDTH and HEIGHT are the width and height of the
1540 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1541 ascent of the glyph (0 <= ASCENT <= 1). */
1544 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1550 struct glyph
*glyph
;
1551 enum glyph_row_area area
= it
->area
;
1553 xassert (ascent
>= 0 && ascent
<= 1);
1555 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1556 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1558 glyph
->charpos
= CHARPOS (it
->position
);
1559 glyph
->object
= object
;
1560 glyph
->pixel_width
= width
;
1561 glyph
->voffset
= it
->voffset
;
1562 glyph
->type
= STRETCH_GLYPH
;
1563 glyph
->multibyte_p
= it
->multibyte_p
;
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
->overlaps_vertically_p
= 0;
1567 glyph
->padding_p
= 0;
1568 glyph
->glyph_not_available_p
= 0;
1569 glyph
->face_id
= it
->face_id
;
1570 glyph
->u
.stretch
.ascent
= height
* ascent
;
1571 glyph
->u
.stretch
.height
= height
;
1572 ++it
->glyph_row
->used
[area
];
1577 /* Produce a stretch glyph for iterator IT. IT->object is the value
1578 of the glyph property displayed. The value must be a list
1579 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1582 1. `:width WIDTH' specifies that the space should be WIDTH *
1583 canonical char width wide. WIDTH may be an integer or floating
1586 2. `:relative-width FACTOR' specifies that the width of the stretch
1587 should be computed from the width of the first character having the
1588 `glyph' property, and should be FACTOR times that width.
1590 3. `:align-to HPOS' specifies that the space should be wide enough
1591 to reach HPOS, a value in canonical character units.
1593 Exactly one of the above pairs must be present.
1595 4. `:height HEIGHT' specifies that the height of the stretch produced
1596 should be HEIGHT, measured in canonical character units.
1598 5. `:relative-height FACTOR' specifies that the height of the the
1599 stretch should be FACTOR times the height of the characters having
1602 Either none or exactly one of 4 or 5 must be present.
1604 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1605 of the stretch should be used for the ascent of the stretch.
1606 ASCENT must be in the range 0 <= ASCENT <= 100. */
1609 ((INTEGERP (X) || FLOATP (X)) \
1615 x_produce_stretch_glyph (it
)
1618 /* (space :width WIDTH :height HEIGHT. */
1620 extern Lisp_Object Qspace
;
1622 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1623 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1624 extern Lisp_Object QCalign_to
;
1625 Lisp_Object prop
, plist
;
1626 double width
= 0, height
= 0, ascent
= 0;
1627 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1628 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1630 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1632 /* List should start with `space'. */
1633 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1634 plist
= XCDR (it
->object
);
1636 /* Compute the width of the stretch. */
1637 if (prop
= Fplist_get (plist
, QCwidth
),
1639 /* Absolute width `:width WIDTH' specified and valid. */
1640 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1641 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1644 /* Relative width `:relative-width FACTOR' specified and valid.
1645 Compute the width of the characters having the `glyph'
1648 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1651 if (it
->multibyte_p
)
1653 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1654 - IT_BYTEPOS (*it
));
1655 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1658 it2
.c
= *p
, it2
.len
= 1;
1660 it2
.glyph_row
= NULL
;
1661 it2
.what
= IT_CHARACTER
;
1662 x_produce_glyphs (&it2
);
1663 width
= NUMVAL (prop
) * it2
.pixel_width
;
1665 else if (prop
= Fplist_get (plist
, QCalign_to
),
1667 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1669 /* Nothing specified -> width defaults to canonical char width. */
1670 width
= CANON_X_UNIT (it
->f
);
1672 /* Compute height. */
1673 if (prop
= Fplist_get (plist
, QCheight
),
1675 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1676 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1678 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1680 height
= FONT_HEIGHT (font
);
1682 /* Compute percentage of height used for ascent. If
1683 `:ascent ASCENT' is present and valid, use that. Otherwise,
1684 derive the ascent from the font in use. */
1685 if (prop
= Fplist_get (plist
, QCascent
),
1686 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1687 ascent
= NUMVAL (prop
) / 100.0;
1689 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1698 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1699 if (!STRINGP (object
))
1700 object
= it
->w
->buffer
;
1701 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1704 it
->pixel_width
= width
;
1705 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1706 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1709 if (face
->box
!= FACE_NO_BOX
)
1711 it
->ascent
+= face
->box_line_width
;
1712 it
->descent
+= face
->box_line_width
;
1714 if (it
->start_of_box_run_p
)
1715 it
->pixel_width
+= face
->box_line_width
;
1716 if (it
->end_of_box_run_p
)
1717 it
->pixel_width
+= face
->box_line_width
;
1720 take_vertical_position_into_account (it
);
1723 /* Return proper value to be used as baseline offset of font that has
1724 ASCENT and DESCENT to draw characters by the font at the vertical
1725 center of the line of frame F.
1727 Here, out task is to find the value of BOFF in the following figure;
1729 -------------------------+-----------+-
1730 -+-+---------+-+ | |
1732 | | | | F_ASCENT F_HEIGHT
1735 | | |-|-+------+-----------|------- baseline
1737 | |---------|-+-+ | |
1739 -+-+---------+-+ F_DESCENT |
1740 -------------------------+-----------+-
1742 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1743 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1744 DESCENT = FONT->descent
1745 HEIGHT = FONT_HEIGHT (FONT)
1746 F_DESCENT = (F->output_data.x->font->descent
1747 - F->output_data.x->baseline_offset)
1748 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1751 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1753 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT))) / 2 \
1754 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1756 /* Produce glyphs/get display metrics for the display element IT is
1757 loaded with. See the description of struct display_iterator in
1758 dispextern.h for an overview of struct display_iterator. */
1761 x_produce_glyphs (it
)
1764 it
->glyph_not_available_p
= 0;
1766 if (it
->what
== IT_CHARACTER
)
1770 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1772 int font_not_found_p
;
1773 struct font_info
*font_info
;
1774 int boff
; /* baseline offset */
1776 /* Maybe translate single-byte characters to multibyte, or the
1778 it
->char_to_display
= it
->c
;
1779 if (!ASCII_BYTE_P (it
->c
))
1781 if (unibyte_display_via_language_environment
1782 && SINGLE_BYTE_CHAR_P (it
->c
)
1784 || !NILP (Vnonascii_translation_table
)))
1786 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1787 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1788 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1790 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1791 && !it
->multibyte_p
)
1793 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1794 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1795 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1799 /* Get font to use. Encode IT->char_to_display. */
1800 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1801 it
->face_id
, &char2b
,
1805 /* When no suitable font found, use the default font. */
1806 font_not_found_p
= font
== NULL
;
1807 if (font_not_found_p
)
1809 font
= FRAME_FONT (it
->f
);
1810 boff
= it
->f
->output_data
.x
->baseline_offset
;
1815 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1816 boff
= font_info
->baseline_offset
;
1817 if (font_info
->vertical_centering
)
1818 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1821 if (it
->char_to_display
>= ' '
1822 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1824 /* Either unibyte or ASCII. */
1829 pcm
= x_per_char_metric (font
, &char2b
);
1830 it
->ascent
= font
->ascent
+ boff
;
1831 it
->descent
= font
->descent
- boff
;
1835 it
->phys_ascent
= pcm
->ascent
+ boff
;
1836 it
->phys_descent
= pcm
->descent
- boff
;
1837 it
->pixel_width
= pcm
->width
;
1841 it
->glyph_not_available_p
= 1;
1842 it
->phys_ascent
= font
->ascent
+ boff
;
1843 it
->phys_descent
= font
->descent
- boff
;
1844 it
->pixel_width
= FONT_WIDTH (font
);
1847 /* If this is a space inside a region of text with
1848 `space-width' property, change its width. */
1849 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1851 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1853 /* If face has a box, add the box thickness to the character
1854 height. If character has a box line to the left and/or
1855 right, add the box line width to the character's width. */
1856 if (face
->box
!= FACE_NO_BOX
)
1858 int thick
= face
->box_line_width
;
1860 it
->ascent
+= thick
;
1861 it
->descent
+= thick
;
1863 if (it
->start_of_box_run_p
)
1864 it
->pixel_width
+= thick
;
1865 if (it
->end_of_box_run_p
)
1866 it
->pixel_width
+= thick
;
1869 /* If face has an overline, add the height of the overline
1870 (1 pixel) and a 1 pixel margin to the character height. */
1871 if (face
->overline_p
)
1874 take_vertical_position_into_account (it
);
1876 /* If we have to actually produce glyphs, do it. */
1881 /* Translate a space with a `space-width' property
1882 into a stretch glyph. */
1883 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1884 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1885 it
->ascent
+ it
->descent
, ascent
);
1888 x_append_glyph (it
);
1890 /* If characters with lbearing or rbearing are displayed
1891 in this line, record that fact in a flag of the
1892 glyph row. This is used to optimize X output code. */
1893 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1894 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1897 else if (it
->char_to_display
== '\n')
1899 /* A newline has no width but we need the height of the line. */
1900 it
->pixel_width
= 0;
1902 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1903 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1905 if (face
->box
!= FACE_NO_BOX
)
1907 int thick
= face
->box_line_width
;
1908 it
->ascent
+= thick
;
1909 it
->descent
+= thick
;
1912 else if (it
->char_to_display
== '\t')
1914 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1915 int x
= it
->current_x
+ it
->continuation_lines_width
;
1916 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1918 it
->pixel_width
= next_tab_x
- x
;
1920 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1921 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1925 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1926 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1927 it
->ascent
+ it
->descent
, ascent
);
1932 /* A multi-byte character. Assume that the display width of the
1933 character is the width of the character multiplied by the
1934 width of the font. */
1936 /* If we found a font, this font should give us the right
1937 metrics. If we didn't find a font, use the frame's
1938 default font and calculate the width of the character
1939 from the charset width; this is what old redisplay code
1941 pcm
= x_per_char_metric (font
, &char2b
);
1942 if (font_not_found_p
|| !pcm
)
1944 int charset
= CHAR_CHARSET (it
->char_to_display
);
1946 it
->glyph_not_available_p
= 1;
1947 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1948 * CHARSET_WIDTH (charset
));
1949 it
->phys_ascent
= font
->ascent
+ boff
;
1950 it
->phys_descent
= font
->descent
- boff
;
1954 it
->pixel_width
= pcm
->width
;
1955 it
->phys_ascent
= pcm
->ascent
+ boff
;
1956 it
->phys_descent
= pcm
->descent
- boff
;
1958 && (pcm
->lbearing
< 0
1959 || pcm
->rbearing
> pcm
->width
))
1960 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1963 it
->ascent
= font
->ascent
+ boff
;
1964 it
->descent
= font
->descent
- boff
;
1965 if (face
->box
!= FACE_NO_BOX
)
1967 int thick
= face
->box_line_width
;
1968 it
->ascent
+= thick
;
1969 it
->descent
+= thick
;
1971 if (it
->start_of_box_run_p
)
1972 it
->pixel_width
+= thick
;
1973 if (it
->end_of_box_run_p
)
1974 it
->pixel_width
+= thick
;
1977 /* If face has an overline, add the height of the overline
1978 (1 pixel) and a 1 pixel margin to the character height. */
1979 if (face
->overline_p
)
1982 take_vertical_position_into_account (it
);
1985 x_append_glyph (it
);
1988 else if (it
->what
== IT_COMPOSITION
)
1990 /* Note: A composition is represented as one glyph in the
1991 glyph matrix. There are no padding glyphs. */
1994 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1996 int font_not_found_p
;
1997 struct font_info
*font_info
;
1998 int boff
; /* baseline offset */
1999 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2001 /* Maybe translate single-byte characters to multibyte. */
2002 it
->char_to_display
= it
->c
;
2003 if (unibyte_display_via_language_environment
2004 && SINGLE_BYTE_CHAR_P (it
->c
)
2007 && !NILP (Vnonascii_translation_table
))))
2009 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2012 /* Get face and font to use. Encode IT->char_to_display. */
2013 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2014 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2015 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2016 it
->face_id
, &char2b
, it
->multibyte_p
);
2019 /* When no suitable font found, use the default font. */
2020 font_not_found_p
= font
== NULL
;
2021 if (font_not_found_p
)
2023 font
= FRAME_FONT (it
->f
);
2024 boff
= it
->f
->output_data
.x
->baseline_offset
;
2029 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2030 boff
= font_info
->baseline_offset
;
2031 if (font_info
->vertical_centering
)
2032 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2035 /* There are no padding glyphs, so there is only one glyph to
2036 produce for the composition. Important is that pixel_width,
2037 ascent and descent are the values of what is drawn by
2038 draw_glyphs (i.e. the values of the overall glyphs composed). */
2041 /* If we have not yet calculated pixel size data of glyphs of
2042 the composition for the current face font, calculate them
2043 now. Theoretically, we have to check all fonts for the
2044 glyphs, but that requires much time and memory space. So,
2045 here we check only the font of the first glyph. This leads
2046 to incorrect display very rarely, and C-l (recenter) can
2047 correct the display anyway. */
2048 if (cmp
->font
!= (void *) font
)
2050 /* Ascent and descent of the font of the first character of
2051 this composition (adjusted by baseline offset). Ascent
2052 and descent of overall glyphs should not be less than
2053 them respectively. */
2054 int font_ascent
= font
->ascent
+ boff
;
2055 int font_descent
= font
->descent
- boff
;
2056 /* Bounding box of the overall glyphs. */
2057 int leftmost
, rightmost
, lowest
, highest
;
2058 int i
, width
, ascent
, descent
;
2060 cmp
->font
= (void *) font
;
2062 /* Initialize the bounding box. */
2063 pcm
= x_per_char_metric (font
, &char2b
);
2067 ascent
= pcm
->ascent
;
2068 descent
= pcm
->descent
;
2072 width
= FONT_WIDTH (font
);
2073 ascent
= font
->ascent
;
2074 descent
= font
->descent
;
2078 lowest
= - descent
+ boff
;
2079 highest
= ascent
+ boff
;
2083 && font_info
->default_ascent
2084 && CHAR_TABLE_P (Vuse_default_ascent
)
2085 && !NILP (Faref (Vuse_default_ascent
,
2086 make_number (it
->char_to_display
))))
2087 highest
= font_info
->default_ascent
+ boff
;
2089 /* Draw the first glyph at the normal position. It may be
2090 shifted to right later if some other glyphs are drawn at
2092 cmp
->offsets
[0] = 0;
2093 cmp
->offsets
[1] = boff
;
2095 /* Set cmp->offsets for the remaining glyphs. */
2096 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2098 int left
, right
, btm
, top
;
2099 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2100 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2102 face
= FACE_FROM_ID (it
->f
, face_id
);
2103 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2108 font
= FRAME_FONT (it
->f
);
2109 boff
= it
->f
->output_data
.x
->baseline_offset
;
2115 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2116 boff
= font_info
->baseline_offset
;
2117 if (font_info
->vertical_centering
)
2118 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2121 pcm
= x_per_char_metric (font
, &char2b
);
2125 ascent
= pcm
->ascent
;
2126 descent
= pcm
->descent
;
2130 width
= FONT_WIDTH (font
);
2131 ascent
= font
->ascent
;
2132 descent
= font
->descent
;
2135 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2137 /* Relative composition with or without
2139 left
= (leftmost
+ rightmost
- width
) / 2;
2140 btm
= - descent
+ boff
;
2141 if (font_info
&& font_info
->relative_compose
2142 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2143 || NILP (Faref (Vignore_relative_composition
,
2144 make_number (ch
)))))
2147 if (- descent
>= font_info
->relative_compose
)
2148 /* One extra pixel between two glyphs. */
2150 else if (ascent
<= 0)
2151 /* One extra pixel between two glyphs. */
2152 btm
= lowest
- 1 - ascent
- descent
;
2157 /* A composition rule is specified by an integer
2158 value that encodes global and new reference
2159 points (GREF and NREF). GREF and NREF are
2160 specified by numbers as below:
2168 ---3---4---5--- baseline
2170 6---7---8 -- descent
2172 int rule
= COMPOSITION_RULE (cmp
, i
);
2173 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2175 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2176 grefx
= gref
% 3, nrefx
= nref
% 3;
2177 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2180 + grefx
* (rightmost
- leftmost
) / 2
2181 - nrefx
* width
/ 2);
2182 btm
= ((grefy
== 0 ? highest
2184 : grefy
== 2 ? lowest
2185 : (highest
+ lowest
) / 2)
2186 - (nrefy
== 0 ? ascent
+ descent
2187 : nrefy
== 1 ? descent
- boff
2189 : (ascent
+ descent
) / 2));
2192 cmp
->offsets
[i
* 2] = left
;
2193 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2195 /* Update the bounding box of the overall glyphs. */
2196 right
= left
+ width
;
2197 top
= btm
+ descent
+ ascent
;
2198 if (left
< leftmost
)
2200 if (right
> rightmost
)
2208 /* If there are glyphs whose x-offsets are negative,
2209 shift all glyphs to the right and make all x-offsets
2213 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2214 cmp
->offsets
[i
* 2] -= leftmost
;
2215 rightmost
-= leftmost
;
2218 cmp
->pixel_width
= rightmost
;
2219 cmp
->ascent
= highest
;
2220 cmp
->descent
= - lowest
;
2221 if (cmp
->ascent
< font_ascent
)
2222 cmp
->ascent
= font_ascent
;
2223 if (cmp
->descent
< font_descent
)
2224 cmp
->descent
= font_descent
;
2227 it
->pixel_width
= cmp
->pixel_width
;
2228 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2229 it
->descent
= it
->phys_descent
= cmp
->descent
;
2231 if (face
->box
!= FACE_NO_BOX
)
2233 int thick
= face
->box_line_width
;
2234 it
->ascent
+= thick
;
2235 it
->descent
+= thick
;
2237 if (it
->start_of_box_run_p
)
2238 it
->pixel_width
+= thick
;
2239 if (it
->end_of_box_run_p
)
2240 it
->pixel_width
+= thick
;
2243 /* If face has an overline, add the height of the overline
2244 (1 pixel) and a 1 pixel margin to the character height. */
2245 if (face
->overline_p
)
2248 take_vertical_position_into_account (it
);
2251 x_append_composite_glyph (it
);
2253 else if (it
->what
== IT_IMAGE
)
2254 x_produce_image_glyph (it
);
2255 else if (it
->what
== IT_STRETCH
)
2256 x_produce_stretch_glyph (it
);
2258 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2259 because this isn't true for images with `:ascent 100'. */
2260 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2261 if (it
->area
== TEXT_AREA
)
2262 it
->current_x
+= it
->pixel_width
;
2264 it
->descent
+= it
->extra_line_spacing
;
2266 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2267 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2268 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2269 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2273 /* Estimate the pixel height of the mode or top line on frame F.
2274 FACE_ID specifies what line's height to estimate. */
2277 x_estimate_mode_line_height (f
, face_id
)
2279 enum face_id face_id
;
2283 /* This function is called so early when Emacs starts that the face
2284 cache and mode line face are not yet initialized. */
2285 if (FRAME_FACE_CACHE (f
))
2287 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2289 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
2296 /***********************************************************************
2298 ***********************************************************************/
2300 /* A sequence of glyphs to be drawn in the same face.
2302 This data structure is not really completely X specific, so it
2303 could possibly, at least partially, be useful for other systems. It
2304 is currently not part of the external redisplay interface because
2305 it's not clear what other systems will need. */
2309 /* X-origin of the string. */
2312 /* Y-origin and y-position of the base line of this string. */
2315 /* The width of the string, not including a face extension. */
2318 /* The width of the string, including a face extension. */
2319 int background_width
;
2321 /* The height of this string. This is the height of the line this
2322 string is drawn in, and can be different from the height of the
2323 font the string is drawn in. */
2326 /* Number of pixels this string overwrites in front of its x-origin.
2327 This number is zero if the string has an lbearing >= 0; it is
2328 -lbearing, if the string has an lbearing < 0. */
2331 /* Number of pixels this string overwrites past its right-most
2332 nominal x-position, i.e. x + width. Zero if the string's
2333 rbearing is <= its nominal width, rbearing - width otherwise. */
2336 /* The frame on which the glyph string is drawn. */
2339 /* The window on which the glyph string is drawn. */
2342 /* X display and window for convenience. */
2346 /* The glyph row for which this string was built. It determines the
2347 y-origin and height of the string. */
2348 struct glyph_row
*row
;
2350 /* The area within row. */
2351 enum glyph_row_area area
;
2353 /* Characters to be drawn, and number of characters. */
2357 /* A face-override for drawing cursors, mouse face and similar. */
2358 enum draw_glyphs_face hl
;
2360 /* Face in which this string is to be drawn. */
2363 /* Font in which this string is to be drawn. */
2366 /* Font info for this string. */
2367 struct font_info
*font_info
;
2369 /* Non-null means this string describes (part of) a composition.
2370 All characters from char2b are drawn composed. */
2371 struct composition
*cmp
;
2373 /* Index of this glyph string's first character in the glyph
2374 definition of CMP. If this is zero, this glyph string describes
2375 the first character of a composition. */
2378 /* 1 means this glyph strings face has to be drawn to the right end
2379 of the window's drawing area. */
2380 unsigned extends_to_end_of_line_p
: 1;
2382 /* 1 means the background of this string has been drawn. */
2383 unsigned background_filled_p
: 1;
2385 /* 1 means glyph string must be drawn with 16-bit functions. */
2386 unsigned two_byte_p
: 1;
2388 /* 1 means that the original font determined for drawing this glyph
2389 string could not be loaded. The member `font' has been set to
2390 the frame's default font in this case. */
2391 unsigned font_not_found_p
: 1;
2393 /* 1 means that the face in which this glyph string is drawn has a
2395 unsigned stippled_p
: 1;
2397 /* 1 means only the foreground of this glyph string must be drawn,
2398 and we should use the physical height of the line this glyph
2399 string appears in as clip rect. */
2400 unsigned for_overlaps_p
: 1;
2402 /* The GC to use for drawing this glyph string. */
2405 /* A pointer to the first glyph in the string. This glyph
2406 corresponds to char2b[0]. Needed to draw rectangles if
2407 font_not_found_p is 1. */
2408 struct glyph
*first_glyph
;
2410 /* Image, if any. */
2413 struct glyph_string
*next
, *prev
;
2420 x_dump_glyph_string (s
)
2421 struct glyph_string
*s
;
2423 fprintf (stderr
, "glyph string\n");
2424 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2425 s
->x
, s
->y
, s
->width
, s
->height
);
2426 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2427 fprintf (stderr
, " hl = %d\n", s
->hl
);
2428 fprintf (stderr
, " left overhang = %d, right = %d\n",
2429 s
->left_overhang
, s
->right_overhang
);
2430 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2431 fprintf (stderr
, " extends to end of line = %d\n",
2432 s
->extends_to_end_of_line_p
);
2433 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2434 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2437 #endif /* GLYPH_DEBUG */
2441 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2442 struct glyph_string
**,
2443 struct glyph_string
*,
2444 struct glyph_string
*));
2445 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2446 struct glyph_string
**,
2447 struct glyph_string
*,
2448 struct glyph_string
*));
2449 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2450 struct glyph_string
**,
2451 struct glyph_string
*));
2452 static int x_left_overwritten
P_ ((struct glyph_string
*));
2453 static int x_left_overwriting
P_ ((struct glyph_string
*));
2454 static int x_right_overwritten
P_ ((struct glyph_string
*));
2455 static int x_right_overwriting
P_ ((struct glyph_string
*));
2456 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2458 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2459 XChar2b
*, struct window
*,
2461 enum glyph_row_area
, int,
2462 enum draw_glyphs_face
));
2463 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2464 enum glyph_row_area
, int, int,
2465 enum draw_glyphs_face
, int *, int *, int));
2466 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2467 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2468 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2470 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2471 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2472 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2473 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2474 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2475 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2476 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2477 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2478 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2480 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2481 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2482 unsigned long *, double, int));
2483 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2484 double, int, unsigned long));
2485 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2486 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2487 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2488 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2489 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2490 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2491 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2493 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2494 int, int, int, int, XRectangle
*));
2495 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2496 int, int, int, XRectangle
*));
2497 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2498 enum glyph_row_area
));
2499 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2501 enum glyph_row_area
, int, int));
2504 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2508 /* Append the list of glyph strings with head H and tail T to the list
2509 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2512 x_append_glyph_string_lists (head
, tail
, h
, t
)
2513 struct glyph_string
**head
, **tail
;
2514 struct glyph_string
*h
, *t
;
2528 /* Prepend the list of glyph strings with head H and tail T to the
2529 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2533 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2534 struct glyph_string
**head
, **tail
;
2535 struct glyph_string
*h
, *t
;
2549 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2550 Set *HEAD and *TAIL to the resulting list. */
2553 x_append_glyph_string (head
, tail
, s
)
2554 struct glyph_string
**head
, **tail
;
2555 struct glyph_string
*s
;
2557 s
->next
= s
->prev
= NULL
;
2558 x_append_glyph_string_lists (head
, tail
, s
, s
);
2562 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2567 struct glyph_string
*s
;
2569 if (s
->font
== FRAME_FONT (s
->f
)
2570 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2571 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2573 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2576 /* Cursor on non-default face: must merge. */
2580 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2581 xgcv
.foreground
= s
->face
->background
;
2583 /* If the glyph would be invisible, try a different foreground. */
2584 if (xgcv
.foreground
== xgcv
.background
)
2585 xgcv
.foreground
= s
->face
->foreground
;
2586 if (xgcv
.foreground
== xgcv
.background
)
2587 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2588 if (xgcv
.foreground
== xgcv
.background
)
2589 xgcv
.foreground
= s
->face
->foreground
;
2591 /* Make sure the cursor is distinct from text in this face. */
2592 if (xgcv
.background
== s
->face
->background
2593 && xgcv
.foreground
== s
->face
->foreground
)
2595 xgcv
.background
= s
->face
->foreground
;
2596 xgcv
.foreground
= s
->face
->background
;
2599 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2600 xgcv
.font
= s
->font
->fid
;
2601 xgcv
.graphics_exposures
= False
;
2602 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2604 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2605 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2608 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2609 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2611 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2616 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2619 x_set_mouse_face_gc (s
)
2620 struct glyph_string
*s
;
2625 /* What face has to be used for the mouse face? */
2626 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2627 face
= FACE_FROM_ID (s
->f
, face_id
);
2628 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2629 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2631 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2632 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2633 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2635 /* If font in this face is same as S->font, use it. */
2636 if (s
->font
== s
->face
->font
)
2637 s
->gc
= s
->face
->gc
;
2640 /* Otherwise construct scratch_cursor_gc with values from FACE
2645 xgcv
.background
= s
->face
->background
;
2646 xgcv
.foreground
= s
->face
->foreground
;
2647 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2648 xgcv
.font
= s
->font
->fid
;
2649 xgcv
.graphics_exposures
= False
;
2650 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2652 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2653 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2656 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2657 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2659 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2662 xassert (s
->gc
!= 0);
2666 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2667 Faces to use in the mode line have already been computed when the
2668 matrix was built, so there isn't much to do, here. */
2671 x_set_mode_line_face_gc (s
)
2672 struct glyph_string
*s
;
2674 s
->gc
= s
->face
->gc
;
2678 /* Set S->gc of glyph string S for drawing that glyph string. Set
2679 S->stippled_p to a non-zero value if the face of S has a stipple
2683 x_set_glyph_string_gc (s
)
2684 struct glyph_string
*s
;
2686 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2688 if (s
->hl
== DRAW_NORMAL_TEXT
)
2690 s
->gc
= s
->face
->gc
;
2691 s
->stippled_p
= s
->face
->stipple
!= 0;
2693 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2695 x_set_mode_line_face_gc (s
);
2696 s
->stippled_p
= s
->face
->stipple
!= 0;
2698 else if (s
->hl
== DRAW_CURSOR
)
2700 x_set_cursor_gc (s
);
2703 else if (s
->hl
== DRAW_MOUSE_FACE
)
2705 x_set_mouse_face_gc (s
);
2706 s
->stippled_p
= s
->face
->stipple
!= 0;
2708 else if (s
->hl
== DRAW_IMAGE_RAISED
2709 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2711 s
->gc
= s
->face
->gc
;
2712 s
->stippled_p
= s
->face
->stipple
!= 0;
2716 s
->gc
= s
->face
->gc
;
2717 s
->stippled_p
= s
->face
->stipple
!= 0;
2720 /* GC must have been set. */
2721 xassert (s
->gc
!= 0);
2725 /* Return in *R the clipping rectangle for glyph string S. */
2728 x_get_glyph_string_clip_rect (s
, r
)
2729 struct glyph_string
*s
;
2732 if (s
->row
->full_width_p
)
2734 /* Draw full-width. X coordinates are relative to S->w->left. */
2735 int canon_x
= CANON_X_UNIT (s
->f
);
2737 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2738 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2740 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2742 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2743 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2747 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2749 /* Unless displaying a mode or menu bar line, which are always
2750 fully visible, clip to the visible part of the row. */
2751 if (s
->w
->pseudo_window_p
)
2752 r
->height
= s
->row
->visible_height
;
2754 r
->height
= s
->height
;
2758 /* This is a text line that may be partially visible. */
2759 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2760 r
->width
= window_box_width (s
->w
, s
->area
);
2761 r
->height
= s
->row
->visible_height
;
2764 /* Don't use S->y for clipping because it doesn't take partially
2765 visible lines into account. For example, it can be negative for
2766 partially visible lines at the top of a window. */
2767 if (!s
->row
->full_width_p
2768 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2769 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2771 r
->y
= max (0, s
->row
->y
);
2773 /* If drawing a tool-bar window, draw it over the internal border
2774 at the top of the window. */
2775 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2776 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2778 /* If S draws overlapping rows, it's sufficient to use the top and
2779 bottom of the window for clipping because this glyph string
2780 intentionally draws over other lines. */
2781 if (s
->for_overlaps_p
)
2783 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2784 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2787 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2791 /* Set clipping for output of glyph string S. S may be part of a mode
2792 line or menu if we don't have X toolkit support. */
2795 x_set_glyph_string_clipping (s
)
2796 struct glyph_string
*s
;
2799 x_get_glyph_string_clip_rect (s
, &r
);
2800 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2804 /* Compute left and right overhang of glyph string S. If S is a glyph
2805 string for a composition, assume overhangs don't exist. */
2808 x_compute_glyph_string_overhangs (s
)
2809 struct glyph_string
*s
;
2812 && s
->first_glyph
->type
== CHAR_GLYPH
)
2815 int direction
, font_ascent
, font_descent
;
2816 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2817 &font_ascent
, &font_descent
, &cs
);
2818 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2819 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2824 /* Compute overhangs and x-positions for glyph string S and its
2825 predecessors, or successors. X is the starting x-position for S.
2826 BACKWARD_P non-zero means process predecessors. */
2829 x_compute_overhangs_and_x (s
, x
, backward_p
)
2830 struct glyph_string
*s
;
2838 x_compute_glyph_string_overhangs (s
);
2848 x_compute_glyph_string_overhangs (s
);
2857 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2858 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2859 assumed to be zero. */
2862 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2863 struct glyph
*glyph
;
2869 if (glyph
->type
== CHAR_GLYPH
)
2873 struct font_info
*font_info
;
2877 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2879 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2881 && (pcm
= x_per_char_metric (font
, &char2b
)))
2883 if (pcm
->rbearing
> pcm
->width
)
2884 *right
= pcm
->rbearing
- pcm
->width
;
2885 if (pcm
->lbearing
< 0)
2886 *left
= -pcm
->lbearing
;
2892 /* Return the index of the first glyph preceding glyph string S that
2893 is overwritten by S because of S's left overhang. Value is -1
2894 if no glyphs are overwritten. */
2897 x_left_overwritten (s
)
2898 struct glyph_string
*s
;
2902 if (s
->left_overhang
)
2905 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2906 int first
= s
->first_glyph
- glyphs
;
2908 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2909 x
-= glyphs
[i
].pixel_width
;
2920 /* Return the index of the first glyph preceding glyph string S that
2921 is overwriting S because of its right overhang. Value is -1 if no
2922 glyph in front of S overwrites S. */
2925 x_left_overwriting (s
)
2926 struct glyph_string
*s
;
2929 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2930 int first
= s
->first_glyph
- glyphs
;
2934 for (i
= first
- 1; i
>= 0; --i
)
2937 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2940 x
-= glyphs
[i
].pixel_width
;
2947 /* Return the index of the last glyph following glyph string S that is
2948 not overwritten by S because of S's right overhang. Value is -1 if
2949 no such glyph is found. */
2952 x_right_overwritten (s
)
2953 struct glyph_string
*s
;
2957 if (s
->right_overhang
)
2960 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2961 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2962 int end
= s
->row
->used
[s
->area
];
2964 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
2965 x
+= glyphs
[i
].pixel_width
;
2974 /* Return the index of the last glyph following glyph string S that
2975 overwrites S because of its left overhang. Value is negative
2976 if no such glyph is found. */
2979 x_right_overwriting (s
)
2980 struct glyph_string
*s
;
2983 int end
= s
->row
->used
[s
->area
];
2984 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2985 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2989 for (i
= first
; i
< end
; ++i
)
2992 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2995 x
+= glyphs
[i
].pixel_width
;
3002 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3005 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3006 struct glyph_string
*s
;
3010 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3011 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3012 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3013 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3017 /* Draw the background of glyph_string S. If S->background_filled_p
3018 is non-zero don't draw it. FORCE_P non-zero means draw the
3019 background even if it wouldn't be drawn normally. This is used
3020 when a string preceding S draws into the background of S, or S
3021 contains the first component of a composition. */
3024 x_draw_glyph_string_background (s
, force_p
)
3025 struct glyph_string
*s
;
3028 /* Nothing to do if background has already been drawn or if it
3029 shouldn't be drawn in the first place. */
3030 if (!s
->background_filled_p
)
3034 /* Fill background with a stipple pattern. */
3035 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3036 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3037 s
->y
+ s
->face
->box_line_width
,
3038 s
->background_width
,
3039 s
->height
- 2 * s
->face
->box_line_width
);
3040 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3041 s
->background_filled_p
= 1;
3043 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
3044 || s
->font_not_found_p
3045 || s
->extends_to_end_of_line_p
3048 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
3049 s
->background_width
,
3050 s
->height
- 2 * s
->face
->box_line_width
);
3051 s
->background_filled_p
= 1;
3057 /* Draw the foreground of glyph string S. */
3060 x_draw_glyph_string_foreground (s
)
3061 struct glyph_string
*s
;
3065 /* If first glyph of S has a left box line, start drawing the text
3066 of S to the right of that box line. */
3067 if (s
->face
->box
!= FACE_NO_BOX
3068 && s
->first_glyph
->left_box_line_p
)
3069 x
= s
->x
+ s
->face
->box_line_width
;
3073 /* Draw characters of S as rectangles if S's font could not be
3075 if (s
->font_not_found_p
)
3077 for (i
= 0; i
< s
->nchars
; ++i
)
3079 struct glyph
*g
= s
->first_glyph
+ i
;
3080 XDrawRectangle (s
->display
, s
->window
,
3081 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3083 x
+= g
->pixel_width
;
3088 char *char1b
= (char *) s
->char2b
;
3089 int boff
= s
->font_info
->baseline_offset
;
3091 if (s
->font_info
->vertical_centering
)
3092 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3094 /* If we can use 8-bit functions, condense S->char2b. */
3096 for (i
= 0; i
< s
->nchars
; ++i
)
3097 char1b
[i
] = s
->char2b
[i
].byte2
;
3099 /* Draw text with XDrawString if background has already been
3100 filled. Otherwise, use XDrawImageString. (Note that
3101 XDrawImageString is usually faster than XDrawString.) Always
3102 use XDrawImageString when drawing the cursor so that there is
3103 no chance that characters under a box cursor are invisible. */
3104 if (s
->for_overlaps_p
3105 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3107 /* Draw characters with 16-bit or 8-bit functions. */
3109 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3110 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3112 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3113 s
->ybase
- boff
, char1b
, s
->nchars
);
3118 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3119 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3121 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3122 s
->ybase
- boff
, char1b
, s
->nchars
);
3127 /* Draw the foreground of composite glyph string S. */
3130 x_draw_composite_glyph_string_foreground (s
)
3131 struct glyph_string
*s
;
3135 /* If first glyph of S has a left box line, start drawing the text
3136 of S to the right of that box line. */
3137 if (s
->face
->box
!= FACE_NO_BOX
3138 && s
->first_glyph
->left_box_line_p
)
3139 x
= s
->x
+ s
->face
->box_line_width
;
3143 /* S is a glyph string for a composition. S->gidx is the index of
3144 the first character drawn for glyphs of this composition.
3145 S->gidx == 0 means we are drawing the very first character of
3146 this composition. */
3148 /* Draw a rectangle for the composition if the font for the very
3149 first character of the composition could not be loaded. */
3150 if (s
->font_not_found_p
)
3153 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3154 s
->width
- 1, s
->height
- 1);
3158 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3159 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3160 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3161 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3167 #ifdef USE_X_TOOLKIT
3169 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3172 /* Return the frame on which widget WIDGET is used.. Abort if frame
3173 cannot be determined. */
3175 static struct frame
*
3176 x_frame_of_widget (widget
)
3179 struct x_display_info
*dpyinfo
;
3183 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3185 /* Find the top-level shell of the widget. Note that this function
3186 can be called when the widget is not yet realized, so XtWindow
3187 (widget) == 0. That's the reason we can't simply use
3188 x_any_window_to_frame. */
3189 while (!XtIsTopLevelShell (widget
))
3190 widget
= XtParent (widget
);
3192 /* Look for a frame with that top-level widget. Allocate the color
3193 on that frame to get the right gamma correction value. */
3194 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3195 if (GC_FRAMEP (XCAR (tail
))
3196 && (f
= XFRAME (XCAR (tail
)),
3197 (f
->output_data
.nothing
!= 1
3198 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3199 && f
->output_data
.x
->widget
== widget
)
3206 /* Allocate the color COLOR->pixel on the screen and display of
3207 widget WIDGET in colormap CMAP. If an exact match cannot be
3208 allocated, try the nearest color available. Value is non-zero
3209 if successful. This is called from lwlib. */
3212 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3217 struct frame
*f
= x_frame_of_widget (widget
);
3218 return x_alloc_nearest_color (f
, cmap
, color
);
3222 #endif /* USE_X_TOOLKIT */
3225 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3226 CMAP. If an exact match can't be allocated, try the nearest color
3227 available. Value is non-zero if successful. Set *COLOR to the
3231 x_alloc_nearest_color (f
, cmap
, color
)
3236 Display
*display
= FRAME_X_DISPLAY (f
);
3237 Screen
*screen
= FRAME_X_SCREEN (f
);
3240 gamma_correct (f
, color
);
3241 rc
= XAllocColor (display
, cmap
, color
);
3244 /* If we got to this point, the colormap is full, so we're going
3245 to try to get the next closest color. The algorithm used is
3246 a least-squares matching, which is what X uses for closest
3247 color matching with StaticColor visuals. */
3249 unsigned long nearest_delta
= ~0;
3250 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3251 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3253 for (i
= 0; i
< ncells
; ++i
)
3255 XQueryColors (display
, cmap
, cells
, ncells
);
3257 for (nearest
= i
= 0; i
< ncells
; ++i
)
3259 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3260 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3261 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3262 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3264 if (delta
< nearest_delta
)
3267 nearest_delta
= delta
;
3271 color
->red
= cells
[nearest
].red
;
3272 color
->green
= cells
[nearest
].green
;
3273 color
->blue
= cells
[nearest
].blue
;
3274 rc
= XAllocColor (display
, cmap
, color
);
3277 #ifdef DEBUG_X_COLORS
3279 register_color (color
->pixel
);
3280 #endif /* DEBUG_X_COLORS */
3286 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3287 It's necessary to do this instead of just using PIXEL directly to
3288 get color reference counts right. */
3291 x_copy_color (f
, pixel
)
3293 unsigned long pixel
;
3297 color
.pixel
= pixel
;
3299 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3300 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3302 #ifdef DEBUG_X_COLORS
3303 register_color (pixel
);
3309 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3310 It's necessary to do this instead of just using PIXEL directly to
3311 get color reference counts right. */
3314 x_copy_dpy_color (dpy
, cmap
, pixel
)
3317 unsigned long pixel
;
3321 color
.pixel
= pixel
;
3323 XQueryColor (dpy
, cmap
, &color
);
3324 XAllocColor (dpy
, cmap
, &color
);
3326 #ifdef DEBUG_X_COLORS
3327 register_color (pixel
);
3333 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3334 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3335 If this produces the same color as PIXEL, try a color where all RGB
3336 values have DELTA added. Return the allocated color in *PIXEL.
3337 DISPLAY is the X display, CMAP is the colormap to operate on.
3338 Value is non-zero if successful. */
3341 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3345 unsigned long *pixel
;
3352 /* Get RGB color values. */
3353 color
.pixel
= *pixel
;
3354 XQueryColor (display
, cmap
, &color
);
3356 /* Change RGB values by specified FACTOR. Avoid overflow! */
3357 xassert (factor
>= 0);
3358 new.red
= min (0xffff, factor
* color
.red
);
3359 new.green
= min (0xffff, factor
* color
.green
);
3360 new.blue
= min (0xffff, factor
* color
.blue
);
3362 /* Try to allocate the color. */
3363 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3366 if (new.pixel
== *pixel
)
3368 /* If we end up with the same color as before, try adding
3369 delta to the RGB values. */
3370 x_free_colors (f
, &new.pixel
, 1);
3372 new.red
= min (0xffff, delta
+ color
.red
);
3373 new.green
= min (0xffff, delta
+ color
.green
);
3374 new.blue
= min (0xffff, delta
+ color
.blue
);
3375 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3386 /* Set up the foreground color for drawing relief lines of glyph
3387 string S. RELIEF is a pointer to a struct relief containing the GC
3388 with which lines will be drawn. Use a color that is FACTOR or
3389 DELTA lighter or darker than the relief's background which is found
3390 in S->f->output_data.x->relief_background. If such a color cannot
3391 be allocated, use DEFAULT_PIXEL, instead. */
3394 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3396 struct relief
*relief
;
3399 unsigned long default_pixel
;
3402 struct x_output
*di
= f
->output_data
.x
;
3403 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3404 unsigned long pixel
;
3405 unsigned long background
= di
->relief_background
;
3406 Colormap cmap
= FRAME_X_COLORMAP (f
);
3407 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3408 Display
*dpy
= FRAME_X_DISPLAY (f
);
3410 xgcv
.graphics_exposures
= False
;
3411 xgcv
.line_width
= 1;
3413 /* Free previously allocated color. The color cell will be reused
3414 when it has been freed as many times as it was allocated, so this
3415 doesn't affect faces using the same colors. */
3417 && relief
->allocated_p
)
3419 x_free_colors (f
, &relief
->pixel
, 1);
3420 relief
->allocated_p
= 0;
3423 /* Allocate new color. */
3424 xgcv
.foreground
= default_pixel
;
3426 if (dpyinfo
->n_planes
!= 1
3427 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3429 relief
->allocated_p
= 1;
3430 xgcv
.foreground
= relief
->pixel
= pixel
;
3433 if (relief
->gc
== 0)
3435 xgcv
.stipple
= dpyinfo
->gray
;
3437 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3440 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3444 /* Set up colors for the relief lines around glyph string S. */
3447 x_setup_relief_colors (s
)
3448 struct glyph_string
*s
;
3450 struct x_output
*di
= s
->f
->output_data
.x
;
3451 unsigned long color
;
3453 if (s
->face
->use_box_color_for_shadows_p
)
3454 color
= s
->face
->box_color
;
3459 /* Get the background color of the face. */
3460 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3461 color
= xgcv
.background
;
3464 if (di
->white_relief
.gc
== 0
3465 || color
!= di
->relief_background
)
3467 di
->relief_background
= color
;
3468 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3469 WHITE_PIX_DEFAULT (s
->f
));
3470 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3471 BLACK_PIX_DEFAULT (s
->f
));
3476 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3477 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3478 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3479 relief. LEFT_P non-zero means draw a relief on the left side of
3480 the rectangle. RIGHT_P non-zero means draw a relief on the right
3481 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3485 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3486 raised_p
, left_p
, right_p
, clip_rect
)
3488 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3489 XRectangle
*clip_rect
;
3495 gc
= f
->output_data
.x
->white_relief
.gc
;
3497 gc
= f
->output_data
.x
->black_relief
.gc
;
3498 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3501 for (i
= 0; i
< width
; ++i
)
3502 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3503 left_x
+ i
* left_p
, top_y
+ i
,
3504 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3508 for (i
= 0; i
< width
; ++i
)
3509 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3510 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3512 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3514 gc
= f
->output_data
.x
->black_relief
.gc
;
3516 gc
= f
->output_data
.x
->white_relief
.gc
;
3517 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3520 for (i
= 0; i
< width
; ++i
)
3521 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3522 left_x
+ i
* left_p
, bottom_y
- i
,
3523 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3527 for (i
= 0; i
< width
; ++i
)
3528 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3529 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3531 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3535 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3536 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3537 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3538 left side of the rectangle. RIGHT_P non-zero means draw a line
3539 on the right side of the rectangle. CLIP_RECT is the clipping
3540 rectangle to use when drawing. */
3543 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3544 left_p
, right_p
, clip_rect
)
3545 struct glyph_string
*s
;
3546 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3547 XRectangle
*clip_rect
;
3551 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3552 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3553 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3556 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3557 left_x
, top_y
, right_x
- left_x
, width
);
3561 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3562 left_x
, top_y
, width
, bottom_y
- top_y
);
3565 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3566 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3570 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3571 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3573 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3574 XSetClipMask (s
->display
, s
->gc
, None
);
3578 /* Draw a box around glyph string S. */
3581 x_draw_glyph_string_box (s
)
3582 struct glyph_string
*s
;
3584 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3585 int left_p
, right_p
;
3586 struct glyph
*last_glyph
;
3587 XRectangle clip_rect
;
3589 last_x
= window_box_right (s
->w
, s
->area
);
3590 if (s
->row
->full_width_p
3591 && !s
->w
->pseudo_window_p
)
3593 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3594 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3595 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3598 /* The glyph that may have a right box line. */
3599 last_glyph
= (s
->cmp
|| s
->img
3601 : s
->first_glyph
+ s
->nchars
- 1);
3603 width
= s
->face
->box_line_width
;
3604 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3606 right_x
= ((s
->row
->full_width_p
3608 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3610 bottom_y
= top_y
+ s
->height
- 1;
3612 left_p
= (s
->first_glyph
->left_box_line_p
3613 || (s
->hl
== DRAW_MOUSE_FACE
3615 || s
->prev
->hl
!= s
->hl
)));
3616 right_p
= (last_glyph
->right_box_line_p
3617 || (s
->hl
== DRAW_MOUSE_FACE
3619 || s
->next
->hl
!= s
->hl
)));
3621 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3623 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3624 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3625 left_p
, right_p
, &clip_rect
);
3628 x_setup_relief_colors (s
);
3629 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3630 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3635 /* Draw foreground of image glyph string S. */
3638 x_draw_image_foreground (s
)
3639 struct glyph_string
*s
;
3642 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3644 /* If first glyph of S has a left box line, start drawing it to the
3645 right of that line. */
3646 if (s
->face
->box
!= FACE_NO_BOX
3647 && s
->first_glyph
->left_box_line_p
)
3648 x
= s
->x
+ s
->face
->box_line_width
;
3652 /* If there is a margin around the image, adjust x- and y-position
3656 x
+= s
->img
->margin
;
3657 y
+= s
->img
->margin
;
3664 /* We can't set both a clip mask and use XSetClipRectangles
3665 because the latter also sets a clip mask. We also can't
3666 trust on the shape extension to be available
3667 (XShapeCombineRegion). So, compute the rectangle to draw
3669 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3672 XRectangle clip_rect
, image_rect
, r
;
3674 xgcv
.clip_mask
= s
->img
->mask
;
3675 xgcv
.clip_x_origin
= x
;
3676 xgcv
.clip_y_origin
= y
;
3677 xgcv
.function
= GXcopy
;
3678 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3680 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3683 image_rect
.width
= s
->img
->width
;
3684 image_rect
.height
= s
->img
->height
;
3685 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3686 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3687 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3691 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3692 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3694 /* When the image has a mask, we can expect that at
3695 least part of a mouse highlight or a block cursor will
3696 be visible. If the image doesn't have a mask, make
3697 a block cursor visible by drawing a rectangle around
3698 the image. I believe it's looking better if we do
3699 nothing here for mouse-face. */
3700 if (s
->hl
== DRAW_CURSOR
)
3701 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3702 s
->img
->width
- 1, s
->img
->height
- 1);
3706 /* Draw a rectangle if image could not be loaded. */
3707 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3708 s
->img
->width
- 1, s
->img
->height
- 1);
3712 /* Draw a relief around the image glyph string S. */
3715 x_draw_image_relief (s
)
3716 struct glyph_string
*s
;
3718 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3721 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3723 /* If first glyph of S has a left box line, start drawing it to the
3724 right of that line. */
3725 if (s
->face
->box
!= FACE_NO_BOX
3726 && s
->first_glyph
->left_box_line_p
)
3727 x
= s
->x
+ s
->face
->box_line_width
;
3731 /* If there is a margin around the image, adjust x- and y-position
3735 x
+= s
->img
->margin
;
3736 y
+= s
->img
->margin
;
3739 if (s
->hl
== DRAW_IMAGE_SUNKEN
3740 || s
->hl
== DRAW_IMAGE_RAISED
)
3742 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3743 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3747 thick
= abs (s
->img
->relief
);
3748 raised_p
= s
->img
->relief
> 0;
3753 x1
= x
+ s
->img
->width
+ thick
- 1;
3754 y1
= y
+ s
->img
->height
+ thick
- 1;
3756 x_setup_relief_colors (s
);
3757 x_get_glyph_string_clip_rect (s
, &r
);
3758 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3762 /* Draw the foreground of image glyph string S to PIXMAP. */
3765 x_draw_image_foreground_1 (s
, pixmap
)
3766 struct glyph_string
*s
;
3770 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3772 /* If first glyph of S has a left box line, start drawing it to the
3773 right of that line. */
3774 if (s
->face
->box
!= FACE_NO_BOX
3775 && s
->first_glyph
->left_box_line_p
)
3776 x
= s
->face
->box_line_width
;
3780 /* If there is a margin around the image, adjust x- and y-position
3784 x
+= s
->img
->margin
;
3785 y
+= s
->img
->margin
;
3792 /* We can't set both a clip mask and use XSetClipRectangles
3793 because the latter also sets a clip mask. We also can't
3794 trust on the shape extension to be available
3795 (XShapeCombineRegion). So, compute the rectangle to draw
3797 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3801 xgcv
.clip_mask
= s
->img
->mask
;
3802 xgcv
.clip_x_origin
= x
;
3803 xgcv
.clip_y_origin
= y
;
3804 xgcv
.function
= GXcopy
;
3805 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3807 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3808 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3809 XSetClipMask (s
->display
, s
->gc
, None
);
3813 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3814 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3816 /* When the image has a mask, we can expect that at
3817 least part of a mouse highlight or a block cursor will
3818 be visible. If the image doesn't have a mask, make
3819 a block cursor visible by drawing a rectangle around
3820 the image. I believe it's looking better if we do
3821 nothing here for mouse-face. */
3822 if (s
->hl
== DRAW_CURSOR
)
3823 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3824 s
->img
->width
- 1, s
->img
->height
- 1);
3828 /* Draw a rectangle if image could not be loaded. */
3829 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3830 s
->img
->width
- 1, s
->img
->height
- 1);
3834 /* Draw part of the background of glyph string S. X, Y, W, and H
3835 give the rectangle to draw. */
3838 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3839 struct glyph_string
*s
;
3844 /* Fill background with a stipple pattern. */
3845 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3846 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3847 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3850 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3854 /* Draw image glyph string S.
3857 s->x +-------------------------
3860 | +-------------------------
3863 | | +-------------------
3869 x_draw_image_glyph_string (s
)
3870 struct glyph_string
*s
;
3873 int box_line_width
= s
->face
->box_line_width
;
3874 int margin
= s
->img
->margin
;
3876 Pixmap pixmap
= None
;
3878 height
= s
->height
- 2 * box_line_width
;
3880 /* Fill background with face under the image. Do it only if row is
3881 taller than image or if image has a clip mask to reduce
3883 s
->stippled_p
= s
->face
->stipple
!= 0;
3884 if (height
> s
->img
->height
3887 || s
->img
->pixmap
== 0
3888 || s
->width
!= s
->background_width
)
3890 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3891 x
= s
->x
+ box_line_width
;
3895 y
= s
->y
+ box_line_width
;
3899 /* Create a pixmap as large as the glyph string Fill it with
3900 the background color. Copy the image to it, using its
3901 mask. Copy the temporary pixmap to the display. */
3902 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3903 int depth
= DefaultDepthOfScreen (screen
);
3905 /* Create a pixmap as large as the glyph string. */
3906 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3907 s
->background_width
,
3910 /* Don't clip in the following because we're working on the
3912 XSetClipMask (s
->display
, s
->gc
, None
);
3914 /* Fill the pixmap with the background color/stipple. */
3917 /* Fill background with a stipple pattern. */
3918 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3919 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3920 0, 0, s
->background_width
, s
->height
);
3921 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3926 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3928 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3929 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3930 0, 0, s
->background_width
, s
->height
);
3931 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3935 /* Implementation idea: Is it possible to construct a mask?
3936 We could look at the color at the margins of the image, and
3937 say that this color is probably the background color of the
3939 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3941 s
->background_filled_p
= 1;
3944 /* Draw the foreground. */
3947 x_draw_image_foreground_1 (s
, pixmap
);
3948 x_set_glyph_string_clipping (s
);
3949 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
3950 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3951 XFreePixmap (s
->display
, pixmap
);
3954 x_draw_image_foreground (s
);
3956 /* If we must draw a relief around the image, do it. */
3958 || s
->hl
== DRAW_IMAGE_RAISED
3959 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3960 x_draw_image_relief (s
);
3964 /* Draw stretch glyph string S. */
3967 x_draw_stretch_glyph_string (s
)
3968 struct glyph_string
*s
;
3970 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3971 s
->stippled_p
= s
->face
->stipple
!= 0;
3973 if (s
->hl
== DRAW_CURSOR
3974 && !x_stretch_cursor_p
)
3976 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3977 as wide as the stretch glyph. */
3978 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
3981 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3983 /* Clear rest using the GC of the original non-cursor face. */
3984 if (width
< s
->background_width
)
3986 GC gc
= s
->face
->gc
;
3987 int x
= s
->x
+ width
, y
= s
->y
;
3988 int w
= s
->background_width
- width
, h
= s
->height
;
3991 x_get_glyph_string_clip_rect (s
, &r
);
3992 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
3994 if (s
->face
->stipple
)
3996 /* Fill background with a stipple pattern. */
3997 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3998 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3999 XSetFillStyle (s
->display
, gc
, FillSolid
);
4004 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4005 XSetForeground (s
->display
, gc
, xgcv
.background
);
4006 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4007 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4012 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4015 s
->background_filled_p
= 1;
4019 /* Draw glyph string S. */
4022 x_draw_glyph_string (s
)
4023 struct glyph_string
*s
;
4025 /* If S draws into the background of its successor, draw the
4026 background of the successor first so that S can draw into it.
4027 This makes S->next use XDrawString instead of XDrawImageString. */
4028 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4030 xassert (s
->next
->img
== NULL
);
4031 x_set_glyph_string_gc (s
->next
);
4032 x_set_glyph_string_clipping (s
->next
);
4033 x_draw_glyph_string_background (s
->next
, 1);
4036 /* Set up S->gc, set clipping and draw S. */
4037 x_set_glyph_string_gc (s
);
4038 x_set_glyph_string_clipping (s
);
4040 switch (s
->first_glyph
->type
)
4043 x_draw_image_glyph_string (s
);
4047 x_draw_stretch_glyph_string (s
);
4051 if (s
->for_overlaps_p
)
4052 s
->background_filled_p
= 1;
4054 x_draw_glyph_string_background (s
, 0);
4055 x_draw_glyph_string_foreground (s
);
4058 case COMPOSITE_GLYPH
:
4059 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4060 s
->background_filled_p
= 1;
4062 x_draw_glyph_string_background (s
, 1);
4063 x_draw_composite_glyph_string_foreground (s
);
4070 if (!s
->for_overlaps_p
)
4072 /* Draw underline. */
4073 if (s
->face
->underline_p
)
4075 unsigned long dy
, h
;
4077 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4079 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
4082 if (s
->face
->underline_defaulted_p
)
4083 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4088 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4089 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4090 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4092 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4096 /* Draw overline. */
4097 if (s
->face
->overline_p
)
4099 unsigned long dy
= 0, h
= 1;
4101 if (s
->face
->overline_color_defaulted_p
)
4102 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4107 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4108 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4109 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4111 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4115 /* Draw strike-through. */
4116 if (s
->face
->strike_through_p
)
4118 unsigned long h
= 1;
4119 unsigned long dy
= (s
->height
- h
) / 2;
4121 if (s
->face
->strike_through_color_defaulted_p
)
4122 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4127 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4128 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4129 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4131 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4136 if (s
->face
->box
!= FACE_NO_BOX
)
4137 x_draw_glyph_string_box (s
);
4140 /* Reset clipping. */
4141 XSetClipMask (s
->display
, s
->gc
, None
);
4145 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4146 struct face
**, int));
4149 /* Fill glyph string S with composition components specified by S->cmp.
4151 FACES is an array of faces for all components of this composition.
4152 S->gidx is the index of the first component for S.
4153 OVERLAPS_P non-zero means S should draw the foreground only, and
4154 use its physical height for clipping.
4156 Value is the index of a component not in S. */
4159 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4160 struct glyph_string
*s
;
4161 struct face
**faces
;
4168 s
->for_overlaps_p
= overlaps_p
;
4170 s
->face
= faces
[s
->gidx
];
4171 s
->font
= s
->face
->font
;
4172 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4174 /* For all glyphs of this composition, starting at the offset
4175 S->gidx, until we reach the end of the definition or encounter a
4176 glyph that requires the different face, add it to S. */
4178 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4181 /* All glyph strings for the same composition has the same width,
4182 i.e. the width set for the first component of the composition. */
4184 s
->width
= s
->first_glyph
->pixel_width
;
4186 /* If the specified font could not be loaded, use the frame's
4187 default font, but record the fact that we couldn't load it in
4188 the glyph string so that we can draw rectangles for the
4189 characters of the glyph string. */
4190 if (s
->font
== NULL
)
4192 s
->font_not_found_p
= 1;
4193 s
->font
= FRAME_FONT (s
->f
);
4196 /* Adjust base line for subscript/superscript text. */
4197 s
->ybase
+= s
->first_glyph
->voffset
;
4199 xassert (s
->face
&& s
->face
->gc
);
4201 /* This glyph string must always be drawn with 16-bit functions. */
4204 return s
->gidx
+ s
->nchars
;
4208 /* Fill glyph string S from a sequence of character glyphs.
4210 FACE_ID is the face id of the string. START is the index of the
4211 first glyph to consider, END is the index of the last + 1.
4212 OVERLAPS_P non-zero means S should draw the foreground only, and
4213 use its physical height for clipping.
4215 Value is the index of the first glyph not in S. */
4218 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4219 struct glyph_string
*s
;
4221 int start
, end
, overlaps_p
;
4223 struct glyph
*glyph
, *last
;
4225 int glyph_not_available_p
;
4227 xassert (s
->f
== XFRAME (s
->w
->frame
));
4228 xassert (s
->nchars
== 0);
4229 xassert (start
>= 0 && end
> start
);
4231 s
->for_overlaps_p
= overlaps_p
,
4232 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4233 last
= s
->row
->glyphs
[s
->area
] + end
;
4234 voffset
= glyph
->voffset
;
4236 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4239 && glyph
->type
== CHAR_GLYPH
4240 && glyph
->voffset
== voffset
4241 /* Same face id implies same font, nowadays. */
4242 && glyph
->face_id
== face_id
4243 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4247 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4248 s
->char2b
+ s
->nchars
,
4250 s
->two_byte_p
= two_byte_p
;
4252 xassert (s
->nchars
<= end
- start
);
4253 s
->width
+= glyph
->pixel_width
;
4257 s
->font
= s
->face
->font
;
4258 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4260 /* If the specified font could not be loaded, use the frame's font,
4261 but record the fact that we couldn't load it in
4262 S->font_not_found_p so that we can draw rectangles for the
4263 characters of the glyph string. */
4264 if (s
->font
== NULL
|| glyph_not_available_p
)
4266 s
->font_not_found_p
= 1;
4267 s
->font
= FRAME_FONT (s
->f
);
4270 /* Adjust base line for subscript/superscript text. */
4271 s
->ybase
+= voffset
;
4273 xassert (s
->face
&& s
->face
->gc
);
4274 return glyph
- s
->row
->glyphs
[s
->area
];
4278 /* Fill glyph string S from image glyph S->first_glyph. */
4281 x_fill_image_glyph_string (s
)
4282 struct glyph_string
*s
;
4284 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4285 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4287 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4288 s
->font
= s
->face
->font
;
4289 s
->width
= s
->first_glyph
->pixel_width
;
4291 /* Adjust base line for subscript/superscript text. */
4292 s
->ybase
+= s
->first_glyph
->voffset
;
4296 /* Fill glyph string S from a sequence of stretch glyphs.
4298 ROW is the glyph row in which the glyphs are found, AREA is the
4299 area within the row. START is the index of the first glyph to
4300 consider, END is the index of the last + 1.
4302 Value is the index of the first glyph not in S. */
4305 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4306 struct glyph_string
*s
;
4307 struct glyph_row
*row
;
4308 enum glyph_row_area area
;
4311 struct glyph
*glyph
, *last
;
4312 int voffset
, face_id
;
4314 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4316 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4317 last
= s
->row
->glyphs
[s
->area
] + end
;
4318 face_id
= glyph
->face_id
;
4319 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4320 s
->font
= s
->face
->font
;
4321 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4322 s
->width
= glyph
->pixel_width
;
4323 voffset
= glyph
->voffset
;
4327 && glyph
->type
== STRETCH_GLYPH
4328 && glyph
->voffset
== voffset
4329 && glyph
->face_id
== face_id
);
4331 s
->width
+= glyph
->pixel_width
;
4333 /* Adjust base line for subscript/superscript text. */
4334 s
->ybase
+= voffset
;
4336 xassert (s
->face
&& s
->face
->gc
);
4337 return glyph
- s
->row
->glyphs
[s
->area
];
4341 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4342 of XChar2b structures for S; it can't be allocated in
4343 x_init_glyph_string because it must be allocated via `alloca'. W
4344 is the window on which S is drawn. ROW and AREA are the glyph row
4345 and area within the row from which S is constructed. START is the
4346 index of the first glyph structure covered by S. HL is a
4347 face-override for drawing S. */
4350 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4351 struct glyph_string
*s
;
4354 struct glyph_row
*row
;
4355 enum glyph_row_area area
;
4357 enum draw_glyphs_face hl
;
4359 bzero (s
, sizeof *s
);
4361 s
->f
= XFRAME (w
->frame
);
4362 s
->display
= FRAME_X_DISPLAY (s
->f
);
4363 s
->window
= FRAME_X_WINDOW (s
->f
);
4368 s
->first_glyph
= row
->glyphs
[area
] + start
;
4369 s
->height
= row
->height
;
4370 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4372 /* Display the internal border below the tool-bar window. */
4373 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4374 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4376 s
->ybase
= s
->y
+ row
->ascent
;
4380 /* Set background width of glyph string S. START is the index of the
4381 first glyph following S. LAST_X is the right-most x-position + 1
4382 in the drawing area. */
4385 x_set_glyph_string_background_width (s
, start
, last_x
)
4386 struct glyph_string
*s
;
4390 /* If the face of this glyph string has to be drawn to the end of
4391 the drawing area, set S->extends_to_end_of_line_p. */
4392 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4394 if (start
== s
->row
->used
[s
->area
]
4395 && s
->hl
== DRAW_NORMAL_TEXT
4396 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4397 || s
->face
->background
!= default_face
->background
4398 || s
->face
->stipple
!= default_face
->stipple
))
4399 s
->extends_to_end_of_line_p
= 1;
4401 /* If S extends its face to the end of the line, set its
4402 background_width to the distance to the right edge of the drawing
4404 if (s
->extends_to_end_of_line_p
)
4405 s
->background_width
= last_x
- s
->x
+ 1;
4407 s
->background_width
= s
->width
;
4411 /* Add a glyph string for a stretch glyph to the list of strings
4412 between HEAD and TAIL. START is the index of the stretch glyph in
4413 row area AREA of glyph row ROW. END is the index of the last glyph
4414 in that glyph row area. X is the current output position assigned
4415 to the new glyph string constructed. HL overrides that face of the
4416 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4417 is the right-most x-position of the drawing area. */
4419 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4420 and below -- keep them on one line. */
4421 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4424 s = (struct glyph_string *) alloca (sizeof *s); \
4425 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4426 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4427 x_append_glyph_string (&HEAD, &TAIL, s); \
4433 /* Add a glyph string for an image glyph to the list of strings
4434 between HEAD and TAIL. START is the index of the image glyph in
4435 row area AREA of glyph row ROW. END is the index of the last glyph
4436 in that glyph row area. X is the current output position assigned
4437 to the new glyph string constructed. HL overrides that face of the
4438 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4439 is the right-most x-position of the drawing area. */
4441 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4444 s = (struct glyph_string *) alloca (sizeof *s); \
4445 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4446 x_fill_image_glyph_string (s); \
4447 x_append_glyph_string (&HEAD, &TAIL, s); \
4454 /* Add a glyph string for a sequence of character glyphs to the list
4455 of strings between HEAD and TAIL. START is the index of the first
4456 glyph in row area AREA of glyph row ROW that is part of the new
4457 glyph string. END is the index of the last glyph in that glyph row
4458 area. X is the current output position assigned to the new glyph
4459 string constructed. HL overrides that face of the glyph; e.g. it
4460 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4461 right-most x-position of the drawing area. */
4463 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4469 c = (ROW)->glyphs[AREA][START].u.ch; \
4470 face_id = (ROW)->glyphs[AREA][START].face_id; \
4472 s = (struct glyph_string *) alloca (sizeof *s); \
4473 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4474 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4475 x_append_glyph_string (&HEAD, &TAIL, s); \
4477 START = x_fill_glyph_string (s, face_id, START, END, \
4483 /* Add a glyph string for a composite sequence to the list of strings
4484 between HEAD and TAIL. START is the index of the first glyph in
4485 row area AREA of glyph row ROW that is part of the new glyph
4486 string. END is the index of the last glyph in that glyph row area.
4487 X is the current output position assigned to the new glyph string
4488 constructed. HL overrides that face of the glyph; e.g. it is
4489 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4490 x-position of the drawing area. */
4492 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4494 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4495 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4496 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4497 struct composition *cmp = composition_table[cmp_id]; \
4498 int glyph_len = cmp->glyph_len; \
4500 struct face **faces; \
4501 struct glyph_string *first_s = NULL; \
4504 base_face = base_face->ascii_face; \
4505 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4506 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4507 /* At first, fill in `char2b' and `faces'. */ \
4508 for (n = 0; n < glyph_len; n++) \
4510 int c = COMPOSITION_GLYPH (cmp, n); \
4511 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4512 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4513 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4514 this_face_id, char2b + n, 1); \
4517 /* Make glyph_strings for each glyph sequence that is drawable by \
4518 the same face, and append them to HEAD/TAIL. */ \
4519 for (n = 0; n < cmp->glyph_len;) \
4521 s = (struct glyph_string *) alloca (sizeof *s); \
4522 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4523 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4531 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4539 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4540 of AREA of glyph row ROW on window W between indices START and END.
4541 HL overrides the face for drawing glyph strings, e.g. it is
4542 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4543 x-positions of the drawing area.
4545 This is an ugly monster macro construct because we must use alloca
4546 to allocate glyph strings (because x_draw_glyphs can be called
4549 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4552 HEAD = TAIL = NULL; \
4553 while (START < END) \
4555 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4556 switch (first_glyph->type) \
4559 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4560 TAIL, HL, X, LAST_X, \
4564 case COMPOSITE_GLYPH: \
4565 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4566 HEAD, TAIL, HL, X, LAST_X,\
4570 case STRETCH_GLYPH: \
4571 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4572 HEAD, TAIL, HL, X, LAST_X); \
4576 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4577 TAIL, HL, X, LAST_X); \
4584 x_set_glyph_string_background_width (s, START, LAST_X); \
4591 /* Draw glyphs between START and END in AREA of ROW on window W,
4592 starting at x-position X. X is relative to AREA in W. HL is a
4593 face-override with the following meaning:
4595 DRAW_NORMAL_TEXT draw normally
4596 DRAW_CURSOR draw in cursor face
4597 DRAW_MOUSE_FACE draw in mouse face.
4598 DRAW_INVERSE_VIDEO draw in mode line face
4599 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4600 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4602 If REAL_START is non-null, return in *REAL_START the real starting
4603 position for display. This can be different from START in case
4604 overlapping glyphs must be displayed. If REAL_END is non-null,
4605 return in *REAL_END the real end position for display. This can be
4606 different from END in case overlapping glyphs must be displayed.
4608 If OVERLAPS_P is non-zero, draw only the foreground of characters
4609 and clip to the physical height of ROW.
4611 Value is the x-position reached, relative to AREA of W. */
4614 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4618 struct glyph_row
*row
;
4619 enum glyph_row_area area
;
4621 enum draw_glyphs_face hl
;
4622 int *real_start
, *real_end
;
4625 struct glyph_string
*head
, *tail
;
4626 struct glyph_string
*s
;
4627 int last_x
, area_width
;
4631 /* Let's rather be paranoid than getting a SEGV. */
4632 start
= max (0, start
);
4633 end
= min (end
, row
->used
[area
]);
4635 *real_start
= start
;
4639 /* Translate X to frame coordinates. Set last_x to the right
4640 end of the drawing area. */
4641 if (row
->full_width_p
)
4643 /* X is relative to the left edge of W, without scroll bars
4645 struct frame
*f
= XFRAME (w
->frame
);
4646 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4647 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4650 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4651 last_x
= window_left_x
+ area_width
;
4653 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4655 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4656 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4662 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4663 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4667 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4668 area_width
= window_box_width (w
, area
);
4669 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4672 /* Build a doubly-linked list of glyph_string structures between
4673 head and tail from what we have to draw. Note that the macro
4674 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4675 the reason we use a separate variable `i'. */
4677 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4680 x_reached
= tail
->x
+ tail
->background_width
;
4684 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4685 the row, redraw some glyphs in front or following the glyph
4686 strings built above. */
4687 if (!overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4690 struct glyph_string
*h
, *t
;
4692 /* Compute overhangs for all glyph strings. */
4693 for (s
= head
; s
; s
= s
->next
)
4694 x_compute_glyph_string_overhangs (s
);
4696 /* Prepend glyph strings for glyphs in front of the first glyph
4697 string that are overwritten because of the first glyph
4698 string's left overhang. The background of all strings
4699 prepended must be drawn because the first glyph string
4701 i
= x_left_overwritten (head
);
4705 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4706 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4710 *real_start
= start
;
4711 x_compute_overhangs_and_x (t
, head
->x
, 1);
4712 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4715 /* Prepend glyph strings for glyphs in front of the first glyph
4716 string that overwrite that glyph string because of their
4717 right overhang. For these strings, only the foreground must
4718 be drawn, because it draws over the glyph string at `head'.
4719 The background must not be drawn because this would overwrite
4720 right overhangs of preceding glyphs for which no glyph
4722 i
= x_left_overwriting (head
);
4725 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4726 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4728 for (s
= h
; s
; s
= s
->next
)
4729 s
->background_filled_p
= 1;
4732 x_compute_overhangs_and_x (t
, head
->x
, 1);
4733 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4736 /* Append glyphs strings for glyphs following the last glyph
4737 string tail that are overwritten by tail. The background of
4738 these strings has to be drawn because tail's foreground draws
4740 i
= x_right_overwritten (tail
);
4743 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4744 DRAW_NORMAL_TEXT
, x
, last_x
,
4746 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4747 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4752 /* Append glyph strings for glyphs following the last glyph
4753 string tail that overwrite tail. The foreground of such
4754 glyphs has to be drawn because it writes into the background
4755 of tail. The background must not be drawn because it could
4756 paint over the foreground of following glyphs. */
4757 i
= x_right_overwriting (tail
);
4760 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4761 DRAW_NORMAL_TEXT
, x
, last_x
,
4763 for (s
= h
; s
; s
= s
->next
)
4764 s
->background_filled_p
= 1;
4765 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4766 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4772 /* Draw all strings. */
4773 for (s
= head
; s
; s
= s
->next
)
4774 x_draw_glyph_string (s
);
4776 /* Value is the x-position up to which drawn, relative to AREA of W.
4777 This doesn't include parts drawn because of overhangs. */
4778 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4779 if (!row
->full_width_p
)
4781 if (area
> LEFT_MARGIN_AREA
)
4782 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4783 if (area
> TEXT_AREA
)
4784 x_reached
-= window_box_width (w
, TEXT_AREA
);
4790 /* Fix the display of area AREA of overlapping row ROW in window W. */
4793 x_fix_overlapping_area (w
, row
, area
)
4795 struct glyph_row
*row
;
4796 enum glyph_row_area area
;
4802 if (area
== LEFT_MARGIN_AREA
)
4804 else if (area
== TEXT_AREA
)
4805 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4807 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4808 + window_box_width (w
, TEXT_AREA
));
4810 for (i
= 0; i
< row
->used
[area
];)
4812 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4814 int start
= i
, start_x
= x
;
4818 x
+= row
->glyphs
[area
][i
].pixel_width
;
4821 while (i
< row
->used
[area
]
4822 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4824 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4826 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4831 x
+= row
->glyphs
[area
][i
].pixel_width
;
4840 /* Output LEN glyphs starting at START at the nominal cursor position.
4841 Advance the nominal cursor over the text. The global variable
4842 updated_window contains the window being updated, updated_row is
4843 the glyph row being updated, and updated_area is the area of that
4844 row being updated. */
4847 x_write_glyphs (start
, len
)
4848 struct glyph
*start
;
4851 int x
, hpos
, real_start
, real_end
;
4853 xassert (updated_window
&& updated_row
);
4858 hpos
= start
- updated_row
->glyphs
[updated_area
];
4859 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4860 updated_row
, updated_area
,
4862 (updated_row
->inverse_p
4863 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4864 &real_start
, &real_end
, 0);
4866 /* If we drew over the cursor, note that it is not visible any more. */
4867 note_overwritten_text_cursor (updated_window
, real_start
,
4868 real_end
- real_start
);
4872 /* Advance the output cursor. */
4873 output_cursor
.hpos
+= len
;
4874 output_cursor
.x
= x
;
4878 /* Insert LEN glyphs from START at the nominal cursor position. */
4881 x_insert_glyphs (start
, len
)
4882 struct glyph
*start
;
4887 int line_height
, shift_by_width
, shifted_region_width
;
4888 struct glyph_row
*row
;
4889 struct glyph
*glyph
;
4890 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4892 xassert (updated_window
&& updated_row
);
4895 f
= XFRAME (WINDOW_FRAME (w
));
4897 /* Get the height of the line we are in. */
4899 line_height
= row
->height
;
4901 /* Get the width of the glyphs to insert. */
4903 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4904 shift_by_width
+= glyph
->pixel_width
;
4906 /* Get the width of the region to shift right. */
4907 shifted_region_width
= (window_box_width (w
, updated_area
)
4912 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4913 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4914 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4915 f
->output_data
.x
->normal_gc
,
4917 shifted_region_width
, line_height
,
4918 frame_x
+ shift_by_width
, frame_y
);
4920 /* Write the glyphs. */
4921 hpos
= start
- row
->glyphs
[updated_area
];
4922 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4923 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4924 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4926 /* Advance the output cursor. */
4927 output_cursor
.hpos
+= len
;
4928 output_cursor
.x
+= shift_by_width
;
4933 /* Delete N glyphs at the nominal cursor position. Not implemented
4944 /* Erase the current text line from the nominal cursor position
4945 (inclusive) to pixel column TO_X (exclusive). The idea is that
4946 everything from TO_X onward is already erased.
4948 TO_X is a pixel position relative to updated_area of
4949 updated_window. TO_X == -1 means clear to the end of this area. */
4952 x_clear_end_of_line (to_x
)
4956 struct window
*w
= updated_window
;
4957 int max_x
, min_y
, max_y
;
4958 int from_x
, from_y
, to_y
;
4960 xassert (updated_window
&& updated_row
);
4961 f
= XFRAME (w
->frame
);
4963 if (updated_row
->full_width_p
)
4965 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4966 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4967 && !w
->pseudo_window_p
)
4968 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4971 max_x
= window_box_width (w
, updated_area
);
4972 max_y
= window_text_bottom_y (w
);
4974 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
4975 of window. For TO_X > 0, truncate to end of drawing area. */
4981 to_x
= min (to_x
, max_x
);
4983 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
4985 /* Notice if the cursor will be cleared by this operation. */
4986 if (!updated_row
->full_width_p
)
4987 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
4989 from_x
= output_cursor
.x
;
4991 /* Translate to frame coordinates. */
4992 if (updated_row
->full_width_p
)
4994 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
4995 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
4999 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5000 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5003 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5004 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5005 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5007 /* Prevent inadvertently clearing to end of the X window. */
5008 if (to_x
> from_x
&& to_y
> from_y
)
5011 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5012 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5019 /* Clear entire frame. If updating_frame is non-null, clear that
5020 frame. Otherwise clear the selected frame. */
5030 f
= SELECTED_FRAME ();
5032 /* Clearing the frame will erase any cursor, so mark them all as no
5034 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5035 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5036 output_cursor
.x
= -1;
5038 /* We don't set the output cursor here because there will always
5039 follow an explicit cursor_to. */
5041 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5043 /* We have to clear the scroll bars, too. If we have changed
5044 colors or something like that, then they should be notified. */
5045 x_scroll_bar_clear (f
);
5047 XFlush (FRAME_X_DISPLAY (f
));
5053 /* Invert the middle quarter of the frame for .15 sec. */
5055 /* We use the select system call to do the waiting, so we have to make
5056 sure it's available. If it isn't, we just won't do visual bells. */
5058 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5061 /* Subtract the `struct timeval' values X and Y, storing the result in
5062 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5065 timeval_subtract (result
, x
, y
)
5066 struct timeval
*result
, x
, y
;
5068 /* Perform the carry for the later subtraction by updating y. This
5069 is safer because on some systems the tv_sec member is unsigned. */
5070 if (x
.tv_usec
< y
.tv_usec
)
5072 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5073 y
.tv_usec
-= 1000000 * nsec
;
5077 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5079 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5080 y
.tv_usec
+= 1000000 * nsec
;
5084 /* Compute the time remaining to wait. tv_usec is certainly
5086 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5087 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5089 /* Return indication of whether the result should be considered
5091 return x
.tv_sec
< y
.tv_sec
;
5103 /* Create a GC that will use the GXxor function to flip foreground
5104 pixels into background pixels. */
5108 values
.function
= GXxor
;
5109 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5110 ^ f
->output_data
.x
->background_pixel
);
5112 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5113 GCFunction
| GCForeground
, &values
);
5117 /* Get the height not including a menu bar widget. */
5118 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5119 /* Height of each line to flash. */
5120 int flash_height
= FRAME_LINE_HEIGHT (f
);
5121 /* These will be the left and right margins of the rectangles. */
5122 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5123 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5127 /* Don't flash the area between a scroll bar and the frame
5128 edge it is next to. */
5129 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5131 case vertical_scroll_bar_left
:
5132 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5135 case vertical_scroll_bar_right
:
5136 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5143 width
= flash_right
- flash_left
;
5145 /* If window is tall, flash top and bottom line. */
5146 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5148 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5150 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5151 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5152 width
, flash_height
);
5153 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5155 (height
- flash_height
5156 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5157 width
, flash_height
);
5160 /* If it is short, flash it all. */
5161 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5162 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5163 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5168 struct timeval wakeup
;
5170 EMACS_GET_TIME (wakeup
);
5172 /* Compute time to wait until, propagating carry from usecs. */
5173 wakeup
.tv_usec
+= 150000;
5174 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5175 wakeup
.tv_usec
%= 1000000;
5177 /* Keep waiting until past the time wakeup. */
5180 struct timeval timeout
;
5182 EMACS_GET_TIME (timeout
);
5184 /* In effect, timeout = wakeup - timeout.
5185 Break if result would be negative. */
5186 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5189 /* Try to wait that long--but we might wake up sooner. */
5190 select (0, NULL
, NULL
, NULL
, &timeout
);
5194 /* If window is tall, flash top and bottom line. */
5195 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5197 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5199 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5200 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5201 width
, flash_height
);
5202 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5204 (height
- flash_height
5205 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5206 width
, flash_height
);
5209 /* If it is short, flash it all. */
5210 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5211 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5212 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5214 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5222 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5225 /* Make audible bell. */
5230 struct frame
*f
= SELECTED_FRAME ();
5232 if (FRAME_X_DISPLAY (f
))
5234 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5241 XBell (FRAME_X_DISPLAY (f
), 0);
5242 XFlush (FRAME_X_DISPLAY (f
));
5249 /* Specify how many text lines, from the top of the window,
5250 should be affected by insert-lines and delete-lines operations.
5251 This, and those operations, are used only within an update
5252 that is bounded by calls to x_update_begin and x_update_end. */
5255 XTset_terminal_window (n
)
5258 /* This function intentionally left blank. */
5263 /***********************************************************************
5265 ***********************************************************************/
5267 /* Perform an insert-lines or delete-lines operation, inserting N
5268 lines or deleting -N lines at vertical position VPOS. */
5271 x_ins_del_lines (vpos
, n
)
5278 /* Scroll part of the display as described by RUN. */
5281 x_scroll_run (w
, run
)
5285 struct frame
*f
= XFRAME (w
->frame
);
5286 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5288 /* Get frame-relative bounding box of the text display area of W,
5289 without mode lines. Include in this box the flags areas to the
5290 left and right of W. */
5291 window_box (w
, -1, &x
, &y
, &width
, &height
);
5292 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5293 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5295 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5296 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5297 bottom_y
= y
+ height
;
5301 /* Scrolling up. Make sure we don't copy part of the mode
5302 line at the bottom. */
5303 if (from_y
+ run
->height
> bottom_y
)
5304 height
= bottom_y
- from_y
;
5306 height
= run
->height
;
5310 /* Scolling down. Make sure we don't copy over the mode line.
5312 if (to_y
+ run
->height
> bottom_y
)
5313 height
= bottom_y
- to_y
;
5315 height
= run
->height
;
5320 /* Cursor off. Will be switched on again in x_update_window_end. */
5324 XCopyArea (FRAME_X_DISPLAY (f
),
5325 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5326 f
->output_data
.x
->normal_gc
,
5336 /***********************************************************************
5338 ***********************************************************************/
5340 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5341 corner of the exposed rectangle. W and H are width and height of
5342 the exposed area. All are pixel values. W or H zero means redraw
5343 the entire frame. */
5346 expose_frame (f
, x
, y
, w
, h
)
5352 TRACE ((stderr
, "expose_frame "));
5354 /* No need to redraw if frame will be redrawn soon. */
5355 if (FRAME_GARBAGED_P (f
))
5357 TRACE ((stderr
, " garbaged\n"));
5361 /* If basic faces haven't been realized yet, there is no point in
5362 trying to redraw anything. This can happen when we get an expose
5363 event while Emacs is starting, e.g. by moving another window. */
5364 if (FRAME_FACE_CACHE (f
) == NULL
5365 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5367 TRACE ((stderr
, " no faces\n"));
5371 if (w
== 0 || h
== 0)
5374 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5375 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5385 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5386 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5388 if (WINDOWP (f
->tool_bar_window
))
5390 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5391 XRectangle window_rect
;
5392 XRectangle intersection_rect
;
5393 int window_x
, window_y
, window_width
, window_height
;
5396 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5397 window_rect
.x
= window_x
;
5398 window_rect
.y
= window_y
;
5399 window_rect
.width
= window_width
;
5400 window_rect
.height
= window_height
;
5402 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5403 expose_window (w
, &intersection_rect
);
5406 #ifndef USE_X_TOOLKIT
5407 if (WINDOWP (f
->menu_bar_window
))
5409 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5410 XRectangle window_rect
;
5411 XRectangle intersection_rect
;
5412 int window_x
, window_y
, window_width
, window_height
;
5415 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5416 window_rect
.x
= window_x
;
5417 window_rect
.y
= window_y
;
5418 window_rect
.width
= window_width
;
5419 window_rect
.height
= window_height
;
5421 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5422 expose_window (w
, &intersection_rect
);
5424 #endif /* not USE_X_TOOLKIT */
5428 /* Redraw (parts) of all windows in the window tree rooted at W that
5429 intersect R. R contains frame pixel coordinates. */
5432 expose_window_tree (w
, r
)
5438 if (!NILP (w
->hchild
))
5439 expose_window_tree (XWINDOW (w
->hchild
), r
);
5440 else if (!NILP (w
->vchild
))
5441 expose_window_tree (XWINDOW (w
->vchild
), r
);
5444 XRectangle window_rect
;
5445 XRectangle intersection_rect
;
5446 struct frame
*f
= XFRAME (w
->frame
);
5447 int window_x
, window_y
, window_width
, window_height
;
5449 /* Frame-relative pixel rectangle of W. */
5450 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5454 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5455 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5456 window_rect
.y
= window_y
;
5459 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5460 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5462 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5464 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5465 expose_window (w
, &intersection_rect
);
5468 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5473 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5474 which intersects rectangle R. R is in window-relative coordinates. */
5477 expose_area (w
, row
, r
, area
)
5479 struct glyph_row
*row
;
5481 enum glyph_row_area area
;
5484 struct glyph
*first
= row
->glyphs
[area
];
5485 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5489 /* Set x to the window-relative start position for drawing glyphs of
5490 AREA. The first glyph of the text area can be partially visible.
5491 The first glyphs of other areas cannot. */
5492 if (area
== LEFT_MARGIN_AREA
)
5494 else if (area
== TEXT_AREA
)
5495 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5497 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5498 + window_box_width (w
, TEXT_AREA
));
5500 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5501 /* If row extends face to end of line write the whole line. */
5502 x_draw_glyphs (w
, x
, row
, area
,
5504 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5508 /* Find the first glyph that must be redrawn. */
5510 && x
+ first
->pixel_width
< r
->x
)
5512 x
+= first
->pixel_width
;
5516 /* Find the last one. */
5520 && x
< r
->x
+ r
->width
)
5522 x
+= last
->pixel_width
;
5528 x_draw_glyphs (w
, first_x
, row
, area
,
5529 first
- row
->glyphs
[area
],
5530 last
- row
->glyphs
[area
],
5531 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5537 /* Redraw the parts of the glyph row ROW on window W intersecting
5538 rectangle R. R is in window-relative coordinates. */
5541 expose_line (w
, row
, r
)
5543 struct glyph_row
*row
;
5546 xassert (row
->enabled_p
);
5548 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5549 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5550 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5554 if (row
->used
[LEFT_MARGIN_AREA
])
5555 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5556 if (row
->used
[TEXT_AREA
])
5557 expose_area (w
, row
, r
, TEXT_AREA
);
5558 if (row
->used
[RIGHT_MARGIN_AREA
])
5559 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5560 x_draw_row_bitmaps (w
, row
);
5565 /* Return non-zero if W's cursor intersects rectangle R. */
5568 x_phys_cursor_in_rect_p (w
, r
)
5572 XRectangle cr
, result
;
5573 struct glyph
*cursor_glyph
;
5575 cursor_glyph
= get_phys_cursor_glyph (w
);
5578 cr
.x
= w
->phys_cursor
.x
;
5579 cr
.y
= w
->phys_cursor
.y
;
5580 cr
.width
= cursor_glyph
->pixel_width
;
5581 cr
.height
= w
->phys_cursor_height
;
5582 return x_intersect_rectangles (&cr
, r
, &result
);
5589 /* Redraw a rectangle of window W. R is a rectangle in window
5590 relative coordinates. Call this function with input blocked. */
5593 expose_window (w
, r
)
5597 struct glyph_row
*row
;
5599 int yb
= window_text_bottom_y (w
);
5600 int cursor_cleared_p
;
5602 /* If window is not yet fully initialized, do nothing. This can
5603 happen when toolkit scroll bars are used and a window is split.
5604 Reconfiguring the scroll bar will generate an expose for a newly
5606 if (w
->current_matrix
== NULL
)
5609 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5610 r
->x
, r
->y
, r
->width
, r
->height
));
5612 /* Convert to window coordinates. */
5613 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5614 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5616 /* Turn off the cursor. */
5617 if (!w
->pseudo_window_p
5618 && x_phys_cursor_in_rect_p (w
, r
))
5621 cursor_cleared_p
= 1;
5624 cursor_cleared_p
= 0;
5626 /* Find the first row intersecting the rectangle R. */
5627 row
= w
->current_matrix
->rows
;
5629 while (row
->enabled_p
5631 && y
+ row
->height
< r
->y
)
5637 /* Display the text in the rectangle, one text line at a time. */
5638 while (row
->enabled_p
5640 && y
< r
->y
+ r
->height
)
5642 expose_line (w
, row
, r
);
5647 /* Display the mode line if there is one. */
5648 if (WINDOW_WANTS_MODELINE_P (w
)
5649 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5651 && row
->y
< r
->y
+ r
->height
)
5652 expose_line (w
, row
, r
);
5654 if (!w
->pseudo_window_p
)
5656 /* Draw border between windows. */
5657 x_draw_vertical_border (w
);
5659 /* Turn the cursor on again. */
5660 if (cursor_cleared_p
)
5661 x_update_window_cursor (w
, 1);
5666 /* Determine the intersection of two rectangles R1 and R2. Return
5667 the intersection in *RESULT. Value is non-zero if RESULT is not
5671 x_intersect_rectangles (r1
, r2
, result
)
5672 XRectangle
*r1
, *r2
, *result
;
5674 XRectangle
*left
, *right
;
5675 XRectangle
*upper
, *lower
;
5676 int intersection_p
= 0;
5678 /* Rearrange so that R1 is the left-most rectangle. */
5680 left
= r1
, right
= r2
;
5682 left
= r2
, right
= r1
;
5684 /* X0 of the intersection is right.x0, if this is inside R1,
5685 otherwise there is no intersection. */
5686 if (right
->x
<= left
->x
+ left
->width
)
5688 result
->x
= right
->x
;
5690 /* The right end of the intersection is the minimum of the
5691 the right ends of left and right. */
5692 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5695 /* Same game for Y. */
5697 upper
= r1
, lower
= r2
;
5699 upper
= r2
, lower
= r1
;
5701 /* The upper end of the intersection is lower.y0, if this is inside
5702 of upper. Otherwise, there is no intersection. */
5703 if (lower
->y
<= upper
->y
+ upper
->height
)
5705 result
->y
= lower
->y
;
5707 /* The lower end of the intersection is the minimum of the lower
5708 ends of upper and lower. */
5709 result
->height
= (min (lower
->y
+ lower
->height
,
5710 upper
->y
+ upper
->height
)
5716 return intersection_p
;
5727 /* We used to only do this if Vx_no_window_manager was non-nil, but
5728 the ICCCM (section 4.1.6) says that the window's border pixmap
5729 and border pixel are window attributes which are "private to the
5730 client", so we can always change it to whatever we want. */
5732 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5733 f
->output_data
.x
->border_pixel
);
5735 x_update_cursor (f
, 1);
5739 frame_unhighlight (f
)
5742 /* We used to only do this if Vx_no_window_manager was non-nil, but
5743 the ICCCM (section 4.1.6) says that the window's border pixmap
5744 and border pixel are window attributes which are "private to the
5745 client", so we can always change it to whatever we want. */
5747 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5748 f
->output_data
.x
->border_tile
);
5750 x_update_cursor (f
, 1);
5753 /* The focus has changed. Update the frames as necessary to reflect
5754 the new situation. Note that we can't change the selected frame
5755 here, because the Lisp code we are interrupting might become confused.
5756 Each event gets marked with the frame in which it occurred, so the
5757 Lisp code can tell when the switch took place by examining the events. */
5760 x_new_focus_frame (dpyinfo
, frame
)
5761 struct x_display_info
*dpyinfo
;
5762 struct frame
*frame
;
5764 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5766 if (frame
!= dpyinfo
->x_focus_frame
)
5768 /* Set this before calling other routines, so that they see
5769 the correct value of x_focus_frame. */
5770 dpyinfo
->x_focus_frame
= frame
;
5772 if (old_focus
&& old_focus
->auto_lower
)
5773 x_lower_frame (old_focus
);
5776 selected_frame
= frame
;
5777 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5779 Fselect_window (selected_frame
->selected_window
);
5780 choose_minibuf_frame ();
5783 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5784 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5786 pending_autoraise_frame
= 0;
5789 x_frame_rehighlight (dpyinfo
);
5792 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5795 x_mouse_leave (dpyinfo
)
5796 struct x_display_info
*dpyinfo
;
5798 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5801 /* The focus has changed, or we have redirected a frame's focus to
5802 another frame (this happens when a frame uses a surrogate
5803 mini-buffer frame). Shift the highlight as appropriate.
5805 The FRAME argument doesn't necessarily have anything to do with which
5806 frame is being highlighted or un-highlighted; we only use it to find
5807 the appropriate X display info. */
5810 XTframe_rehighlight (frame
)
5811 struct frame
*frame
;
5813 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5817 x_frame_rehighlight (dpyinfo
)
5818 struct x_display_info
*dpyinfo
;
5820 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5822 if (dpyinfo
->x_focus_frame
)
5824 dpyinfo
->x_highlight_frame
5825 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5826 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5827 : dpyinfo
->x_focus_frame
);
5828 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5830 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5831 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5835 dpyinfo
->x_highlight_frame
= 0;
5837 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5840 frame_unhighlight (old_highlight
);
5841 if (dpyinfo
->x_highlight_frame
)
5842 frame_highlight (dpyinfo
->x_highlight_frame
);
5848 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5850 /* Initialize mode_switch_bit and modifier_meaning. */
5852 x_find_modifier_meanings (dpyinfo
)
5853 struct x_display_info
*dpyinfo
;
5855 int min_code
, max_code
;
5858 XModifierKeymap
*mods
;
5860 dpyinfo
->meta_mod_mask
= 0;
5861 dpyinfo
->shift_lock_mask
= 0;
5862 dpyinfo
->alt_mod_mask
= 0;
5863 dpyinfo
->super_mod_mask
= 0;
5864 dpyinfo
->hyper_mod_mask
= 0;
5867 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5869 min_code
= dpyinfo
->display
->min_keycode
;
5870 max_code
= dpyinfo
->display
->max_keycode
;
5873 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5874 min_code
, max_code
- min_code
+ 1,
5876 mods
= XGetModifierMapping (dpyinfo
->display
);
5878 /* Scan the modifier table to see which modifier bits the Meta and
5879 Alt keysyms are on. */
5881 int row
, col
; /* The row and column in the modifier table. */
5883 for (row
= 3; row
< 8; row
++)
5884 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5887 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5889 /* Zeroes are used for filler. Skip them. */
5893 /* Are any of this keycode's keysyms a meta key? */
5897 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5899 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5905 dpyinfo
->meta_mod_mask
|= (1 << row
);
5910 dpyinfo
->alt_mod_mask
|= (1 << row
);
5915 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5920 dpyinfo
->super_mod_mask
|= (1 << row
);
5924 /* Ignore this if it's not on the lock modifier. */
5925 if ((1 << row
) == LockMask
)
5926 dpyinfo
->shift_lock_mask
= LockMask
;
5934 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5935 if (! dpyinfo
->meta_mod_mask
)
5937 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
5938 dpyinfo
->alt_mod_mask
= 0;
5941 /* If some keys are both alt and meta,
5942 make them just meta, not alt. */
5943 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
5945 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
5948 XFree ((char *) syms
);
5949 XFreeModifiermap (mods
);
5952 /* Convert between the modifier bits X uses and the modifier bits
5956 x_x_to_emacs_modifiers (dpyinfo
, state
)
5957 struct x_display_info
*dpyinfo
;
5960 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
5961 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
5962 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
5963 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
5964 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
5965 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
5969 x_emacs_to_x_modifiers (dpyinfo
, state
)
5970 struct x_display_info
*dpyinfo
;
5973 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
5974 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
5975 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
5976 | ((state
& shift_modifier
) ? ShiftMask
: 0)
5977 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
5978 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
5981 /* Convert a keysym to its name. */
5984 x_get_keysym_name (keysym
)
5990 value
= XKeysymToString (keysym
);
5998 /* Mouse clicks and mouse movement. Rah. */
6000 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6001 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6002 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6003 not force the value into range. */
6006 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6008 register int pix_x
, pix_y
;
6009 register int *x
, *y
;
6013 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6014 even for negative values. */
6016 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6018 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6020 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6021 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6025 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6026 bounds
->height
= f
->output_data
.x
->line_height
;
6027 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6028 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6035 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6036 pix_x
= FRAME_WINDOW_WIDTH (f
);
6040 else if (pix_y
> f
->height
)
6049 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6050 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6051 can't tell the positions because W's display is not up to date,
6055 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6058 int *frame_x
, *frame_y
;
6062 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6063 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6065 if (display_completed
)
6067 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6068 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6069 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6075 *frame_x
+= glyph
->pixel_width
;
6083 *frame_y
= *frame_x
= 0;
6087 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6088 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6093 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6095 If the event is a button press, then note that we have grabbed
6099 construct_mouse_click (result
, event
, f
)
6100 struct input_event
*result
;
6101 XButtonEvent
*event
;
6104 /* Make the event type no_event; we'll change that when we decide
6106 result
->kind
= mouse_click
;
6107 result
->code
= event
->button
- Button1
;
6108 result
->timestamp
= event
->time
;
6109 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6111 | (event
->type
== ButtonRelease
6115 XSETINT (result
->x
, event
->x
);
6116 XSETINT (result
->y
, event
->y
);
6117 XSETFRAME (result
->frame_or_window
, f
);
6121 #if 0 /* This function isn't called. --gerd */
6123 /* Prepare a menu-event in *RESULT for placement in the input queue. */
6126 construct_menu_click (result
, event
, f
)
6127 struct input_event
*result
;
6128 XButtonEvent
*event
;
6131 /* Make the event type no_event; we'll change that when we decide
6133 result
->kind
= mouse_click
;
6134 result
->code
= event
->button
- Button1
;
6135 result
->timestamp
= event
->time
;
6136 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6138 | (event
->type
== ButtonRelease
6142 XSETINT (result
->x
, event
->x
);
6143 XSETINT (result
->y
, -1);
6144 XSETFRAME (result
->frame_or_window
, f
);
6150 /* Function to report a mouse movement to the mainstream Emacs code.
6151 The input handler calls this.
6153 We have received a mouse movement event, which is given in *event.
6154 If the mouse is over a different glyph than it was last time, tell
6155 the mainstream emacs code by setting mouse_moved. If not, ask for
6156 another motion event, so we can check again the next time it moves. */
6158 static XMotionEvent last_mouse_motion_event
;
6159 static Lisp_Object last_mouse_motion_frame
;
6162 note_mouse_movement (frame
, event
)
6164 XMotionEvent
*event
;
6166 last_mouse_movement_time
= event
->time
;
6167 last_mouse_motion_event
= *event
;
6168 XSETFRAME (last_mouse_motion_frame
, frame
);
6170 if (event
->window
!= FRAME_X_WINDOW (frame
))
6172 frame
->mouse_moved
= 1;
6173 last_mouse_scroll_bar
= Qnil
;
6174 note_mouse_highlight (frame
, -1, -1);
6177 /* Has the mouse moved off the glyph it was on at the last sighting? */
6178 else if (event
->x
< last_mouse_glyph
.x
6179 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6180 || event
->y
< last_mouse_glyph
.y
6181 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6183 frame
->mouse_moved
= 1;
6184 last_mouse_scroll_bar
= Qnil
;
6185 note_mouse_highlight (frame
, event
->x
, event
->y
);
6189 /* This is used for debugging, to turn off note_mouse_highlight. */
6191 int disable_mouse_highlight
;
6195 /************************************************************************
6197 ************************************************************************/
6199 /* Find the glyph under window-relative coordinates X/Y in window W.
6200 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6201 strings. Return in *HPOS and *VPOS the row and column number of
6202 the glyph found. Return in *AREA the glyph area containing X.
6203 Value is a pointer to the glyph found or null if X/Y is not on
6204 text, or we can't tell because W's current matrix is not up to
6207 static struct glyph
*
6208 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6211 int *hpos
, *vpos
, *area
;
6213 struct glyph
*glyph
, *end
;
6214 struct glyph_row
*row
= NULL
;
6215 int x0
, i
, left_area_width
;
6217 /* Find row containing Y. Give up if some row is not enabled. */
6218 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6220 row
= MATRIX_ROW (w
->current_matrix
, i
);
6221 if (!row
->enabled_p
)
6223 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6230 /* Give up if Y is not in the window. */
6231 if (i
== w
->current_matrix
->nrows
)
6234 /* Get the glyph area containing X. */
6235 if (w
->pseudo_window_p
)
6242 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6243 if (x
< left_area_width
)
6245 *area
= LEFT_MARGIN_AREA
;
6248 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6251 x0
= row
->x
+ left_area_width
;
6255 *area
= RIGHT_MARGIN_AREA
;
6256 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6260 /* Find glyph containing X. */
6261 glyph
= row
->glyphs
[*area
];
6262 end
= glyph
+ row
->used
[*area
];
6265 if (x
< x0
+ glyph
->pixel_width
)
6267 if (w
->pseudo_window_p
)
6269 else if (BUFFERP (glyph
->object
))
6273 x0
+= glyph
->pixel_width
;
6280 *hpos
= glyph
- row
->glyphs
[*area
];
6285 /* Convert frame-relative x/y to coordinates relative to window W.
6286 Takes pseudo-windows into account. */
6289 frame_to_window_pixel_xy (w
, x
, y
)
6293 if (w
->pseudo_window_p
)
6295 /* A pseudo-window is always full-width, and starts at the
6296 left edge of the frame, plus a frame border. */
6297 struct frame
*f
= XFRAME (w
->frame
);
6298 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6299 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6303 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6304 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6309 /* Take proper action when mouse has moved to the mode or top line of
6310 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6311 mode line. X is relative to the start of the text display area of
6312 W, so the width of bitmap areas and scroll bars must be subtracted
6313 to get a position relative to the start of the mode line. */
6316 note_mode_line_highlight (w
, x
, mode_line_p
)
6320 struct frame
*f
= XFRAME (w
->frame
);
6321 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6322 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6323 struct glyph_row
*row
;
6326 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6328 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6332 struct glyph
*glyph
, *end
;
6333 Lisp_Object help
, map
;
6336 /* Find the glyph under X. */
6337 glyph
= row
->glyphs
[TEXT_AREA
];
6338 end
= glyph
+ row
->used
[TEXT_AREA
];
6339 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6340 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6342 && x
>= x0
+ glyph
->pixel_width
)
6344 x0
+= glyph
->pixel_width
;
6349 && STRINGP (glyph
->object
)
6350 && XSTRING (glyph
->object
)->intervals
6351 && glyph
->charpos
>= 0
6352 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6354 /* If we're on a string with `help-echo' text property,
6355 arrange for the help to be displayed. This is done by
6356 setting the global variable help_echo to the help string. */
6357 help
= Fget_text_property (make_number (glyph
->charpos
),
6358 Qhelp_echo
, glyph
->object
);
6362 /* Change the mouse pointer according to what is under X/Y. */
6363 map
= Fget_text_property (make_number (glyph
->charpos
),
6364 Qlocal_map
, glyph
->object
);
6365 if (!NILP (Fkeymapp (map
)))
6366 cursor
= f
->output_data
.x
->nontext_cursor
;
6370 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6374 /* Take proper action when the mouse has moved to position X, Y on
6375 frame F as regards highlighting characters that have mouse-face
6376 properties. Also de-highlighting chars where the mouse was before.
6377 X and Y can be negative or out of range. */
6380 note_mouse_highlight (f
, x
, y
)
6384 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6389 /* When a menu is active, don't highlight because this looks odd. */
6390 #ifdef USE_X_TOOLKIT
6391 if (popup_activated ())
6395 if (disable_mouse_highlight
6396 || !f
->glyphs_initialized_p
)
6399 dpyinfo
->mouse_face_mouse_x
= x
;
6400 dpyinfo
->mouse_face_mouse_y
= y
;
6401 dpyinfo
->mouse_face_mouse_frame
= f
;
6403 if (dpyinfo
->mouse_face_defer
)
6408 dpyinfo
->mouse_face_deferred_gc
= 1;
6412 /* Which window is that in? */
6413 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6415 /* If we were displaying active text in another window, clear that. */
6416 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6417 clear_mouse_face (dpyinfo
);
6419 /* Not on a window -> return. */
6420 if (!WINDOWP (window
))
6423 /* Convert to window-relative pixel coordinates. */
6424 w
= XWINDOW (window
);
6425 frame_to_window_pixel_xy (w
, &x
, &y
);
6427 /* Handle tool-bar window differently since it doesn't display a
6429 if (EQ (window
, f
->tool_bar_window
))
6431 note_tool_bar_highlight (f
, x
, y
);
6435 if (portion
== 1 || portion
== 3)
6437 /* Mouse is on the mode or top line. */
6438 note_mode_line_highlight (w
, x
, portion
== 1);
6442 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6443 f
->output_data
.x
->text_cursor
);
6445 /* Are we in a window whose display is up to date?
6446 And verify the buffer's text has not changed. */
6447 if (/* Within text portion of the window. */
6449 && EQ (w
->window_end_valid
, w
->buffer
)
6450 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6451 && (XFASTINT (w
->last_overlay_modified
)
6452 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6454 int hpos
, vpos
, pos
, i
, area
;
6455 struct glyph
*glyph
;
6457 /* Find the glyph under X/Y. */
6458 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6460 /* Clear mouse face if X/Y not over text. */
6462 || area
!= TEXT_AREA
6463 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6465 clear_mouse_face (dpyinfo
);
6469 pos
= glyph
->charpos
;
6470 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6472 /* Check for mouse-face and help-echo. */
6474 Lisp_Object mouse_face
, overlay
, position
;
6475 Lisp_Object
*overlay_vec
;
6477 struct buffer
*obuf
;
6480 /* If we get an out-of-range value, return now; avoid an error. */
6481 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6484 /* Make the window's buffer temporarily current for
6485 overlays_at and compute_char_face. */
6486 obuf
= current_buffer
;
6487 current_buffer
= XBUFFER (w
->buffer
);
6493 /* Is this char mouse-active or does it have help-echo? */
6494 XSETINT (position
, pos
);
6496 /* Put all the overlays we want in a vector in overlay_vec.
6497 Store the length in len. If there are more than 10, make
6498 enough space for all, and try again. */
6500 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6501 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6502 if (noverlays
> len
)
6505 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6506 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6509 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6511 /* Check mouse-face highlighting. */
6512 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6513 && vpos
>= dpyinfo
->mouse_face_beg_row
6514 && vpos
<= dpyinfo
->mouse_face_end_row
6515 && (vpos
> dpyinfo
->mouse_face_beg_row
6516 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6517 && (vpos
< dpyinfo
->mouse_face_end_row
6518 || hpos
< dpyinfo
->mouse_face_end_col
6519 || dpyinfo
->mouse_face_past_end
)))
6521 /* Clear the display of the old active region, if any. */
6522 clear_mouse_face (dpyinfo
);
6524 /* Find the highest priority overlay that has a mouse-face prop. */
6526 for (i
= 0; i
< noverlays
; i
++)
6528 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6529 if (!NILP (mouse_face
))
6531 overlay
= overlay_vec
[i
];
6536 /* If no overlay applies, get a text property. */
6538 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6540 /* Handle the overlay case. */
6541 if (! NILP (overlay
))
6543 /* Find the range of text around this char that
6544 should be active. */
6545 Lisp_Object before
, after
;
6548 before
= Foverlay_start (overlay
);
6549 after
= Foverlay_end (overlay
);
6550 /* Record this as the current active region. */
6551 fast_find_position (w
, XFASTINT (before
),
6552 &dpyinfo
->mouse_face_beg_col
,
6553 &dpyinfo
->mouse_face_beg_row
,
6554 &dpyinfo
->mouse_face_beg_x
,
6555 &dpyinfo
->mouse_face_beg_y
);
6556 dpyinfo
->mouse_face_past_end
6557 = !fast_find_position (w
, XFASTINT (after
),
6558 &dpyinfo
->mouse_face_end_col
,
6559 &dpyinfo
->mouse_face_end_row
,
6560 &dpyinfo
->mouse_face_end_x
,
6561 &dpyinfo
->mouse_face_end_y
);
6562 dpyinfo
->mouse_face_window
= window
;
6563 dpyinfo
->mouse_face_face_id
6564 = face_at_buffer_position (w
, pos
, 0, 0,
6565 &ignore
, pos
+ 1, 1);
6567 /* Display it as active. */
6568 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6570 /* Handle the text property case. */
6571 else if (! NILP (mouse_face
))
6573 /* Find the range of text around this char that
6574 should be active. */
6575 Lisp_Object before
, after
, beginning
, end
;
6578 beginning
= Fmarker_position (w
->start
);
6579 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6580 - XFASTINT (w
->window_end_pos
)));
6582 = Fprevious_single_property_change (make_number (pos
+ 1),
6584 w
->buffer
, beginning
);
6586 = Fnext_single_property_change (position
, Qmouse_face
,
6588 /* Record this as the current active region. */
6589 fast_find_position (w
, XFASTINT (before
),
6590 &dpyinfo
->mouse_face_beg_col
,
6591 &dpyinfo
->mouse_face_beg_row
,
6592 &dpyinfo
->mouse_face_beg_x
,
6593 &dpyinfo
->mouse_face_beg_y
);
6594 dpyinfo
->mouse_face_past_end
6595 = !fast_find_position (w
, XFASTINT (after
),
6596 &dpyinfo
->mouse_face_end_col
,
6597 &dpyinfo
->mouse_face_end_row
,
6598 &dpyinfo
->mouse_face_end_x
,
6599 &dpyinfo
->mouse_face_end_y
);
6600 dpyinfo
->mouse_face_window
= window
;
6601 dpyinfo
->mouse_face_face_id
6602 = face_at_buffer_position (w
, pos
, 0, 0,
6603 &ignore
, pos
+ 1, 1);
6605 /* Display it as active. */
6606 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6610 /* Look for a `help-echo' property. */
6614 /* Check overlays first. */
6616 for (i
= 0; i
< noverlays
&& NILP (help
); ++i
)
6617 help
= Foverlay_get (overlay_vec
[i
], Qhelp_echo
);
6619 /* Try text properties. */
6621 && ((STRINGP (glyph
->object
)
6622 && glyph
->charpos
>= 0
6623 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6624 || (BUFFERP (glyph
->object
)
6625 && glyph
->charpos
>= BEGV
6626 && glyph
->charpos
< ZV
)))
6627 help
= Fget_text_property (make_number (glyph
->charpos
),
6628 Qhelp_echo
, glyph
->object
);
6636 current_buffer
= obuf
;
6642 redo_mouse_highlight ()
6644 if (!NILP (last_mouse_motion_frame
)
6645 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6646 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6647 last_mouse_motion_event
.x
,
6648 last_mouse_motion_event
.y
);
6653 /***********************************************************************
6655 ***********************************************************************/
6657 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6658 struct glyph
**, int *, int *, int *));
6660 /* Tool-bar item index of the item on which a mouse button was pressed
6663 static int last_tool_bar_item
;
6666 /* Get information about the tool-bar item at position X/Y on frame F.
6667 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6668 the current matrix of the tool-bar window of F, or NULL if not
6669 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6670 item in F->current_tool_bar_items. Value is
6672 -1 if X/Y is not on a tool-bar item
6673 0 if X/Y is on the same item that was highlighted before.
6677 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6680 struct glyph
**glyph
;
6681 int *hpos
, *vpos
, *prop_idx
;
6683 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6684 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6687 /* Find the glyph under X/Y. */
6688 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6692 /* Get the start of this tool-bar item's properties in
6693 f->current_tool_bar_items. */
6694 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6697 /* Is mouse on the highlighted item? */
6698 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6699 && *vpos
>= dpyinfo
->mouse_face_beg_row
6700 && *vpos
<= dpyinfo
->mouse_face_end_row
6701 && (*vpos
> dpyinfo
->mouse_face_beg_row
6702 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6703 && (*vpos
< dpyinfo
->mouse_face_end_row
6704 || *hpos
< dpyinfo
->mouse_face_end_col
6705 || dpyinfo
->mouse_face_past_end
))
6712 /* Handle mouse button event on the tool-bar of frame F, at
6713 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6717 x_handle_tool_bar_click (f
, button_event
)
6719 XButtonEvent
*button_event
;
6721 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6722 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6723 int hpos
, vpos
, prop_idx
;
6724 struct glyph
*glyph
;
6725 Lisp_Object enabled_p
;
6726 int x
= button_event
->x
;
6727 int y
= button_event
->y
;
6729 /* If not on the highlighted tool-bar item, return. */
6730 frame_to_window_pixel_xy (w
, &x
, &y
);
6731 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6734 /* If item is disabled, do nothing. */
6735 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6736 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6737 if (NILP (enabled_p
))
6740 if (button_event
->type
== ButtonPress
)
6742 /* Show item in pressed state. */
6743 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6744 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6745 last_tool_bar_item
= prop_idx
;
6749 Lisp_Object key
, frame
;
6750 struct input_event event
;
6752 /* Show item in released state. */
6753 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6754 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6756 key
= (XVECTOR (f
->current_tool_bar_items
)
6757 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6759 XSETFRAME (frame
, f
);
6760 event
.kind
= TOOL_BAR_EVENT
;
6761 event
.frame_or_window
= Fcons (frame
, Fcons (Qtool_bar
, Qnil
));
6762 kbd_buffer_store_event (&event
);
6764 event
.kind
= TOOL_BAR_EVENT
;
6765 event
.frame_or_window
= Fcons (frame
, key
);
6766 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6767 button_event
->state
);
6768 kbd_buffer_store_event (&event
);
6769 last_tool_bar_item
= -1;
6774 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6775 tool-bar window-relative coordinates X/Y. Called from
6776 note_mouse_highlight. */
6779 note_tool_bar_highlight (f
, x
, y
)
6783 Lisp_Object window
= f
->tool_bar_window
;
6784 struct window
*w
= XWINDOW (window
);
6785 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6787 struct glyph
*glyph
;
6788 struct glyph_row
*row
;
6790 Lisp_Object enabled_p
;
6792 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6793 int mouse_down_p
, rc
;
6795 /* Function note_mouse_highlight is called with negative x(y
6796 values when mouse moves outside of the frame. */
6797 if (x
<= 0 || y
<= 0)
6799 clear_mouse_face (dpyinfo
);
6803 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6806 /* Not on tool-bar item. */
6807 clear_mouse_face (dpyinfo
);
6811 /* On same tool-bar item as before. */
6814 clear_mouse_face (dpyinfo
);
6816 /* Mouse is down, but on different tool-bar item? */
6817 mouse_down_p
= (dpyinfo
->grabbed
6818 && f
== last_mouse_frame
6819 && FRAME_LIVE_P (f
));
6821 && last_tool_bar_item
!= prop_idx
)
6824 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6825 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6827 /* If tool-bar item is not enabled, don't highlight it. */
6828 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6829 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6830 if (!NILP (enabled_p
))
6832 /* Compute the x-position of the glyph. In front and past the
6833 image is a space. We include this is the highlighted area. */
6834 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6835 for (i
= x
= 0; i
< hpos
; ++i
)
6836 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6838 /* Record this as the current active region. */
6839 dpyinfo
->mouse_face_beg_col
= hpos
;
6840 dpyinfo
->mouse_face_beg_row
= vpos
;
6841 dpyinfo
->mouse_face_beg_x
= x
;
6842 dpyinfo
->mouse_face_beg_y
= row
->y
;
6843 dpyinfo
->mouse_face_past_end
= 0;
6845 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6846 dpyinfo
->mouse_face_end_row
= vpos
;
6847 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6848 dpyinfo
->mouse_face_end_y
= row
->y
;
6849 dpyinfo
->mouse_face_window
= window
;
6850 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6852 /* Display it as active. */
6853 show_mouse_face (dpyinfo
, draw
);
6854 dpyinfo
->mouse_face_image_state
= draw
;
6859 /* Set help_echo to a help string.to display for this tool-bar item.
6860 XTread_socket does the rest. */
6861 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6862 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6863 if (NILP (help_echo
))
6864 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6865 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6870 /* Find the glyph matrix position of buffer position POS in window W.
6871 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6872 current glyphs must be up to date. If POS is above window start
6873 return (0, 0, 0, 0). If POS is after end of W, return end of
6877 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6880 int *hpos
, *vpos
, *x
, *y
;
6884 int maybe_next_line_p
= 0;
6885 int line_start_position
;
6886 int yb
= window_text_bottom_y (w
);
6887 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6888 struct glyph_row
*best_row
= row
;
6889 int row_vpos
= 0, best_row_vpos
= 0;
6894 if (row
->used
[TEXT_AREA
])
6895 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6897 line_start_position
= 0;
6899 if (line_start_position
> pos
)
6901 /* If the position sought is the end of the buffer,
6902 don't include the blank lines at the bottom of the window. */
6903 else if (line_start_position
== pos
6904 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6906 maybe_next_line_p
= 1;
6909 else if (line_start_position
> 0)
6912 best_row_vpos
= row_vpos
;
6915 if (row
->y
+ row
->height
>= yb
)
6922 /* Find the right column within BEST_ROW. */
6924 current_x
= best_row
->x
;
6925 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6927 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6930 charpos
= glyph
->charpos
;
6934 *vpos
= best_row_vpos
;
6939 else if (charpos
> pos
)
6941 else if (charpos
> 0)
6944 current_x
+= glyph
->pixel_width
;
6947 /* If we're looking for the end of the buffer,
6948 and we didn't find it in the line we scanned,
6949 use the start of the following line. */
6950 if (maybe_next_line_p
)
6955 current_x
= best_row
->x
;
6958 *vpos
= best_row_vpos
;
6959 *hpos
= lastcol
+ 1;
6966 /* Display the active region described by mouse_face_*
6967 in its mouse-face if HL > 0, in its normal face if HL = 0. */
6970 show_mouse_face (dpyinfo
, draw
)
6971 struct x_display_info
*dpyinfo
;
6972 enum draw_glyphs_face draw
;
6974 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
6975 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6977 int cursor_off_p
= 0;
6978 struct cursor_pos saved_cursor
;
6980 saved_cursor
= output_cursor
;
6982 /* If window is in the process of being destroyed, don't bother
6984 if (w
->current_matrix
== NULL
)
6987 /* Recognize when we are called to operate on rows that don't exist
6988 anymore. This can happen when a window is split. */
6989 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
6992 set_output_cursor (&w
->phys_cursor
);
6994 /* Note that mouse_face_beg_row etc. are window relative. */
6995 for (i
= dpyinfo
->mouse_face_beg_row
;
6996 i
<= dpyinfo
->mouse_face_end_row
;
6999 int start_hpos
, end_hpos
, start_x
;
7000 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7002 /* Don't do anything if row doesn't have valid contents. */
7003 if (!row
->enabled_p
)
7006 /* For all but the first row, the highlight starts at column 0. */
7007 if (i
== dpyinfo
->mouse_face_beg_row
)
7009 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7010 start_x
= dpyinfo
->mouse_face_beg_x
;
7018 if (i
== dpyinfo
->mouse_face_end_row
)
7019 end_hpos
= dpyinfo
->mouse_face_end_col
;
7021 end_hpos
= row
->used
[TEXT_AREA
];
7023 /* If the cursor's in the text we are about to rewrite, turn the
7025 if (!w
->pseudo_window_p
7026 && i
== output_cursor
.vpos
7027 && output_cursor
.hpos
>= start_hpos
- 1
7028 && output_cursor
.hpos
<= end_hpos
)
7030 x_update_window_cursor (w
, 0);
7034 if (end_hpos
> start_hpos
)
7036 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7037 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7038 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7042 /* If we turned the cursor off, turn it back on. */
7044 x_display_cursor (w
, 1,
7045 output_cursor
.hpos
, output_cursor
.vpos
,
7046 output_cursor
.x
, output_cursor
.y
);
7048 output_cursor
= saved_cursor
;
7052 /* Change the mouse cursor. */
7053 if (draw
== DRAW_NORMAL_TEXT
)
7054 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7055 f
->output_data
.x
->text_cursor
);
7056 else if (draw
== DRAW_MOUSE_FACE
)
7057 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7058 f
->output_data
.x
->cross_cursor
);
7060 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7061 f
->output_data
.x
->nontext_cursor
);
7064 /* Clear out the mouse-highlighted active region.
7065 Redraw it un-highlighted first. */
7068 clear_mouse_face (dpyinfo
)
7069 struct x_display_info
*dpyinfo
;
7074 if (! NILP (dpyinfo
->mouse_face_window
))
7075 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7077 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7078 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7079 dpyinfo
->mouse_face_window
= Qnil
;
7082 /* Just discard the mouse face information for frame F, if any.
7083 This is used when the size of F is changed. */
7086 cancel_mouse_face (f
)
7090 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7092 window
= dpyinfo
->mouse_face_window
;
7093 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7095 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7096 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7097 dpyinfo
->mouse_face_window
= Qnil
;
7101 static struct scroll_bar
*x_window_to_scroll_bar ();
7102 static void x_scroll_bar_report_motion ();
7104 /* Return the current position of the mouse.
7105 *fp should be a frame which indicates which display to ask about.
7107 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7108 and *part to the frame, window, and scroll bar part that the mouse
7109 is over. Set *x and *y to the portion and whole of the mouse's
7110 position on the scroll bar.
7112 If the mouse movement started elsewhere, set *fp to the frame the
7113 mouse is on, *bar_window to nil, and *x and *y to the character cell
7116 Set *time to the server time-stamp for the time at which the mouse
7117 was at this position.
7119 Don't store anything if we don't have a valid set of values to report.
7121 This clears the mouse_moved flag, so we can wait for the next mouse
7125 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7128 Lisp_Object
*bar_window
;
7129 enum scroll_bar_part
*part
;
7131 unsigned long *time
;
7137 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7138 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7144 Window dummy_window
;
7147 Lisp_Object frame
, tail
;
7149 /* Clear the mouse-moved flag for every frame on this display. */
7150 FOR_EACH_FRAME (tail
, frame
)
7151 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7152 XFRAME (frame
)->mouse_moved
= 0;
7154 last_mouse_scroll_bar
= Qnil
;
7156 /* Figure out which root window we're on. */
7157 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7158 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7160 /* The root window which contains the pointer. */
7163 /* Trash which we can't trust if the pointer is on
7164 a different screen. */
7167 /* The position on that root window. */
7170 /* More trash we can't trust. */
7173 /* Modifier keys and pointer buttons, about which
7175 (unsigned int *) &dummy
);
7177 /* Now we have a position on the root; find the innermost window
7178 containing the pointer. */
7182 int parent_x
= 0, parent_y
= 0;
7187 /* XTranslateCoordinates can get errors if the window
7188 structure is changing at the same time this function
7189 is running. So at least we must not crash from them. */
7191 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7193 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7194 && FRAME_LIVE_P (last_mouse_frame
))
7196 /* If mouse was grabbed on a frame, give coords for that frame
7197 even if the mouse is now outside it. */
7198 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7200 /* From-window, to-window. */
7201 root
, FRAME_X_WINDOW (last_mouse_frame
),
7203 /* From-position, to-position. */
7204 root_x
, root_y
, &win_x
, &win_y
,
7208 f1
= last_mouse_frame
;
7214 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7216 /* From-window, to-window. */
7219 /* From-position, to-position. */
7220 root_x
, root_y
, &win_x
, &win_y
,
7225 if (child
== None
|| child
== win
)
7233 /* Now we know that:
7234 win is the innermost window containing the pointer
7235 (XTC says it has no child containing the pointer),
7236 win_x and win_y are the pointer's position in it
7237 (XTC did this the last time through), and
7238 parent_x and parent_y are the pointer's position in win's parent.
7239 (They are what win_x and win_y were when win was child.
7240 If win is the root window, it has no parent, and
7241 parent_{x,y} are invalid, but that's okay, because we'll
7242 never use them in that case.) */
7244 /* Is win one of our frames? */
7245 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7248 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7251 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7253 /* If not, is it one of our scroll bars? */
7256 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7260 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7266 if (f1
== 0 && insist
> 0)
7267 f1
= SELECTED_FRAME ();
7271 /* Ok, we found a frame. Store all the values.
7272 last_mouse_glyph is a rectangle used to reduce the
7273 generation of mouse events. To not miss any motion
7274 events, we must divide the frame into rectangles of the
7275 size of the smallest character that could be displayed
7276 on it, i.e. into the same rectangles that matrices on
7277 the frame are divided into. */
7279 #if OLD_REDISPLAY_CODE
7280 int ignore1
, ignore2
;
7281 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7283 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7287 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7288 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7292 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7293 round down even for negative values. */
7299 last_mouse_glyph
.width
= width
;
7300 last_mouse_glyph
.height
= height
;
7301 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7302 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7309 XSETINT (*x
, win_x
);
7310 XSETINT (*y
, win_y
);
7311 *time
= last_mouse_movement_time
;
7320 #ifdef USE_X_TOOLKIT
7322 /* Atimer callback function for TIMER. Called every 0.1s to process
7323 Xt timeouts, if needed. We must avoid calling XtAppPending as
7324 much as possible because that function does an implicit XFlush
7325 that slows us down. */
7328 x_process_timeouts (timer
)
7329 struct atimer
*timer
;
7331 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7334 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7335 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7340 #endif /* USE_X_TOOLKIT */
7343 /* Scroll bar support. */
7345 /* Given an X window ID, find the struct scroll_bar which manages it.
7346 This can be called in GC, so we have to make sure to strip off mark
7349 static struct scroll_bar
*
7350 x_window_to_scroll_bar (window_id
)
7355 for (tail
= Vframe_list
;
7356 XGCTYPE (tail
) == Lisp_Cons
;
7359 Lisp_Object frame
, bar
, condemned
;
7361 frame
= XCAR (tail
);
7362 /* All elements of Vframe_list should be frames. */
7363 if (! GC_FRAMEP (frame
))
7366 /* Scan this frame's scroll bar list for a scroll bar with the
7368 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7369 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7370 /* This trick allows us to search both the ordinary and
7371 condemned scroll bar lists with one loop. */
7372 ! GC_NILP (bar
) || (bar
= condemned
,
7375 bar
= XSCROLL_BAR (bar
)->next
)
7376 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7377 return XSCROLL_BAR (bar
);
7385 /************************************************************************
7387 ************************************************************************/
7389 #if USE_TOOLKIT_SCROLL_BARS
7391 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7392 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7393 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7394 struct scroll_bar
*));
7395 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7399 /* Id of action hook installed for scroll bars. */
7401 static XtActionHookId action_hook_id
;
7403 /* Lisp window being scrolled. Set when starting to interact with
7404 a toolkit scroll bar, reset to nil when ending the interaction. */
7406 static Lisp_Object window_being_scrolled
;
7408 /* Last scroll bar part sent in xm_scroll_callback. */
7410 static int last_scroll_bar_part
;
7412 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7413 that movements of 1/20 of the screen size are mapped to up/down. */
7415 static Boolean xaw3d_arrow_scroll
;
7417 /* Whether the drag scrolling maintains the mouse at the top of the
7418 thumb. If not, resizing the thumb needs to be done more carefully
7419 to avoid jerkyness. */
7421 static Boolean xaw3d_pick_top
;
7424 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7425 bars are used.. The hook is responsible for detecting when
7426 the user ends an interaction with the scroll bar, and generates
7427 a `end-scroll' scroll_bar_click' event if so. */
7430 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7433 XtPointer client_data
;
7437 Cardinal
*num_params
;
7443 scroll_bar_p
= XmIsScrollBar (widget
);
7444 end_action
= "Release";
7445 #else /* !USE_MOTIF i.e. use Xaw */
7446 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7447 end_action
= "EndScroll";
7448 #endif /* USE_MOTIF */
7451 && strcmp (action_name
, end_action
) == 0
7452 && WINDOWP (window_being_scrolled
))
7456 x_send_scroll_bar_event (window_being_scrolled
,
7457 scroll_bar_end_scroll
, 0, 0);
7458 w
= XWINDOW (window_being_scrolled
);
7459 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7460 window_being_scrolled
= Qnil
;
7461 last_scroll_bar_part
= -1;
7463 /* Xt timeouts no longer needed. */
7464 toolkit_scroll_bar_interaction
= 0;
7469 /* Send a client message with message type Xatom_Scrollbar for a
7470 scroll action to the frame of WINDOW. PART is a value identifying
7471 the part of the scroll bar that was clicked on. PORTION is the
7472 amount to scroll of a whole of WHOLE. */
7475 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7477 int part
, portion
, whole
;
7480 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7481 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7483 /* Construct a ClientMessage event to send to the frame. */
7484 ev
->type
= ClientMessage
;
7485 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7486 ev
->display
= FRAME_X_DISPLAY (f
);
7487 ev
->window
= FRAME_X_WINDOW (f
);
7489 ev
->data
.l
[0] = (long) XFASTINT (window
);
7490 ev
->data
.l
[1] = (long) part
;
7491 ev
->data
.l
[2] = (long) 0;
7492 ev
->data
.l
[3] = (long) portion
;
7493 ev
->data
.l
[4] = (long) whole
;
7495 /* Make Xt timeouts work while the scroll bar is active. */
7496 toolkit_scroll_bar_interaction
= 1;
7498 /* Setting the event mask to zero means that the message will
7499 be sent to the client that created the window, and if that
7500 window no longer exists, no event will be sent. */
7502 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7507 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7511 x_scroll_bar_to_input_event (event
, ievent
)
7513 struct input_event
*ievent
;
7515 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7519 XSETFASTINT (window
, ev
->data
.l
[0]);
7520 f
= XFRAME (XWINDOW (window
)->frame
);
7522 ievent
->kind
= scroll_bar_click
;
7523 ievent
->frame_or_window
= window
;
7524 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7525 ievent
->part
= ev
->data
.l
[1];
7526 ievent
->code
= ev
->data
.l
[2];
7527 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7528 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7529 ievent
->modifiers
= 0;
7535 /* Minimum and maximum values used for Motif scroll bars. */
7538 #define XM_SB_MAX 10000000
7539 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7542 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7543 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7544 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7547 xm_scroll_callback (widget
, client_data
, call_data
)
7549 XtPointer client_data
, call_data
;
7551 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7552 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7554 int part
= -1, whole
= 0, portion
= 0;
7558 case XmCR_DECREMENT
:
7559 bar
->dragging
= Qnil
;
7560 part
= scroll_bar_up_arrow
;
7563 case XmCR_INCREMENT
:
7564 bar
->dragging
= Qnil
;
7565 part
= scroll_bar_down_arrow
;
7568 case XmCR_PAGE_DECREMENT
:
7569 bar
->dragging
= Qnil
;
7570 part
= scroll_bar_above_handle
;
7573 case XmCR_PAGE_INCREMENT
:
7574 bar
->dragging
= Qnil
;
7575 part
= scroll_bar_below_handle
;
7579 bar
->dragging
= Qnil
;
7580 part
= scroll_bar_to_top
;
7583 case XmCR_TO_BOTTOM
:
7584 bar
->dragging
= Qnil
;
7585 part
= scroll_bar_to_bottom
;
7591 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7592 && XINT (bar
->dragging
) <= cs
->value
);
7594 /* Get the slider size. */
7596 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7599 /* At the max position of the scroll bar, do a line-wise
7600 movement. Without doing anything, the LessTif scroll bar
7601 calls us with the same cs->value again and again. If we
7602 want to make sure that we can reach the end of the buffer,
7603 we have to do something.
7605 Implementation note: setting bar->dragging always to
7606 cs->value gives a smoother movement at the max position.
7607 Setting it to nil when doing line-wise movement gives
7608 a better slider behavior. */
7610 if (cs
->value
+ slider_size
== XM_SB_MAX
7612 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7614 part
= scroll_bar_down_arrow
;
7615 bar
->dragging
= Qnil
;
7619 whole
= XM_SB_RANGE
;
7620 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7621 part
= scroll_bar_handle
;
7622 bar
->dragging
= make_number (cs
->value
);
7627 case XmCR_VALUE_CHANGED
:
7633 window_being_scrolled
= bar
->window
;
7634 last_scroll_bar_part
= part
;
7635 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7640 #else /* !USE_MOTIF, i.e. Xaw. */
7643 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7644 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7645 scroll bar struct. CALL_DATA is a pointer to a float saying where
7649 xaw_jump_callback (widget
, client_data
, call_data
)
7651 XtPointer client_data
, call_data
;
7653 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7654 float top
= *(float *) call_data
;
7656 int whole
, portion
, height
;
7659 /* Get the size of the thumb, a value between 0 and 1. */
7661 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7665 portion
= shown
< 1 ? top
* whole
: 0;
7667 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7668 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7669 the bottom, so we force the scrolling whenever we see that we're
7670 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7671 we try to ensure that we always stay two pixels away from the
7673 part
= scroll_bar_down_arrow
;
7675 part
= scroll_bar_handle
;
7677 window_being_scrolled
= bar
->window
;
7678 bar
->dragging
= make_number (portion
);
7679 last_scroll_bar_part
= part
;
7680 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7684 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7685 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7686 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7687 the scroll bar. CALL_DATA is an integer specifying the action that
7688 has taken place. It's magnitude is in the range 0..height of the
7689 scroll bar. Negative values mean scroll towards buffer start.
7690 Values < height of scroll bar mean line-wise movement. */
7693 xaw_scroll_callback (widget
, client_data
, call_data
)
7695 XtPointer client_data
, call_data
;
7697 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7698 int position
= (int) call_data
;
7702 /* Get the height of the scroll bar. */
7704 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7707 if (abs (position
) >= height
)
7708 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
7710 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
7711 it maps line-movement to call_data = max(5, height/20). */
7712 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
7713 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
7715 part
= scroll_bar_move_ratio
;
7717 window_being_scrolled
= bar
->window
;
7718 bar
->dragging
= Qnil
;
7719 last_scroll_bar_part
= part
;
7720 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
7724 #endif /* not USE_MOTIF */
7727 /* Create the widget for scroll bar BAR on frame F. Record the widget
7728 and X window of the scroll bar in BAR. */
7731 x_create_toolkit_scroll_bar (f
, bar
)
7733 struct scroll_bar
*bar
;
7739 char *scroll_bar_name
= "verticalScrollBar";
7740 unsigned long pixel
;
7745 /* LessTif 0.85, problems:
7747 1. When the mouse if over the scroll bar, the scroll bar will
7748 get keyboard events. I didn't find a way to turn this off.
7750 2. Do we have to explicitly set the cursor to get an arrow
7751 cursor (see below)? */
7753 /* Set resources. Create the widget. */
7754 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7755 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7756 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7757 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7758 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7759 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7760 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7762 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7765 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7769 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7772 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7776 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7777 scroll_bar_name
, av
, ac
);
7779 /* Add one callback for everything that can happen. */
7780 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7782 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7784 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7786 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7788 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7790 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7792 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7795 /* Realize the widget. Only after that is the X window created. */
7796 XtRealizeWidget (widget
);
7798 /* Set the cursor to an arrow. I didn't find a resource to do that.
7799 And I'm wondering why it hasn't an arrow cursor by default. */
7800 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7801 f
->output_data
.x
->nontext_cursor
);
7803 #else /* !USE_MOTIF i.e. use Xaw */
7805 /* Set resources. Create the widget. The background of the
7806 Xaw3d scroll bar widget is a little bit light for my taste.
7807 We don't alter it here to let users change it according
7808 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7809 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7810 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7811 /* For smoother scrolling with Xaw3d -sm */
7812 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
7813 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
7815 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7818 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7822 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7825 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7829 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7830 f
->output_data
.x
->edit_widget
, av
, ac
);
7834 char *val
= initial
;
7835 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
7836 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
7838 { /* ARROW_SCROLL */
7839 xaw3d_arrow_scroll
= True
;
7840 /* Isn't that just a personal preference ? -sm */
7841 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
7845 /* Define callbacks. */
7846 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
7847 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
7850 /* Realize the widget. Only after that is the X window created. */
7851 XtRealizeWidget (widget
);
7853 #endif /* !USE_MOTIF */
7855 /* Install an action hook that let's us detect when the user
7856 finishes interacting with a scroll bar. */
7857 if (action_hook_id
== 0)
7858 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7860 /* Remember X window and widget in the scroll bar vector. */
7861 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7862 xwindow
= XtWindow (widget
);
7863 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7869 /* Set the thumb size and position of scroll bar BAR. We are currently
7870 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7873 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7874 struct scroll_bar
*bar
;
7875 int portion
, position
, whole
;
7878 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7884 top
= (float) position
/ whole
;
7885 shown
= (float) portion
/ whole
;
7893 Boolean arrow1_selected
, arrow2_selected
;
7894 unsigned char flags
;
7895 XmScrollBarWidget sb
;
7897 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
7898 is the scroll bar's maximum and MIN is the scroll bar's minimum
7900 size
= shown
* XM_SB_RANGE
;
7901 size
= min (size
, XM_SB_RANGE
);
7902 size
= max (size
, 1);
7904 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7905 value
= top
* XM_SB_RANGE
;
7906 value
= min (value
, XM_SB_MAX
- size
);
7907 value
= max (value
, XM_SB_MIN
);
7909 /* LessTif: Calling XmScrollBarSetValues after an increment or
7910 decrement turns off auto-repeat LessTif-internally. This can
7911 be seen in ScrollBar.c which resets Arrow1Selected and
7912 Arrow2Selected. It also sets internal flags so that LessTif
7913 believes the mouse is in the slider. We either have to change
7914 our code, or work around that by accessing private data. */
7916 sb
= (XmScrollBarWidget
) widget
;
7917 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
7918 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
7919 flags
= sb
->scrollBar
.flags
;
7921 if (NILP (bar
->dragging
))
7922 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
7923 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7924 /* This has the negative side effect that the slider value is
7925 not what it would be if we scrolled here using line-wise or
7926 page-wise movement. */
7927 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
7930 /* If currently dragging, only update the slider size.
7931 This reduces flicker effects. */
7932 int old_value
, old_size
, increment
, page_increment
;
7934 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
7935 &increment
, &page_increment
);
7936 XmScrollBarSetValues (widget
, old_value
,
7937 min (size
, XM_SB_RANGE
- old_value
),
7941 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
7942 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
7943 sb
->scrollBar
.flags
= flags
;
7945 #else /* !USE_MOTIF i.e. use Xaw */
7947 float old_top
, old_shown
;
7949 XtVaGetValues (widget
,
7950 XtNtopOfThumb
, &old_top
,
7951 XtNshown
, &old_shown
,
7955 /* Massage the top+shown values. */
7956 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
7957 top
= max (0, min (1, top
));
7960 /* Keep two pixels available for moving the thumb down. */
7961 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
7963 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
7964 check that your system's configuration file contains a define
7965 for `NARROWPROTO'. See s/freebsd.h for an example. */
7966 if (top
!= old_top
|| shown
!= old_shown
)
7968 if (NILP (bar
->dragging
))
7969 XawScrollbarSetThumb (widget
, top
, shown
);
7973 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
7974 int scroll_mode
= 0;
7976 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
7977 if (xaw3d_arrow_scroll
)
7979 /* Xaw3d stupidly ignores resize requests while dragging
7980 so we have to make it believe it's not in dragging mode. */
7981 scroll_mode
= sb
->scrollbar
.scroll_mode
;
7982 if (scroll_mode
== 2)
7983 sb
->scrollbar
.scroll_mode
= 0;
7986 /* Try to make the scrolling a tad smoother. */
7987 if (!xaw3d_pick_top
)
7988 shown
= min (shown
, old_shown
);
7990 XawScrollbarSetThumb (widget
, top
, shown
);
7993 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
7994 sb
->scrollbar
.scroll_mode
= scroll_mode
;
7999 #endif /* !USE_MOTIF */
8004 #endif /* USE_TOOLKIT_SCROLL_BARS */
8008 /************************************************************************
8009 Scroll bars, general
8010 ************************************************************************/
8012 /* Create a scroll bar and return the scroll bar vector for it. W is
8013 the Emacs window on which to create the scroll bar. TOP, LEFT,
8014 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8017 static struct scroll_bar
*
8018 x_scroll_bar_create (w
, top
, left
, width
, height
)
8020 int top
, left
, width
, height
;
8022 struct frame
*f
= XFRAME (w
->frame
);
8023 struct scroll_bar
*bar
8024 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8028 #if USE_TOOLKIT_SCROLL_BARS
8029 x_create_toolkit_scroll_bar (f
, bar
);
8030 #else /* not USE_TOOLKIT_SCROLL_BARS */
8032 XSetWindowAttributes a
;
8036 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8037 if (a
.background_pixel
== -1)
8038 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8040 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8041 | ButtonMotionMask
| PointerMotionHintMask
8043 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8045 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8047 /* Clear the area of W that will serve as a scroll bar. This is
8048 for the case that a window has been split horizontally. In
8049 this case, no clear_frame is generated to reduce flickering. */
8050 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8052 window_box_height (w
), False
);
8054 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8055 /* Position and size of scroll bar. */
8056 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8058 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8060 /* Border width, depth, class, and visual. */
8067 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8069 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8071 XSETWINDOW (bar
->window
, w
);
8072 XSETINT (bar
->top
, top
);
8073 XSETINT (bar
->left
, left
);
8074 XSETINT (bar
->width
, width
);
8075 XSETINT (bar
->height
, height
);
8076 XSETINT (bar
->start
, 0);
8077 XSETINT (bar
->end
, 0);
8078 bar
->dragging
= Qnil
;
8080 /* Add bar to its frame's list of scroll bars. */
8081 bar
->next
= FRAME_SCROLL_BARS (f
);
8083 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8084 if (!NILP (bar
->next
))
8085 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8087 /* Map the window/widget. */
8088 #if USE_TOOLKIT_SCROLL_BARS
8089 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
8090 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8091 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8093 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8095 #else /* not USE_TOOLKIT_SCROLL_BARS */
8096 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8097 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8104 /* Draw BAR's handle in the proper position.
8106 If the handle is already drawn from START to END, don't bother
8107 redrawing it, unless REBUILD is non-zero; in that case, always
8108 redraw it. (REBUILD is handy for drawing the handle after expose
8111 Normally, we want to constrain the start and end of the handle to
8112 fit inside its rectangle, but if the user is dragging the scroll
8113 bar handle, we want to let them drag it down all the way, so that
8114 the bar's top is as far down as it goes; otherwise, there's no way
8115 to move to the very end of the buffer. */
8117 #ifndef USE_TOOLKIT_SCROLL_BARS
8120 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8121 struct scroll_bar
*bar
;
8125 int dragging
= ! NILP (bar
->dragging
);
8126 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8127 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8128 GC gc
= f
->output_data
.x
->normal_gc
;
8130 /* If the display is already accurate, do nothing. */
8132 && start
== XINT (bar
->start
)
8133 && end
== XINT (bar
->end
))
8139 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8140 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8141 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8143 /* Make sure the values are reasonable, and try to preserve
8144 the distance between start and end. */
8146 int length
= end
- start
;
8150 else if (start
> top_range
)
8152 end
= start
+ length
;
8156 else if (end
> top_range
&& ! dragging
)
8160 /* Store the adjusted setting in the scroll bar. */
8161 XSETINT (bar
->start
, start
);
8162 XSETINT (bar
->end
, end
);
8164 /* Clip the end position, just for display. */
8165 if (end
> top_range
)
8168 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8169 below top positions, to make sure the handle is always at least
8170 that many pixels tall. */
8171 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8173 /* Draw the empty space above the handle. Note that we can't clear
8174 zero-height areas; that means "clear to end of window." */
8176 XClearArea (FRAME_X_DISPLAY (f
), w
,
8178 /* x, y, width, height, and exposures. */
8179 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8180 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8181 inside_width
, start
,
8184 /* Change to proper foreground color if one is specified. */
8185 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8186 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8187 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8189 /* Draw the handle itself. */
8190 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8192 /* x, y, width, height */
8193 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8194 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8195 inside_width
, end
- start
);
8197 /* Restore the foreground color of the GC if we changed it above. */
8198 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8199 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8200 f
->output_data
.x
->foreground_pixel
);
8202 /* Draw the empty space below the handle. Note that we can't
8203 clear zero-height areas; that means "clear to end of window." */
8204 if (end
< inside_height
)
8205 XClearArea (FRAME_X_DISPLAY (f
), w
,
8207 /* x, y, width, height, and exposures. */
8208 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8209 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8210 inside_width
, inside_height
- end
,
8218 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8220 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8224 x_scroll_bar_remove (bar
)
8225 struct scroll_bar
*bar
;
8229 #if USE_TOOLKIT_SCROLL_BARS
8230 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
8231 #else /* not USE_TOOLKIT_SCROLL_BARS */
8233 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8234 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8236 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8238 /* Disassociate this scroll bar from its window. */
8239 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8245 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8246 that we are displaying PORTION characters out of a total of WHOLE
8247 characters, starting at POSITION. If WINDOW has no scroll bar,
8251 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8253 int portion
, whole
, position
;
8255 struct frame
*f
= XFRAME (w
->frame
);
8256 struct scroll_bar
*bar
;
8257 int top
, height
, left
, sb_left
, width
, sb_width
;
8258 int window_x
, window_y
, window_width
, window_height
;
8260 /* Get window dimensions. */
8261 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8263 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8264 height
= window_height
;
8266 /* Compute the left edge of the scroll bar area. */
8267 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8268 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8270 left
= XFASTINT (w
->left
);
8271 left
*= CANON_X_UNIT (f
);
8272 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8274 /* Compute the width of the scroll bar which might be less than
8275 the width of the area reserved for the scroll bar. */
8276 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8277 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8281 /* Compute the left edge of the scroll bar. */
8282 #ifdef USE_TOOLKIT_SCROLL_BARS
8283 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8284 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8286 sb_left
= left
+ (width
- sb_width
) / 2;
8288 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8289 sb_left
= left
+ width
- sb_width
;
8294 /* Does the scroll bar exist yet? */
8295 if (NILP (w
->vertical_scroll_bar
))
8298 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8299 left
, top
, width
, height
, False
);
8301 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8305 /* It may just need to be moved and resized. */
8306 unsigned int mask
= 0;
8308 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8312 if (sb_left
!= XINT (bar
->left
))
8314 if (top
!= XINT (bar
->top
))
8316 if (sb_width
!= XINT (bar
->width
))
8318 if (height
!= XINT (bar
->height
))
8321 #ifdef USE_TOOLKIT_SCROLL_BARS
8323 /* Since toolkit scroll bars are smaller than the space reserved
8324 for them on the frame, we have to clear "under" them. */
8325 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8326 left
, top
, width
, height
, False
);
8328 /* Move/size the scroll bar widget. */
8330 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8331 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8333 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8336 #else /* not USE_TOOLKIT_SCROLL_BARS */
8338 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8340 /* Clear areas not covered by the scroll bar. This makes sure a
8341 previous mode line display is cleared after C-x 2 C-x 1, for
8342 example. Non-toolkit scroll bars are as wide as the area
8343 reserved for scroll bars - trim at both sides. */
8344 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8345 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8347 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8348 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8349 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8353 /* Move/size the scroll bar window. */
8358 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8360 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8362 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8366 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8368 /* Remember new settings. */
8369 XSETINT (bar
->left
, sb_left
);
8370 XSETINT (bar
->top
, top
);
8371 XSETINT (bar
->width
, sb_width
);
8372 XSETINT (bar
->height
, height
);
8377 #if USE_TOOLKIT_SCROLL_BARS
8378 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8379 #else /* not USE_TOOLKIT_SCROLL_BARS */
8380 /* Set the scroll bar's current state, unless we're currently being
8382 if (NILP (bar
->dragging
))
8384 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8387 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8390 int start
= ((double) position
* top_range
) / whole
;
8391 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8392 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8395 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8397 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8401 /* The following three hooks are used when we're doing a thorough
8402 redisplay of the frame. We don't explicitly know which scroll bars
8403 are going to be deleted, because keeping track of when windows go
8404 away is a real pain - "Can you say set-window-configuration, boys
8405 and girls?" Instead, we just assert at the beginning of redisplay
8406 that *all* scroll bars are to be removed, and then save a scroll bar
8407 from the fiery pit when we actually redisplay its window. */
8409 /* Arrange for all scroll bars on FRAME to be removed at the next call
8410 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8411 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8414 XTcondemn_scroll_bars (frame
)
8417 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8418 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8421 bar
= FRAME_SCROLL_BARS (frame
);
8422 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8423 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8424 XSCROLL_BAR (bar
)->prev
= Qnil
;
8425 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8426 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8427 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8431 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8432 Note that WINDOW isn't necessarily condemned at all. */
8434 XTredeem_scroll_bar (window
)
8435 struct window
*window
;
8437 struct scroll_bar
*bar
;
8439 /* We can't redeem this window's scroll bar if it doesn't have one. */
8440 if (NILP (window
->vertical_scroll_bar
))
8443 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8445 /* Unlink it from the condemned list. */
8447 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8449 if (NILP (bar
->prev
))
8451 /* If the prev pointer is nil, it must be the first in one of
8453 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8454 /* It's not condemned. Everything's fine. */
8456 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8457 window
->vertical_scroll_bar
))
8458 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8460 /* If its prev pointer is nil, it must be at the front of
8461 one or the other! */
8465 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8467 if (! NILP (bar
->next
))
8468 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8470 bar
->next
= FRAME_SCROLL_BARS (f
);
8472 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8473 if (! NILP (bar
->next
))
8474 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8478 /* Remove all scroll bars on FRAME that haven't been saved since the
8479 last call to `*condemn_scroll_bars_hook'. */
8482 XTjudge_scroll_bars (f
)
8485 Lisp_Object bar
, next
;
8487 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8489 /* Clear out the condemned list now so we won't try to process any
8490 more events on the hapless scroll bars. */
8491 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8493 for (; ! NILP (bar
); bar
= next
)
8495 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8497 x_scroll_bar_remove (b
);
8500 b
->next
= b
->prev
= Qnil
;
8503 /* Now there should be no references to the condemned scroll bars,
8504 and they should get garbage-collected. */
8508 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8509 is a no-op when using toolkit scroll bars.
8511 This may be called from a signal handler, so we have to ignore GC
8515 x_scroll_bar_expose (bar
, event
)
8516 struct scroll_bar
*bar
;
8519 #ifndef USE_TOOLKIT_SCROLL_BARS
8521 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8522 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8523 GC gc
= f
->output_data
.x
->normal_gc
;
8524 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8528 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8530 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8531 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8533 /* x, y, width, height */
8535 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8536 XINT (bar
->height
) - 1);
8540 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8543 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8544 is set to something other than no_event, it is enqueued.
8546 This may be called from a signal handler, so we have to ignore GC
8549 #ifndef USE_TOOLKIT_SCROLL_BARS
8552 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8553 struct scroll_bar
*bar
;
8555 struct input_event
*emacs_event
;
8557 if (! GC_WINDOWP (bar
->window
))
8560 emacs_event
->kind
= scroll_bar_click
;
8561 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8562 emacs_event
->modifiers
8563 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8564 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8565 event
->xbutton
.state
)
8566 | (event
->type
== ButtonRelease
8569 emacs_event
->frame_or_window
= bar
->window
;
8570 emacs_event
->timestamp
= event
->xbutton
.time
;
8573 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8575 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8578 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8579 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8582 if (y
> top_range
) y
= top_range
;
8584 if (y
< XINT (bar
->start
))
8585 emacs_event
->part
= scroll_bar_above_handle
;
8586 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8587 emacs_event
->part
= scroll_bar_handle
;
8589 emacs_event
->part
= scroll_bar_below_handle
;
8591 /* Just because the user has clicked on the handle doesn't mean
8592 they want to drag it. Lisp code needs to be able to decide
8593 whether or not we're dragging. */
8595 /* If the user has just clicked on the handle, record where they're
8597 if (event
->type
== ButtonPress
8598 && emacs_event
->part
== scroll_bar_handle
)
8599 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8602 /* If the user has released the handle, set it to its final position. */
8603 if (event
->type
== ButtonRelease
8604 && ! NILP (bar
->dragging
))
8606 int new_start
= y
- XINT (bar
->dragging
);
8607 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8609 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8610 bar
->dragging
= Qnil
;
8613 /* Same deal here as the other #if 0. */
8615 /* Clicks on the handle are always reported as occurring at the top of
8617 if (emacs_event
->part
== scroll_bar_handle
)
8618 emacs_event
->x
= bar
->start
;
8620 XSETINT (emacs_event
->x
, y
);
8622 XSETINT (emacs_event
->x
, y
);
8625 XSETINT (emacs_event
->y
, top_range
);
8629 /* Handle some mouse motion while someone is dragging the scroll bar.
8631 This may be called from a signal handler, so we have to ignore GC
8635 x_scroll_bar_note_movement (bar
, event
)
8636 struct scroll_bar
*bar
;
8639 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8641 last_mouse_movement_time
= event
->xmotion
.time
;
8644 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8646 /* If we're dragging the bar, display it. */
8647 if (! GC_NILP (bar
->dragging
))
8649 /* Where should the handle be now? */
8650 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8652 if (new_start
!= XINT (bar
->start
))
8654 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8656 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8661 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8663 /* Return information to the user about the current position of the mouse
8664 on the scroll bar. */
8667 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8669 Lisp_Object
*bar_window
;
8670 enum scroll_bar_part
*part
;
8672 unsigned long *time
;
8674 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8675 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8676 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8678 Window dummy_window
;
8680 unsigned int dummy_mask
;
8684 /* Get the mouse's position relative to the scroll bar window, and
8686 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8688 /* Root, child, root x and root y. */
8689 &dummy_window
, &dummy_window
,
8690 &dummy_coord
, &dummy_coord
,
8692 /* Position relative to scroll bar. */
8695 /* Mouse buttons and modifier keys. */
8702 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8705 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8707 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8709 if (! NILP (bar
->dragging
))
8710 win_y
-= XINT (bar
->dragging
);
8714 if (win_y
> top_range
)
8718 *bar_window
= bar
->window
;
8720 if (! NILP (bar
->dragging
))
8721 *part
= scroll_bar_handle
;
8722 else if (win_y
< XINT (bar
->start
))
8723 *part
= scroll_bar_above_handle
;
8724 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8725 *part
= scroll_bar_handle
;
8727 *part
= scroll_bar_below_handle
;
8729 XSETINT (*x
, win_y
);
8730 XSETINT (*y
, top_range
);
8733 last_mouse_scroll_bar
= Qnil
;
8736 *time
= last_mouse_movement_time
;
8742 /* The screen has been cleared so we may have changed foreground or
8743 background colors, and the scroll bars may need to be redrawn.
8744 Clear out the scroll bars, and ask for expose events, so we can
8748 x_scroll_bar_clear (f
)
8751 #ifndef USE_TOOLKIT_SCROLL_BARS
8754 /* We can have scroll bars even if this is 0,
8755 if we just turned off scroll bar mode.
8756 But in that case we should not clear them. */
8757 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8758 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8759 bar
= XSCROLL_BAR (bar
)->next
)
8760 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8762 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8765 /* This processes Expose events from the menu-bar specific X event
8766 loop in xmenu.c. This allows to redisplay the frame if necessary
8767 when handling menu-bar or pop-up items. */
8770 process_expose_from_menu (event
)
8774 struct x_display_info
*dpyinfo
;
8775 int frame_exposed_p
= 0;
8779 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8780 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8783 if (f
->async_visible
== 0)
8785 f
->async_visible
= 1;
8786 f
->async_iconified
= 0;
8787 f
->output_data
.x
->has_been_visible
= 1;
8788 SET_FRAME_GARBAGED (f
);
8792 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8793 event
.xexpose
.x
, event
.xexpose
.y
,
8794 event
.xexpose
.width
, event
.xexpose
.height
);
8795 frame_exposed_p
= 1;
8800 struct scroll_bar
*bar
8801 = x_window_to_scroll_bar (event
.xexpose
.window
);
8804 x_scroll_bar_expose (bar
, &event
);
8808 return frame_exposed_p
;
8811 /* Define a queue to save up SelectionRequest events for later handling. */
8813 struct selection_event_queue
8816 struct selection_event_queue
*next
;
8819 static struct selection_event_queue
*queue
;
8821 /* Nonzero means queue up certain events--don't process them yet. */
8823 static int x_queue_selection_requests
;
8825 /* Queue up an X event *EVENT, to be processed later. */
8828 x_queue_event (f
, event
)
8832 struct selection_event_queue
*queue_tmp
8833 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8835 if (queue_tmp
!= NULL
)
8837 queue_tmp
->event
= *event
;
8838 queue_tmp
->next
= queue
;
8843 /* Take all the queued events and put them back
8844 so that they get processed afresh. */
8847 x_unqueue_events (display
)
8850 while (queue
!= NULL
)
8852 struct selection_event_queue
*queue_tmp
= queue
;
8853 XPutBackEvent (display
, &queue_tmp
->event
);
8854 queue
= queue_tmp
->next
;
8855 xfree ((char *)queue_tmp
);
8859 /* Start queuing SelectionRequest events. */
8862 x_start_queuing_selection_requests (display
)
8865 x_queue_selection_requests
++;
8868 /* Stop queuing SelectionRequest events. */
8871 x_stop_queuing_selection_requests (display
)
8874 x_queue_selection_requests
--;
8875 x_unqueue_events (display
);
8878 /* The main X event-reading loop - XTread_socket. */
8880 /* Time stamp of enter window event. This is only used by XTread_socket,
8881 but we have to put it out here, since static variables within functions
8882 sometimes don't work. */
8884 static Time enter_timestamp
;
8886 /* This holds the state XLookupString needs to implement dead keys
8887 and other tricks known as "compose processing". _X Window System_
8888 says that a portable program can't use this, but Stephen Gildea assures
8889 me that letting the compiler initialize it to zeros will work okay.
8891 This must be defined outside of XTread_socket, for the same reasons
8892 given for enter_time stamp, above. */
8894 static XComposeStatus compose_status
;
8896 /* Record the last 100 characters stored
8897 to help debug the loss-of-chars-during-GC problem. */
8899 static int temp_index
;
8900 static short temp_buffer
[100];
8902 /* Set this to nonzero to fake an "X I/O error"
8903 on a particular display. */
8905 struct x_display_info
*XTread_socket_fake_io_error
;
8907 /* When we find no input here, we occasionally do a no-op command
8908 to verify that the X server is still running and we can still talk with it.
8909 We try all the open displays, one by one.
8910 This variable is used for cycling thru the displays. */
8912 static struct x_display_info
*next_noop_dpyinfo
;
8914 #define SET_SAVED_MENU_EVENT(size) \
8917 if (f->output_data.x->saved_menu_event == 0) \
8918 f->output_data.x->saved_menu_event \
8919 = (XEvent *) xmalloc (sizeof (XEvent)); \
8920 bcopy (&event, f->output_data.x->saved_menu_event, size); \
8921 if (numchars >= 1) \
8923 bufp->kind = menu_bar_activate_event; \
8924 XSETFRAME (bufp->frame_or_window, f); \
8932 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
8933 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
8935 /* Read events coming from the X server.
8936 This routine is called by the SIGIO handler.
8937 We return as soon as there are no more events to be read.
8939 Events representing keys are stored in buffer BUFP,
8940 which can hold up to NUMCHARS characters.
8941 We return the number of characters stored into the buffer,
8942 thus pretending to be `read'.
8944 EXPECTED is nonzero if the caller knows input is available. */
8947 XTread_socket (sd
, bufp
, numchars
, expected
)
8949 /* register */ struct input_event
*bufp
;
8950 /* register */ int numchars
;
8957 int event_found
= 0;
8958 struct x_display_info
*dpyinfo
;
8960 if (interrupt_input_blocked
)
8962 interrupt_input_pending
= 1;
8966 interrupt_input_pending
= 0;
8969 /* So people can tell when we have read the available input. */
8970 input_signal_count
++;
8973 abort (); /* Don't think this happens. */
8977 /* Find the display we are supposed to read input for.
8978 It's the one communicating on descriptor SD. */
8979 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
8981 #if 0 /* This ought to be unnecessary; let's verify it. */
8983 /* If available, Xlib uses FIOSNBIO to make the socket
8984 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
8985 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
8986 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
8987 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
8988 #endif /* ! defined (FIOSNBIO) */
8991 #if 0 /* This code can't be made to work, with multiple displays,
8992 and appears not to be used on any system any more.
8993 Also keyboard.c doesn't turn O_NDELAY on and off
8994 for X connections. */
8997 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
8999 extern int read_alarm_should_throw
;
9000 read_alarm_should_throw
= 1;
9001 XPeekEvent (dpyinfo
->display
, &event
);
9002 read_alarm_should_throw
= 0;
9004 #endif /* HAVE_SELECT */
9008 /* For debugging, this gives a way to fake an I/O error. */
9009 if (dpyinfo
== XTread_socket_fake_io_error
)
9011 XTread_socket_fake_io_error
= 0;
9012 x_io_error_quitter (dpyinfo
->display
);
9015 while (XPending (dpyinfo
->display
))
9017 XNextEvent (dpyinfo
->display
, &event
);
9021 /* Filter events for the current X input method.
9022 XFilterEvent returns non-zero if the input method has
9023 consumed the event. We pass the frame's X window to
9024 XFilterEvent because that's the one for which the IC
9026 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9027 event
.xclient
.window
);
9028 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9038 if (event
.xclient
.message_type
9039 == dpyinfo
->Xatom_wm_protocols
9040 && event
.xclient
.format
== 32)
9042 if (event
.xclient
.data
.l
[0]
9043 == dpyinfo
->Xatom_wm_take_focus
)
9045 /* Use x_any_window_to_frame because this
9046 could be the shell widget window
9047 if the frame has no title bar. */
9048 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9050 /* Not quite sure this is needed -pd */
9051 if (f
&& FRAME_XIC (f
))
9052 XSetICFocus (FRAME_XIC (f
));
9054 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9055 instructs the WM to set the input focus automatically for
9056 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9057 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9058 it has set the focus. So, XSetInputFocus below is not
9061 The call to XSetInputFocus below has also caused trouble. In
9062 cases where the XSetInputFocus done by the WM and the one
9063 below are temporally close (on a fast machine), the call
9064 below can generate additional FocusIn events which confuse
9067 /* Since we set WM_TAKE_FOCUS, we must call
9068 XSetInputFocus explicitly. But not if f is null,
9069 since that might be an event for a deleted frame. */
9072 Display
*d
= event
.xclient
.display
;
9073 /* Catch and ignore errors, in case window has been
9074 iconified by a window manager such as GWM. */
9075 int count
= x_catch_errors (d
);
9076 XSetInputFocus (d
, event
.xclient
.window
,
9077 /* The ICCCM says this is
9078 the only valid choice. */
9080 event
.xclient
.data
.l
[1]);
9081 /* This is needed to detect the error
9082 if there is an error. */
9084 x_uncatch_errors (d
, count
);
9086 /* Not certain about handling scroll bars here */
9089 else if (event
.xclient
.data
.l
[0]
9090 == dpyinfo
->Xatom_wm_save_yourself
)
9092 /* Save state modify the WM_COMMAND property to
9093 something which can reinstate us. This notifies
9094 the session manager, who's looking for such a
9095 PropertyNotify. Can restart processing when
9096 a keyboard or mouse event arrives. */
9099 f
= x_top_window_to_frame (dpyinfo
,
9100 event
.xclient
.window
);
9102 /* This is just so we only give real data once
9103 for a single Emacs process. */
9104 if (f
== SELECTED_FRAME ())
9105 XSetCommand (FRAME_X_DISPLAY (f
),
9106 event
.xclient
.window
,
9107 initial_argv
, initial_argc
);
9109 XSetCommand (FRAME_X_DISPLAY (f
),
9110 event
.xclient
.window
,
9114 else if (event
.xclient
.data
.l
[0]
9115 == dpyinfo
->Xatom_wm_delete_window
)
9118 = x_any_window_to_frame (dpyinfo
,
9119 event
.xclient
.window
);
9126 bufp
->kind
= delete_window_event
;
9127 XSETFRAME (bufp
->frame_or_window
, f
);
9135 else if (event
.xclient
.message_type
9136 == dpyinfo
->Xatom_wm_configure_denied
)
9139 else if (event
.xclient
.message_type
9140 == dpyinfo
->Xatom_wm_window_moved
)
9144 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9146 new_x
= event
.xclient
.data
.s
[0];
9147 new_y
= event
.xclient
.data
.s
[1];
9151 f
->output_data
.x
->left_pos
= new_x
;
9152 f
->output_data
.x
->top_pos
= new_y
;
9156 else if (event
.xclient
.message_type
9157 == dpyinfo
->Xatom_editres
)
9160 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9161 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9164 #endif /* HACK_EDITRES */
9165 else if ((event
.xclient
.message_type
9166 == dpyinfo
->Xatom_DONE
)
9167 || (event
.xclient
.message_type
9168 == dpyinfo
->Xatom_PAGE
))
9170 /* Ghostview job completed. Kill it. We could
9171 reply with "Next" if we received "Page", but we
9172 currently never do because we are interested in
9173 images, only, which should have 1 page. */
9174 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9176 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9177 x_kill_gs_process (pixmap
, f
);
9178 expose_frame (f
, 0, 0, 0, 0);
9180 #ifdef USE_TOOLKIT_SCROLL_BARS
9181 /* Scroll bar callbacks send a ClientMessage from which
9182 we construct an input_event. */
9183 else if (event
.xclient
.message_type
9184 == dpyinfo
->Xatom_Scrollbar
)
9186 x_scroll_bar_to_input_event (&event
, bufp
);
9187 ++bufp
, ++count
, --numchars
;
9190 #endif /* USE_TOOLKIT_SCROLL_BARS */
9196 case SelectionNotify
:
9197 #ifdef USE_X_TOOLKIT
9198 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9200 #endif /* not USE_X_TOOLKIT */
9201 x_handle_selection_notify (&event
.xselection
);
9204 case SelectionClear
: /* Someone has grabbed ownership. */
9205 #ifdef USE_X_TOOLKIT
9206 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9208 #endif /* USE_X_TOOLKIT */
9210 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9215 bufp
->kind
= selection_clear_event
;
9216 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9217 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9218 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9219 bufp
->frame_or_window
= Qnil
;
9227 case SelectionRequest
: /* Someone wants our selection. */
9228 #ifdef USE_X_TOOLKIT
9229 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9231 #endif /* USE_X_TOOLKIT */
9232 if (x_queue_selection_requests
)
9233 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9237 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9242 bufp
->kind
= selection_request_event
;
9243 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9244 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9245 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9246 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9247 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9248 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9249 bufp
->frame_or_window
= Qnil
;
9257 case PropertyNotify
:
9258 #ifdef USE_X_TOOLKIT
9259 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9261 #endif /* not USE_X_TOOLKIT */
9262 x_handle_property_notify (&event
.xproperty
);
9265 case ReparentNotify
:
9266 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9270 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9271 x_real_positions (f
, &x
, &y
);
9272 f
->output_data
.x
->left_pos
= x
;
9273 f
->output_data
.x
->top_pos
= y
;
9278 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9281 if (f
->async_visible
== 0)
9283 f
->async_visible
= 1;
9284 f
->async_iconified
= 0;
9285 f
->output_data
.x
->has_been_visible
= 1;
9286 SET_FRAME_GARBAGED (f
);
9289 expose_frame (x_window_to_frame (dpyinfo
,
9290 event
.xexpose
.window
),
9291 event
.xexpose
.x
, event
.xexpose
.y
,
9292 event
.xexpose
.width
, event
.xexpose
.height
);
9296 #ifdef USE_TOOLKIT_SCROLL_BARS
9297 /* Dispatch event to the widget. */
9299 #else /* not USE_TOOLKIT_SCROLL_BARS */
9300 struct scroll_bar
*bar
9301 = x_window_to_scroll_bar (event
.xexpose
.window
);
9304 x_scroll_bar_expose (bar
, &event
);
9305 #ifdef USE_X_TOOLKIT
9308 #endif /* USE_X_TOOLKIT */
9309 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9313 case GraphicsExpose
: /* This occurs when an XCopyArea's
9314 source area was obscured or not
9316 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9320 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9321 event
.xgraphicsexpose
.width
,
9322 event
.xgraphicsexpose
.height
);
9324 #ifdef USE_X_TOOLKIT
9327 #endif /* USE_X_TOOLKIT */
9330 case NoExpose
: /* This occurs when an XCopyArea's
9331 source area was completely
9336 /* Redo the mouse-highlight after the tooltip has gone. */
9337 if (event
.xmap
.window
== tip_window
)
9340 redo_mouse_highlight ();
9343 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9344 if (f
) /* F may no longer exist if
9345 the frame was deleted. */
9347 /* While a frame is unmapped, display generation is
9348 disabled; you don't want to spend time updating a
9349 display that won't ever be seen. */
9350 f
->async_visible
= 0;
9351 /* We can't distinguish, from the event, whether the window
9352 has become iconified or invisible. So assume, if it
9353 was previously visible, than now it is iconified.
9354 But x_make_frame_invisible clears both
9355 the visible flag and the iconified flag;
9356 and that way, we know the window is not iconified now. */
9357 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9359 f
->async_iconified
= 1;
9361 bufp
->kind
= iconify_event
;
9362 XSETFRAME (bufp
->frame_or_window
, f
);
9371 if (event
.xmap
.window
== tip_window
)
9372 /* The tooltip has been drawn already. Avoid
9373 the SET_FRAME_GARBAGED below. */
9376 /* We use x_top_window_to_frame because map events can
9377 come for sub-windows and they don't mean that the
9378 frame is visible. */
9379 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9382 f
->async_visible
= 1;
9383 f
->async_iconified
= 0;
9384 f
->output_data
.x
->has_been_visible
= 1;
9386 /* wait_reading_process_input will notice this and update
9387 the frame's display structures. */
9388 SET_FRAME_GARBAGED (f
);
9392 bufp
->kind
= deiconify_event
;
9393 XSETFRAME (bufp
->frame_or_window
, f
);
9398 else if (! NILP (Vframe_list
)
9399 && ! NILP (XCDR (Vframe_list
)))
9400 /* Force a redisplay sooner or later
9401 to update the frame titles
9402 in case this is the second frame. */
9403 record_asynch_buffer_change ();
9408 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9411 /* I couldn't find a way to prevent LessTif scroll bars
9412 from consuming key events. */
9415 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9417 if (widget
&& XmIsScrollBar (widget
))
9419 widget
= XtParent (widget
);
9420 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9423 #endif /* USE_MOTIF */
9427 KeySym keysym
, orig_keysym
;
9428 /* al%imercury@uunet.uu.net says that making this 81 instead of
9429 80 fixed a bug whereby meta chars made his Emacs hang. */
9430 unsigned char copy_buffer
[81];
9434 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9435 extra_keyboard_modifiers
);
9436 modifiers
= event
.xkey
.state
;
9438 /* This will have to go some day... */
9440 /* make_lispy_event turns chars into control chars.
9441 Don't do it here because XLookupString is too eager. */
9442 event
.xkey
.state
&= ~ControlMask
;
9443 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9444 | dpyinfo
->super_mod_mask
9445 | dpyinfo
->hyper_mod_mask
9446 | dpyinfo
->alt_mod_mask
);
9448 /* In case Meta is ComposeCharacter,
9449 clear its status. According to Markus Ehrnsperger
9450 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9451 this enables ComposeCharacter to work whether or
9452 not it is combined with Meta. */
9453 if (modifiers
& dpyinfo
->meta_mod_mask
)
9454 bzero (&compose_status
, sizeof (compose_status
));
9459 unsigned char *copy_bufptr
= copy_buffer
;
9460 int copy_bufsiz
= sizeof (copy_buffer
);
9461 Status status_return
;
9463 nbytes
= XmbLookupString (FRAME_XIC (f
),
9464 &event
.xkey
, copy_bufptr
,
9465 copy_bufsiz
, &keysym
,
9467 if (status_return
== XBufferOverflow
)
9469 copy_bufsiz
= nbytes
+ 1;
9470 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9471 nbytes
= XmbLookupString (FRAME_XIC (f
),
9472 &event
.xkey
, copy_bufptr
,
9473 copy_bufsiz
, &keysym
,
9477 if (status_return
== XLookupNone
)
9479 else if (status_return
== XLookupChars
)
9484 else if (status_return
!= XLookupKeySym
9485 && status_return
!= XLookupBoth
)
9489 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9490 80, &keysym
, &compose_status
);
9492 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9493 80, &keysym
, &compose_status
);
9496 orig_keysym
= keysym
;
9500 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9501 || keysym
== XK_Delete
9502 #ifdef XK_ISO_Left_Tab
9503 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9505 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9506 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9507 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9509 /* This recognizes the "extended function keys".
9510 It seems there's no cleaner way.
9511 Test IsModifierKey to avoid handling mode_switch
9513 || ((unsigned) (keysym
) >= XK_Select
9514 && (unsigned)(keysym
) < XK_KP_Space
)
9516 #ifdef XK_dead_circumflex
9517 || orig_keysym
== XK_dead_circumflex
9519 #ifdef XK_dead_grave
9520 || orig_keysym
== XK_dead_grave
9522 #ifdef XK_dead_tilde
9523 || orig_keysym
== XK_dead_tilde
9525 #ifdef XK_dead_diaeresis
9526 || orig_keysym
== XK_dead_diaeresis
9528 #ifdef XK_dead_macron
9529 || orig_keysym
== XK_dead_macron
9531 #ifdef XK_dead_degree
9532 || orig_keysym
== XK_dead_degree
9534 #ifdef XK_dead_acute
9535 || orig_keysym
== XK_dead_acute
9537 #ifdef XK_dead_cedilla
9538 || orig_keysym
== XK_dead_cedilla
9540 #ifdef XK_dead_breve
9541 || orig_keysym
== XK_dead_breve
9543 #ifdef XK_dead_ogonek
9544 || orig_keysym
== XK_dead_ogonek
9546 #ifdef XK_dead_caron
9547 || orig_keysym
== XK_dead_caron
9549 #ifdef XK_dead_doubleacute
9550 || orig_keysym
== XK_dead_doubleacute
9552 #ifdef XK_dead_abovedot
9553 || orig_keysym
== XK_dead_abovedot
9555 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9556 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9557 /* Any "vendor-specific" key is ok. */
9558 || (orig_keysym
& (1 << 28)))
9559 && ! (IsModifierKey (orig_keysym
)
9561 #ifdef XK_Mode_switch
9562 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9565 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9567 #endif /* not HAVE_X11R5 */
9570 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9572 temp_buffer
[temp_index
++] = keysym
;
9573 bufp
->kind
= non_ascii_keystroke
;
9574 bufp
->code
= keysym
;
9575 XSETFRAME (bufp
->frame_or_window
, f
);
9577 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9579 bufp
->timestamp
= event
.xkey
.time
;
9584 else if (numchars
> nbytes
)
9588 for (i
= 0; i
< nbytes
; i
++)
9590 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9592 temp_buffer
[temp_index
++] = copy_buffer
[i
];
9593 bufp
->kind
= ascii_keystroke
;
9594 bufp
->code
= copy_buffer
[i
];
9595 XSETFRAME (bufp
->frame_or_window
, f
);
9597 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9599 bufp
->timestamp
= event
.xkey
.time
;
9606 if (keysym
== NoSymbol
)
9616 /* Don't dispatch this event since XtDispatchEvent calls
9617 XFilterEvent, and two calls in a row may freeze the
9626 /* Don't dispatch this event since XtDispatchEvent calls
9627 XFilterEvent, and two calls in a row may freeze the
9634 /* Here's a possible interpretation of the whole
9635 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9636 you get a FocusIn event, you have to get a FocusOut
9637 event before you relinquish the focus. If you
9638 haven't received a FocusIn event, then a mere
9639 LeaveNotify is enough to free you. */
9643 int from_menu_bar_p
= 0;
9645 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9647 #ifdef LESSTIF_VERSION
9648 /* When clicking outside of a menu bar popup to close
9649 it, we get a FocusIn/ EnterNotify sequence of
9650 events. The flag event.xcrossing.focus is not set
9651 in the EnterNotify event of that sequence because
9652 the focus is in the menu bar,
9653 event.xcrossing.window is the frame's X window.
9654 Unconditionally setting the focus frame to null in
9655 this case is not the right thing, because no event
9656 follows that could set the focus frame to the right
9659 This could be a LessTif bug, but I wasn't able to
9660 reproduce the behavior in a simple test program.
9662 (gerd, LessTif 0.88.1). */
9664 if (!event
.xcrossing
.focus
9666 && f
->output_data
.x
->menubar_widget
)
9671 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9672 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9673 from_menu_bar_p
= 1;
9675 #endif /* LESSTIF_VERSION */
9677 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9679 /* Avoid nasty pop/raise loops. */
9680 if (f
&& (!(f
->auto_raise
)
9682 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9684 x_new_focus_frame (dpyinfo
, f
);
9685 enter_timestamp
= event
.xcrossing
.time
;
9688 else if (f
== dpyinfo
->x_focus_frame
)
9689 x_new_focus_frame (dpyinfo
, 0);
9691 /* EnterNotify counts as mouse movement,
9692 so update things that depend on mouse position. */
9693 if (f
&& !f
->output_data
.x
->busy_p
)
9694 note_mouse_movement (f
, &event
.xmotion
);
9699 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9700 if (event
.xfocus
.detail
!= NotifyPointer
)
9701 dpyinfo
->x_focus_event_frame
= f
;
9704 x_new_focus_frame (dpyinfo
, f
);
9706 /* Don't stop displaying the initial startup message
9707 for a switch-frame event we don't need. */
9708 if (GC_NILP (Vterminal_frame
)
9709 && GC_CONSP (Vframe_list
)
9710 && !GC_NILP (XCDR (Vframe_list
)))
9712 bufp
->kind
= FOCUS_IN_EVENT
;
9713 XSETFRAME (bufp
->frame_or_window
, f
);
9714 ++bufp
, ++count
, --numchars
;
9719 if (f
&& FRAME_XIC (f
))
9720 XSetICFocus (FRAME_XIC (f
));
9726 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9730 int from_menu_bar_p
= 0;
9732 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9734 /* If we move outside the frame, then we're
9735 certainly no longer on any text in the frame. */
9736 clear_mouse_face (dpyinfo
);
9737 dpyinfo
->mouse_face_mouse_frame
= 0;
9740 /* Generate a nil HELP_EVENT to cancel a help-echo.
9741 Do it only if there's something to cancel.
9742 Otherwise, the startup message is cleared when
9743 the mouse leaves the frame. */
9744 if (any_help_event_p
)
9746 XSETFRAME (frame
, f
);
9747 bufp
->kind
= HELP_EVENT
;
9748 bufp
->frame_or_window
= Fcons (frame
, Qnil
);
9749 ++bufp
, ++count
, --numchars
;
9752 #ifdef LESSTIF_VERSION
9753 /* Please see the comment at the start of the
9754 EnterNotify case. */
9755 if (!event
.xcrossing
.focus
9756 && f
->output_data
.x
->menubar_widget
)
9760 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9761 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9762 from_menu_bar_p
= 1;
9764 #endif /* LESSTIF_VERSION */
9766 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9767 x_mouse_leave (dpyinfo
);
9770 if (f
== dpyinfo
->x_focus_event_frame
)
9771 dpyinfo
->x_focus_event_frame
= 0;
9772 if (f
== dpyinfo
->x_focus_frame
)
9773 x_new_focus_frame (dpyinfo
, 0);
9779 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9780 if (event
.xfocus
.detail
!= NotifyPointer
9781 && f
== dpyinfo
->x_focus_event_frame
)
9782 dpyinfo
->x_focus_event_frame
= 0;
9783 if (f
&& f
== dpyinfo
->x_focus_frame
)
9784 x_new_focus_frame (dpyinfo
, 0);
9787 if (f
&& FRAME_XIC (f
))
9788 XUnsetICFocus (FRAME_XIC (f
));
9795 previous_help_echo
= help_echo
;
9798 if (dpyinfo
->grabbed
&& last_mouse_frame
9799 && FRAME_LIVE_P (last_mouse_frame
))
9800 f
= last_mouse_frame
;
9802 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9805 note_mouse_movement (f
, &event
.xmotion
);
9808 #ifndef USE_TOOLKIT_SCROLL_BARS
9809 struct scroll_bar
*bar
9810 = x_window_to_scroll_bar (event
.xmotion
.window
);
9813 x_scroll_bar_note_movement (bar
, &event
);
9814 #endif /* USE_TOOLKIT_SCROLL_BARS */
9816 /* If we move outside the frame, then we're
9817 certainly no longer on any text in the frame. */
9818 clear_mouse_face (dpyinfo
);
9821 /* If the contents of the global variable help_echo
9822 has changed, generate a HELP_EVENT. */
9823 if (!NILP (help_echo
)
9824 || !NILP (previous_help_echo
))
9829 XSETFRAME (frame
, f
);
9833 any_help_event_p
= 1;
9834 bufp
->kind
= HELP_EVENT
;
9835 bufp
->frame_or_window
= Fcons (frame
, help_echo
);
9836 ++bufp
, ++count
, --numchars
;
9842 case ConfigureNotify
:
9843 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
9846 #ifndef USE_X_TOOLKIT
9847 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
9848 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
9850 /* In the toolkit version, change_frame_size
9851 is called by the code that handles resizing
9852 of the EmacsFrame widget. */
9854 /* Even if the number of character rows and columns has
9855 not changed, the font size may have changed, so we need
9856 to check the pixel dimensions as well. */
9857 if (columns
!= f
->width
9858 || rows
!= f
->height
9859 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
9860 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
9862 change_frame_size (f
, rows
, columns
, 0, 1, 0);
9863 SET_FRAME_GARBAGED (f
);
9864 cancel_mouse_face (f
);
9868 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
9869 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
9871 /* What we have now is the position of Emacs's own window.
9872 Convert that to the position of the window manager window. */
9873 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
9874 &f
->output_data
.x
->top_pos
);
9877 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
9878 xic_set_statusarea (f
);
9881 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
9883 /* Since the WM decorations come below top_pos now,
9884 we must put them below top_pos in the future. */
9885 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
9886 x_wm_set_size_hint (f
, (long) 0, 0);
9889 /* Some window managers pass (0,0) as the location of
9890 the window, and the Motif event handler stores it
9891 in the emacs widget, which messes up Motif menus. */
9892 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
9894 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
9895 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
9897 #endif /* USE_MOTIF */
9904 /* If we decide we want to generate an event to be seen
9905 by the rest of Emacs, we put it here. */
9906 struct input_event emacs_event
;
9909 emacs_event
.kind
= no_event
;
9910 bzero (&compose_status
, sizeof (compose_status
));
9912 if (dpyinfo
->grabbed
9914 && FRAME_LIVE_P (last_mouse_frame
))
9915 f
= last_mouse_frame
;
9917 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9921 /* Is this in the tool-bar? */
9922 if (WINDOWP (f
->tool_bar_window
)
9923 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
9928 x
= event
.xbutton
.x
;
9929 y
= event
.xbutton
.y
;
9932 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
9933 if (EQ (window
, f
->tool_bar_window
))
9935 x_handle_tool_bar_click (f
, &event
.xbutton
);
9941 if (!dpyinfo
->x_focus_frame
9942 || f
== dpyinfo
->x_focus_frame
)
9943 construct_mouse_click (&emacs_event
, &event
, f
);
9947 #ifndef USE_TOOLKIT_SCROLL_BARS
9948 struct scroll_bar
*bar
9949 = x_window_to_scroll_bar (event
.xbutton
.window
);
9952 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
9953 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9956 if (event
.type
== ButtonPress
)
9958 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
9959 last_mouse_frame
= f
;
9960 /* Ignore any mouse motion that happened
9961 before this event; any subsequent mouse-movement
9962 Emacs events should reflect only motion after
9968 last_tool_bar_item
= -1;
9972 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
9975 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
9977 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
9983 #ifdef USE_X_TOOLKIT
9984 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9985 /* For a down-event in the menu bar,
9986 don't pass it to Xt right now.
9987 Instead, save it away
9988 and we will pass it to Xt from kbd_buffer_get_event.
9989 That way, we can run some Lisp code first. */
9990 if (f
&& event
.type
== ButtonPress
9991 /* Verify the event is really within the menu bar
9992 and not just sent to it due to grabbing. */
9993 && event
.xbutton
.x
>= 0
9994 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
9995 && event
.xbutton
.y
>= 0
9996 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
9997 && event
.xbutton
.same_screen
)
9999 SET_SAVED_BUTTON_EVENT
;
10000 XSETFRAME (last_mouse_press_frame
, f
);
10002 else if (event
.type
== ButtonPress
)
10004 last_mouse_press_frame
= Qnil
;
10008 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10009 but I am trying to be cautious. */
10010 else if (event
.type
== ButtonRelease
)
10012 if (!NILP (last_mouse_press_frame
))
10014 f
= XFRAME (last_mouse_press_frame
);
10015 if (f
->output_data
.x
)
10016 SET_SAVED_BUTTON_EVENT
;
10021 #endif /* USE_MOTIF */
10024 #endif /* USE_X_TOOLKIT */
10028 case CirculateNotify
:
10031 case CirculateRequest
:
10034 case VisibilityNotify
:
10037 case MappingNotify
:
10038 /* Someone has changed the keyboard mapping - update the
10040 switch (event
.xmapping
.request
)
10042 case MappingModifier
:
10043 x_find_modifier_meanings (dpyinfo
);
10044 /* This is meant to fall through. */
10045 case MappingKeyboard
:
10046 XRefreshKeyboardMapping (&event
.xmapping
);
10052 #ifdef USE_X_TOOLKIT
10054 XtDispatchEvent (&event
);
10056 #endif /* USE_X_TOOLKIT */
10064 /* On some systems, an X bug causes Emacs to get no more events
10065 when the window is destroyed. Detect that. (1994.) */
10068 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10069 One XNOOP in 100 loops will make Emacs terminate.
10070 B. Bretthauer, 1994 */
10072 if (x_noop_count
>= 100)
10076 if (next_noop_dpyinfo
== 0)
10077 next_noop_dpyinfo
= x_display_list
;
10079 XNoOp (next_noop_dpyinfo
->display
);
10081 /* Each time we get here, cycle through the displays now open. */
10082 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10086 /* If the focus was just given to an auto-raising frame,
10088 /* ??? This ought to be able to handle more than one such frame. */
10089 if (pending_autoraise_frame
)
10091 x_raise_frame (pending_autoraise_frame
);
10092 pending_autoraise_frame
= 0;
10103 /***********************************************************************
10105 ***********************************************************************/
10107 /* Note if the text cursor of window W has been overwritten by a
10108 drawing operation that outputs N glyphs starting at HPOS in the
10109 line given by output_cursor.vpos. N < 0 means all the rest of the
10110 line after HPOS has been written. */
10113 note_overwritten_text_cursor (w
, hpos
, n
)
10117 if (updated_area
== TEXT_AREA
10118 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10119 && hpos
<= w
->phys_cursor
.hpos
10121 || hpos
+ n
> w
->phys_cursor
.hpos
))
10122 w
->phys_cursor_on_p
= 0;
10126 /* Set clipping for output in glyph row ROW. W is the window in which
10127 we operate. GC is the graphics context to set clipping in.
10128 WHOLE_LINE_P non-zero means include the areas used for truncation
10129 mark display and alike in the clipping rectangle.
10131 ROW may be a text row or, e.g., a mode line. Text rows must be
10132 clipped to the interior of the window dedicated to text display,
10133 mode lines must be clipped to the whole window. */
10136 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10138 struct glyph_row
*row
;
10142 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10143 XRectangle clip_rect
;
10144 int window_x
, window_y
, window_width
, window_height
;
10146 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10148 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10149 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10150 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10151 clip_rect
.width
= window_width
;
10152 clip_rect
.height
= row
->visible_height
;
10154 /* If clipping to the whole line, including trunc marks, extend
10155 the rectangle to the left and increase its width. */
10158 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10159 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10162 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10166 /* Draw a hollow box cursor on window W in glyph row ROW. */
10169 x_draw_hollow_cursor (w
, row
)
10171 struct glyph_row
*row
;
10173 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10174 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10175 Display
*dpy
= FRAME_X_DISPLAY (f
);
10178 struct glyph
*cursor_glyph
;
10181 /* Compute frame-relative coordinates from window-relative
10183 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10184 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10185 + row
->ascent
- w
->phys_cursor_ascent
);
10186 h
= row
->height
- 1;
10188 /* Get the glyph the cursor is on. If we can't tell because
10189 the current matrix is invalid or such, give up. */
10190 cursor_glyph
= get_phys_cursor_glyph (w
);
10191 if (cursor_glyph
== NULL
)
10194 /* Compute the width of the rectangle to draw. If on a stretch
10195 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10196 rectangle as wide as the glyph, but use a canonical character
10198 wd
= cursor_glyph
->pixel_width
- 1;
10199 if (cursor_glyph
->type
== STRETCH_GLYPH
10200 && !x_stretch_cursor_p
)
10201 wd
= min (CANON_X_UNIT (f
), wd
);
10203 /* The foreground of cursor_gc is typically the same as the normal
10204 background color, which can cause the cursor box to be invisible. */
10205 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10206 if (dpyinfo
->scratch_cursor_gc
)
10207 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10209 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10210 GCForeground
, &xgcv
);
10211 gc
= dpyinfo
->scratch_cursor_gc
;
10213 /* Set clipping, draw the rectangle, and reset clipping again. */
10214 x_clip_to_row (w
, row
, gc
, 0);
10215 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10216 XSetClipMask (dpy
, gc
, None
);
10220 /* Draw a bar cursor on window W in glyph row ROW.
10222 Implementation note: One would like to draw a bar cursor with an
10223 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10224 Unfortunately, I didn't find a font yet that has this property set.
10228 x_draw_bar_cursor (w
, row
, width
)
10230 struct glyph_row
*row
;
10233 /* If cursor hpos is out of bounds, don't draw garbage. This can
10234 happen in mini-buffer windows when switching between echo area
10235 glyphs and mini-buffer. */
10236 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10238 struct frame
*f
= XFRAME (w
->frame
);
10239 struct glyph
*cursor_glyph
;
10242 unsigned long mask
;
10247 cursor_glyph
= get_phys_cursor_glyph (w
);
10248 if (cursor_glyph
== NULL
)
10251 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10252 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10253 xgcv
.graphics_exposures
= 0;
10254 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10255 dpy
= FRAME_X_DISPLAY (f
);
10256 window
= FRAME_X_WINDOW (f
);
10257 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10260 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10263 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10264 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10268 width
= f
->output_data
.x
->cursor_width
;
10270 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10271 x_clip_to_row (w
, row
, gc
, 0);
10272 XFillRectangle (dpy
, window
, gc
,
10274 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10275 min (cursor_glyph
->pixel_width
, width
),
10277 XSetClipMask (dpy
, gc
, None
);
10282 /* Clear the cursor of window W to background color, and mark the
10283 cursor as not shown. This is used when the text where the cursor
10284 is is about to be rewritten. */
10290 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10291 x_update_window_cursor (w
, 0);
10295 /* Draw the cursor glyph of window W in glyph row ROW. See the
10296 comment of x_draw_glyphs for the meaning of HL. */
10299 x_draw_phys_cursor_glyph (w
, row
, hl
)
10301 struct glyph_row
*row
;
10302 enum draw_glyphs_face hl
;
10304 /* If cursor hpos is out of bounds, don't draw garbage. This can
10305 happen in mini-buffer windows when switching between echo area
10306 glyphs and mini-buffer. */
10307 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10309 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10310 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10313 /* When we erase the cursor, and ROW is overlapped by other
10314 rows, make sure that these overlapping parts of other rows
10316 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10318 if (row
> w
->current_matrix
->rows
10319 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10320 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10322 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10323 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10324 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10330 /* Erase the image of a cursor of window W from the screen. */
10333 x_erase_phys_cursor (w
)
10336 struct frame
*f
= XFRAME (w
->frame
);
10337 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10338 int hpos
= w
->phys_cursor
.hpos
;
10339 int vpos
= w
->phys_cursor
.vpos
;
10340 int mouse_face_here_p
= 0;
10341 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10342 struct glyph_row
*cursor_row
;
10343 struct glyph
*cursor_glyph
;
10344 enum draw_glyphs_face hl
;
10346 /* No cursor displayed or row invalidated => nothing to do on the
10348 if (w
->phys_cursor_type
== NO_CURSOR
)
10349 goto mark_cursor_off
;
10351 /* VPOS >= active_glyphs->nrows means that window has been resized.
10352 Don't bother to erase the cursor. */
10353 if (vpos
>= active_glyphs
->nrows
)
10354 goto mark_cursor_off
;
10356 /* If row containing cursor is marked invalid, there is nothing we
10358 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10359 if (!cursor_row
->enabled_p
)
10360 goto mark_cursor_off
;
10362 /* This can happen when the new row is shorter than the old one.
10363 In this case, either x_draw_glyphs or clear_end_of_line
10364 should have cleared the cursor. Note that we wouldn't be
10365 able to erase the cursor in this case because we don't have a
10366 cursor glyph at hand. */
10367 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10368 goto mark_cursor_off
;
10370 /* If the cursor is in the mouse face area, redisplay that when
10371 we clear the cursor. */
10372 if (! NILP (dpyinfo
->mouse_face_window
)
10373 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10374 && (vpos
> dpyinfo
->mouse_face_beg_row
10375 || (vpos
== dpyinfo
->mouse_face_beg_row
10376 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10377 && (vpos
< dpyinfo
->mouse_face_end_row
10378 || (vpos
== dpyinfo
->mouse_face_end_row
10379 && hpos
< dpyinfo
->mouse_face_end_col
))
10380 /* Don't redraw the cursor's spot in mouse face if it is at the
10381 end of a line (on a newline). The cursor appears there, but
10382 mouse highlighting does not. */
10383 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10384 mouse_face_here_p
= 1;
10386 /* Maybe clear the display under the cursor. */
10387 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10390 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10392 cursor_glyph
= get_phys_cursor_glyph (w
);
10393 if (cursor_glyph
== NULL
)
10394 goto mark_cursor_off
;
10396 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10398 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10400 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10402 cursor_glyph
->pixel_width
,
10403 cursor_row
->visible_height
,
10407 /* Erase the cursor by redrawing the character underneath it. */
10408 if (mouse_face_here_p
)
10409 hl
= DRAW_MOUSE_FACE
;
10410 else if (cursor_row
->inverse_p
)
10411 hl
= DRAW_INVERSE_VIDEO
;
10413 hl
= DRAW_NORMAL_TEXT
;
10414 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10417 w
->phys_cursor_on_p
= 0;
10418 w
->phys_cursor_type
= NO_CURSOR
;
10422 /* Display or clear cursor of window W. If ON is zero, clear the
10423 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10424 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10427 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10429 int on
, hpos
, vpos
, x
, y
;
10431 struct frame
*f
= XFRAME (w
->frame
);
10432 int new_cursor_type
;
10433 int new_cursor_width
;
10434 struct glyph_matrix
*current_glyphs
;
10435 struct glyph_row
*glyph_row
;
10436 struct glyph
*glyph
;
10438 /* This is pointless on invisible frames, and dangerous on garbaged
10439 windows and frames; in the latter case, the frame or window may
10440 be in the midst of changing its size, and x and y may be off the
10442 if (! FRAME_VISIBLE_P (f
)
10443 || FRAME_GARBAGED_P (f
)
10444 || vpos
>= w
->current_matrix
->nrows
10445 || hpos
>= w
->current_matrix
->matrix_w
)
10448 /* If cursor is off and we want it off, return quickly. */
10449 if (!on
&& !w
->phys_cursor_on_p
)
10452 current_glyphs
= w
->current_matrix
;
10453 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10454 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10456 /* If cursor row is not enabled, we don't really know where to
10457 display the cursor. */
10458 if (!glyph_row
->enabled_p
)
10460 w
->phys_cursor_on_p
= 0;
10464 xassert (interrupt_input_blocked
);
10466 /* Set new_cursor_type to the cursor we want to be displayed. In a
10467 mini-buffer window, we want the cursor only to appear if we are
10468 reading input from this window. For the selected window, we want
10469 the cursor type given by the frame parameter. If explicitly
10470 marked off, draw no cursor. In all other cases, we want a hollow
10472 new_cursor_width
= -1;
10473 if (cursor_in_echo_area
10474 && FRAME_HAS_MINIBUF_P (f
)
10475 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10477 if (w
== XWINDOW (echo_area_window
))
10478 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10480 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10484 if (w
!= XWINDOW (selected_window
)
10485 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10487 extern int cursor_in_non_selected_windows
;
10489 if (MINI_WINDOW_P (w
) || !cursor_in_non_selected_windows
)
10490 new_cursor_type
= NO_CURSOR
;
10492 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10494 else if (w
->cursor_off_p
)
10495 new_cursor_type
= NO_CURSOR
;
10498 struct buffer
*b
= XBUFFER (w
->buffer
);
10500 if (EQ (b
->cursor_type
, Qt
))
10501 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10503 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10504 &new_cursor_width
);
10508 /* If cursor is currently being shown and we don't want it to be or
10509 it is in the wrong place, or the cursor type is not what we want,
10511 if (w
->phys_cursor_on_p
10513 || w
->phys_cursor
.x
!= x
10514 || w
->phys_cursor
.y
!= y
10515 || new_cursor_type
!= w
->phys_cursor_type
))
10516 x_erase_phys_cursor (w
);
10518 /* If the cursor is now invisible and we want it to be visible,
10520 if (on
&& !w
->phys_cursor_on_p
)
10522 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10523 w
->phys_cursor_height
= glyph_row
->height
;
10525 /* Set phys_cursor_.* before x_draw_.* is called because some
10526 of them may need the information. */
10527 w
->phys_cursor
.x
= x
;
10528 w
->phys_cursor
.y
= glyph_row
->y
;
10529 w
->phys_cursor
.hpos
= hpos
;
10530 w
->phys_cursor
.vpos
= vpos
;
10531 w
->phys_cursor_type
= new_cursor_type
;
10532 w
->phys_cursor_on_p
= 1;
10534 switch (new_cursor_type
)
10536 case HOLLOW_BOX_CURSOR
:
10537 x_draw_hollow_cursor (w
, glyph_row
);
10540 case FILLED_BOX_CURSOR
:
10541 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10545 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10556 if (w
== XWINDOW (f
->selected_window
))
10557 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10558 xic_set_preeditarea (w
, x
, y
);
10563 if (updating_frame
!= f
)
10564 XFlush (FRAME_X_DISPLAY (f
));
10569 /* Display the cursor on window W, or clear it. X and Y are window
10570 relative pixel coordinates. HPOS and VPOS are glyph matrix
10571 positions. If W is not the selected window, display a hollow
10572 cursor. ON non-zero means display the cursor at X, Y which
10573 correspond to HPOS, VPOS, otherwise it is cleared. */
10576 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10578 int on
, hpos
, vpos
, x
, y
;
10581 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10586 /* Display the cursor on window W, or clear it, according to ON_P.
10587 Don't change the cursor's position. */
10590 x_update_cursor (f
, on_p
)
10593 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10597 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10598 in the window tree rooted at W. */
10601 x_update_cursor_in_window_tree (w
, on_p
)
10607 if (!NILP (w
->hchild
))
10608 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10609 else if (!NILP (w
->vchild
))
10610 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10612 x_update_window_cursor (w
, on_p
);
10614 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10619 /* Switch the display of W's cursor on or off, according to the value
10623 x_update_window_cursor (w
, on
)
10627 /* Don't update cursor in windows whose frame is in the process
10628 of being deleted. */
10629 if (w
->current_matrix
)
10632 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10633 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10643 /* Refresh bitmap kitchen sink icon for frame F
10644 when we get an expose event for it. */
10650 /* Normally, the window manager handles this function. */
10653 /* Make the x-window of frame F use the gnu icon bitmap. */
10656 x_bitmap_icon (f
, file
)
10662 if (FRAME_X_WINDOW (f
) == 0)
10665 /* Free up our existing icon bitmap if any. */
10666 if (f
->output_data
.x
->icon_bitmap
> 0)
10667 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10668 f
->output_data
.x
->icon_bitmap
= 0;
10670 if (STRINGP (file
))
10671 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10674 /* Create the GNU bitmap if necessary. */
10675 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10676 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10677 = x_create_bitmap_from_data (f
, gnu_bits
,
10678 gnu_width
, gnu_height
);
10680 /* The first time we create the GNU bitmap,
10681 this increments the ref-count one extra time.
10682 As a result, the GNU bitmap is never freed.
10683 That way, we don't have to worry about allocating it again. */
10684 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10686 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10689 x_wm_set_icon_pixmap (f
, bitmap_id
);
10690 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10696 /* Make the x-window of frame F use a rectangle with text.
10697 Use ICON_NAME as the text. */
10700 x_text_icon (f
, icon_name
)
10704 if (FRAME_X_WINDOW (f
) == 0)
10709 XTextProperty text
;
10710 text
.value
= (unsigned char *) icon_name
;
10711 text
.encoding
= XA_STRING
;
10713 text
.nitems
= strlen (icon_name
);
10714 #ifdef USE_X_TOOLKIT
10715 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10717 #else /* not USE_X_TOOLKIT */
10718 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10719 #endif /* not USE_X_TOOLKIT */
10721 #else /* not HAVE_X11R4 */
10722 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10723 #endif /* not HAVE_X11R4 */
10725 if (f
->output_data
.x
->icon_bitmap
> 0)
10726 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10727 f
->output_data
.x
->icon_bitmap
= 0;
10728 x_wm_set_icon_pixmap (f
, 0);
10733 #define X_ERROR_MESSAGE_SIZE 200
10735 /* If non-nil, this should be a string.
10736 It means catch X errors and store the error message in this string. */
10738 static Lisp_Object x_error_message_string
;
10740 /* An X error handler which stores the error message in
10741 x_error_message_string. This is called from x_error_handler if
10742 x_catch_errors is in effect. */
10745 x_error_catcher (display
, error
)
10747 XErrorEvent
*error
;
10749 XGetErrorText (display
, error
->error_code
,
10750 XSTRING (x_error_message_string
)->data
,
10751 X_ERROR_MESSAGE_SIZE
);
10754 /* Begin trapping X errors for display DPY. Actually we trap X errors
10755 for all displays, but DPY should be the display you are actually
10758 After calling this function, X protocol errors no longer cause
10759 Emacs to exit; instead, they are recorded in the string
10760 stored in x_error_message_string.
10762 Calling x_check_errors signals an Emacs error if an X error has
10763 occurred since the last call to x_catch_errors or x_check_errors.
10765 Calling x_uncatch_errors resumes the normal error handling. */
10767 void x_check_errors ();
10768 static Lisp_Object
x_catch_errors_unwind ();
10771 x_catch_errors (dpy
)
10774 int count
= specpdl_ptr
- specpdl
;
10776 /* Make sure any errors from previous requests have been dealt with. */
10777 XSync (dpy
, False
);
10779 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10781 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10782 XSTRING (x_error_message_string
)->data
[0] = 0;
10787 /* Unbind the binding that we made to check for X errors. */
10790 x_catch_errors_unwind (old_val
)
10791 Lisp_Object old_val
;
10793 x_error_message_string
= old_val
;
10797 /* If any X protocol errors have arrived since the last call to
10798 x_catch_errors or x_check_errors, signal an Emacs error using
10799 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10802 x_check_errors (dpy
, format
)
10806 /* Make sure to catch any errors incurred so far. */
10807 XSync (dpy
, False
);
10809 if (XSTRING (x_error_message_string
)->data
[0])
10810 error (format
, XSTRING (x_error_message_string
)->data
);
10813 /* Nonzero if we had any X protocol errors
10814 since we did x_catch_errors on DPY. */
10817 x_had_errors_p (dpy
)
10820 /* Make sure to catch any errors incurred so far. */
10821 XSync (dpy
, False
);
10823 return XSTRING (x_error_message_string
)->data
[0] != 0;
10826 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
10829 x_clear_errors (dpy
)
10832 XSTRING (x_error_message_string
)->data
[0] = 0;
10835 /* Stop catching X protocol errors and let them make Emacs die.
10836 DPY should be the display that was passed to x_catch_errors.
10837 COUNT should be the value that was returned by
10838 the corresponding call to x_catch_errors. */
10841 x_uncatch_errors (dpy
, count
)
10845 unbind_to (count
, Qnil
);
10849 static unsigned int x_wire_count
;
10852 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
10857 /* Handle SIGPIPE, which can happen when the connection to a server
10858 simply goes away. SIGPIPE is handled by x_connection_signal.
10859 Don't need to do anything, because the write which caused the
10860 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
10861 which will do the appropriate cleanup for us. */
10864 x_connection_signal (signalnum
) /* If we don't have an argument, */
10865 int signalnum
; /* some compilers complain in signal calls. */
10868 /* USG systems forget handlers when they are used;
10869 must reestablish each time */
10870 signal (signalnum
, x_connection_signal
);
10874 /* Handling X errors. */
10876 /* Handle the loss of connection to display DISPLAY. */
10879 x_connection_closed (display
, error_message
)
10881 char *error_message
;
10883 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
10884 Lisp_Object frame
, tail
;
10886 /* Indicate that this display is dead. */
10888 #if 0 /* Closing the display caused a bus error on OpenWindows. */
10889 #ifdef USE_X_TOOLKIT
10890 XtCloseDisplay (display
);
10895 dpyinfo
->display
= 0;
10897 /* First delete frames whose mini-buffers are on frames
10898 that are on the dead display. */
10899 FOR_EACH_FRAME (tail
, frame
)
10901 Lisp_Object minibuf_frame
;
10903 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
10904 if (FRAME_X_P (XFRAME (frame
))
10905 && FRAME_X_P (XFRAME (minibuf_frame
))
10906 && ! EQ (frame
, minibuf_frame
)
10907 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
10908 Fdelete_frame (frame
, Qt
);
10911 /* Now delete all remaining frames on the dead display.
10912 We are now sure none of these is used as the mini-buffer
10913 for another frame that we need to delete. */
10914 FOR_EACH_FRAME (tail
, frame
)
10915 if (FRAME_X_P (XFRAME (frame
))
10916 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
10918 /* Set this to t so that Fdelete_frame won't get confused
10919 trying to find a replacement. */
10920 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
10921 Fdelete_frame (frame
, Qt
);
10925 x_delete_display (dpyinfo
);
10927 if (x_display_list
== 0)
10929 fprintf (stderr
, "%s\n", error_message
);
10930 shut_down_emacs (0, 0, Qnil
);
10934 /* Ordinary stack unwind doesn't deal with these. */
10936 sigunblock (sigmask (SIGIO
));
10938 sigunblock (sigmask (SIGALRM
));
10939 TOTALLY_UNBLOCK_INPUT
;
10941 clear_waiting_for_input ();
10942 error ("%s", error_message
);
10945 /* This is the usual handler for X protocol errors.
10946 It kills all frames on the display that we got the error for.
10947 If that was the only one, it prints an error message and kills Emacs. */
10950 x_error_quitter (display
, error
)
10952 XErrorEvent
*error
;
10954 char buf
[256], buf1
[356];
10956 /* Note that there is no real way portable across R3/R4 to get the
10957 original error handler. */
10959 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
10960 sprintf (buf1
, "X protocol error: %s on protocol request %d",
10961 buf
, error
->request_code
);
10962 x_connection_closed (display
, buf1
);
10965 /* This is the first-level handler for X protocol errors.
10966 It calls x_error_quitter or x_error_catcher. */
10969 x_error_handler (display
, error
)
10971 XErrorEvent
*error
;
10973 if (! NILP (x_error_message_string
))
10974 x_error_catcher (display
, error
);
10976 x_error_quitter (display
, error
);
10980 /* This is the handler for X IO errors, always.
10981 It kills all frames on the display that we lost touch with.
10982 If that was the only one, it prints an error message and kills Emacs. */
10985 x_io_error_quitter (display
)
10990 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
10991 x_connection_closed (display
, buf
);
10995 /* Changing the font of the frame. */
10997 /* Give frame F the font named FONTNAME as its default font, and
10998 return the full name of that font. FONTNAME may be a wildcard
10999 pattern; in that case, we choose some font that fits the pattern.
11000 The return value shows which font we chose. */
11003 x_new_font (f
, fontname
)
11005 register char *fontname
;
11007 struct font_info
*fontp
11008 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11013 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11014 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11015 f
->output_data
.x
->fontset
= -1;
11017 /* Compute the scroll bar width in character columns. */
11018 if (f
->scroll_bar_pixel_width
> 0)
11020 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11021 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11025 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11026 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11029 /* Now make the frame display the given font. */
11030 if (FRAME_X_WINDOW (f
) != 0)
11032 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11033 f
->output_data
.x
->font
->fid
);
11034 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11035 f
->output_data
.x
->font
->fid
);
11036 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11037 f
->output_data
.x
->font
->fid
);
11039 frame_update_line_height (f
);
11040 x_set_window_size (f
, 0, f
->width
, f
->height
);
11043 /* If we are setting a new frame's font for the first time,
11044 there are no faces yet, so this font's height is the line height. */
11045 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11047 return build_string (fontp
->full_name
);
11050 /* Give frame F the fontset named FONTSETNAME as its default font, and
11051 return the full name of that fontset. FONTSETNAME may be a wildcard
11052 pattern; in that case, we choose some fontset that fits the pattern.
11053 The return value shows which fontset we chose. */
11056 x_new_fontset (f
, fontsetname
)
11060 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11061 Lisp_Object result
;
11066 if (f
->output_data
.x
->fontset
== fontset
)
11067 /* This fontset is already set in frame F. There's nothing more
11069 return fontset_name (fontset
);
11071 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11073 if (!STRINGP (result
))
11074 /* Can't load ASCII font. */
11077 /* Since x_new_font doesn't update any fontset information, do it now. */
11078 f
->output_data
.x
->fontset
= fontset
;
11082 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11083 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11086 return build_string (fontsetname
);
11090 /***********************************************************************
11092 ***********************************************************************/
11098 /* XIM destroy callback function, which is called whenever the
11099 connection to input method XIM dies. CLIENT_DATA contains a
11100 pointer to the x_display_info structure corresponding to XIM. */
11103 xim_destroy_callback (xim
, client_data
, call_data
)
11105 XPointer client_data
;
11106 XPointer call_data
;
11108 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11109 Lisp_Object frame
, tail
;
11113 /* No need to call XDestroyIC.. */
11114 FOR_EACH_FRAME (tail
, frame
)
11116 struct frame
*f
= XFRAME (frame
);
11117 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11119 FRAME_XIC (f
) = NULL
;
11120 if (FRAME_XIC_FONTSET (f
))
11122 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11123 FRAME_XIC_FONTSET (f
) = NULL
;
11128 /* No need to call XCloseIM. */
11129 dpyinfo
->xim
= NULL
;
11130 XFree (dpyinfo
->xim_styles
);
11134 #endif /* HAVE_X11R6 */
11136 /* Open the connection to the XIM server on display DPYINFO.
11137 RESOURCE_NAME is the resource name Emacs uses. */
11140 xim_open_dpy (dpyinfo
, resource_name
)
11141 struct x_display_info
*dpyinfo
;
11142 char *resource_name
;
11147 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11148 dpyinfo
->xim
= xim
;
11153 XIMCallback destroy
;
11156 /* Get supported styles and XIM values. */
11157 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11160 destroy
.callback
= xim_destroy_callback
;
11161 destroy
.client_data
= (XPointer
)dpyinfo
;
11162 /* This isn't prptotyped in OSF 5.0. */
11163 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11167 #else /* not USE_XIM */
11168 dpyinfo
->xim
= NULL
;
11169 #endif /* not USE_XIM */
11173 #ifdef HAVE_X11R6_XIM
11177 struct x_display_info
*dpyinfo
;
11178 char *resource_name
;
11181 /* XIM instantiate callback function, which is called whenever an XIM
11182 server is available. DISPLAY is teh display of the XIM.
11183 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11184 when the callback was registered. */
11187 xim_instantiate_callback (display
, client_data
, call_data
)
11189 XPointer client_data
;
11190 XPointer call_data
;
11192 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11193 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11195 /* We don't support multiple XIM connections. */
11199 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11201 /* Create XIC for the existing frames on the same display, as long
11202 as they have no XIC. */
11203 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11205 Lisp_Object tail
, frame
;
11208 FOR_EACH_FRAME (tail
, frame
)
11210 struct frame
*f
= XFRAME (frame
);
11212 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11213 if (FRAME_XIC (f
) == NULL
)
11215 create_frame_xic (f
);
11216 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11217 xic_set_statusarea (f
);
11218 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11220 struct window
*w
= XWINDOW (f
->selected_window
);
11221 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11230 #endif /* HAVE_X11R6_XIM */
11233 /* Open a connection to the XIM server on display DPYINFO.
11234 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11235 connection only at the first time. On X11R6, open the connection
11236 in the XIM instantiate callback function. */
11239 xim_initialize (dpyinfo
, resource_name
)
11240 struct x_display_info
*dpyinfo
;
11241 char *resource_name
;
11244 #ifdef HAVE_X11R6_XIM
11245 struct xim_inst_t
*xim_inst
;
11248 dpyinfo
->xim
= NULL
;
11249 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11250 xim_inst
->dpyinfo
= dpyinfo
;
11251 len
= strlen (resource_name
);
11252 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11253 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11254 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11255 resource_name
, EMACS_CLASS
,
11256 xim_instantiate_callback
,
11257 /* Fixme: This is XPointer in
11258 XFree86 but (XPointer *) on
11259 Tru64, at least. */
11260 (XPointer
) xim_inst
);
11261 #else /* not HAVE_X11R6_XIM */
11262 dpyinfo
->xim
= NULL
;
11263 xim_open_dpy (dpyinfo
, resource_name
);
11264 #endif /* not HAVE_X11R6_XIM */
11266 #else /* not USE_XIM */
11267 dpyinfo
->xim
= NULL
;
11268 #endif /* not USE_XIM */
11272 /* Close the connection to the XIM server on display DPYINFO. */
11275 xim_close_dpy (dpyinfo
)
11276 struct x_display_info
*dpyinfo
;
11279 #ifdef HAVE_X11R6_XIM
11280 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11282 xim_instantiate_callback
, NULL
);
11283 #endif /* not HAVE_X11R6_XIM */
11284 XCloseIM (dpyinfo
->xim
);
11285 dpyinfo
->xim
= NULL
;
11286 XFree (dpyinfo
->xim_styles
);
11287 #endif /* USE_XIM */
11290 #endif /* not HAVE_X11R6_XIM */
11294 /* Calculate the absolute position in frame F
11295 from its current recorded position values and gravity. */
11298 x_calc_absolute_position (f
)
11302 int win_x
= 0, win_y
= 0;
11303 int flags
= f
->output_data
.x
->size_hint_flags
;
11306 /* We have nothing to do if the current position
11307 is already for the top-left corner. */
11308 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11311 #ifdef USE_X_TOOLKIT
11312 this_window
= XtWindow (f
->output_data
.x
->widget
);
11314 this_window
= FRAME_X_WINDOW (f
);
11317 /* Find the position of the outside upper-left corner of
11318 the inner window, with respect to the outer window.
11319 But do this only if we will need the results. */
11320 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11325 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11328 x_clear_errors (FRAME_X_DISPLAY (f
));
11329 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11331 /* From-window, to-window. */
11333 f
->output_data
.x
->parent_desc
,
11335 /* From-position, to-position. */
11336 0, 0, &win_x
, &win_y
,
11338 /* Child of win. */
11340 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11342 Window newroot
, newparent
= 0xdeadbeef;
11343 Window
*newchildren
;
11344 unsigned int nchildren
;
11346 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11347 &newparent
, &newchildren
, &nchildren
))
11350 XFree ((char *) newchildren
);
11352 f
->output_data
.x
->parent_desc
= newparent
;
11358 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11362 /* Treat negative positions as relative to the leftmost bottommost
11363 position that fits on the screen. */
11364 if (flags
& XNegative
)
11365 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11366 - 2 * f
->output_data
.x
->border_width
- win_x
11368 + f
->output_data
.x
->left_pos
);
11370 if (flags
& YNegative
)
11372 int menubar_height
= 0;
11374 #ifdef USE_X_TOOLKIT
11375 if (f
->output_data
.x
->menubar_widget
)
11377 = (f
->output_data
.x
->menubar_widget
->core
.height
11378 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
11381 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11382 - 2 * f
->output_data
.x
->border_width
11386 + f
->output_data
.x
->top_pos
);
11389 /* The left_pos and top_pos
11390 are now relative to the top and left screen edges,
11391 so the flags should correspond. */
11392 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11395 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11396 to really change the position, and 0 when calling from
11397 x_make_frame_visible (in that case, XOFF and YOFF are the current
11398 position values). It is -1 when calling from x_set_frame_parameters,
11399 which means, do adjust for borders but don't change the gravity. */
11402 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11404 register int xoff
, yoff
;
11405 int change_gravity
;
11407 int modified_top
, modified_left
;
11409 if (change_gravity
> 0)
11411 f
->output_data
.x
->top_pos
= yoff
;
11412 f
->output_data
.x
->left_pos
= xoff
;
11413 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11415 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11417 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11418 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11420 x_calc_absolute_position (f
);
11423 x_wm_set_size_hint (f
, (long) 0, 0);
11425 modified_left
= f
->output_data
.x
->left_pos
;
11426 modified_top
= f
->output_data
.x
->top_pos
;
11427 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11428 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11429 /* It is a mystery why we need to add the border_width here
11430 when the frame is already visible, but experiment says we do. */
11431 if (change_gravity
!= 0)
11433 modified_left
+= f
->output_data
.x
->border_width
;
11434 modified_top
+= f
->output_data
.x
->border_width
;
11438 #ifdef USE_X_TOOLKIT
11439 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11440 modified_left
, modified_top
);
11441 #else /* not USE_X_TOOLKIT */
11442 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11443 modified_left
, modified_top
);
11444 #endif /* not USE_X_TOOLKIT */
11448 /* Call this to change the size of frame F's x-window.
11449 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11450 for this size change and subsequent size changes.
11451 Otherwise we leave the window gravity unchanged. */
11454 x_set_window_size (f
, change_gravity
, cols
, rows
)
11456 int change_gravity
;
11459 #ifndef USE_X_TOOLKIT
11460 int pixelwidth
, pixelheight
;
11465 #ifdef USE_X_TOOLKIT
11467 /* The x and y position of the widget is clobbered by the
11468 call to XtSetValues within EmacsFrameSetCharSize.
11469 This is a real kludge, but I don't understand Xt so I can't
11470 figure out a correct fix. Can anyone else tell me? -- rms. */
11471 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11472 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11473 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11474 f
->output_data
.x
->widget
->core
.x
= xpos
;
11475 f
->output_data
.x
->widget
->core
.y
= ypos
;
11478 #else /* not USE_X_TOOLKIT */
11480 check_frame_size (f
, &rows
, &cols
);
11481 f
->output_data
.x
->vertical_scroll_bar_extra
11482 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11484 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11485 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11486 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11487 f
->output_data
.x
->flags_areas_extra
11488 = FRAME_FLAGS_AREA_WIDTH (f
);
11489 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11490 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11492 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11493 x_wm_set_size_hint (f
, (long) 0, 0);
11495 XSync (FRAME_X_DISPLAY (f
), False
);
11496 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11497 pixelwidth
, pixelheight
);
11499 /* Now, strictly speaking, we can't be sure that this is accurate,
11500 but the window manager will get around to dealing with the size
11501 change request eventually, and we'll hear how it went when the
11502 ConfigureNotify event gets here.
11504 We could just not bother storing any of this information here,
11505 and let the ConfigureNotify event set everything up, but that
11506 might be kind of confusing to the Lisp code, since size changes
11507 wouldn't be reported in the frame parameters until some random
11508 point in the future when the ConfigureNotify event arrives.
11510 We pass 1 for DELAY since we can't run Lisp code inside of
11512 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11513 PIXEL_WIDTH (f
) = pixelwidth
;
11514 PIXEL_HEIGHT (f
) = pixelheight
;
11516 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11517 receive in the ConfigureNotify event; if we get what we asked
11518 for, then the event won't cause the screen to become garbaged, so
11519 we have to make sure to do it here. */
11520 SET_FRAME_GARBAGED (f
);
11522 XFlush (FRAME_X_DISPLAY (f
));
11524 #endif /* not USE_X_TOOLKIT */
11526 /* If cursor was outside the new size, mark it as off. */
11527 mark_window_cursors_off (XWINDOW (f
->root_window
));
11529 /* Clear out any recollection of where the mouse highlighting was,
11530 since it might be in a place that's outside the new frame size.
11531 Actually checking whether it is outside is a pain in the neck,
11532 so don't try--just let the highlighting be done afresh with new size. */
11533 cancel_mouse_face (f
);
11538 /* Mouse warping. */
11541 x_set_mouse_position (f
, x
, y
)
11547 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11548 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11550 if (pix_x
< 0) pix_x
= 0;
11551 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11553 if (pix_y
< 0) pix_y
= 0;
11554 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11558 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11559 0, 0, 0, 0, pix_x
, pix_y
);
11563 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11566 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11572 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11573 0, 0, 0, 0, pix_x
, pix_y
);
11577 /* focus shifting, raising and lowering. */
11580 x_focus_on_frame (f
)
11583 #if 0 /* This proves to be unpleasant. */
11587 /* I don't think that the ICCCM allows programs to do things like this
11588 without the interaction of the window manager. Whatever you end up
11589 doing with this code, do it to x_unfocus_frame too. */
11590 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11591 RevertToPointerRoot
, CurrentTime
);
11596 x_unfocus_frame (f
)
11600 /* Look at the remarks in x_focus_on_frame. */
11601 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11602 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11603 RevertToPointerRoot
, CurrentTime
);
11607 /* Raise frame F. */
11613 if (f
->async_visible
)
11616 #ifdef USE_X_TOOLKIT
11617 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11618 #else /* not USE_X_TOOLKIT */
11619 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11620 #endif /* not USE_X_TOOLKIT */
11621 XFlush (FRAME_X_DISPLAY (f
));
11626 /* Lower frame F. */
11632 if (f
->async_visible
)
11635 #ifdef USE_X_TOOLKIT
11636 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11637 #else /* not USE_X_TOOLKIT */
11638 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11639 #endif /* not USE_X_TOOLKIT */
11640 XFlush (FRAME_X_DISPLAY (f
));
11646 XTframe_raise_lower (f
, raise_flag
)
11656 /* Change of visibility. */
11658 /* This tries to wait until the frame is really visible.
11659 However, if the window manager asks the user where to position
11660 the frame, this will return before the user finishes doing that.
11661 The frame will not actually be visible at that time,
11662 but it will become visible later when the window manager
11663 finishes with it. */
11666 x_make_frame_visible (f
)
11670 int original_top
, original_left
;
11674 type
= x_icon_type (f
);
11676 x_bitmap_icon (f
, type
);
11678 if (! FRAME_VISIBLE_P (f
))
11680 /* We test FRAME_GARBAGED_P here to make sure we don't
11681 call x_set_offset a second time
11682 if we get to x_make_frame_visible a second time
11683 before the window gets really visible. */
11684 if (! FRAME_ICONIFIED_P (f
)
11685 && ! f
->output_data
.x
->asked_for_visible
)
11686 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11688 f
->output_data
.x
->asked_for_visible
= 1;
11690 if (! EQ (Vx_no_window_manager
, Qt
))
11691 x_wm_set_window_state (f
, NormalState
);
11692 #ifdef USE_X_TOOLKIT
11693 /* This was XtPopup, but that did nothing for an iconified frame. */
11694 XtMapWidget (f
->output_data
.x
->widget
);
11695 #else /* not USE_X_TOOLKIT */
11696 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11697 #endif /* not USE_X_TOOLKIT */
11698 #if 0 /* This seems to bring back scroll bars in the wrong places
11699 if the window configuration has changed. They seem
11700 to come back ok without this. */
11701 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11702 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11706 XFlush (FRAME_X_DISPLAY (f
));
11708 /* Synchronize to ensure Emacs knows the frame is visible
11709 before we do anything else. We do this loop with input not blocked
11710 so that incoming events are handled. */
11714 /* This must be before UNBLOCK_INPUT
11715 since events that arrive in response to the actions above
11716 will set it when they are handled. */
11717 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11719 original_left
= f
->output_data
.x
->left_pos
;
11720 original_top
= f
->output_data
.x
->top_pos
;
11722 /* This must come after we set COUNT. */
11725 /* We unblock here so that arriving X events are processed. */
11727 /* Now move the window back to where it was "supposed to be".
11728 But don't do it if the gravity is negative.
11729 When the gravity is negative, this uses a position
11730 that is 3 pixels too low. Perhaps that's really the border width.
11732 Don't do this if the window has never been visible before,
11733 because the window manager may choose the position
11734 and we don't want to override it. */
11736 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11737 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11738 && previously_visible
)
11742 unsigned int width
, height
, border
, depth
;
11746 /* On some window managers (such as FVWM) moving an existing
11747 window, even to the same place, causes the window manager
11748 to introduce an offset. This can cause the window to move
11749 to an unexpected location. Check the geometry (a little
11750 slow here) and then verify that the window is in the right
11751 place. If the window is not in the right place, move it
11752 there, and take the potential window manager hit. */
11753 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11754 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11756 if (original_left
!= x
|| original_top
!= y
)
11757 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11758 original_left
, original_top
);
11763 XSETFRAME (frame
, f
);
11765 /* Wait until the frame is visible. Process X events until a
11766 MapNotify event has been seen, or until we think we won't get a
11767 MapNotify at all.. */
11768 for (count
= input_signal_count
+ 10;
11769 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
11771 /* Force processing of queued events. */
11774 /* Machines that do polling rather than SIGIO have been
11775 observed to go into a busy-wait here. So we'll fake an
11776 alarm signal to let the handler know that there's something
11777 to be read. We used to raise a real alarm, but it seems
11778 that the handler isn't always enabled here. This is
11780 if (input_polling_used ())
11782 /* It could be confusing if a real alarm arrives while
11783 processing the fake one. Turn it off and let the
11784 handler reset it. */
11785 extern void poll_for_input_1
P_ ((void));
11786 int old_poll_suppress_count
= poll_suppress_count
;
11787 poll_suppress_count
= 1;
11788 poll_for_input_1 ();
11789 poll_suppress_count
= old_poll_suppress_count
;
11792 /* See if a MapNotify event has been processed. */
11793 FRAME_SAMPLE_VISIBILITY (f
);
11798 /* Change from mapped state to withdrawn state. */
11800 /* Make the frame visible (mapped and not iconified). */
11803 x_make_frame_invisible (f
)
11808 #ifdef USE_X_TOOLKIT
11809 /* Use the frame's outermost window, not the one we normally draw on. */
11810 window
= XtWindow (f
->output_data
.x
->widget
);
11811 #else /* not USE_X_TOOLKIT */
11812 window
= FRAME_X_WINDOW (f
);
11813 #endif /* not USE_X_TOOLKIT */
11815 /* Don't keep the highlight on an invisible frame. */
11816 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11817 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11819 #if 0/* This might add unreliability; I don't trust it -- rms. */
11820 if (! f
->async_visible
&& ! f
->async_iconified
)
11826 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11827 that the current position of the window is user-specified, rather than
11828 program-specified, so that when the window is mapped again, it will be
11829 placed at the same location, without forcing the user to position it
11830 by hand again (they have already done that once for this window.) */
11831 x_wm_set_size_hint (f
, (long) 0, 1);
11835 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11836 DefaultScreen (FRAME_X_DISPLAY (f
))))
11838 UNBLOCK_INPUT_RESIGNAL
;
11839 error ("Can't notify window manager of window withdrawal");
11841 #else /* ! defined (HAVE_X11R4) */
11843 /* Tell the window manager what we're going to do. */
11844 if (! EQ (Vx_no_window_manager
, Qt
))
11848 unmap
.xunmap
.type
= UnmapNotify
;
11849 unmap
.xunmap
.window
= window
;
11850 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
11851 unmap
.xunmap
.from_configure
= False
;
11852 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11853 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11855 SubstructureRedirectMaskSubstructureNotifyMask
,
11858 UNBLOCK_INPUT_RESIGNAL
;
11859 error ("Can't notify window manager of withdrawal");
11863 /* Unmap the window ourselves. Cheeky! */
11864 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
11865 #endif /* ! defined (HAVE_X11R4) */
11867 /* We can't distinguish this from iconification
11868 just by the event that we get from the server.
11869 So we can't win using the usual strategy of letting
11870 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11871 and synchronize with the server to make sure we agree. */
11873 FRAME_ICONIFIED_P (f
) = 0;
11874 f
->async_visible
= 0;
11875 f
->async_iconified
= 0;
11882 /* Change window state from mapped to iconified. */
11885 x_iconify_frame (f
)
11891 /* Don't keep the highlight on an invisible frame. */
11892 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11893 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11895 if (f
->async_iconified
)
11900 FRAME_SAMPLE_VISIBILITY (f
);
11902 type
= x_icon_type (f
);
11904 x_bitmap_icon (f
, type
);
11906 #ifdef USE_X_TOOLKIT
11908 if (! FRAME_VISIBLE_P (f
))
11910 if (! EQ (Vx_no_window_manager
, Qt
))
11911 x_wm_set_window_state (f
, IconicState
);
11912 /* This was XtPopup, but that did nothing for an iconified frame. */
11913 XtMapWidget (f
->output_data
.x
->widget
);
11914 /* The server won't give us any event to indicate
11915 that an invisible frame was changed to an icon,
11916 so we have to record it here. */
11919 f
->async_iconified
= 1;
11920 f
->async_visible
= 0;
11925 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11926 XtWindow (f
->output_data
.x
->widget
),
11927 DefaultScreen (FRAME_X_DISPLAY (f
)));
11931 error ("Can't notify window manager of iconification");
11933 f
->async_iconified
= 1;
11934 f
->async_visible
= 0;
11938 XFlush (FRAME_X_DISPLAY (f
));
11940 #else /* not USE_X_TOOLKIT */
11942 /* Make sure the X server knows where the window should be positioned,
11943 in case the user deiconifies with the window manager. */
11944 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
11945 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11947 /* Since we don't know which revision of X we're running, we'll use both
11948 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11950 /* X11R4: send a ClientMessage to the window manager using the
11951 WM_CHANGE_STATE type. */
11955 message
.xclient
.window
= FRAME_X_WINDOW (f
);
11956 message
.xclient
.type
= ClientMessage
;
11957 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11958 message
.xclient
.format
= 32;
11959 message
.xclient
.data
.l
[0] = IconicState
;
11961 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11962 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11964 SubstructureRedirectMask
| SubstructureNotifyMask
,
11967 UNBLOCK_INPUT_RESIGNAL
;
11968 error ("Can't notify window manager of iconification");
11972 /* X11R3: set the initial_state field of the window manager hints to
11974 x_wm_set_window_state (f
, IconicState
);
11976 if (!FRAME_VISIBLE_P (f
))
11978 /* If the frame was withdrawn, before, we must map it. */
11979 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11982 f
->async_iconified
= 1;
11983 f
->async_visible
= 0;
11985 XFlush (FRAME_X_DISPLAY (f
));
11987 #endif /* not USE_X_TOOLKIT */
11990 /* Destroy the X window of frame F. */
11993 x_destroy_window (f
)
11996 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12000 /* If a display connection is dead, don't try sending more
12001 commands to the X server. */
12002 if (dpyinfo
->display
!= 0)
12004 if (f
->output_data
.x
->icon_desc
!= 0)
12005 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12008 free_frame_xic (f
);
12010 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
12011 #ifdef USE_X_TOOLKIT
12012 if (f
->output_data
.x
->widget
)
12013 XtDestroyWidget (f
->output_data
.x
->widget
);
12014 free_frame_menubar (f
);
12015 #endif /* USE_X_TOOLKIT */
12017 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12018 unload_color (f
, f
->output_data
.x
->background_pixel
);
12019 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12020 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12021 unload_color (f
, f
->output_data
.x
->border_pixel
);
12022 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12023 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12024 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12025 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12026 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12027 if (f
->output_data
.x
->white_relief
.allocated_p
)
12028 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12029 if (f
->output_data
.x
->black_relief
.allocated_p
)
12030 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12032 free_frame_faces (f
);
12033 XFlush (FRAME_X_DISPLAY (f
));
12036 if (f
->output_data
.x
->saved_menu_event
)
12037 xfree (f
->output_data
.x
->saved_menu_event
);
12039 xfree (f
->output_data
.x
);
12040 f
->output_data
.x
= 0;
12041 if (f
== dpyinfo
->x_focus_frame
)
12042 dpyinfo
->x_focus_frame
= 0;
12043 if (f
== dpyinfo
->x_focus_event_frame
)
12044 dpyinfo
->x_focus_event_frame
= 0;
12045 if (f
== dpyinfo
->x_highlight_frame
)
12046 dpyinfo
->x_highlight_frame
= 0;
12048 dpyinfo
->reference_count
--;
12050 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12052 dpyinfo
->mouse_face_beg_row
12053 = dpyinfo
->mouse_face_beg_col
= -1;
12054 dpyinfo
->mouse_face_end_row
12055 = dpyinfo
->mouse_face_end_col
= -1;
12056 dpyinfo
->mouse_face_window
= Qnil
;
12057 dpyinfo
->mouse_face_deferred_gc
= 0;
12058 dpyinfo
->mouse_face_mouse_frame
= 0;
12064 /* Setting window manager hints. */
12066 /* Set the normal size hints for the window manager, for frame F.
12067 FLAGS is the flags word to use--or 0 meaning preserve the flags
12068 that the window now has.
12069 If USER_POSITION is nonzero, we set the USPosition
12070 flag (this is useful when FLAGS is 0). */
12073 x_wm_set_size_hint (f
, flags
, user_position
)
12078 XSizeHints size_hints
;
12080 #ifdef USE_X_TOOLKIT
12083 Dimension widget_width
, widget_height
;
12084 Window window
= XtWindow (f
->output_data
.x
->widget
);
12085 #else /* not USE_X_TOOLKIT */
12086 Window window
= FRAME_X_WINDOW (f
);
12087 #endif /* not USE_X_TOOLKIT */
12089 /* Setting PMaxSize caused various problems. */
12090 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12092 size_hints
.x
= f
->output_data
.x
->left_pos
;
12093 size_hints
.y
= f
->output_data
.x
->top_pos
;
12095 #ifdef USE_X_TOOLKIT
12096 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12097 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12098 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12099 size_hints
.height
= widget_height
;
12100 size_hints
.width
= widget_width
;
12101 #else /* not USE_X_TOOLKIT */
12102 size_hints
.height
= PIXEL_HEIGHT (f
);
12103 size_hints
.width
= PIXEL_WIDTH (f
);
12104 #endif /* not USE_X_TOOLKIT */
12106 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12107 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12108 size_hints
.max_width
12109 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12110 size_hints
.max_height
12111 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12113 /* Calculate the base and minimum sizes.
12115 (When we use the X toolkit, we don't do it here.
12116 Instead we copy the values that the widgets are using, below.) */
12117 #ifndef USE_X_TOOLKIT
12119 int base_width
, base_height
;
12120 int min_rows
= 0, min_cols
= 0;
12122 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12123 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12125 check_frame_size (f
, &min_rows
, &min_cols
);
12127 /* The window manager uses the base width hints to calculate the
12128 current number of rows and columns in the frame while
12129 resizing; min_width and min_height aren't useful for this
12130 purpose, since they might not give the dimensions for a
12131 zero-row, zero-column frame.
12133 We use the base_width and base_height members if we have
12134 them; otherwise, we set the min_width and min_height members
12135 to the size for a zero x zero frame. */
12138 size_hints
.flags
|= PBaseSize
;
12139 size_hints
.base_width
= base_width
;
12140 size_hints
.base_height
= base_height
;
12141 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12142 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12144 size_hints
.min_width
= base_width
;
12145 size_hints
.min_height
= base_height
;
12149 /* If we don't need the old flags, we don't need the old hint at all. */
12152 size_hints
.flags
|= flags
;
12155 #endif /* not USE_X_TOOLKIT */
12158 XSizeHints hints
; /* Sometimes I hate X Windows... */
12159 long supplied_return
;
12163 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12166 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12169 #ifdef USE_X_TOOLKIT
12170 size_hints
.base_height
= hints
.base_height
;
12171 size_hints
.base_width
= hints
.base_width
;
12172 size_hints
.min_height
= hints
.min_height
;
12173 size_hints
.min_width
= hints
.min_width
;
12177 size_hints
.flags
|= flags
;
12182 if (hints
.flags
& PSize
)
12183 size_hints
.flags
|= PSize
;
12184 if (hints
.flags
& PPosition
)
12185 size_hints
.flags
|= PPosition
;
12186 if (hints
.flags
& USPosition
)
12187 size_hints
.flags
|= USPosition
;
12188 if (hints
.flags
& USSize
)
12189 size_hints
.flags
|= USSize
;
12193 #ifndef USE_X_TOOLKIT
12198 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12199 size_hints
.flags
|= PWinGravity
;
12203 size_hints
.flags
&= ~ PPosition
;
12204 size_hints
.flags
|= USPosition
;
12206 #endif /* PWinGravity */
12209 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12211 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12215 /* Used for IconicState or NormalState */
12218 x_wm_set_window_state (f
, state
)
12222 #ifdef USE_X_TOOLKIT
12225 XtSetArg (al
[0], XtNinitialState
, state
);
12226 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12227 #else /* not USE_X_TOOLKIT */
12228 Window window
= FRAME_X_WINDOW (f
);
12230 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12231 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12233 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12234 #endif /* not USE_X_TOOLKIT */
12238 x_wm_set_icon_pixmap (f
, pixmap_id
)
12242 Pixmap icon_pixmap
;
12244 #ifndef USE_X_TOOLKIT
12245 Window window
= FRAME_X_WINDOW (f
);
12250 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12251 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12255 /* It seems there is no way to turn off use of an icon pixmap.
12256 The following line does it, only if no icon has yet been created,
12257 for some window managers. But with mwm it crashes.
12258 Some people say it should clear the IconPixmapHint bit in this case,
12259 but that doesn't work, and the X consortium said it isn't the
12260 right thing at all. Since there is no way to win,
12261 best to explicitly give up. */
12263 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12269 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12273 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12274 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12277 #else /* not USE_X_TOOLKIT */
12279 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12280 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12282 #endif /* not USE_X_TOOLKIT */
12286 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12288 int icon_x
, icon_y
;
12290 #ifdef USE_X_TOOLKIT
12291 Window window
= XtWindow (f
->output_data
.x
->widget
);
12293 Window window
= FRAME_X_WINDOW (f
);
12296 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12297 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12298 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12300 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12304 /***********************************************************************
12306 ***********************************************************************/
12308 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12311 x_get_font_info (f
, font_idx
)
12315 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12319 /* Return a list of names of available fonts matching PATTERN on frame
12320 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
12321 to be listed. Frame F NULL means we have not yet created any
12322 frame on X, and consult the first display in x_display_list.
12323 MAXNAMES sets a limit on how many fonts to match. */
12326 x_list_fonts (f
, pattern
, size
, maxnames
)
12328 Lisp_Object pattern
;
12332 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12333 Lisp_Object tem
, second_best
;
12334 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
12335 int try_XLoadQueryFont
= 0;
12338 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12339 if (NILP (patterns
))
12340 patterns
= Fcons (pattern
, Qnil
);
12342 if (maxnames
== 1 && !size
)
12343 /* We can return any single font matching PATTERN. */
12344 try_XLoadQueryFont
= 1;
12346 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12349 char **names
= NULL
;
12351 pattern
= XCAR (patterns
);
12352 /* See if we cached the result for this particular query.
12353 The cache is an alist of the form:
12354 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
12356 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
12357 key
= Fcons (pattern
, make_number (maxnames
)),
12358 !NILP (list
= Fassoc (key
, tem
))))
12360 list
= Fcdr_safe (list
);
12361 /* We have a cashed list. Don't have to get the list again. */
12365 /* At first, put PATTERN in the cache. */
12368 count
= x_catch_errors (dpy
);
12370 if (try_XLoadQueryFont
)
12373 unsigned long value
;
12375 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12376 if (x_had_errors_p (dpy
))
12378 /* This error is perhaps due to insufficient memory on X
12379 server. Let's just ignore it. */
12381 x_clear_errors (dpy
);
12385 && XGetFontProperty (font
, XA_FONT
, &value
))
12387 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12388 int len
= strlen (name
);
12391 /* If DXPC (a Differential X Protocol Compressor)
12392 Ver.3.7 is running, XGetAtomName will return null
12393 string. We must avoid such a name. */
12395 try_XLoadQueryFont
= 0;
12399 names
= (char **) alloca (sizeof (char *));
12400 /* Some systems only allow alloca assigned to a
12402 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12403 bcopy (name
, names
[0], len
+ 1);
12408 try_XLoadQueryFont
= 0;
12411 XFreeFont (dpy
, font
);
12414 if (!try_XLoadQueryFont
)
12416 /* We try at least 10 fonts because XListFonts will return
12417 auto-scaled fonts at the head. */
12418 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12420 if (x_had_errors_p (dpy
))
12422 /* This error is perhaps due to insufficient memory on X
12423 server. Let's just ignore it. */
12425 x_clear_errors (dpy
);
12429 x_uncatch_errors (dpy
, count
);
12436 /* Make a list of all the fonts we got back.
12437 Store that in the font cache for the display. */
12438 for (i
= 0; i
< num_fonts
; i
++)
12441 char *p
= names
[i
];
12442 int average_width
= -1, dashes
= 0;
12444 /* Count the number of dashes in NAMES[I]. If there are
12445 14 dashes, and the field value following 12th dash
12446 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12447 is usually too ugly to be used for editing. Let's
12453 if (dashes
== 7) /* PIXEL_SIZE field */
12455 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12456 average_width
= atoi (p
);
12458 if (dashes
< 14 || average_width
!= 0)
12460 tem
= build_string (names
[i
]);
12461 if (NILP (Fassoc (tem
, list
)))
12463 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12464 && ((fast_c_string_match_ignore_case
12465 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12467 /* We can set the value of PIXEL_SIZE to the
12468 width of this font. */
12469 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12471 /* For the moment, width is not known. */
12472 list
= Fcons (Fcons (tem
, Qnil
), list
);
12476 if (!try_XLoadQueryFont
)
12477 XFreeFontNames (names
);
12480 /* Now store the result in the cache. */
12482 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
12483 = Fcons (Fcons (key
, list
),
12484 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
12487 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12489 newlist
= second_best
= Qnil
;
12490 /* Make a list of the fonts that have the right width. */
12491 for (; CONSP (list
); list
= XCDR (list
))
12497 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12501 newlist
= Fcons (XCAR (tem
), newlist
);
12505 if (!INTEGERP (XCDR (tem
)))
12507 /* Since we have not yet known the size of this font, we
12508 must try slow function call XLoadQueryFont. */
12509 XFontStruct
*thisinfo
;
12512 count
= x_catch_errors (dpy
);
12513 thisinfo
= XLoadQueryFont (dpy
,
12514 XSTRING (XCAR (tem
))->data
);
12515 if (x_had_errors_p (dpy
))
12517 /* This error is perhaps due to insufficient memory on X
12518 server. Let's just ignore it. */
12520 x_clear_errors (dpy
);
12522 x_uncatch_errors (dpy
, count
);
12528 = (thisinfo
->min_bounds
.width
== 0
12530 : make_number (thisinfo
->max_bounds
.width
));
12531 XFreeFont (dpy
, thisinfo
);
12534 /* For unknown reason, the previous call of XListFont had
12535 returned a font which can't be opened. Record the size
12536 as 0 not to try to open it again. */
12537 XCDR (tem
) = make_number (0);
12540 found_size
= XINT (XCDR (tem
));
12541 if (found_size
== size
)
12542 newlist
= Fcons (XCAR (tem
), newlist
);
12543 else if (found_size
> 0)
12545 if (NILP (second_best
))
12547 else if (found_size
< size
)
12549 if (XINT (XCDR (second_best
)) > size
12550 || XINT (XCDR (second_best
)) < found_size
)
12555 if (XINT (XCDR (second_best
)) > size
12556 && XINT (XCDR (second_best
)) > found_size
)
12561 if (!NILP (newlist
))
12563 else if (!NILP (second_best
))
12565 newlist
= Fcons (XCAR (second_best
), Qnil
);
12576 /* Check that FONT is valid on frame F. It is if it can be found in F's
12580 x_check_font (f
, font
)
12585 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12587 xassert (font
!= NULL
);
12589 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12590 if (dpyinfo
->font_table
[i
].name
12591 && font
== dpyinfo
->font_table
[i
].font
)
12594 xassert (i
< dpyinfo
->n_fonts
);
12597 #endif /* GLYPH_DEBUG != 0 */
12599 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12600 Note: There are (broken) X fonts out there with invalid XFontStruct
12601 min_bounds contents. For example, handa@etl.go.jp reports that
12602 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
12603 have font->min_bounds.width == 0. */
12606 x_font_min_bounds (font
, w
, h
)
12610 *h
= FONT_HEIGHT (font
);
12611 *w
= font
->min_bounds
.width
;
12613 /* Try to handle the case where FONT->min_bounds has invalid
12614 contents. Since the only font known to have invalid min_bounds
12615 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12617 *w
= font
->max_bounds
.width
;
12621 /* Compute the smallest character width and smallest font height over
12622 all fonts available on frame F. Set the members smallest_char_width
12623 and smallest_font_height in F's x_display_info structure to
12624 the values computed. Value is non-zero if smallest_font_height or
12625 smallest_char_width become smaller than they were before. */
12628 x_compute_min_glyph_bounds (f
)
12632 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12634 int old_width
= dpyinfo
->smallest_char_width
;
12635 int old_height
= dpyinfo
->smallest_font_height
;
12637 dpyinfo
->smallest_font_height
= 100000;
12638 dpyinfo
->smallest_char_width
= 100000;
12640 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12641 if (dpyinfo
->font_table
[i
].name
)
12643 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12646 font
= (XFontStruct
*) fontp
->font
;
12647 xassert (font
!= (XFontStruct
*) ~0);
12648 x_font_min_bounds (font
, &w
, &h
);
12650 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12651 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12654 xassert (dpyinfo
->smallest_char_width
> 0
12655 && dpyinfo
->smallest_font_height
> 0);
12657 return (dpyinfo
->n_fonts
== 1
12658 || dpyinfo
->smallest_char_width
< old_width
12659 || dpyinfo
->smallest_font_height
< old_height
);
12663 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12664 pointer to the structure font_info while allocating it dynamically.
12665 If SIZE is 0, load any size of font.
12666 If loading is failed, return NULL. */
12669 x_load_font (f
, fontname
, size
)
12671 register char *fontname
;
12674 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12675 Lisp_Object font_names
;
12678 /* Get a list of all the fonts that match this name. Once we
12679 have a list of matching fonts, we compare them against the fonts
12680 we already have by comparing names. */
12681 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12683 if (!NILP (font_names
))
12688 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12689 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12690 if (dpyinfo
->font_table
[i
].name
12691 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12692 XSTRING (XCAR (tail
))->data
)
12693 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12694 XSTRING (XCAR (tail
))->data
)))
12695 return (dpyinfo
->font_table
+ i
);
12698 /* Load the font and add it to the table. */
12702 struct font_info
*fontp
;
12703 unsigned long value
;
12706 /* If we have found fonts by x_list_font, load one of them. If
12707 not, we still try to load a font by the name given as FONTNAME
12708 because XListFonts (called in x_list_font) of some X server has
12709 a bug of not finding a font even if the font surely exists and
12710 is loadable by XLoadQueryFont. */
12711 if (size
> 0 && !NILP (font_names
))
12712 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12715 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12716 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12717 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12719 /* This error is perhaps due to insufficient memory on X
12720 server. Let's just ignore it. */
12722 x_clear_errors (FRAME_X_DISPLAY (f
));
12724 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12729 /* Find a free slot in the font table. */
12730 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12731 if (dpyinfo
->font_table
[i
].name
== NULL
)
12734 /* If no free slot found, maybe enlarge the font table. */
12735 if (i
== dpyinfo
->n_fonts
12736 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12739 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12740 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12741 dpyinfo
->font_table
12742 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12745 fontp
= dpyinfo
->font_table
+ i
;
12746 if (i
== dpyinfo
->n_fonts
)
12747 ++dpyinfo
->n_fonts
;
12749 /* Now fill in the slots of *FONTP. */
12751 fontp
->font
= font
;
12752 fontp
->font_idx
= i
;
12753 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12754 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12756 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12758 if (XGetFontProperty (font
, XA_FONT
, &value
))
12760 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12764 /* Count the number of dashes in the "full name".
12765 If it is too few, this isn't really the font's full name,
12767 In X11R4, the fonts did not come with their canonical names
12778 full_name
= (char *) xmalloc (p
- name
+ 1);
12779 bcopy (name
, full_name
, p
- name
+ 1);
12785 if (full_name
!= 0)
12786 fontp
->full_name
= full_name
;
12788 fontp
->full_name
= fontp
->name
;
12790 fontp
->size
= font
->max_bounds
.width
;
12791 fontp
->height
= FONT_HEIGHT (font
);
12793 /* For some font, ascent and descent in max_bounds field is
12794 larger than the above value. */
12795 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12796 if (max_height
> fontp
->height
)
12797 fontp
->height
= max_height
;
12800 if (NILP (font_names
))
12802 /* We come here because of a bug of XListFonts mentioned at
12803 the head of this block. Let's store this information in
12804 the cache for x_list_fonts. */
12805 Lisp_Object lispy_name
= build_string (fontname
);
12806 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12808 XCDR (dpyinfo
->name_list_element
)
12809 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
12810 Fcons (Fcons (lispy_full_name
,
12811 make_number (fontp
->size
)),
12813 XCDR (dpyinfo
->name_list_element
));
12815 XCDR (dpyinfo
->name_list_element
)
12816 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
12817 Fcons (Fcons (lispy_full_name
,
12818 make_number (fontp
->size
)),
12820 XCDR (dpyinfo
->name_list_element
));
12823 /* The slot `encoding' specifies how to map a character
12824 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
12825 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
12826 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
12827 2:0xA020..0xFF7F). For the moment, we don't know which charset
12828 uses this font. So, we set information in fontp->encoding[1]
12829 which is never used by any charset. If mapping can't be
12830 decided, set FONT_ENCODING_NOT_DECIDED. */
12832 = (font
->max_byte1
== 0
12834 ? (font
->min_char_or_byte2
< 0x80
12835 ? (font
->max_char_or_byte2
< 0x80
12836 ? 0 /* 0x20..0x7F */
12837 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
12838 : 1) /* 0xA0..0xFF */
12840 : (font
->min_byte1
< 0x80
12841 ? (font
->max_byte1
< 0x80
12842 ? (font
->min_char_or_byte2
< 0x80
12843 ? (font
->max_char_or_byte2
< 0x80
12844 ? 0 /* 0x2020..0x7F7F */
12845 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
12846 : 3) /* 0x20A0..0x7FFF */
12847 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
12848 : (font
->min_char_or_byte2
< 0x80
12849 ? (font
->max_char_or_byte2
< 0x80
12850 ? 2 /* 0xA020..0xFF7F */
12851 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
12852 : 1))); /* 0xA0A0..0xFFFF */
12854 fontp
->baseline_offset
12855 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
12856 ? (long) value
: 0);
12857 fontp
->relative_compose
12858 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
12859 ? (long) value
: 0);
12860 fontp
->default_ascent
12861 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
12862 ? (long) value
: 0);
12864 /* Set global flag fonts_changed_p to non-zero if the font loaded
12865 has a character with a smaller width than any other character
12866 before, or if the font loaded has a smalle>r height than any
12867 other font loaded before. If this happens, it will make a
12868 glyph matrix reallocation necessary. */
12869 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
12876 /* Return a pointer to struct font_info of a font named FONTNAME for
12877 frame F. If no such font is loaded, return NULL. */
12880 x_query_font (f
, fontname
)
12882 register char *fontname
;
12884 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12887 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12888 if (dpyinfo
->font_table
[i
].name
12889 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
12890 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
12891 return (dpyinfo
->font_table
+ i
);
12896 /* Find a CCL program for a font specified by FONTP, and set the member
12897 `encoder' of the structure. */
12900 x_find_ccl_program (fontp
)
12901 struct font_info
*fontp
;
12903 Lisp_Object list
, elt
;
12905 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
12909 && STRINGP (XCAR (elt
))
12910 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
12916 struct ccl_program
*ccl
12917 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
12919 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
12922 fontp
->font_encoder
= ccl
;
12928 /***********************************************************************
12930 ***********************************************************************/
12932 #ifdef USE_X_TOOLKIT
12933 static XrmOptionDescRec emacs_options
[] = {
12934 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
12935 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
12937 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
12938 XrmoptionSepArg
, NULL
},
12939 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
12941 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12942 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12943 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12944 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12945 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12946 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
12947 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
12949 #endif /* USE_X_TOOLKIT */
12951 static int x_initialized
;
12953 #ifdef MULTI_KBOARD
12954 /* Test whether two display-name strings agree up to the dot that separates
12955 the screen number from the server number. */
12957 same_x_server (name1
, name2
)
12958 char *name1
, *name2
;
12960 int seen_colon
= 0;
12961 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
12962 int system_name_length
= strlen (system_name
);
12963 int length_until_period
= 0;
12965 while (system_name
[length_until_period
] != 0
12966 && system_name
[length_until_period
] != '.')
12967 length_until_period
++;
12969 /* Treat `unix' like an empty host name. */
12970 if (! strncmp (name1
, "unix:", 5))
12972 if (! strncmp (name2
, "unix:", 5))
12974 /* Treat this host's name like an empty host name. */
12975 if (! strncmp (name1
, system_name
, system_name_length
)
12976 && name1
[system_name_length
] == ':')
12977 name1
+= system_name_length
;
12978 if (! strncmp (name2
, system_name
, system_name_length
)
12979 && name2
[system_name_length
] == ':')
12980 name2
+= system_name_length
;
12981 /* Treat this host's domainless name like an empty host name. */
12982 if (! strncmp (name1
, system_name
, length_until_period
)
12983 && name1
[length_until_period
] == ':')
12984 name1
+= length_until_period
;
12985 if (! strncmp (name2
, system_name
, length_until_period
)
12986 && name2
[length_until_period
] == ':')
12987 name2
+= length_until_period
;
12989 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
12993 if (seen_colon
&& *name1
== '.')
12997 && (*name1
== '.' || *name1
== '\0')
12998 && (*name2
== '.' || *name2
== '\0'));
13002 struct x_display_info
*
13003 x_term_init (display_name
, xrm_option
, resource_name
)
13004 Lisp_Object display_name
;
13006 char *resource_name
;
13010 struct x_display_info
*dpyinfo
;
13015 if (!x_initialized
)
13021 #ifdef USE_X_TOOLKIT
13022 /* weiner@footloose.sps.mot.com reports that this causes
13024 X protocol error: BadAtom (invalid Atom parameter)
13025 on protocol request 18skiloaf.
13026 So let's not use it until R6. */
13027 #ifdef HAVE_X11XTR6
13028 XtSetLanguageProc (NULL
, NULL
, NULL
);
13039 argv
[argc
++] = "-xrm";
13040 argv
[argc
++] = xrm_option
;
13042 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13043 resource_name
, EMACS_CLASS
,
13044 emacs_options
, XtNumber (emacs_options
),
13047 #ifdef HAVE_X11XTR6
13048 /* I think this is to compensate for XtSetLanguageProc. */
13053 #else /* not USE_X_TOOLKIT */
13055 XSetLocaleModifiers ("");
13057 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13058 #endif /* not USE_X_TOOLKIT */
13060 /* Detect failure. */
13067 /* We have definitely succeeded. Record the new connection. */
13069 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13071 #ifdef MULTI_KBOARD
13073 struct x_display_info
*share
;
13076 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13077 share
= share
->next
, tail
= XCDR (tail
))
13078 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13079 XSTRING (display_name
)->data
))
13082 dpyinfo
->kboard
= share
->kboard
;
13085 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13086 init_kboard (dpyinfo
->kboard
);
13087 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13089 char *vendor
= ServerVendor (dpy
);
13091 dpyinfo
->kboard
->Vsystem_key_alist
13092 = call1 (Qvendor_specific_keysyms
,
13093 build_string (vendor
? vendor
: ""));
13097 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13098 all_kboards
= dpyinfo
->kboard
;
13099 /* Don't let the initial kboard remain current longer than necessary.
13100 That would cause problems if a file loaded on startup tries to
13101 prompt in the mini-buffer. */
13102 if (current_kboard
== initial_kboard
)
13103 current_kboard
= dpyinfo
->kboard
;
13105 dpyinfo
->kboard
->reference_count
++;
13109 /* Put this display on the chain. */
13110 dpyinfo
->next
= x_display_list
;
13111 x_display_list
= dpyinfo
;
13113 /* Put it on x_display_name_list as well, to keep them parallel. */
13114 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13115 x_display_name_list
);
13116 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13118 dpyinfo
->display
= dpy
;
13121 XSetAfterFunction (x_current_display
, x_trace_wire
);
13125 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13126 + STRING_BYTES (XSTRING (Vsystem_name
))
13128 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13129 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13131 /* Figure out which modifier bits mean what. */
13132 x_find_modifier_meanings (dpyinfo
);
13134 /* Get the scroll bar cursor. */
13135 dpyinfo
->vertical_scroll_bar_cursor
13136 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13138 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13139 resource_name
, EMACS_CLASS
);
13140 #ifdef HAVE_XRMSETDATABASE
13141 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13143 dpyinfo
->display
->db
= xrdb
;
13145 /* Put the rdb where we can find it in a way that works on
13147 dpyinfo
->xrdb
= xrdb
;
13149 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13150 DefaultScreen (dpyinfo
->display
));
13151 select_visual (dpyinfo
);
13152 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13153 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13154 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13155 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13156 dpyinfo
->grabbed
= 0;
13157 dpyinfo
->reference_count
= 0;
13158 dpyinfo
->icon_bitmap_id
= -1;
13159 dpyinfo
->font_table
= NULL
;
13160 dpyinfo
->n_fonts
= 0;
13161 dpyinfo
->font_table_size
= 0;
13162 dpyinfo
->bitmaps
= 0;
13163 dpyinfo
->bitmaps_size
= 0;
13164 dpyinfo
->bitmaps_last
= 0;
13165 dpyinfo
->scratch_cursor_gc
= 0;
13166 dpyinfo
->mouse_face_mouse_frame
= 0;
13167 dpyinfo
->mouse_face_deferred_gc
= 0;
13168 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13169 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13170 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13171 dpyinfo
->mouse_face_window
= Qnil
;
13172 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13173 dpyinfo
->mouse_face_defer
= 0;
13174 dpyinfo
->x_focus_frame
= 0;
13175 dpyinfo
->x_focus_event_frame
= 0;
13176 dpyinfo
->x_highlight_frame
= 0;
13177 dpyinfo
->image_cache
= make_image_cache ();
13179 /* See if a private colormap is requested. */
13180 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13182 if (dpyinfo
->visual
->class == PseudoColor
)
13185 value
= display_x_get_resource (dpyinfo
,
13186 build_string ("privateColormap"),
13187 build_string ("PrivateColormap"),
13189 if (STRINGP (value
)
13190 && (!strcmp (XSTRING (value
)->data
, "true")
13191 || !strcmp (XSTRING (value
)->data
, "on")))
13192 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13196 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13197 dpyinfo
->visual
, AllocNone
);
13200 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13201 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13202 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13203 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13204 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13205 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13206 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13209 dpyinfo
->Xatom_wm_protocols
13210 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13211 dpyinfo
->Xatom_wm_take_focus
13212 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13213 dpyinfo
->Xatom_wm_save_yourself
13214 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13215 dpyinfo
->Xatom_wm_delete_window
13216 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13217 dpyinfo
->Xatom_wm_change_state
13218 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13219 dpyinfo
->Xatom_wm_configure_denied
13220 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13221 dpyinfo
->Xatom_wm_window_moved
13222 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13223 dpyinfo
->Xatom_editres
13224 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13225 dpyinfo
->Xatom_CLIPBOARD
13226 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13227 dpyinfo
->Xatom_TIMESTAMP
13228 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13229 dpyinfo
->Xatom_TEXT
13230 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13231 dpyinfo
->Xatom_COMPOUND_TEXT
13232 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13233 dpyinfo
->Xatom_DELETE
13234 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13235 dpyinfo
->Xatom_MULTIPLE
13236 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13237 dpyinfo
->Xatom_INCR
13238 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13239 dpyinfo
->Xatom_EMACS_TMP
13240 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13241 dpyinfo
->Xatom_TARGETS
13242 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13243 dpyinfo
->Xatom_NULL
13244 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13245 dpyinfo
->Xatom_ATOM_PAIR
13246 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13247 /* For properties of font. */
13248 dpyinfo
->Xatom_PIXEL_SIZE
13249 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13250 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13251 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13252 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13253 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13254 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13255 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13257 /* Ghostscript support. */
13258 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13259 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13261 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13264 dpyinfo
->cut_buffers_initialized
= 0;
13266 connection
= ConnectionNumber (dpyinfo
->display
);
13267 dpyinfo
->connection
= connection
;
13272 null_bits
[0] = 0x00;
13274 dpyinfo
->null_pixel
13275 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13276 null_bits
, 1, 1, (long) 0, (long) 0,
13281 extern int gray_bitmap_width
, gray_bitmap_height
;
13282 extern unsigned char *gray_bitmap_bits
;
13284 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13286 gray_bitmap_width
, gray_bitmap_height
,
13287 (unsigned long) 1, (unsigned long) 0, 1);
13291 xim_initialize (dpyinfo
, resource_name
);
13294 #ifdef subprocesses
13295 /* This is only needed for distinguishing keyboard and process input. */
13296 if (connection
!= 0)
13297 add_keyboard_wait_descriptor (connection
);
13300 #ifndef F_SETOWN_BUG
13302 #ifdef F_SETOWN_SOCK_NEG
13303 /* stdin is a socket here */
13304 fcntl (connection
, F_SETOWN
, -getpid ());
13305 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13306 fcntl (connection
, F_SETOWN
, getpid ());
13307 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13308 #endif /* ! defined (F_SETOWN) */
13309 #endif /* F_SETOWN_BUG */
13312 if (interrupt_input
)
13313 init_sigio (connection
);
13314 #endif /* ! defined (SIGIO) */
13317 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13318 /* Make sure that we have a valid font for dialog boxes
13319 so that Xt does not crash. */
13321 Display
*dpy
= dpyinfo
->display
;
13322 XrmValue d
, fr
, to
;
13326 d
.addr
= (XPointer
)&dpy
;
13327 d
.size
= sizeof (Display
*);
13328 fr
.addr
= XtDefaultFont
;
13329 fr
.size
= sizeof (XtDefaultFont
);
13330 to
.size
= sizeof (Font
*);
13331 to
.addr
= (XPointer
)&font
;
13332 count
= x_catch_errors (dpy
);
13333 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13335 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13336 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13337 x_uncatch_errors (dpy
, count
);
13342 /* See if we should run in synchronous mode. This is useful
13343 for debugging X code. */
13346 value
= display_x_get_resource (dpyinfo
,
13347 build_string ("synchronous"),
13348 build_string ("Synchronous"),
13350 if (STRINGP (value
)
13351 && (!strcmp (XSTRING (value
)->data
, "true")
13352 || !strcmp (XSTRING (value
)->data
, "on")))
13353 XSynchronize (dpyinfo
->display
, True
);
13361 /* Get rid of display DPYINFO, assuming all frames are already gone,
13362 and without sending any more commands to the X server. */
13365 x_delete_display (dpyinfo
)
13366 struct x_display_info
*dpyinfo
;
13368 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13370 /* Discard this display from x_display_name_list and x_display_list.
13371 We can't use Fdelq because that can quit. */
13372 if (! NILP (x_display_name_list
)
13373 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13374 x_display_name_list
= XCDR (x_display_name_list
);
13379 tail
= x_display_name_list
;
13380 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13382 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13384 XCDR (tail
) = XCDR (XCDR (tail
));
13387 tail
= XCDR (tail
);
13391 if (next_noop_dpyinfo
== dpyinfo
)
13392 next_noop_dpyinfo
= dpyinfo
->next
;
13394 if (x_display_list
== dpyinfo
)
13395 x_display_list
= dpyinfo
->next
;
13398 struct x_display_info
*tail
;
13400 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13401 if (tail
->next
== dpyinfo
)
13402 tail
->next
= tail
->next
->next
;
13405 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13406 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13407 XrmDestroyDatabase (dpyinfo
->xrdb
);
13410 #ifdef MULTI_KBOARD
13411 if (--dpyinfo
->kboard
->reference_count
== 0)
13412 delete_kboard (dpyinfo
->kboard
);
13416 xim_close_dpy (dpyinfo
);
13419 xfree (dpyinfo
->font_table
);
13420 xfree (dpyinfo
->x_id_name
);
13424 /* Set up use of X before we make the first connection. */
13426 static struct redisplay_interface x_redisplay_interface
=
13431 x_clear_end_of_line
,
13433 x_after_update_window_line
,
13434 x_update_window_begin
,
13435 x_update_window_end
,
13438 x_get_glyph_overhangs
,
13439 x_fix_overlapping_area
13445 rif
= &x_redisplay_interface
;
13447 clear_frame_hook
= x_clear_frame
;
13448 ins_del_lines_hook
= x_ins_del_lines
;
13449 change_line_highlight_hook
= x_change_line_highlight
;
13450 delete_glyphs_hook
= x_delete_glyphs
;
13451 ring_bell_hook
= XTring_bell
;
13452 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13453 set_terminal_modes_hook
= XTset_terminal_modes
;
13454 update_begin_hook
= x_update_begin
;
13455 update_end_hook
= x_update_end
;
13456 set_terminal_window_hook
= XTset_terminal_window
;
13457 read_socket_hook
= XTread_socket
;
13458 frame_up_to_date_hook
= XTframe_up_to_date
;
13459 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13460 mouse_position_hook
= XTmouse_position
;
13461 frame_rehighlight_hook
= XTframe_rehighlight
;
13462 frame_raise_lower_hook
= XTframe_raise_lower
;
13463 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13464 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13465 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13466 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13467 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13469 scroll_region_ok
= 1; /* we'll scroll partial frames */
13470 char_ins_del_ok
= 0; /* just as fast to write the line */
13471 line_ins_del_ok
= 1; /* we'll just blt 'em */
13472 fast_clear_end_of_line
= 1; /* X does this well */
13473 memory_below_frame
= 0; /* we don't remember what scrolls
13478 last_tool_bar_item
= -1;
13479 any_help_event_p
= 0;
13481 /* Try to use interrupt input; if we can't, then start polling. */
13482 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13484 #ifdef USE_X_TOOLKIT
13485 XtToolkitInitialize ();
13486 Xt_app_con
= XtCreateApplicationContext ();
13487 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13489 /* Install an asynchronous timer that processes Xt timeout events
13490 every 0.1s. This is necessary because some widget sets use
13491 timeouts internally, for example the LessTif menu bar, or the
13492 Xaw3d scroll bar. When Xt timouts aren't processed, these
13493 widgets don't behave normally. */
13495 EMACS_TIME interval
;
13496 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13497 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13501 #if USE_TOOLKIT_SCROLL_BARS
13502 xaw3d_arrow_scroll
= False
;
13503 xaw3d_pick_top
= True
;
13506 /* Note that there is no real way portable across R3/R4 to get the
13507 original error handler. */
13508 XSetErrorHandler (x_error_handler
);
13509 XSetIOErrorHandler (x_io_error_quitter
);
13511 /* Disable Window Change signals; they are handled by X events. */
13513 signal (SIGWINCH
, SIG_DFL
);
13514 #endif /* ! defined (SIGWINCH) */
13516 signal (SIGPIPE
, x_connection_signal
);
13523 staticpro (&x_error_message_string
);
13524 x_error_message_string
= Qnil
;
13526 staticpro (&x_display_name_list
);
13527 x_display_name_list
= Qnil
;
13529 staticpro (&last_mouse_scroll_bar
);
13530 last_mouse_scroll_bar
= Qnil
;
13532 staticpro (&Qvendor_specific_keysyms
);
13533 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13535 staticpro (&last_mouse_press_frame
);
13536 last_mouse_press_frame
= Qnil
;
13538 staticpro (&help_echo
);
13540 staticpro (&previous_help_echo
);
13541 previous_help_echo
= Qnil
;
13543 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13544 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
13545 For example, if a block cursor is over a tab, it will be drawn as\n\
13546 wide as that tab on the display.");
13547 x_stretch_cursor_p
= 0;
13549 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
13550 "If not nil, Emacs uses toolkit scroll bars.");
13551 #if USE_TOOLKIT_SCROLL_BARS
13552 x_toolkit_scroll_bars_p
= 1;
13554 x_toolkit_scroll_bars_p
= 0;
13557 staticpro (&last_mouse_motion_frame
);
13558 last_mouse_motion_frame
= Qnil
;
13561 #endif /* not HAVE_X_WINDOWS */