1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
74 #include "dispextern.h"
76 #include "termhooks.h"
88 #include "intervals.h"
93 #include <X11/Shell.h>
96 #ifdef HAVE_SYS_TIME_H
105 extern void free_frame_menubar
P_ ((struct frame
*));
106 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
109 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
111 extern void _XEditResCheckMessages ();
112 #endif /* not NO_EDITRES */
114 /* Include toolkit specific headers for the scroll bar widget. */
116 #ifdef USE_TOOLKIT_SCROLL_BARS
117 #if defined USE_MOTIF
118 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
119 #include <Xm/ScrollBar.h>
120 #include <Xm/ScrollBarP.h>
121 #else /* !USE_MOTIF i.e. use Xaw */
124 #include <X11/Xaw3d/Simple.h>
125 #include <X11/Xaw3d/Scrollbar.h>
126 #define ARROW_SCROLLBAR
127 #include <X11/Xaw3d/ScrollbarP.h>
128 #else /* !HAVE_XAW3D */
129 #include <X11/Xaw/Simple.h>
130 #include <X11/Xaw/Scrollbar.h>
131 #endif /* !HAVE_XAW3D */
133 #define XtNpickTop "pickTop"
134 #endif /* !XtNpickTop */
135 #endif /* !USE_MOTIF */
136 #endif /* USE_TOOLKIT_SCROLL_BARS */
138 #endif /* USE_X_TOOLKIT */
140 #ifndef USE_X_TOOLKIT
141 #define x_any_window_to_frame x_window_to_frame
142 #define x_top_window_to_frame x_window_to_frame
147 #ifndef XtNinitialState
148 #define XtNinitialState "initialState"
153 #define min(a,b) ((a) < (b) ? (a) : (b))
156 #define max(a,b) ((a) > (b) ? (a) : (b))
159 #define abs(x) ((x) < 0 ? -(x) : (x))
161 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
164 /* Bitmaps for truncated lines. */
169 LEFT_TRUNCATION_BITMAP
,
170 RIGHT_TRUNCATION_BITMAP
,
171 OVERLAY_ARROW_BITMAP
,
172 CONTINUED_LINE_BITMAP
,
173 CONTINUATION_LINE_BITMAP
,
177 /* Bitmap drawn to indicate lines not displaying text if
178 `indicate-empty-lines' is non-nil. */
182 static unsigned char zv_bits
[] = {
183 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
185 /* An arrow like this: `<-'. */
188 #define left_height 8
189 static unsigned char left_bits
[] = {
190 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
192 /* Right truncation arrow bitmap `->'. */
194 #define right_width 8
195 #define right_height 8
196 static unsigned char right_bits
[] = {
197 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
199 /* Marker for continued lines. */
201 #define continued_width 8
202 #define continued_height 8
203 static unsigned char continued_bits
[] = {
204 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
206 /* Marker for continuation lines. */
208 #define continuation_width 8
209 #define continuation_height 8
210 static unsigned char continuation_bits
[] = {
211 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
213 /* Overlay arrow bitmap. */
219 static unsigned char ov_bits
[] = {
220 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
222 /* A triangular arrow. */
225 static unsigned char ov_bits
[] = {
226 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
230 extern Lisp_Object Qhelp_echo
;
233 /* Non-nil means Emacs uses toolkit scroll bars. */
235 Lisp_Object Vx_toolkit_scroll_bars
;
237 /* If a string, XTread_socket generates an event to display that string.
238 (The display is done in read_char.) */
240 static Lisp_Object help_echo
;
241 static Lisp_Object help_echo_window
;
242 static Lisp_Object help_echo_object
;
243 static int help_echo_pos
;
245 /* Temporary variable for XTread_socket. */
247 static Lisp_Object previous_help_echo
;
249 /* Non-zero means that a HELP_EVENT has been generated since Emacs
252 static int any_help_event_p
;
254 /* Non-zero means draw block and hollow cursor as wide as the glyph
255 under it. For example, if a block cursor is over a tab, it will be
256 drawn as wide as that tab on the display. */
258 int x_stretch_cursor_p
;
260 /* This is a chain of structures for all the X displays currently in
263 struct x_display_info
*x_display_list
;
265 /* This is a list of cons cells, each of the form (NAME
266 . FONT-LIST-CACHE), one for each element of x_display_list and in
267 the same order. NAME is the name of the frame. FONT-LIST-CACHE
268 records previous values returned by x-list-fonts. */
270 Lisp_Object x_display_name_list
;
272 /* Frame being updated by update_frame. This is declared in term.c.
273 This is set by update_begin and looked at by all the XT functions.
274 It is zero while not inside an update. In that case, the XT
275 functions assume that `selected_frame' is the frame to apply to. */
277 extern struct frame
*updating_frame
;
279 extern int waiting_for_input
;
281 /* This is a frame waiting to be auto-raised, within XTread_socket. */
283 struct frame
*pending_autoraise_frame
;
286 /* The application context for Xt use. */
287 XtAppContext Xt_app_con
;
288 static String Xt_default_resources
[] = {0};
289 #endif /* USE_X_TOOLKIT */
291 /* Nominal cursor position -- where to draw output.
292 HPOS and VPOS are window relative glyph matrix coordinates.
293 X and Y are window relative pixel coordinates. */
295 struct cursor_pos output_cursor
;
297 /* Non-zero means user is interacting with a toolkit scroll bar. */
299 static int toolkit_scroll_bar_interaction
;
303 Formerly, we used PointerMotionHintMask (in standard_event_mask)
304 so that we would have to call XQueryPointer after each MotionNotify
305 event to ask for another such event. However, this made mouse tracking
306 slow, and there was a bug that made it eventually stop.
308 Simply asking for MotionNotify all the time seems to work better.
310 In order to avoid asking for motion events and then throwing most
311 of them away or busy-polling the server for mouse positions, we ask
312 the server for pointer motion hints. This means that we get only
313 one event per group of mouse movements. "Groups" are delimited by
314 other kinds of events (focus changes and button clicks, for
315 example), or by XQueryPointer calls; when one of these happens, we
316 get another MotionNotify event the next time the mouse moves. This
317 is at least as efficient as getting motion events when mouse
318 tracking is on, and I suspect only negligibly worse when tracking
321 /* Where the mouse was last time we reported a mouse event. */
323 FRAME_PTR last_mouse_frame
;
324 static XRectangle last_mouse_glyph
;
325 static Lisp_Object last_mouse_press_frame
;
327 /* The scroll bar in which the last X motion event occurred.
329 If the last X motion event occurred in a scroll bar, we set this so
330 XTmouse_position can know whether to report a scroll bar motion or
333 If the last X motion event didn't occur in a scroll bar, we set
334 this to Qnil, to tell XTmouse_position to return an ordinary motion
337 static Lisp_Object last_mouse_scroll_bar
;
339 /* This is a hack. We would really prefer that XTmouse_position would
340 return the time associated with the position it returns, but there
341 doesn't seem to be any way to wrest the time-stamp from the server
342 along with the position query. So, we just keep track of the time
343 of the last movement we received, and return that in hopes that
344 it's somewhat accurate. */
346 static Time last_mouse_movement_time
;
348 /* Incremented by XTread_socket whenever it really tries to read
352 static int volatile input_signal_count
;
354 static int input_signal_count
;
357 /* Used locally within XTread_socket. */
359 static int x_noop_count
;
361 /* Initial values of argv and argc. */
363 extern char **initial_argv
;
364 extern int initial_argc
;
366 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
368 /* Tells if a window manager is present or not. */
370 extern Lisp_Object Vx_no_window_manager
;
372 extern Lisp_Object Qface
, Qmouse_face
;
376 /* A mask of extra modifier bits to put into every keyboard char. */
378 extern int extra_keyboard_modifiers
;
380 static Lisp_Object Qvendor_specific_keysyms
;
382 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
383 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
386 /* Enumeration for overriding/changing the face to use for drawing
387 glyphs in x_draw_glyphs. */
389 enum draw_glyphs_face
399 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
400 static const XColor
*x_color_cells
P_ ((struct frame
*, int *));
401 static void x_update_window_end
P_ ((struct window
*, int, 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 int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
409 int *, int *, int *, int *, int));
410 static void set_output_cursor
P_ ((struct cursor_pos
*));
411 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
412 int *, int *, int *, int));
413 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
414 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
415 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
416 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
417 static void show_mouse_face
P_ ((struct x_display_info
*,
418 enum draw_glyphs_face
));
419 static int x_io_error_quitter
P_ ((Display
*));
420 int x_catch_errors
P_ ((Display
*));
421 void x_uncatch_errors
P_ ((Display
*, int));
422 void x_lower_frame
P_ ((struct frame
*));
423 void x_scroll_bar_clear
P_ ((struct frame
*));
424 int x_had_errors_p
P_ ((Display
*));
425 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
426 void x_raise_frame
P_ ((struct frame
*));
427 void x_set_window_size
P_ ((struct frame
*, int, int, int));
428 void x_wm_set_window_state
P_ ((struct frame
*, int));
429 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
430 void x_initialize
P_ ((void));
431 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
432 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
433 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
435 enum draw_glyphs_face
));
436 static void x_update_end
P_ ((struct frame
*));
437 static void XTframe_up_to_date
P_ ((struct frame
*));
438 static void XTreassert_line_highlight
P_ ((int, int));
439 static void x_change_line_highlight
P_ ((int, int, int, int));
440 static void XTset_terminal_modes
P_ ((void));
441 static void XTreset_terminal_modes
P_ ((void));
442 static void XTcursor_to
P_ ((int, int, int, int));
443 static void x_write_glyphs
P_ ((struct glyph
*, int));
444 static void x_clear_end_of_line
P_ ((int));
445 static void x_clear_frame
P_ ((void));
446 static void x_clear_cursor
P_ ((struct window
*));
447 static void frame_highlight
P_ ((struct frame
*));
448 static void frame_unhighlight
P_ ((struct frame
*));
449 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
450 static void XTframe_rehighlight
P_ ((struct frame
*));
451 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
452 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
453 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
454 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
456 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
457 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
458 static void expose_window
P_ ((struct window
*, XRectangle
*));
459 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
460 XRectangle
*, enum glyph_row_area
));
461 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
463 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
464 static void x_update_window_cursor
P_ ((struct window
*, int));
465 static void x_erase_phys_cursor
P_ ((struct window
*));
466 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
467 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
470 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
472 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
473 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
474 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
475 static void x_flush
P_ ((struct frame
*f
));
476 static void x_update_begin
P_ ((struct frame
*));
477 static void x_update_window_begin
P_ ((struct window
*));
478 static void x_draw_vertical_border
P_ ((struct window
*));
479 static void x_after_update_window_line
P_ ((struct glyph_row
*));
480 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
481 static void x_produce_stretch_glyph
P_ ((struct it
*));
482 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
483 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
484 enum scroll_bar_part
*,
485 Lisp_Object
*, Lisp_Object
*,
488 /* Flush display of frame F, or of all frames if F is null. */
497 Lisp_Object rest
, frame
;
498 FOR_EACH_FRAME (rest
, frame
)
499 x_flush (XFRAME (frame
));
501 else if (FRAME_X_P (f
))
502 XFlush (FRAME_X_DISPLAY (f
));
507 /* Remove calls to XFlush by defining XFlush to an empty replacement.
508 Calls to XFlush should be unnecessary because the X output buffer
509 is flushed automatically as needed by calls to XPending,
510 XNextEvent, or XWindowEvent according to the XFlush man page.
511 XTread_socket calls XPending. Removing XFlush improves
514 #define XFlush(DISPLAY) (void) 0
517 /***********************************************************************
519 ***********************************************************************/
523 /* This is a function useful for recording debugging information about
524 the sequence of occurrences in this file. */
532 struct record event_record
[100];
534 int event_record_index
;
536 record_event (locus
, type
)
540 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
541 event_record_index
= 0;
543 event_record
[event_record_index
].locus
= locus
;
544 event_record
[event_record_index
].type
= type
;
545 event_record_index
++;
552 /* Return the struct x_display_info corresponding to DPY. */
554 struct x_display_info
*
555 x_display_info_for_display (dpy
)
558 struct x_display_info
*dpyinfo
;
560 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
561 if (dpyinfo
->display
== dpy
)
569 /***********************************************************************
570 Starting and ending an update
571 ***********************************************************************/
573 /* Start an update of frame F. This function is installed as a hook
574 for update_begin, i.e. it is called when update_begin is called.
575 This function is called prior to calls to x_update_window_begin for
576 each window being updated. Currently, there is nothing to do here
577 because all interesting stuff is done on a window basis. */
587 /* Start update of window W. Set the global variable updated_window
588 to the window being updated and set output_cursor to the cursor
592 x_update_window_begin (w
)
595 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
596 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
599 set_output_cursor (&w
->cursor
);
603 if (f
== display_info
->mouse_face_mouse_frame
)
605 /* Don't do highlighting for mouse motion during the update. */
606 display_info
->mouse_face_defer
= 1;
608 /* If F needs to be redrawn, simply forget about any prior mouse
610 if (FRAME_GARBAGED_P (f
))
611 display_info
->mouse_face_window
= Qnil
;
613 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
614 their mouse_face_p flag set, which means that they are always
615 unequal to rows in a desired matrix which never have that
616 flag set. So, rows containing mouse-face glyphs are never
617 scrolled, and we don't have to switch the mouse highlight off
618 here to prevent it from being scrolled. */
620 /* Can we tell that this update does not affect the window
621 where the mouse highlight is? If so, no need to turn off.
622 Likewise, don't do anything if the frame is garbaged;
623 in that case, the frame's current matrix that we would use
624 is all wrong, and we will redisplay that line anyway. */
625 if (!NILP (display_info
->mouse_face_window
)
626 && w
== XWINDOW (display_info
->mouse_face_window
))
630 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
631 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
634 if (i
< w
->desired_matrix
->nrows
)
635 clear_mouse_face (display_info
);
644 /* Draw a vertical window border to the right of window W if W doesn't
645 have vertical scroll bars. */
648 x_draw_vertical_border (w
)
651 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
653 /* Redraw borders between horizontally adjacent windows. Don't
654 do it for frames with vertical scroll bars because either the
655 right scroll bar of a window, or the left scroll bar of its
656 neighbor will suffice as a border. */
657 if (!WINDOW_RIGHTMOST_P (w
)
658 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
662 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
663 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
666 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
667 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
672 /* End update of window W (which is equal to updated_window).
674 Draw vertical borders between horizontally adjacent windows, and
675 display W's cursor if CURSOR_ON_P is non-zero.
677 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
678 glyphs in mouse-face were overwritten. In that case we have to
679 make sure that the mouse-highlight is properly redrawn.
681 W may be a menu bar pseudo-window in case we don't have X toolkit
682 support. Such windows don't have a cursor, so don't display it
686 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
688 int cursor_on_p
, mouse_face_overwritten_p
;
690 if (!w
->pseudo_window_p
)
692 struct x_display_info
*dpyinfo
693 = FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
697 /* If a row with mouse-face was overwritten, arrange for
698 XTframe_up_to_date to redisplay the mouse highlight. */
699 if (mouse_face_overwritten_p
)
701 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
702 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
703 dpyinfo
->mouse_face_window
= Qnil
;
707 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
709 output_cursor
.x
, output_cursor
.y
);
711 x_draw_vertical_border (w
);
715 updated_window
= NULL
;
719 /* End update of frame F. This function is installed as a hook in
726 /* Mouse highlight may be displayed again. */
727 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
730 XFlush (FRAME_X_DISPLAY (f
));
735 /* This function is called from various places in xdisp.c whenever a
736 complete update has been performed. The global variable
737 updated_window is not available here. */
740 XTframe_up_to_date (f
)
745 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
747 if (dpyinfo
->mouse_face_deferred_gc
748 || f
== dpyinfo
->mouse_face_mouse_frame
)
751 if (dpyinfo
->mouse_face_mouse_frame
)
752 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
753 dpyinfo
->mouse_face_mouse_x
,
754 dpyinfo
->mouse_face_mouse_y
);
755 dpyinfo
->mouse_face_deferred_gc
= 0;
762 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
763 arrow bitmaps, or clear the areas where they would be displayed
764 before DESIRED_ROW is made current. The window being updated is
765 found in updated_window. This function It is called from
766 update_window_line only if it is known that there are differences
767 between bitmaps to be drawn between current row and DESIRED_ROW. */
770 x_after_update_window_line (desired_row
)
771 struct glyph_row
*desired_row
;
773 struct window
*w
= updated_window
;
777 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
783 x_draw_row_bitmaps (w
, desired_row
);
785 /* When a window has disappeared, make sure that no rest of
786 full-width rows stays visible in the internal border. */
787 if (windows_or_buffers_changed
788 && (f
= XFRAME (w
->frame
),
789 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
792 int height
= desired_row
->visible_height
;
793 int x
= (window_box_right (w
, -1)
794 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
795 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
797 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
798 x
, y
, width
, height
, False
);
806 /* Draw the bitmap WHICH in one of the areas to the left or right of
807 window W. ROW is the glyph row for which to display the bitmap; it
808 determines the vertical position at which the bitmap has to be
812 x_draw_bitmap (w
, row
, which
)
814 struct glyph_row
*row
;
815 enum bitmap_type which
;
817 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
818 Display
*display
= FRAME_X_DISPLAY (f
);
819 Window window
= FRAME_X_WINDOW (f
);
823 GC gc
= f
->output_data
.x
->normal_gc
;
825 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
827 /* Must clip because of partially visible lines. */
828 x_clip_to_row (w
, row
, gc
, 1);
832 case LEFT_TRUNCATION_BITMAP
:
836 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
838 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
841 case OVERLAY_ARROW_BITMAP
:
845 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
847 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
850 case RIGHT_TRUNCATION_BITMAP
:
854 x
= window_box_right (w
, -1);
855 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
858 case CONTINUED_LINE_BITMAP
:
861 bits
= continued_bits
;
862 x
= window_box_right (w
, -1);
863 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
866 case CONTINUATION_LINE_BITMAP
:
867 wd
= continuation_width
;
868 h
= continuation_height
;
869 bits
= continuation_bits
;
870 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
872 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
879 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
881 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
888 /* Convert to frame coordinates. Set dy to the offset in the row to
889 start drawing the bitmap. */
890 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
891 dy
= (row
->height
- h
) / 2;
893 /* Draw the bitmap. I believe these small pixmaps can be cached
895 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
896 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
898 face
->background
, depth
);
899 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
900 XFreePixmap (display
, pixmap
);
901 XSetClipMask (display
, gc
, None
);
905 /* Draw flags bitmaps for glyph row ROW on window W. Call this
906 function with input blocked. */
909 x_draw_row_bitmaps (w
, row
)
911 struct glyph_row
*row
;
913 struct frame
*f
= XFRAME (w
->frame
);
914 enum bitmap_type bitmap
;
916 int header_line_height
= -1;
918 xassert (interrupt_input_blocked
);
920 /* If row is completely invisible, because of vscrolling, we
921 don't have to draw anything. */
922 if (row
->visible_height
<= 0)
925 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
926 PREPARE_FACE_FOR_DISPLAY (f
, face
);
928 /* Decide which bitmap to draw at the left side. */
929 if (row
->overlay_arrow_p
)
930 bitmap
= OVERLAY_ARROW_BITMAP
;
931 else if (row
->truncated_on_left_p
)
932 bitmap
= LEFT_TRUNCATION_BITMAP
;
933 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
934 bitmap
= CONTINUATION_LINE_BITMAP
;
935 else if (row
->indicate_empty_line_p
)
936 bitmap
= ZV_LINE_BITMAP
;
940 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
942 if (bitmap
== NO_BITMAP
943 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
944 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
946 /* If W has a vertical border to its left, don't draw over it. */
947 int border
= ((XFASTINT (w
->left
) > 0
948 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
950 int left
= window_box_left (w
, -1);
952 if (header_line_height
< 0)
953 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
955 /* In case the same realized face is used for bitmap areas and
956 for something displayed in the text (e.g. face `region' on
957 mono-displays, the fill style may have been changed to
958 FillSolid in x_draw_glyph_string_background. */
960 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
962 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
964 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
967 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
969 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
971 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
972 row
->visible_height
);
974 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
977 /* Draw the left bitmap. */
978 if (bitmap
!= NO_BITMAP
)
979 x_draw_bitmap (w
, row
, bitmap
);
981 /* Decide which bitmap to draw at the right side. */
982 if (row
->truncated_on_right_p
)
983 bitmap
= RIGHT_TRUNCATION_BITMAP
;
984 else if (row
->continued_p
)
985 bitmap
= CONTINUED_LINE_BITMAP
;
989 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
991 if (bitmap
== NO_BITMAP
992 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
993 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
995 int right
= window_box_right (w
, -1);
997 if (header_line_height
< 0)
998 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1000 /* In case the same realized face is used for bitmap areas and
1001 for something displayed in the text (e.g. face `region' on
1002 mono-displays, the fill style may have been changed to
1003 FillSolid in x_draw_glyph_string_background. */
1005 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1007 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1008 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1011 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1013 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
1014 row
->visible_height
);
1016 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1019 /* Draw the right bitmap. */
1020 if (bitmap
!= NO_BITMAP
)
1021 x_draw_bitmap (w
, row
, bitmap
);
1025 /***********************************************************************
1027 ***********************************************************************/
1029 /* External interface to control of standout mode. Not used for X
1030 frames. Aborts when called. */
1033 XTreassert_line_highlight (new, vpos
)
1040 /* Call this when about to modify line at position VPOS and change
1041 whether it is highlighted. Not used for X frames. Aborts when
1045 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1046 int new_highlight
, vpos
, y
, first_unused_hpos
;
1052 /* This is called when starting Emacs and when restarting after
1053 suspend. When starting Emacs, no X window is mapped. And nothing
1054 must be done to Emacs's own window if it is suspended (though that
1058 XTset_terminal_modes ()
1062 /* This is called when exiting or suspending Emacs. Exiting will make
1063 the X-windows go away, and suspending requires no action. */
1066 XTreset_terminal_modes ()
1072 /***********************************************************************
1074 ***********************************************************************/
1076 /* Set the global variable output_cursor to CURSOR. All cursor
1077 positions are relative to updated_window. */
1080 set_output_cursor (cursor
)
1081 struct cursor_pos
*cursor
;
1083 output_cursor
.hpos
= cursor
->hpos
;
1084 output_cursor
.vpos
= cursor
->vpos
;
1085 output_cursor
.x
= cursor
->x
;
1086 output_cursor
.y
= cursor
->y
;
1090 /* Set a nominal cursor position.
1092 HPOS and VPOS are column/row positions in a window glyph matrix. X
1093 and Y are window text area relative pixel positions.
1095 If this is done during an update, updated_window will contain the
1096 window that is being updated and the position is the future output
1097 cursor position for that window. If updated_window is null, use
1098 selected_window and display the cursor at the given position. */
1101 XTcursor_to (vpos
, hpos
, y
, x
)
1102 int vpos
, hpos
, y
, x
;
1106 /* If updated_window is not set, work on selected_window. */
1110 w
= XWINDOW (selected_window
);
1112 /* Set the output cursor. */
1113 output_cursor
.hpos
= hpos
;
1114 output_cursor
.vpos
= vpos
;
1115 output_cursor
.x
= x
;
1116 output_cursor
.y
= y
;
1118 /* If not called as part of an update, really display the cursor.
1119 This will also set the cursor position of W. */
1120 if (updated_window
== NULL
)
1123 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1124 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1131 /***********************************************************************
1133 ***********************************************************************/
1135 /* Function prototypes of this page. */
1137 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1141 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1142 int, XChar2b
*, int));
1143 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1144 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1145 static void x_append_glyph
P_ ((struct it
*));
1146 static void x_append_composite_glyph
P_ ((struct it
*));
1147 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1149 static void x_produce_glyphs
P_ ((struct it
*));
1150 static void x_produce_image_glyph
P_ ((struct it
*it
));
1153 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1154 is not contained in the font. */
1156 static INLINE XCharStruct
*
1157 x_per_char_metric (font
, char2b
)
1161 /* The result metric information. */
1162 XCharStruct
*pcm
= NULL
;
1164 xassert (font
&& char2b
);
1166 if (font
->per_char
!= NULL
)
1168 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1170 /* min_char_or_byte2 specifies the linear character index
1171 corresponding to the first element of the per_char array,
1172 max_char_or_byte2 is the index of the last character. A
1173 character with non-zero CHAR2B->byte1 is not in the font.
1174 A character with byte2 less than min_char_or_byte2 or
1175 greater max_char_or_byte2 is not in the font. */
1176 if (char2b
->byte1
== 0
1177 && char2b
->byte2
>= font
->min_char_or_byte2
1178 && char2b
->byte2
<= font
->max_char_or_byte2
)
1179 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1183 /* If either min_byte1 or max_byte1 are nonzero, both
1184 min_char_or_byte2 and max_char_or_byte2 are less than
1185 256, and the 2-byte character index values corresponding
1186 to the per_char array element N (counting from 0) are:
1188 byte1 = N/D + min_byte1
1189 byte2 = N\D + min_char_or_byte2
1193 D = max_char_or_byte2 - min_char_or_byte2 + 1
1194 / = integer division
1195 \ = integer modulus */
1196 if (char2b
->byte1
>= font
->min_byte1
1197 && char2b
->byte1
<= font
->max_byte1
1198 && char2b
->byte2
>= font
->min_char_or_byte2
1199 && char2b
->byte2
<= font
->max_char_or_byte2
)
1201 pcm
= (font
->per_char
1202 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1203 * (char2b
->byte1
- font
->min_byte1
))
1204 + (char2b
->byte2
- font
->min_char_or_byte2
));
1210 /* If the per_char pointer is null, all glyphs between the first
1211 and last character indexes inclusive have the same
1212 information, as given by both min_bounds and max_bounds. */
1213 if (char2b
->byte2
>= font
->min_char_or_byte2
1214 && char2b
->byte2
<= font
->max_char_or_byte2
)
1215 pcm
= &font
->max_bounds
;
1218 return ((pcm
== NULL
1219 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1224 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1225 the two-byte form of C. Encoding is returned in *CHAR2B. */
1228 x_encode_char (c
, char2b
, font_info
)
1231 struct font_info
*font_info
;
1233 int charset
= CHAR_CHARSET (c
);
1234 XFontStruct
*font
= font_info
->font
;
1236 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1237 This may be either a program in a special encoder language or a
1239 if (font_info
->font_encoder
)
1241 /* It's a program. */
1242 struct ccl_program
*ccl
= font_info
->font_encoder
;
1244 if (CHARSET_DIMENSION (charset
) == 1)
1246 ccl
->reg
[0] = charset
;
1247 ccl
->reg
[1] = char2b
->byte2
;
1251 ccl
->reg
[0] = charset
;
1252 ccl
->reg
[1] = char2b
->byte1
;
1253 ccl
->reg
[2] = char2b
->byte2
;
1256 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1258 /* We assume that MSBs are appropriately set/reset by CCL
1260 if (font
->max_byte1
== 0) /* 1-byte font */
1261 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1263 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1265 else if (font_info
->encoding
[charset
])
1267 /* Fixed encoding scheme. See fontset.h for the meaning of the
1268 encoding numbers. */
1269 int enc
= font_info
->encoding
[charset
];
1271 if ((enc
== 1 || enc
== 2)
1272 && CHARSET_DIMENSION (charset
) == 2)
1273 char2b
->byte1
|= 0x80;
1275 if (enc
== 1 || enc
== 3)
1276 char2b
->byte2
|= 0x80;
1281 /* Get face and two-byte form of character C in face FACE_ID on frame
1282 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1283 means we want to display multibyte text. Value is a pointer to a
1284 realized face that is ready for display. */
1286 static INLINE
struct face
*
1287 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1293 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1297 /* Unibyte case. We don't have to encode, but we have to make
1298 sure to use a face suitable for unibyte. */
1301 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1302 face
= FACE_FROM_ID (f
, face_id
);
1304 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1306 /* Case of ASCII in a face known to fit ASCII. */
1312 int c1
, c2
, charset
;
1314 /* Split characters into bytes. If c2 is -1 afterwards, C is
1315 really a one-byte character so that byte1 is zero. */
1316 SPLIT_CHAR (c
, charset
, c1
, c2
);
1318 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1320 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1322 /* Maybe encode the character in *CHAR2B. */
1323 if (face
->font
!= NULL
)
1325 struct font_info
*font_info
1326 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1328 x_encode_char (c
, char2b
, font_info
);
1332 /* Make sure X resources of the face are allocated. */
1333 xassert (face
!= NULL
);
1334 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1340 /* Get face and two-byte form of character glyph GLYPH on frame F.
1341 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1342 a pointer to a realized face that is ready for display. */
1344 static INLINE
struct face
*
1345 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1347 struct glyph
*glyph
;
1353 xassert (glyph
->type
== CHAR_GLYPH
);
1354 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1359 if (!glyph
->multibyte_p
)
1361 /* Unibyte case. We don't have to encode, but we have to make
1362 sure to use a face suitable for unibyte. */
1364 char2b
->byte2
= glyph
->u
.ch
;
1366 else if (glyph
->u
.ch
< 128
1367 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1369 /* Case of ASCII in a face known to fit ASCII. */
1371 char2b
->byte2
= glyph
->u
.ch
;
1375 int c1
, c2
, charset
;
1377 /* Split characters into bytes. If c2 is -1 afterwards, C is
1378 really a one-byte character so that byte1 is zero. */
1379 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1381 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1383 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1385 /* Maybe encode the character in *CHAR2B. */
1386 if (charset
!= CHARSET_ASCII
)
1388 struct font_info
*font_info
1389 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1392 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1395 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1400 /* Make sure X resources of the face are allocated. */
1401 xassert (face
!= NULL
);
1402 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1407 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1408 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1414 struct glyph
*glyph
;
1415 enum glyph_row_area area
= it
->area
;
1417 xassert (it
->glyph_row
);
1418 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1420 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1421 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1423 glyph
->charpos
= CHARPOS (it
->position
);
1424 glyph
->object
= it
->object
;
1425 glyph
->pixel_width
= it
->pixel_width
;
1426 glyph
->voffset
= it
->voffset
;
1427 glyph
->type
= CHAR_GLYPH
;
1428 glyph
->multibyte_p
= it
->multibyte_p
;
1429 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1430 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1431 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1432 || it
->phys_descent
> it
->descent
);
1433 glyph
->padding_p
= 0;
1434 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1435 glyph
->face_id
= it
->face_id
;
1436 glyph
->u
.ch
= it
->char_to_display
;
1437 ++it
->glyph_row
->used
[area
];
1441 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1442 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1445 x_append_composite_glyph (it
)
1448 struct glyph
*glyph
;
1449 enum glyph_row_area area
= it
->area
;
1451 xassert (it
->glyph_row
);
1453 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1454 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1456 glyph
->charpos
= CHARPOS (it
->position
);
1457 glyph
->object
= it
->object
;
1458 glyph
->pixel_width
= it
->pixel_width
;
1459 glyph
->voffset
= it
->voffset
;
1460 glyph
->type
= COMPOSITE_GLYPH
;
1461 glyph
->multibyte_p
= it
->multibyte_p
;
1462 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1463 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1464 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1465 || it
->phys_descent
> it
->descent
);
1466 glyph
->padding_p
= 0;
1467 glyph
->glyph_not_available_p
= 0;
1468 glyph
->face_id
= it
->face_id
;
1469 glyph
->u
.cmp_id
= it
->cmp_id
;
1470 ++it
->glyph_row
->used
[area
];
1475 /* Change IT->ascent and IT->height according to the setting of
1479 take_vertical_position_into_account (it
)
1484 if (it
->voffset
< 0)
1485 /* Increase the ascent so that we can display the text higher
1487 it
->ascent
+= abs (it
->voffset
);
1489 /* Increase the descent so that we can display the text lower
1491 it
->descent
+= it
->voffset
;
1496 /* Produce glyphs/get display metrics for the image IT is loaded with.
1497 See the description of struct display_iterator in dispextern.h for
1498 an overview of struct display_iterator. */
1501 x_produce_image_glyph (it
)
1507 xassert (it
->what
== IT_IMAGE
);
1509 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1510 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1513 /* Make sure X resources of the face and image are loaded. */
1514 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1515 prepare_image_for_display (it
->f
, img
);
1517 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1518 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1519 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1523 if (face
->box
!= FACE_NO_BOX
)
1525 if (face
->box_line_width
> 0)
1527 it
->ascent
+= face
->box_line_width
;
1528 it
->descent
+= face
->box_line_width
;
1531 if (it
->start_of_box_run_p
)
1532 it
->pixel_width
+= abs (face
->box_line_width
);
1533 if (it
->end_of_box_run_p
)
1534 it
->pixel_width
+= abs (face
->box_line_width
);
1537 take_vertical_position_into_account (it
);
1541 struct glyph
*glyph
;
1542 enum glyph_row_area area
= it
->area
;
1544 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1545 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1547 glyph
->charpos
= CHARPOS (it
->position
);
1548 glyph
->object
= it
->object
;
1549 glyph
->pixel_width
= it
->pixel_width
;
1550 glyph
->voffset
= it
->voffset
;
1551 glyph
->type
= IMAGE_GLYPH
;
1552 glyph
->multibyte_p
= it
->multibyte_p
;
1553 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1554 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1555 glyph
->overlaps_vertically_p
= 0;
1556 glyph
->padding_p
= 0;
1557 glyph
->glyph_not_available_p
= 0;
1558 glyph
->face_id
= it
->face_id
;
1559 glyph
->u
.img_id
= img
->id
;
1560 ++it
->glyph_row
->used
[area
];
1566 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1567 of the glyph, WIDTH and HEIGHT are the width and height of the
1568 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1569 ascent of the glyph (0 <= ASCENT <= 1). */
1572 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1578 struct glyph
*glyph
;
1579 enum glyph_row_area area
= it
->area
;
1581 xassert (ascent
>= 0 && ascent
<= 1);
1583 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1584 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1586 glyph
->charpos
= CHARPOS (it
->position
);
1587 glyph
->object
= object
;
1588 glyph
->pixel_width
= width
;
1589 glyph
->voffset
= it
->voffset
;
1590 glyph
->type
= STRETCH_GLYPH
;
1591 glyph
->multibyte_p
= it
->multibyte_p
;
1592 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1593 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1594 glyph
->overlaps_vertically_p
= 0;
1595 glyph
->padding_p
= 0;
1596 glyph
->glyph_not_available_p
= 0;
1597 glyph
->face_id
= it
->face_id
;
1598 glyph
->u
.stretch
.ascent
= height
* ascent
;
1599 glyph
->u
.stretch
.height
= height
;
1600 ++it
->glyph_row
->used
[area
];
1605 /* Produce a stretch glyph for iterator IT. IT->object is the value
1606 of the glyph property displayed. The value must be a list
1607 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1610 1. `:width WIDTH' specifies that the space should be WIDTH *
1611 canonical char width wide. WIDTH may be an integer or floating
1614 2. `:relative-width FACTOR' specifies that the width of the stretch
1615 should be computed from the width of the first character having the
1616 `glyph' property, and should be FACTOR times that width.
1618 3. `:align-to HPOS' specifies that the space should be wide enough
1619 to reach HPOS, a value in canonical character units.
1621 Exactly one of the above pairs must be present.
1623 4. `:height HEIGHT' specifies that the height of the stretch produced
1624 should be HEIGHT, measured in canonical character units.
1626 5. `:relative-height FACTOR' specifies that the height of the the
1627 stretch should be FACTOR times the height of the characters having
1630 Either none or exactly one of 4 or 5 must be present.
1632 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1633 of the stretch should be used for the ascent of the stretch.
1634 ASCENT must be in the range 0 <= ASCENT <= 100. */
1637 ((INTEGERP (X) || FLOATP (X)) \
1643 x_produce_stretch_glyph (it
)
1646 /* (space :width WIDTH :height HEIGHT. */
1648 extern Lisp_Object Qspace
;
1650 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1651 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1652 extern Lisp_Object QCalign_to
;
1653 Lisp_Object prop
, plist
;
1654 double width
= 0, height
= 0, ascent
= 0;
1655 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1656 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1658 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1660 /* List should start with `space'. */
1661 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1662 plist
= XCDR (it
->object
);
1664 /* Compute the width of the stretch. */
1665 if (prop
= Fplist_get (plist
, QCwidth
),
1667 /* Absolute width `:width WIDTH' specified and valid. */
1668 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1669 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1672 /* Relative width `:relative-width FACTOR' specified and valid.
1673 Compute the width of the characters having the `glyph'
1676 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1679 if (it
->multibyte_p
)
1681 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1682 - IT_BYTEPOS (*it
));
1683 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1686 it2
.c
= *p
, it2
.len
= 1;
1688 it2
.glyph_row
= NULL
;
1689 it2
.what
= IT_CHARACTER
;
1690 x_produce_glyphs (&it2
);
1691 width
= NUMVAL (prop
) * it2
.pixel_width
;
1693 else if (prop
= Fplist_get (plist
, QCalign_to
),
1695 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1697 /* Nothing specified -> width defaults to canonical char width. */
1698 width
= CANON_X_UNIT (it
->f
);
1700 /* Compute height. */
1701 if (prop
= Fplist_get (plist
, QCheight
),
1703 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1704 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1706 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1708 height
= FONT_HEIGHT (font
);
1710 /* Compute percentage of height used for ascent. If
1711 `:ascent ASCENT' is present and valid, use that. Otherwise,
1712 derive the ascent from the font in use. */
1713 if (prop
= Fplist_get (plist
, QCascent
),
1714 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1715 ascent
= NUMVAL (prop
) / 100.0;
1717 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1726 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1727 if (!STRINGP (object
))
1728 object
= it
->w
->buffer
;
1729 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1732 it
->pixel_width
= width
;
1733 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1734 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1737 if (face
->box
!= FACE_NO_BOX
)
1739 if (face
->box_line_width
> 0)
1741 it
->ascent
+= face
->box_line_width
;
1742 it
->descent
+= face
->box_line_width
;
1745 if (it
->start_of_box_run_p
)
1746 it
->pixel_width
+= abs (face
->box_line_width
);
1747 if (it
->end_of_box_run_p
)
1748 it
->pixel_width
+= abs (face
->box_line_width
);
1751 take_vertical_position_into_account (it
);
1754 /* Return proper value to be used as baseline offset of font that has
1755 ASCENT and DESCENT to draw characters by the font at the vertical
1756 center of the line of frame F.
1758 Here, out task is to find the value of BOFF in the following figure;
1760 -------------------------+-----------+-
1761 -+-+---------+-+ | |
1763 | | | | F_ASCENT F_HEIGHT
1766 | | |-|-+------+-----------|------- baseline
1768 | |---------|-+-+ | |
1770 -+-+---------+-+ F_DESCENT |
1771 -------------------------+-----------+-
1773 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1774 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1775 DESCENT = FONT->descent
1776 HEIGHT = FONT_HEIGHT (FONT)
1777 F_DESCENT = (F->output_data.x->font->descent
1778 - F->output_data.x->baseline_offset)
1779 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1782 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1784 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1785 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1786 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1788 /* Produce glyphs/get display metrics for the display element IT is
1789 loaded with. See the description of struct display_iterator in
1790 dispextern.h for an overview of struct display_iterator. */
1793 x_produce_glyphs (it
)
1796 it
->glyph_not_available_p
= 0;
1798 if (it
->what
== IT_CHARACTER
)
1802 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1804 int font_not_found_p
;
1805 struct font_info
*font_info
;
1806 int boff
; /* baseline offset */
1807 /* We may change it->multibyte_p upon unibyte<->multibyte
1808 conversion. So, save the current value now and restore it
1811 Note: It seems that we don't have to record multibyte_p in
1812 struct glyph because the character code itself tells if or
1813 not the character is multibyte. Thus, in the future, we must
1814 consider eliminating the field `multibyte_p' in the struct
1817 int saved_multibyte_p
= it
->multibyte_p
;
1819 /* Maybe translate single-byte characters to multibyte, or the
1821 it
->char_to_display
= it
->c
;
1822 if (!ASCII_BYTE_P (it
->c
))
1824 if (unibyte_display_via_language_environment
1825 && SINGLE_BYTE_CHAR_P (it
->c
)
1827 || !NILP (Vnonascii_translation_table
)))
1829 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1830 it
->multibyte_p
= 1;
1831 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1832 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1834 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1835 && !it
->multibyte_p
)
1837 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1838 it
->multibyte_p
= 0;
1839 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1840 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1844 /* Get font to use. Encode IT->char_to_display. */
1845 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1846 it
->face_id
, &char2b
,
1850 /* When no suitable font found, use the default font. */
1851 font_not_found_p
= font
== NULL
;
1852 if (font_not_found_p
)
1854 font
= FRAME_FONT (it
->f
);
1855 boff
= it
->f
->output_data
.x
->baseline_offset
;
1860 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1861 boff
= font_info
->baseline_offset
;
1862 if (font_info
->vertical_centering
)
1863 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1866 if (it
->char_to_display
>= ' '
1867 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1869 /* Either unibyte or ASCII. */
1874 pcm
= x_per_char_metric (font
, &char2b
);
1875 it
->ascent
= font
->ascent
+ boff
;
1876 it
->descent
= font
->descent
- boff
;
1880 it
->phys_ascent
= pcm
->ascent
+ boff
;
1881 it
->phys_descent
= pcm
->descent
- boff
;
1882 it
->pixel_width
= pcm
->width
;
1886 it
->glyph_not_available_p
= 1;
1887 it
->phys_ascent
= font
->ascent
+ boff
;
1888 it
->phys_descent
= font
->descent
- boff
;
1889 it
->pixel_width
= FONT_WIDTH (font
);
1892 /* If this is a space inside a region of text with
1893 `space-width' property, change its width. */
1894 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1896 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1898 /* If face has a box, add the box thickness to the character
1899 height. If character has a box line to the left and/or
1900 right, add the box line width to the character's width. */
1901 if (face
->box
!= FACE_NO_BOX
)
1903 int thick
= face
->box_line_width
;
1907 it
->ascent
+= thick
;
1908 it
->descent
+= thick
;
1913 if (it
->start_of_box_run_p
)
1914 it
->pixel_width
+= thick
;
1915 if (it
->end_of_box_run_p
)
1916 it
->pixel_width
+= thick
;
1919 /* If face has an overline, add the height of the overline
1920 (1 pixel) and a 1 pixel margin to the character height. */
1921 if (face
->overline_p
)
1924 take_vertical_position_into_account (it
);
1926 /* If we have to actually produce glyphs, do it. */
1931 /* Translate a space with a `space-width' property
1932 into a stretch glyph. */
1933 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1934 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1935 it
->ascent
+ it
->descent
, ascent
);
1938 x_append_glyph (it
);
1940 /* If characters with lbearing or rbearing are displayed
1941 in this line, record that fact in a flag of the
1942 glyph row. This is used to optimize X output code. */
1943 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1944 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1947 else if (it
->char_to_display
== '\n')
1949 /* A newline has no width but we need the height of the line. */
1950 it
->pixel_width
= 0;
1952 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1953 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1955 if (face
->box
!= FACE_NO_BOX
1956 && face
->box_line_width
> 0)
1958 it
->ascent
+= face
->box_line_width
;
1959 it
->descent
+= face
->box_line_width
;
1962 else if (it
->char_to_display
== '\t')
1964 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1965 int x
= it
->current_x
+ it
->continuation_lines_width
;
1966 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1968 /* If the distance from the current position to the next tab
1969 stop is less than a canonical character width, use the
1970 tab stop after that. */
1971 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1972 next_tab_x
+= tab_width
;
1974 it
->pixel_width
= next_tab_x
- x
;
1976 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1977 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1981 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1982 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1983 it
->ascent
+ it
->descent
, ascent
);
1988 /* A multi-byte character. Assume that the display width of the
1989 character is the width of the character multiplied by the
1990 width of the font. */
1992 /* If we found a font, this font should give us the right
1993 metrics. If we didn't find a font, use the frame's
1994 default font and calculate the width of the character
1995 from the charset width; this is what old redisplay code
1997 pcm
= x_per_char_metric (font
, &char2b
);
1998 if (font_not_found_p
|| !pcm
)
2000 int charset
= CHAR_CHARSET (it
->char_to_display
);
2002 it
->glyph_not_available_p
= 1;
2003 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2004 * CHARSET_WIDTH (charset
));
2005 it
->phys_ascent
= font
->ascent
+ boff
;
2006 it
->phys_descent
= font
->descent
- boff
;
2010 it
->pixel_width
= pcm
->width
;
2011 it
->phys_ascent
= pcm
->ascent
+ boff
;
2012 it
->phys_descent
= pcm
->descent
- boff
;
2014 && (pcm
->lbearing
< 0
2015 || pcm
->rbearing
> pcm
->width
))
2016 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2019 it
->ascent
= font
->ascent
+ boff
;
2020 it
->descent
= font
->descent
- boff
;
2021 if (face
->box
!= FACE_NO_BOX
)
2023 int thick
= face
->box_line_width
;
2027 it
->ascent
+= thick
;
2028 it
->descent
+= thick
;
2033 if (it
->start_of_box_run_p
)
2034 it
->pixel_width
+= thick
;
2035 if (it
->end_of_box_run_p
)
2036 it
->pixel_width
+= thick
;
2039 /* If face has an overline, add the height of the overline
2040 (1 pixel) and a 1 pixel margin to the character height. */
2041 if (face
->overline_p
)
2044 take_vertical_position_into_account (it
);
2047 x_append_glyph (it
);
2049 it
->multibyte_p
= saved_multibyte_p
;
2051 else if (it
->what
== IT_COMPOSITION
)
2053 /* Note: A composition is represented as one glyph in the
2054 glyph matrix. There are no padding glyphs. */
2057 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2059 int font_not_found_p
;
2060 struct font_info
*font_info
;
2061 int boff
; /* baseline offset */
2062 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2064 /* Maybe translate single-byte characters to multibyte. */
2065 it
->char_to_display
= it
->c
;
2066 if (unibyte_display_via_language_environment
2067 && SINGLE_BYTE_CHAR_P (it
->c
)
2070 && !NILP (Vnonascii_translation_table
))))
2072 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2075 /* Get face and font to use. Encode IT->char_to_display. */
2076 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2077 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2078 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2079 it
->face_id
, &char2b
, it
->multibyte_p
);
2082 /* When no suitable font found, use the default font. */
2083 font_not_found_p
= font
== NULL
;
2084 if (font_not_found_p
)
2086 font
= FRAME_FONT (it
->f
);
2087 boff
= it
->f
->output_data
.x
->baseline_offset
;
2092 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2093 boff
= font_info
->baseline_offset
;
2094 if (font_info
->vertical_centering
)
2095 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2098 /* There are no padding glyphs, so there is only one glyph to
2099 produce for the composition. Important is that pixel_width,
2100 ascent and descent are the values of what is drawn by
2101 draw_glyphs (i.e. the values of the overall glyphs composed). */
2104 /* If we have not yet calculated pixel size data of glyphs of
2105 the composition for the current face font, calculate them
2106 now. Theoretically, we have to check all fonts for the
2107 glyphs, but that requires much time and memory space. So,
2108 here we check only the font of the first glyph. This leads
2109 to incorrect display very rarely, and C-l (recenter) can
2110 correct the display anyway. */
2111 if (cmp
->font
!= (void *) font
)
2113 /* Ascent and descent of the font of the first character of
2114 this composition (adjusted by baseline offset). Ascent
2115 and descent of overall glyphs should not be less than
2116 them respectively. */
2117 int font_ascent
= font
->ascent
+ boff
;
2118 int font_descent
= font
->descent
- boff
;
2119 /* Bounding box of the overall glyphs. */
2120 int leftmost
, rightmost
, lowest
, highest
;
2121 int i
, width
, ascent
, descent
;
2123 cmp
->font
= (void *) font
;
2125 /* Initialize the bounding box. */
2127 && (pcm
= x_per_char_metric (font
, &char2b
)))
2130 ascent
= pcm
->ascent
;
2131 descent
= pcm
->descent
;
2135 width
= FONT_WIDTH (font
);
2136 ascent
= font
->ascent
;
2137 descent
= font
->descent
;
2141 lowest
= - descent
+ boff
;
2142 highest
= ascent
+ boff
;
2146 && font_info
->default_ascent
2147 && CHAR_TABLE_P (Vuse_default_ascent
)
2148 && !NILP (Faref (Vuse_default_ascent
,
2149 make_number (it
->char_to_display
))))
2150 highest
= font_info
->default_ascent
+ boff
;
2152 /* Draw the first glyph at the normal position. It may be
2153 shifted to right later if some other glyphs are drawn at
2155 cmp
->offsets
[0] = 0;
2156 cmp
->offsets
[1] = boff
;
2158 /* Set cmp->offsets for the remaining glyphs. */
2159 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2161 int left
, right
, btm
, top
;
2162 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2163 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2165 face
= FACE_FROM_ID (it
->f
, face_id
);
2166 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2171 font
= FRAME_FONT (it
->f
);
2172 boff
= it
->f
->output_data
.x
->baseline_offset
;
2178 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2179 boff
= font_info
->baseline_offset
;
2180 if (font_info
->vertical_centering
)
2181 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2185 && (pcm
= x_per_char_metric (font
, &char2b
)))
2188 ascent
= pcm
->ascent
;
2189 descent
= pcm
->descent
;
2193 width
= FONT_WIDTH (font
);
2198 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2200 /* Relative composition with or without
2202 left
= (leftmost
+ rightmost
- width
) / 2;
2203 btm
= - descent
+ boff
;
2204 if (font_info
&& font_info
->relative_compose
2205 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2206 || NILP (Faref (Vignore_relative_composition
,
2207 make_number (ch
)))))
2210 if (- descent
>= font_info
->relative_compose
)
2211 /* One extra pixel between two glyphs. */
2213 else if (ascent
<= 0)
2214 /* One extra pixel between two glyphs. */
2215 btm
= lowest
- 1 - ascent
- descent
;
2220 /* A composition rule is specified by an integer
2221 value that encodes global and new reference
2222 points (GREF and NREF). GREF and NREF are
2223 specified by numbers as below:
2231 ---3---4---5--- baseline
2233 6---7---8 -- descent
2235 int rule
= COMPOSITION_RULE (cmp
, i
);
2236 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2238 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2239 grefx
= gref
% 3, nrefx
= nref
% 3;
2240 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2243 + grefx
* (rightmost
- leftmost
) / 2
2244 - nrefx
* width
/ 2);
2245 btm
= ((grefy
== 0 ? highest
2247 : grefy
== 2 ? lowest
2248 : (highest
+ lowest
) / 2)
2249 - (nrefy
== 0 ? ascent
+ descent
2250 : nrefy
== 1 ? descent
- boff
2252 : (ascent
+ descent
) / 2));
2255 cmp
->offsets
[i
* 2] = left
;
2256 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2258 /* Update the bounding box of the overall glyphs. */
2259 right
= left
+ width
;
2260 top
= btm
+ descent
+ ascent
;
2261 if (left
< leftmost
)
2263 if (right
> rightmost
)
2271 /* If there are glyphs whose x-offsets are negative,
2272 shift all glyphs to the right and make all x-offsets
2276 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2277 cmp
->offsets
[i
* 2] -= leftmost
;
2278 rightmost
-= leftmost
;
2281 cmp
->pixel_width
= rightmost
;
2282 cmp
->ascent
= highest
;
2283 cmp
->descent
= - lowest
;
2284 if (cmp
->ascent
< font_ascent
)
2285 cmp
->ascent
= font_ascent
;
2286 if (cmp
->descent
< font_descent
)
2287 cmp
->descent
= font_descent
;
2290 it
->pixel_width
= cmp
->pixel_width
;
2291 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2292 it
->descent
= it
->phys_descent
= cmp
->descent
;
2294 if (face
->box
!= FACE_NO_BOX
)
2296 int thick
= face
->box_line_width
;
2300 it
->ascent
+= thick
;
2301 it
->descent
+= thick
;
2306 if (it
->start_of_box_run_p
)
2307 it
->pixel_width
+= thick
;
2308 if (it
->end_of_box_run_p
)
2309 it
->pixel_width
+= thick
;
2312 /* If face has an overline, add the height of the overline
2313 (1 pixel) and a 1 pixel margin to the character height. */
2314 if (face
->overline_p
)
2317 take_vertical_position_into_account (it
);
2320 x_append_composite_glyph (it
);
2322 else if (it
->what
== IT_IMAGE
)
2323 x_produce_image_glyph (it
);
2324 else if (it
->what
== IT_STRETCH
)
2325 x_produce_stretch_glyph (it
);
2327 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2328 because this isn't true for images with `:ascent 100'. */
2329 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2330 if (it
->area
== TEXT_AREA
)
2331 it
->current_x
+= it
->pixel_width
;
2333 it
->descent
+= it
->extra_line_spacing
;
2335 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2336 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2337 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2338 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2342 /* Estimate the pixel height of the mode or top line on frame F.
2343 FACE_ID specifies what line's height to estimate. */
2346 x_estimate_mode_line_height (f
, face_id
)
2348 enum face_id face_id
;
2350 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2352 /* This function is called so early when Emacs starts that the face
2353 cache and mode line face are not yet initialized. */
2354 if (FRAME_FACE_CACHE (f
))
2356 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2360 height
= FONT_HEIGHT (face
->font
);
2361 if (face
->box_line_width
> 0)
2362 height
+= 2 * face
->box_line_width
;
2370 /***********************************************************************
2372 ***********************************************************************/
2374 /* A sequence of glyphs to be drawn in the same face.
2376 This data structure is not really completely X specific, so it
2377 could possibly, at least partially, be useful for other systems. It
2378 is currently not part of the external redisplay interface because
2379 it's not clear what other systems will need. */
2383 /* X-origin of the string. */
2386 /* Y-origin and y-position of the base line of this string. */
2389 /* The width of the string, not including a face extension. */
2392 /* The width of the string, including a face extension. */
2393 int background_width
;
2395 /* The height of this string. This is the height of the line this
2396 string is drawn in, and can be different from the height of the
2397 font the string is drawn in. */
2400 /* Number of pixels this string overwrites in front of its x-origin.
2401 This number is zero if the string has an lbearing >= 0; it is
2402 -lbearing, if the string has an lbearing < 0. */
2405 /* Number of pixels this string overwrites past its right-most
2406 nominal x-position, i.e. x + width. Zero if the string's
2407 rbearing is <= its nominal width, rbearing - width otherwise. */
2410 /* The frame on which the glyph string is drawn. */
2413 /* The window on which the glyph string is drawn. */
2416 /* X display and window for convenience. */
2420 /* The glyph row for which this string was built. It determines the
2421 y-origin and height of the string. */
2422 struct glyph_row
*row
;
2424 /* The area within row. */
2425 enum glyph_row_area area
;
2427 /* Characters to be drawn, and number of characters. */
2431 /* A face-override for drawing cursors, mouse face and similar. */
2432 enum draw_glyphs_face hl
;
2434 /* Face in which this string is to be drawn. */
2437 /* Font in which this string is to be drawn. */
2440 /* Font info for this string. */
2441 struct font_info
*font_info
;
2443 /* Non-null means this string describes (part of) a composition.
2444 All characters from char2b are drawn composed. */
2445 struct composition
*cmp
;
2447 /* Index of this glyph string's first character in the glyph
2448 definition of CMP. If this is zero, this glyph string describes
2449 the first character of a composition. */
2452 /* 1 means this glyph strings face has to be drawn to the right end
2453 of the window's drawing area. */
2454 unsigned extends_to_end_of_line_p
: 1;
2456 /* 1 means the background of this string has been drawn. */
2457 unsigned background_filled_p
: 1;
2459 /* 1 means glyph string must be drawn with 16-bit functions. */
2460 unsigned two_byte_p
: 1;
2462 /* 1 means that the original font determined for drawing this glyph
2463 string could not be loaded. The member `font' has been set to
2464 the frame's default font in this case. */
2465 unsigned font_not_found_p
: 1;
2467 /* 1 means that the face in which this glyph string is drawn has a
2469 unsigned stippled_p
: 1;
2471 /* 1 means only the foreground of this glyph string must be drawn,
2472 and we should use the physical height of the line this glyph
2473 string appears in as clip rect. */
2474 unsigned for_overlaps_p
: 1;
2476 /* The GC to use for drawing this glyph string. */
2479 /* A pointer to the first glyph in the string. This glyph
2480 corresponds to char2b[0]. Needed to draw rectangles if
2481 font_not_found_p is 1. */
2482 struct glyph
*first_glyph
;
2484 /* Image, if any. */
2487 struct glyph_string
*next
, *prev
;
2494 x_dump_glyph_string (s
)
2495 struct glyph_string
*s
;
2497 fprintf (stderr
, "glyph string\n");
2498 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2499 s
->x
, s
->y
, s
->width
, s
->height
);
2500 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2501 fprintf (stderr
, " hl = %d\n", s
->hl
);
2502 fprintf (stderr
, " left overhang = %d, right = %d\n",
2503 s
->left_overhang
, s
->right_overhang
);
2504 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2505 fprintf (stderr
, " extends to end of line = %d\n",
2506 s
->extends_to_end_of_line_p
);
2507 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2508 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2511 #endif /* GLYPH_DEBUG */
2515 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2516 struct glyph_string
**,
2517 struct glyph_string
*,
2518 struct glyph_string
*));
2519 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2520 struct glyph_string
**,
2521 struct glyph_string
*,
2522 struct glyph_string
*));
2523 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2524 struct glyph_string
**,
2525 struct glyph_string
*));
2526 static int x_left_overwritten
P_ ((struct glyph_string
*));
2527 static int x_left_overwriting
P_ ((struct glyph_string
*));
2528 static int x_right_overwritten
P_ ((struct glyph_string
*));
2529 static int x_right_overwriting
P_ ((struct glyph_string
*));
2530 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2532 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2533 XChar2b
*, struct window
*,
2535 enum glyph_row_area
, int,
2536 enum draw_glyphs_face
));
2537 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2538 enum glyph_row_area
, int, int,
2539 enum draw_glyphs_face
, int *, int *, int));
2540 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2541 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2542 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2544 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2545 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2546 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2547 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2548 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2549 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2550 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2551 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2552 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2554 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2555 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2556 unsigned long *, double, int));
2557 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2558 double, int, unsigned long));
2559 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2560 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2561 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2562 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2563 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2564 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2565 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2567 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2568 int, int, int, int, XRectangle
*));
2569 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2570 int, int, int, XRectangle
*));
2571 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2572 enum glyph_row_area
));
2573 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2575 enum glyph_row_area
, int, int));
2578 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2582 /* Append the list of glyph strings with head H and tail T to the list
2583 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2586 x_append_glyph_string_lists (head
, tail
, h
, t
)
2587 struct glyph_string
**head
, **tail
;
2588 struct glyph_string
*h
, *t
;
2602 /* Prepend the list of glyph strings with head H and tail T to the
2603 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2607 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2608 struct glyph_string
**head
, **tail
;
2609 struct glyph_string
*h
, *t
;
2623 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2624 Set *HEAD and *TAIL to the resulting list. */
2627 x_append_glyph_string (head
, tail
, s
)
2628 struct glyph_string
**head
, **tail
;
2629 struct glyph_string
*s
;
2631 s
->next
= s
->prev
= NULL
;
2632 x_append_glyph_string_lists (head
, tail
, s
, s
);
2636 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2641 struct glyph_string
*s
;
2643 if (s
->font
== FRAME_FONT (s
->f
)
2644 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2645 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2647 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2650 /* Cursor on non-default face: must merge. */
2654 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2655 xgcv
.foreground
= s
->face
->background
;
2657 /* If the glyph would be invisible, try a different foreground. */
2658 if (xgcv
.foreground
== xgcv
.background
)
2659 xgcv
.foreground
= s
->face
->foreground
;
2660 if (xgcv
.foreground
== xgcv
.background
)
2661 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2662 if (xgcv
.foreground
== xgcv
.background
)
2663 xgcv
.foreground
= s
->face
->foreground
;
2665 /* Make sure the cursor is distinct from text in this face. */
2666 if (xgcv
.background
== s
->face
->background
2667 && xgcv
.foreground
== s
->face
->foreground
)
2669 xgcv
.background
= s
->face
->foreground
;
2670 xgcv
.foreground
= s
->face
->background
;
2673 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2674 xgcv
.font
= s
->font
->fid
;
2675 xgcv
.graphics_exposures
= False
;
2676 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2678 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2679 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2682 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2683 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2685 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2690 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2693 x_set_mouse_face_gc (s
)
2694 struct glyph_string
*s
;
2699 /* What face has to be used last for the mouse face? */
2700 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2701 face
= FACE_FROM_ID (s
->f
, face_id
);
2703 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2705 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2706 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2708 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2709 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2710 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2712 /* If font in this face is same as S->font, use it. */
2713 if (s
->font
== s
->face
->font
)
2714 s
->gc
= s
->face
->gc
;
2717 /* Otherwise construct scratch_cursor_gc with values from FACE
2722 xgcv
.background
= s
->face
->background
;
2723 xgcv
.foreground
= s
->face
->foreground
;
2724 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2725 xgcv
.font
= s
->font
->fid
;
2726 xgcv
.graphics_exposures
= False
;
2727 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2729 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2730 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2733 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2734 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2736 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2739 xassert (s
->gc
!= 0);
2743 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2744 Faces to use in the mode line have already been computed when the
2745 matrix was built, so there isn't much to do, here. */
2748 x_set_mode_line_face_gc (s
)
2749 struct glyph_string
*s
;
2751 s
->gc
= s
->face
->gc
;
2755 /* Set S->gc of glyph string S for drawing that glyph string. Set
2756 S->stippled_p to a non-zero value if the face of S has a stipple
2760 x_set_glyph_string_gc (s
)
2761 struct glyph_string
*s
;
2763 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2765 if (s
->hl
== DRAW_NORMAL_TEXT
)
2767 s
->gc
= s
->face
->gc
;
2768 s
->stippled_p
= s
->face
->stipple
!= 0;
2770 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2772 x_set_mode_line_face_gc (s
);
2773 s
->stippled_p
= s
->face
->stipple
!= 0;
2775 else if (s
->hl
== DRAW_CURSOR
)
2777 x_set_cursor_gc (s
);
2780 else if (s
->hl
== DRAW_MOUSE_FACE
)
2782 x_set_mouse_face_gc (s
);
2783 s
->stippled_p
= s
->face
->stipple
!= 0;
2785 else if (s
->hl
== DRAW_IMAGE_RAISED
2786 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2788 s
->gc
= s
->face
->gc
;
2789 s
->stippled_p
= s
->face
->stipple
!= 0;
2793 s
->gc
= s
->face
->gc
;
2794 s
->stippled_p
= s
->face
->stipple
!= 0;
2797 /* GC must have been set. */
2798 xassert (s
->gc
!= 0);
2802 /* Return in *R the clipping rectangle for glyph string S. */
2805 x_get_glyph_string_clip_rect (s
, r
)
2806 struct glyph_string
*s
;
2809 if (s
->row
->full_width_p
)
2811 /* Draw full-width. X coordinates are relative to S->w->left. */
2812 int canon_x
= CANON_X_UNIT (s
->f
);
2814 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2815 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2817 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2819 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2820 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2824 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2826 /* Unless displaying a mode or menu bar line, which are always
2827 fully visible, clip to the visible part of the row. */
2828 if (s
->w
->pseudo_window_p
)
2829 r
->height
= s
->row
->visible_height
;
2831 r
->height
= s
->height
;
2835 /* This is a text line that may be partially visible. */
2836 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2837 r
->width
= window_box_width (s
->w
, s
->area
);
2838 r
->height
= s
->row
->visible_height
;
2841 /* Don't use S->y for clipping because it doesn't take partially
2842 visible lines into account. For example, it can be negative for
2843 partially visible lines at the top of a window. */
2844 if (!s
->row
->full_width_p
2845 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2846 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2848 r
->y
= max (0, s
->row
->y
);
2850 /* If drawing a tool-bar window, draw it over the internal border
2851 at the top of the window. */
2852 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2853 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2855 /* If S draws overlapping rows, it's sufficient to use the top and
2856 bottom of the window for clipping because this glyph string
2857 intentionally draws over other lines. */
2858 if (s
->for_overlaps_p
)
2860 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2861 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2864 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2868 /* Set clipping for output of glyph string S. S may be part of a mode
2869 line or menu if we don't have X toolkit support. */
2872 x_set_glyph_string_clipping (s
)
2873 struct glyph_string
*s
;
2876 x_get_glyph_string_clip_rect (s
, &r
);
2877 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2881 /* Compute left and right overhang of glyph string S. If S is a glyph
2882 string for a composition, assume overhangs don't exist. */
2885 x_compute_glyph_string_overhangs (s
)
2886 struct glyph_string
*s
;
2889 && s
->first_glyph
->type
== CHAR_GLYPH
)
2892 int direction
, font_ascent
, font_descent
;
2893 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2894 &font_ascent
, &font_descent
, &cs
);
2895 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2896 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2901 /* Compute overhangs and x-positions for glyph string S and its
2902 predecessors, or successors. X is the starting x-position for S.
2903 BACKWARD_P non-zero means process predecessors. */
2906 x_compute_overhangs_and_x (s
, x
, backward_p
)
2907 struct glyph_string
*s
;
2915 x_compute_glyph_string_overhangs (s
);
2925 x_compute_glyph_string_overhangs (s
);
2934 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2935 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2936 assumed to be zero. */
2939 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2940 struct glyph
*glyph
;
2946 if (glyph
->type
== CHAR_GLYPH
)
2950 struct font_info
*font_info
;
2954 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2956 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2958 && (pcm
= x_per_char_metric (font
, &char2b
)))
2960 if (pcm
->rbearing
> pcm
->width
)
2961 *right
= pcm
->rbearing
- pcm
->width
;
2962 if (pcm
->lbearing
< 0)
2963 *left
= -pcm
->lbearing
;
2969 /* Return the index of the first glyph preceding glyph string S that
2970 is overwritten by S because of S's left overhang. Value is -1
2971 if no glyphs are overwritten. */
2974 x_left_overwritten (s
)
2975 struct glyph_string
*s
;
2979 if (s
->left_overhang
)
2982 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2983 int first
= s
->first_glyph
- glyphs
;
2985 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2986 x
-= glyphs
[i
].pixel_width
;
2997 /* Return the index of the first glyph preceding glyph string S that
2998 is overwriting S because of its right overhang. Value is -1 if no
2999 glyph in front of S overwrites S. */
3002 x_left_overwriting (s
)
3003 struct glyph_string
*s
;
3006 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3007 int first
= s
->first_glyph
- glyphs
;
3011 for (i
= first
- 1; i
>= 0; --i
)
3014 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3017 x
-= glyphs
[i
].pixel_width
;
3024 /* Return the index of the last glyph following glyph string S that is
3025 not overwritten by S because of S's right overhang. Value is -1 if
3026 no such glyph is found. */
3029 x_right_overwritten (s
)
3030 struct glyph_string
*s
;
3034 if (s
->right_overhang
)
3037 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3038 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3039 int end
= s
->row
->used
[s
->area
];
3041 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3042 x
+= glyphs
[i
].pixel_width
;
3051 /* Return the index of the last glyph following glyph string S that
3052 overwrites S because of its left overhang. Value is negative
3053 if no such glyph is found. */
3056 x_right_overwriting (s
)
3057 struct glyph_string
*s
;
3060 int end
= s
->row
->used
[s
->area
];
3061 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3062 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3066 for (i
= first
; i
< end
; ++i
)
3069 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3072 x
+= glyphs
[i
].pixel_width
;
3079 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3082 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3083 struct glyph_string
*s
;
3087 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3088 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3089 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3090 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3094 /* Draw the background of glyph_string S. If S->background_filled_p
3095 is non-zero don't draw it. FORCE_P non-zero means draw the
3096 background even if it wouldn't be drawn normally. This is used
3097 when a string preceding S draws into the background of S, or S
3098 contains the first component of a composition. */
3101 x_draw_glyph_string_background (s
, force_p
)
3102 struct glyph_string
*s
;
3105 /* Nothing to do if background has already been drawn or if it
3106 shouldn't be drawn in the first place. */
3107 if (!s
->background_filled_p
)
3109 int box_line_width
= max (s
->face
->box_line_width
, 0);
3113 /* Fill background with a stipple pattern. */
3114 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3115 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3116 s
->y
+ box_line_width
,
3117 s
->background_width
,
3118 s
->height
- 2 * box_line_width
);
3119 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3120 s
->background_filled_p
= 1;
3122 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3123 || s
->font_not_found_p
3124 || s
->extends_to_end_of_line_p
3127 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3128 s
->background_width
,
3129 s
->height
- 2 * box_line_width
);
3130 s
->background_filled_p
= 1;
3136 /* Draw the foreground of glyph string S. */
3139 x_draw_glyph_string_foreground (s
)
3140 struct glyph_string
*s
;
3144 /* If first glyph of S has a left box line, start drawing the text
3145 of S to the right of that box line. */
3146 if (s
->face
->box
!= FACE_NO_BOX
3147 && s
->first_glyph
->left_box_line_p
)
3148 x
= s
->x
+ abs (s
->face
->box_line_width
);
3152 /* Draw characters of S as rectangles if S's font could not be
3154 if (s
->font_not_found_p
)
3156 for (i
= 0; i
< s
->nchars
; ++i
)
3158 struct glyph
*g
= s
->first_glyph
+ i
;
3159 XDrawRectangle (s
->display
, s
->window
,
3160 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3162 x
+= g
->pixel_width
;
3167 char *char1b
= (char *) s
->char2b
;
3168 int boff
= s
->font_info
->baseline_offset
;
3170 if (s
->font_info
->vertical_centering
)
3171 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3173 /* If we can use 8-bit functions, condense S->char2b. */
3175 for (i
= 0; i
< s
->nchars
; ++i
)
3176 char1b
[i
] = s
->char2b
[i
].byte2
;
3178 /* Draw text with XDrawString if background has already been
3179 filled. Otherwise, use XDrawImageString. (Note that
3180 XDrawImageString is usually faster than XDrawString.) Always
3181 use XDrawImageString when drawing the cursor so that there is
3182 no chance that characters under a box cursor are invisible. */
3183 if (s
->for_overlaps_p
3184 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3186 /* Draw characters with 16-bit or 8-bit functions. */
3188 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3189 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3191 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3192 s
->ybase
- boff
, char1b
, s
->nchars
);
3197 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3198 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3200 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3201 s
->ybase
- boff
, char1b
, s
->nchars
);
3206 /* Draw the foreground of composite glyph string S. */
3209 x_draw_composite_glyph_string_foreground (s
)
3210 struct glyph_string
*s
;
3214 /* If first glyph of S has a left box line, start drawing the text
3215 of S to the right of that box line. */
3216 if (s
->face
->box
!= FACE_NO_BOX
3217 && s
->first_glyph
->left_box_line_p
)
3218 x
= s
->x
+ abs (s
->face
->box_line_width
);
3222 /* S is a glyph string for a composition. S->gidx is the index of
3223 the first character drawn for glyphs of this composition.
3224 S->gidx == 0 means we are drawing the very first character of
3225 this composition. */
3227 /* Draw a rectangle for the composition if the font for the very
3228 first character of the composition could not be loaded. */
3229 if (s
->font_not_found_p
)
3232 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3233 s
->width
- 1, s
->height
- 1);
3237 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3238 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3239 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3240 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3246 #ifdef USE_X_TOOLKIT
3248 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3251 /* Return the frame on which widget WIDGET is used.. Abort if frame
3252 cannot be determined. */
3254 static struct frame
*
3255 x_frame_of_widget (widget
)
3258 struct x_display_info
*dpyinfo
;
3262 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3264 /* Find the top-level shell of the widget. Note that this function
3265 can be called when the widget is not yet realized, so XtWindow
3266 (widget) == 0. That's the reason we can't simply use
3267 x_any_window_to_frame. */
3268 while (!XtIsTopLevelShell (widget
))
3269 widget
= XtParent (widget
);
3271 /* Look for a frame with that top-level widget. Allocate the color
3272 on that frame to get the right gamma correction value. */
3273 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3274 if (GC_FRAMEP (XCAR (tail
))
3275 && (f
= XFRAME (XCAR (tail
)),
3276 (f
->output_data
.nothing
!= 1
3277 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3278 && f
->output_data
.x
->widget
== widget
)
3285 /* Allocate the color COLOR->pixel on the screen and display of
3286 widget WIDGET in colormap CMAP. If an exact match cannot be
3287 allocated, try the nearest color available. Value is non-zero
3288 if successful. This is called from lwlib. */
3291 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3296 struct frame
*f
= x_frame_of_widget (widget
);
3297 return x_alloc_nearest_color (f
, cmap
, color
);
3301 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3302 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3303 If this produces the same color as PIXEL, try a color where all RGB
3304 values have DELTA added. Return the allocated color in *PIXEL.
3305 DISPLAY is the X display, CMAP is the colormap to operate on.
3306 Value is non-zero if successful. */
3309 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3313 unsigned long *pixel
;
3317 struct frame
*f
= x_frame_of_widget (widget
);
3318 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3322 #endif /* USE_X_TOOLKIT */
3325 /* Value is an array of XColor structures for the contents of the
3326 color map of frame F. Set *NCELLS to the size of the array.
3327 Note that this probably shouldn't be called for large color maps,
3328 say a 24-bit TrueColor map. */
3330 static const XColor
*
3331 x_color_cells (f
, ncells
)
3335 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3337 if (dpyinfo
->color_cells
== NULL
)
3339 Display
*display
= FRAME_X_DISPLAY (f
);
3340 Screen
*screen
= FRAME_X_SCREEN (f
);
3343 dpyinfo
->ncolor_cells
3344 = XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3345 dpyinfo
->color_cells
3346 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3347 * sizeof *dpyinfo
->color_cells
);
3349 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3350 dpyinfo
->color_cells
[i
].pixel
= i
;
3352 XQueryColors (display
, FRAME_X_COLORMAP (f
),
3353 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3356 *ncells
= dpyinfo
->ncolor_cells
;
3357 return dpyinfo
->color_cells
;
3361 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3362 colors in COLORS. Use cached information, if available. */
3365 x_query_colors (f
, colors
, ncolors
)
3370 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3372 if (dpyinfo
->color_cells
)
3375 for (i
= 0; i
< ncolors
; ++i
)
3377 unsigned long pixel
= colors
[i
].pixel
;
3378 xassert (pixel
< dpyinfo
->ncolor_cells
);
3379 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3380 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3384 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3388 /* On frame F, translate pixel color to RGB values for the color in
3389 COLOR. Use cached information, if available. */
3392 x_query_color (f
, color
)
3396 x_query_colors (f
, color
, 1);
3400 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3401 CMAP. If an exact match can't be allocated, try the nearest color
3402 available. Value is non-zero if successful. Set *COLOR to the
3406 x_alloc_nearest_color (f
, cmap
, color
)
3411 Display
*display
= FRAME_X_DISPLAY (f
);
3412 Screen
*screen
= FRAME_X_SCREEN (f
);
3415 gamma_correct (f
, color
);
3416 rc
= XAllocColor (display
, cmap
, color
);
3419 /* If we got to this point, the colormap is full, so we're going
3420 to try to get the next closest color. The algorithm used is
3421 a least-squares matching, which is what X uses for closest
3422 color matching with StaticColor visuals. */
3424 unsigned long nearest_delta
= ~0;
3426 const XColor
*cells
= x_color_cells (f
, &ncells
);
3428 for (nearest
= i
= 0; i
< ncells
; ++i
)
3430 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3431 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3432 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3433 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3435 if (delta
< nearest_delta
)
3438 nearest_delta
= delta
;
3442 color
->red
= cells
[nearest
].red
;
3443 color
->green
= cells
[nearest
].green
;
3444 color
->blue
= cells
[nearest
].blue
;
3445 rc
= XAllocColor (display
, cmap
, color
);
3449 /* If allocation succeeded, and the allocated pixel color is not
3450 equal to a cached pixel color recorded earlier, there was a
3451 change in the colormap, so clear the color cache. */
3452 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3453 XColor
*cached_color
;
3455 if (dpyinfo
->color_cells
3456 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3457 (cached_color
->red
!= color
->red
3458 || cached_color
->blue
!= color
->blue
3459 || cached_color
->green
!= color
->green
)))
3461 xfree (dpyinfo
->color_cells
);
3462 dpyinfo
->color_cells
= NULL
;
3463 dpyinfo
->ncolor_cells
= 0;
3467 #ifdef DEBUG_X_COLORS
3469 register_color (color
->pixel
);
3470 #endif /* DEBUG_X_COLORS */
3476 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3477 It's necessary to do this instead of just using PIXEL directly to
3478 get color reference counts right. */
3481 x_copy_color (f
, pixel
)
3483 unsigned long pixel
;
3487 color
.pixel
= pixel
;
3489 x_query_color (f
, &color
);
3490 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3492 #ifdef DEBUG_X_COLORS
3493 register_color (pixel
);
3499 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3500 It's necessary to do this instead of just using PIXEL directly to
3501 get color reference counts right. */
3504 x_copy_dpy_color (dpy
, cmap
, pixel
)
3507 unsigned long pixel
;
3511 color
.pixel
= pixel
;
3513 XQueryColor (dpy
, cmap
, &color
);
3514 XAllocColor (dpy
, cmap
, &color
);
3516 #ifdef DEBUG_X_COLORS
3517 register_color (pixel
);
3523 /* Brightness beyond which a color won't have its highlight brightness
3526 Nominally, highlight colors for `3d' faces are calculated by
3527 brightening an object's color by a constant scale factor, but this
3528 doesn't yield good results for dark colors, so for colors who's
3529 brightness is less than this value (on a scale of 0-65535) have an
3530 use an additional additive factor.
3532 The value here is set so that the default menu-bar/mode-line color
3533 (grey75) will not have its highlights changed at all. */
3534 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3537 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3538 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3539 If this produces the same color as PIXEL, try a color where all RGB
3540 values have DELTA added. Return the allocated color in *PIXEL.
3541 DISPLAY is the X display, CMAP is the colormap to operate on.
3542 Value is non-zero if successful. */
3545 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3549 unsigned long *pixel
;
3557 /* Get RGB color values. */
3558 color
.pixel
= *pixel
;
3559 x_query_color (f
, &color
);
3561 /* Change RGB values by specified FACTOR. Avoid overflow! */
3562 xassert (factor
>= 0);
3563 new.red
= min (0xffff, factor
* color
.red
);
3564 new.green
= min (0xffff, factor
* color
.green
);
3565 new.blue
= min (0xffff, factor
* color
.blue
);
3567 /* Calculate brightness of COLOR. */
3568 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3570 /* We only boost colors that are darker than
3571 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3572 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3573 /* Make an additive adjustment to NEW, because it's dark enough so
3574 that scaling by FACTOR alone isn't enough. */
3576 /* How far below the limit this color is (0 - 1, 1 being darker). */
3577 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3578 /* The additive adjustment. */
3579 int min_delta
= delta
* dimness
* factor
/ 2;
3583 new.red
= max (0, new.red
- min_delta
);
3584 new.green
= max (0, new.green
- min_delta
);
3585 new.blue
= max (0, new.blue
- min_delta
);
3589 new.red
= min (0xffff, min_delta
+ new.red
);
3590 new.green
= min (0xffff, min_delta
+ new.green
);
3591 new.blue
= min (0xffff, min_delta
+ new.blue
);
3595 /* Try to allocate the color. */
3596 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3599 if (new.pixel
== *pixel
)
3601 /* If we end up with the same color as before, try adding
3602 delta to the RGB values. */
3603 x_free_colors (f
, &new.pixel
, 1);
3605 new.red
= min (0xffff, delta
+ color
.red
);
3606 new.green
= min (0xffff, delta
+ color
.green
);
3607 new.blue
= min (0xffff, delta
+ color
.blue
);
3608 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3619 /* Set up the foreground color for drawing relief lines of glyph
3620 string S. RELIEF is a pointer to a struct relief containing the GC
3621 with which lines will be drawn. Use a color that is FACTOR or
3622 DELTA lighter or darker than the relief's background which is found
3623 in S->f->output_data.x->relief_background. If such a color cannot
3624 be allocated, use DEFAULT_PIXEL, instead. */
3627 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3629 struct relief
*relief
;
3632 unsigned long default_pixel
;
3635 struct x_output
*di
= f
->output_data
.x
;
3636 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3637 unsigned long pixel
;
3638 unsigned long background
= di
->relief_background
;
3639 Colormap cmap
= FRAME_X_COLORMAP (f
);
3640 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3641 Display
*dpy
= FRAME_X_DISPLAY (f
);
3643 xgcv
.graphics_exposures
= False
;
3644 xgcv
.line_width
= 1;
3646 /* Free previously allocated color. The color cell will be reused
3647 when it has been freed as many times as it was allocated, so this
3648 doesn't affect faces using the same colors. */
3650 && relief
->allocated_p
)
3652 x_free_colors (f
, &relief
->pixel
, 1);
3653 relief
->allocated_p
= 0;
3656 /* Allocate new color. */
3657 xgcv
.foreground
= default_pixel
;
3659 if (dpyinfo
->n_planes
!= 1
3660 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3662 relief
->allocated_p
= 1;
3663 xgcv
.foreground
= relief
->pixel
= pixel
;
3666 if (relief
->gc
== 0)
3668 xgcv
.stipple
= dpyinfo
->gray
;
3670 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3673 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3677 /* Set up colors for the relief lines around glyph string S. */
3680 x_setup_relief_colors (s
)
3681 struct glyph_string
*s
;
3683 struct x_output
*di
= s
->f
->output_data
.x
;
3684 unsigned long color
;
3686 if (s
->face
->use_box_color_for_shadows_p
)
3687 color
= s
->face
->box_color
;
3692 /* Get the background color of the face. */
3693 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3694 color
= xgcv
.background
;
3697 if (di
->white_relief
.gc
== 0
3698 || color
!= di
->relief_background
)
3700 di
->relief_background
= color
;
3701 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3702 WHITE_PIX_DEFAULT (s
->f
));
3703 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3704 BLACK_PIX_DEFAULT (s
->f
));
3709 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3710 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3711 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3712 relief. LEFT_P non-zero means draw a relief on the left side of
3713 the rectangle. RIGHT_P non-zero means draw a relief on the right
3714 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3718 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3719 raised_p
, left_p
, right_p
, clip_rect
)
3721 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3722 XRectangle
*clip_rect
;
3728 gc
= f
->output_data
.x
->white_relief
.gc
;
3730 gc
= f
->output_data
.x
->black_relief
.gc
;
3731 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3734 for (i
= 0; i
< width
; ++i
)
3735 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3736 left_x
+ i
* left_p
, top_y
+ i
,
3737 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3741 for (i
= 0; i
< width
; ++i
)
3742 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3743 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3745 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3747 gc
= f
->output_data
.x
->black_relief
.gc
;
3749 gc
= f
->output_data
.x
->white_relief
.gc
;
3750 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3753 for (i
= 0; i
< width
; ++i
)
3754 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3755 left_x
+ i
* left_p
, bottom_y
- i
,
3756 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3760 for (i
= 0; i
< width
; ++i
)
3761 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3762 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3764 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3768 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3769 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3770 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3771 left side of the rectangle. RIGHT_P non-zero means draw a line
3772 on the right side of the rectangle. CLIP_RECT is the clipping
3773 rectangle to use when drawing. */
3776 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3777 left_p
, right_p
, clip_rect
)
3778 struct glyph_string
*s
;
3779 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3780 XRectangle
*clip_rect
;
3784 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3785 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3786 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3789 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3790 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3794 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3795 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3798 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3799 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3803 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3804 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3806 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3807 XSetClipMask (s
->display
, s
->gc
, None
);
3811 /* Draw a box around glyph string S. */
3814 x_draw_glyph_string_box (s
)
3815 struct glyph_string
*s
;
3817 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3818 int left_p
, right_p
;
3819 struct glyph
*last_glyph
;
3820 XRectangle clip_rect
;
3822 last_x
= window_box_right (s
->w
, s
->area
);
3823 if (s
->row
->full_width_p
3824 && !s
->w
->pseudo_window_p
)
3826 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3827 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3828 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3831 /* The glyph that may have a right box line. */
3832 last_glyph
= (s
->cmp
|| s
->img
3834 : s
->first_glyph
+ s
->nchars
- 1);
3836 width
= abs (s
->face
->box_line_width
);
3837 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3839 right_x
= ((s
->row
->full_width_p
3841 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3843 bottom_y
= top_y
+ s
->height
- 1;
3845 left_p
= (s
->first_glyph
->left_box_line_p
3846 || (s
->hl
== DRAW_MOUSE_FACE
3848 || s
->prev
->hl
!= s
->hl
)));
3849 right_p
= (last_glyph
->right_box_line_p
3850 || (s
->hl
== DRAW_MOUSE_FACE
3852 || s
->next
->hl
!= s
->hl
)));
3854 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3856 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3857 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3858 left_p
, right_p
, &clip_rect
);
3861 x_setup_relief_colors (s
);
3862 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3863 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3868 /* Draw foreground of image glyph string S. */
3871 x_draw_image_foreground (s
)
3872 struct glyph_string
*s
;
3875 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3877 /* If first glyph of S has a left box line, start drawing it to the
3878 right of that line. */
3879 if (s
->face
->box
!= FACE_NO_BOX
3880 && s
->first_glyph
->left_box_line_p
)
3881 x
= s
->x
+ abs (s
->face
->box_line_width
);
3885 /* If there is a margin around the image, adjust x- and y-position
3887 x
+= s
->img
->hmargin
;
3888 y
+= s
->img
->vmargin
;
3894 /* We can't set both a clip mask and use XSetClipRectangles
3895 because the latter also sets a clip mask. We also can't
3896 trust on the shape extension to be available
3897 (XShapeCombineRegion). So, compute the rectangle to draw
3899 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3902 XRectangle clip_rect
, image_rect
, r
;
3904 xgcv
.clip_mask
= s
->img
->mask
;
3905 xgcv
.clip_x_origin
= x
;
3906 xgcv
.clip_y_origin
= y
;
3907 xgcv
.function
= GXcopy
;
3908 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3910 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3913 image_rect
.width
= s
->img
->width
;
3914 image_rect
.height
= s
->img
->height
;
3915 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3916 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3917 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3921 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
3923 XRectangle clip_rect
, image_rect
, r
;
3925 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3928 image_rect
.width
= s
->img
->width
;
3929 image_rect
.height
= s
->img
->height
;
3930 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3931 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3932 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3934 /* When the image has a mask, we can expect that at
3935 least part of a mouse highlight or a block cursor will
3936 be visible. If the image doesn't have a mask, make
3937 a block cursor visible by drawing a rectangle around
3938 the image. I believe it's looking better if we do
3939 nothing here for mouse-face. */
3940 if (s
->hl
== DRAW_CURSOR
)
3941 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3942 s
->img
->width
- 1, s
->img
->height
- 1);
3946 /* Draw a rectangle if image could not be loaded. */
3947 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3948 s
->img
->width
- 1, s
->img
->height
- 1);
3952 /* Draw a relief around the image glyph string S. */
3955 x_draw_image_relief (s
)
3956 struct glyph_string
*s
;
3958 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3961 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3963 /* If first glyph of S has a left box line, start drawing it to the
3964 right of that line. */
3965 if (s
->face
->box
!= FACE_NO_BOX
3966 && s
->first_glyph
->left_box_line_p
)
3967 x
= s
->x
+ abs (s
->face
->box_line_width
);
3971 /* If there is a margin around the image, adjust x- and y-position
3973 x
+= s
->img
->hmargin
;
3974 y
+= s
->img
->vmargin
;
3976 if (s
->hl
== DRAW_IMAGE_SUNKEN
3977 || s
->hl
== DRAW_IMAGE_RAISED
)
3979 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3980 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3984 thick
= abs (s
->img
->relief
);
3985 raised_p
= s
->img
->relief
> 0;
3990 x1
= x
+ s
->img
->width
+ thick
- 1;
3991 y1
= y
+ s
->img
->height
+ thick
- 1;
3993 x_setup_relief_colors (s
);
3994 x_get_glyph_string_clip_rect (s
, &r
);
3995 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3999 /* Draw the foreground of image glyph string S to PIXMAP. */
4002 x_draw_image_foreground_1 (s
, pixmap
)
4003 struct glyph_string
*s
;
4007 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4009 /* If first glyph of S has a left box line, start drawing it to the
4010 right of that line. */
4011 if (s
->face
->box
!= FACE_NO_BOX
4012 && s
->first_glyph
->left_box_line_p
)
4013 x
= abs (s
->face
->box_line_width
);
4017 /* If there is a margin around the image, adjust x- and y-position
4019 x
+= s
->img
->hmargin
;
4020 y
+= s
->img
->vmargin
;
4026 /* We can't set both a clip mask and use XSetClipRectangles
4027 because the latter also sets a clip mask. We also can't
4028 trust on the shape extension to be available
4029 (XShapeCombineRegion). So, compute the rectangle to draw
4031 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4035 xgcv
.clip_mask
= s
->img
->mask
;
4036 xgcv
.clip_x_origin
= x
;
4037 xgcv
.clip_y_origin
= y
;
4038 xgcv
.function
= GXcopy
;
4039 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4041 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4042 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4043 XSetClipMask (s
->display
, s
->gc
, None
);
4047 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4048 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4050 /* When the image has a mask, we can expect that at
4051 least part of a mouse highlight or a block cursor will
4052 be visible. If the image doesn't have a mask, make
4053 a block cursor visible by drawing a rectangle around
4054 the image. I believe it's looking better if we do
4055 nothing here for mouse-face. */
4056 if (s
->hl
== DRAW_CURSOR
)
4057 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4058 s
->img
->width
- 1, s
->img
->height
- 1);
4062 /* Draw a rectangle if image could not be loaded. */
4063 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4064 s
->img
->width
- 1, s
->img
->height
- 1);
4068 /* Draw part of the background of glyph string S. X, Y, W, and H
4069 give the rectangle to draw. */
4072 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4073 struct glyph_string
*s
;
4078 /* Fill background with a stipple pattern. */
4079 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4080 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4081 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4084 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4088 /* Draw image glyph string S.
4091 s->x +-------------------------
4094 | +-------------------------
4097 | | +-------------------
4103 x_draw_image_glyph_string (s
)
4104 struct glyph_string
*s
;
4107 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4108 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4110 Pixmap pixmap
= None
;
4112 height
= s
->height
- 2 * box_line_vwidth
;
4114 /* Fill background with face under the image. Do it only if row is
4115 taller than image or if image has a clip mask to reduce
4117 s
->stippled_p
= s
->face
->stipple
!= 0;
4118 if (height
> s
->img
->height
4122 || s
->img
->pixmap
== 0
4123 || s
->width
!= s
->background_width
)
4125 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4126 x
= s
->x
+ box_line_hwidth
;
4130 y
= s
->y
+ box_line_vwidth
;
4134 /* Create a pixmap as large as the glyph string. Fill it
4135 with the background color. Copy the image to it, using
4136 its mask. Copy the temporary pixmap to the display. */
4137 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4138 int depth
= DefaultDepthOfScreen (screen
);
4140 /* Create a pixmap as large as the glyph string. */
4141 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4142 s
->background_width
,
4145 /* Don't clip in the following because we're working on the
4147 XSetClipMask (s
->display
, s
->gc
, None
);
4149 /* Fill the pixmap with the background color/stipple. */
4152 /* Fill background with a stipple pattern. */
4153 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4154 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4155 0, 0, s
->background_width
, s
->height
);
4156 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4161 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4163 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4164 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4165 0, 0, s
->background_width
, s
->height
);
4166 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4170 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4172 s
->background_filled_p
= 1;
4175 /* Draw the foreground. */
4178 x_draw_image_foreground_1 (s
, pixmap
);
4179 x_set_glyph_string_clipping (s
);
4180 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4181 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4182 XFreePixmap (s
->display
, pixmap
);
4185 x_draw_image_foreground (s
);
4187 /* If we must draw a relief around the image, do it. */
4189 || s
->hl
== DRAW_IMAGE_RAISED
4190 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4191 x_draw_image_relief (s
);
4195 /* Draw stretch glyph string S. */
4198 x_draw_stretch_glyph_string (s
)
4199 struct glyph_string
*s
;
4201 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4202 s
->stippled_p
= s
->face
->stipple
!= 0;
4204 if (s
->hl
== DRAW_CURSOR
4205 && !x_stretch_cursor_p
)
4207 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4208 as wide as the stretch glyph. */
4209 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4212 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4214 /* Clear rest using the GC of the original non-cursor face. */
4215 if (width
< s
->background_width
)
4217 GC gc
= s
->face
->gc
;
4218 int x
= s
->x
+ width
, y
= s
->y
;
4219 int w
= s
->background_width
- width
, h
= s
->height
;
4222 x_get_glyph_string_clip_rect (s
, &r
);
4223 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4225 if (s
->face
->stipple
)
4227 /* Fill background with a stipple pattern. */
4228 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4229 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4230 XSetFillStyle (s
->display
, gc
, FillSolid
);
4235 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4236 XSetForeground (s
->display
, gc
, xgcv
.background
);
4237 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4238 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4243 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4246 s
->background_filled_p
= 1;
4250 /* Draw glyph string S. */
4253 x_draw_glyph_string (s
)
4254 struct glyph_string
*s
;
4256 /* If S draws into the background of its successor, draw the
4257 background of the successor first so that S can draw into it.
4258 This makes S->next use XDrawString instead of XDrawImageString. */
4259 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4261 xassert (s
->next
->img
== NULL
);
4262 x_set_glyph_string_gc (s
->next
);
4263 x_set_glyph_string_clipping (s
->next
);
4264 x_draw_glyph_string_background (s
->next
, 1);
4267 /* Set up S->gc, set clipping and draw S. */
4268 x_set_glyph_string_gc (s
);
4269 x_set_glyph_string_clipping (s
);
4271 switch (s
->first_glyph
->type
)
4274 x_draw_image_glyph_string (s
);
4278 x_draw_stretch_glyph_string (s
);
4282 if (s
->for_overlaps_p
)
4283 s
->background_filled_p
= 1;
4285 x_draw_glyph_string_background (s
, 0);
4286 x_draw_glyph_string_foreground (s
);
4289 case COMPOSITE_GLYPH
:
4290 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4291 s
->background_filled_p
= 1;
4293 x_draw_glyph_string_background (s
, 1);
4294 x_draw_composite_glyph_string_foreground (s
);
4301 if (!s
->for_overlaps_p
)
4303 /* Draw underline. */
4304 if (s
->face
->underline_p
)
4306 unsigned long tem
, h
;
4309 /* Get the underline thickness. Default is 1 pixel. */
4310 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4313 /* Get the underline position. This is the recommended
4314 vertical offset in pixels from the baseline to the top of
4315 the underline. This is a signed value according to the
4316 specs, and its default is
4318 ROUND ((maximum descent) / 2), with
4319 ROUND(x) = floor (x + 0.5) */
4321 if (XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4322 y
= s
->ybase
+ (long) tem
;
4323 else if (s
->face
->font
)
4324 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4328 if (s
->face
->underline_defaulted_p
)
4329 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4330 s
->x
, y
, s
->width
, h
);
4334 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4335 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4336 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4337 s
->x
, y
, s
->width
, h
);
4338 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4342 /* Draw overline. */
4343 if (s
->face
->overline_p
)
4345 unsigned long dy
= 0, h
= 1;
4347 if (s
->face
->overline_color_defaulted_p
)
4348 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4353 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4354 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4355 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4357 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4361 /* Draw strike-through. */
4362 if (s
->face
->strike_through_p
)
4364 unsigned long h
= 1;
4365 unsigned long dy
= (s
->height
- h
) / 2;
4367 if (s
->face
->strike_through_color_defaulted_p
)
4368 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4373 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4374 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4375 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4377 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4382 if (s
->face
->box
!= FACE_NO_BOX
)
4383 x_draw_glyph_string_box (s
);
4386 /* Reset clipping. */
4387 XSetClipMask (s
->display
, s
->gc
, None
);
4391 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4392 struct face
**, int));
4395 /* Fill glyph string S with composition components specified by S->cmp.
4397 FACES is an array of faces for all components of this composition.
4398 S->gidx is the index of the first component for S.
4399 OVERLAPS_P non-zero means S should draw the foreground only, and
4400 use its physical height for clipping.
4402 Value is the index of a component not in S. */
4405 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4406 struct glyph_string
*s
;
4407 struct face
**faces
;
4414 s
->for_overlaps_p
= overlaps_p
;
4416 s
->face
= faces
[s
->gidx
];
4417 s
->font
= s
->face
->font
;
4418 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4420 /* For all glyphs of this composition, starting at the offset
4421 S->gidx, until we reach the end of the definition or encounter a
4422 glyph that requires the different face, add it to S. */
4424 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4427 /* All glyph strings for the same composition has the same width,
4428 i.e. the width set for the first component of the composition. */
4430 s
->width
= s
->first_glyph
->pixel_width
;
4432 /* If the specified font could not be loaded, use the frame's
4433 default font, but record the fact that we couldn't load it in
4434 the glyph string so that we can draw rectangles for the
4435 characters of the glyph string. */
4436 if (s
->font
== NULL
)
4438 s
->font_not_found_p
= 1;
4439 s
->font
= FRAME_FONT (s
->f
);
4442 /* Adjust base line for subscript/superscript text. */
4443 s
->ybase
+= s
->first_glyph
->voffset
;
4445 xassert (s
->face
&& s
->face
->gc
);
4447 /* This glyph string must always be drawn with 16-bit functions. */
4450 return s
->gidx
+ s
->nchars
;
4454 /* Fill glyph string S from a sequence of character glyphs.
4456 FACE_ID is the face id of the string. START is the index of the
4457 first glyph to consider, END is the index of the last + 1.
4458 OVERLAPS_P non-zero means S should draw the foreground only, and
4459 use its physical height for clipping.
4461 Value is the index of the first glyph not in S. */
4464 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4465 struct glyph_string
*s
;
4467 int start
, end
, overlaps_p
;
4469 struct glyph
*glyph
, *last
;
4471 int glyph_not_available_p
;
4473 xassert (s
->f
== XFRAME (s
->w
->frame
));
4474 xassert (s
->nchars
== 0);
4475 xassert (start
>= 0 && end
> start
);
4477 s
->for_overlaps_p
= overlaps_p
,
4478 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4479 last
= s
->row
->glyphs
[s
->area
] + end
;
4480 voffset
= glyph
->voffset
;
4482 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4485 && glyph
->type
== CHAR_GLYPH
4486 && glyph
->voffset
== voffset
4487 /* Same face id implies same font, nowadays. */
4488 && glyph
->face_id
== face_id
4489 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4493 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4494 s
->char2b
+ s
->nchars
,
4496 s
->two_byte_p
= two_byte_p
;
4498 xassert (s
->nchars
<= end
- start
);
4499 s
->width
+= glyph
->pixel_width
;
4503 s
->font
= s
->face
->font
;
4504 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4506 /* If the specified font could not be loaded, use the frame's font,
4507 but record the fact that we couldn't load it in
4508 S->font_not_found_p so that we can draw rectangles for the
4509 characters of the glyph string. */
4510 if (s
->font
== NULL
|| glyph_not_available_p
)
4512 s
->font_not_found_p
= 1;
4513 s
->font
= FRAME_FONT (s
->f
);
4516 /* Adjust base line for subscript/superscript text. */
4517 s
->ybase
+= voffset
;
4519 xassert (s
->face
&& s
->face
->gc
);
4520 return glyph
- s
->row
->glyphs
[s
->area
];
4524 /* Fill glyph string S from image glyph S->first_glyph. */
4527 x_fill_image_glyph_string (s
)
4528 struct glyph_string
*s
;
4530 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4531 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4533 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4534 s
->font
= s
->face
->font
;
4535 s
->width
= s
->first_glyph
->pixel_width
;
4537 /* Adjust base line for subscript/superscript text. */
4538 s
->ybase
+= s
->first_glyph
->voffset
;
4542 /* Fill glyph string S from a sequence of stretch glyphs.
4544 ROW is the glyph row in which the glyphs are found, AREA is the
4545 area within the row. START is the index of the first glyph to
4546 consider, END is the index of the last + 1.
4548 Value is the index of the first glyph not in S. */
4551 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4552 struct glyph_string
*s
;
4553 struct glyph_row
*row
;
4554 enum glyph_row_area area
;
4557 struct glyph
*glyph
, *last
;
4558 int voffset
, face_id
;
4560 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4562 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4563 last
= s
->row
->glyphs
[s
->area
] + end
;
4564 face_id
= glyph
->face_id
;
4565 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4566 s
->font
= s
->face
->font
;
4567 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4568 s
->width
= glyph
->pixel_width
;
4569 voffset
= glyph
->voffset
;
4573 && glyph
->type
== STRETCH_GLYPH
4574 && glyph
->voffset
== voffset
4575 && glyph
->face_id
== face_id
);
4577 s
->width
+= glyph
->pixel_width
;
4579 /* Adjust base line for subscript/superscript text. */
4580 s
->ybase
+= voffset
;
4582 xassert (s
->face
&& s
->face
->gc
);
4583 return glyph
- s
->row
->glyphs
[s
->area
];
4587 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4588 of XChar2b structures for S; it can't be allocated in
4589 x_init_glyph_string because it must be allocated via `alloca'. W
4590 is the window on which S is drawn. ROW and AREA are the glyph row
4591 and area within the row from which S is constructed. START is the
4592 index of the first glyph structure covered by S. HL is a
4593 face-override for drawing S. */
4596 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4597 struct glyph_string
*s
;
4600 struct glyph_row
*row
;
4601 enum glyph_row_area area
;
4603 enum draw_glyphs_face hl
;
4605 bzero (s
, sizeof *s
);
4607 s
->f
= XFRAME (w
->frame
);
4608 s
->display
= FRAME_X_DISPLAY (s
->f
);
4609 s
->window
= FRAME_X_WINDOW (s
->f
);
4614 s
->first_glyph
= row
->glyphs
[area
] + start
;
4615 s
->height
= row
->height
;
4616 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4618 /* Display the internal border below the tool-bar window. */
4619 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4620 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4622 s
->ybase
= s
->y
+ row
->ascent
;
4626 /* Set background width of glyph string S. START is the index of the
4627 first glyph following S. LAST_X is the right-most x-position + 1
4628 in the drawing area. */
4631 x_set_glyph_string_background_width (s
, start
, last_x
)
4632 struct glyph_string
*s
;
4636 /* If the face of this glyph string has to be drawn to the end of
4637 the drawing area, set S->extends_to_end_of_line_p. */
4638 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4640 if (start
== s
->row
->used
[s
->area
]
4641 && s
->hl
== DRAW_NORMAL_TEXT
4642 && s
->area
== TEXT_AREA
4643 && (s
->row
->fill_line_p
4644 || s
->face
->background
!= default_face
->background
4645 || s
->face
->stipple
!= default_face
->stipple
))
4646 s
->extends_to_end_of_line_p
= 1;
4648 /* If S extends its face to the end of the line, set its
4649 background_width to the distance to the right edge of the drawing
4651 if (s
->extends_to_end_of_line_p
)
4652 s
->background_width
= last_x
- s
->x
+ 1;
4654 s
->background_width
= s
->width
;
4658 /* Add a glyph string for a stretch glyph to the list of strings
4659 between HEAD and TAIL. START is the index of the stretch glyph in
4660 row area AREA of glyph row ROW. END is the index of the last glyph
4661 in that glyph row area. X is the current output position assigned
4662 to the new glyph string constructed. HL overrides that face of the
4663 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4664 is the right-most x-position of the drawing area. */
4666 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4667 and below -- keep them on one line. */
4668 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4671 s = (struct glyph_string *) alloca (sizeof *s); \
4672 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4673 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4674 x_append_glyph_string (&HEAD, &TAIL, s); \
4680 /* Add a glyph string for an image glyph to the list of strings
4681 between HEAD and TAIL. START is the index of the image glyph in
4682 row area AREA of glyph row ROW. END is the index of the last glyph
4683 in that glyph row area. X is the current output position assigned
4684 to the new glyph string constructed. HL overrides that face of the
4685 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4686 is the right-most x-position of the drawing area. */
4688 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4691 s = (struct glyph_string *) alloca (sizeof *s); \
4692 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4693 x_fill_image_glyph_string (s); \
4694 x_append_glyph_string (&HEAD, &TAIL, s); \
4701 /* Add a glyph string for a sequence of character glyphs to the list
4702 of strings between HEAD and TAIL. START is the index of the first
4703 glyph in row area AREA of glyph row ROW that is part of the new
4704 glyph string. END is the index of the last glyph in that glyph row
4705 area. X is the current output position assigned to the new glyph
4706 string constructed. HL overrides that face of the glyph; e.g. it
4707 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4708 right-most x-position of the drawing area. */
4710 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4716 c = (ROW)->glyphs[AREA][START].u.ch; \
4717 face_id = (ROW)->glyphs[AREA][START].face_id; \
4719 s = (struct glyph_string *) alloca (sizeof *s); \
4720 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4721 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4722 x_append_glyph_string (&HEAD, &TAIL, s); \
4724 START = x_fill_glyph_string (s, face_id, START, END, \
4730 /* Add a glyph string for a composite sequence to the list of strings
4731 between HEAD and TAIL. START is the index of the first glyph in
4732 row area AREA of glyph row ROW that is part of the new glyph
4733 string. END is the index of the last glyph in that glyph row area.
4734 X is the current output position assigned to the new glyph string
4735 constructed. HL overrides that face of the glyph; e.g. it is
4736 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4737 x-position of the drawing area. */
4739 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4741 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4742 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4743 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4744 struct composition *cmp = composition_table[cmp_id]; \
4745 int glyph_len = cmp->glyph_len; \
4747 struct face **faces; \
4748 struct glyph_string *first_s = NULL; \
4751 base_face = base_face->ascii_face; \
4752 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4753 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4754 /* At first, fill in `char2b' and `faces'. */ \
4755 for (n = 0; n < glyph_len; n++) \
4757 int c = COMPOSITION_GLYPH (cmp, n); \
4758 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4759 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4760 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4761 this_face_id, char2b + n, 1); \
4764 /* Make glyph_strings for each glyph sequence that is drawable by \
4765 the same face, and append them to HEAD/TAIL. */ \
4766 for (n = 0; n < cmp->glyph_len;) \
4768 s = (struct glyph_string *) alloca (sizeof *s); \
4769 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4770 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4778 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4786 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4787 of AREA of glyph row ROW on window W between indices START and END.
4788 HL overrides the face for drawing glyph strings, e.g. it is
4789 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4790 x-positions of the drawing area.
4792 This is an ugly monster macro construct because we must use alloca
4793 to allocate glyph strings (because x_draw_glyphs can be called
4796 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4799 HEAD = TAIL = NULL; \
4800 while (START < END) \
4802 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4803 switch (first_glyph->type) \
4806 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4807 TAIL, HL, X, LAST_X, \
4811 case COMPOSITE_GLYPH: \
4812 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4813 HEAD, TAIL, HL, X, LAST_X,\
4817 case STRETCH_GLYPH: \
4818 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4819 HEAD, TAIL, HL, X, LAST_X); \
4823 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4824 TAIL, HL, X, LAST_X); \
4831 x_set_glyph_string_background_width (s, START, LAST_X); \
4838 /* Draw glyphs between START and END in AREA of ROW on window W,
4839 starting at x-position X. X is relative to AREA in W. HL is a
4840 face-override with the following meaning:
4842 DRAW_NORMAL_TEXT draw normally
4843 DRAW_CURSOR draw in cursor face
4844 DRAW_MOUSE_FACE draw in mouse face.
4845 DRAW_INVERSE_VIDEO draw in mode line face
4846 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4847 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4849 If REAL_START is non-null, return in *REAL_START the real starting
4850 position for display. This can be different from START in case
4851 overlapping glyphs must be displayed. If REAL_END is non-null,
4852 return in *REAL_END the real end position for display. This can be
4853 different from END in case overlapping glyphs must be displayed.
4855 If OVERLAPS_P is non-zero, draw only the foreground of characters
4856 and clip to the physical height of ROW.
4858 Value is the x-position reached, relative to AREA of W. */
4861 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4865 struct glyph_row
*row
;
4866 enum glyph_row_area area
;
4868 enum draw_glyphs_face hl
;
4869 int *real_start
, *real_end
;
4872 struct glyph_string
*head
, *tail
;
4873 struct glyph_string
*s
;
4874 int last_x
, area_width
;
4878 /* Let's rather be paranoid than getting a SEGV. */
4879 end
= min (end
, row
->used
[area
]);
4880 start
= max (0, start
);
4881 start
= min (end
, start
);
4883 *real_start
= start
;
4887 /* Translate X to frame coordinates. Set last_x to the right
4888 end of the drawing area. */
4889 if (row
->full_width_p
)
4891 /* X is relative to the left edge of W, without scroll bars
4893 struct frame
*f
= XFRAME (w
->frame
);
4894 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4895 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4898 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4899 last_x
= window_left_x
+ area_width
;
4901 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4903 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4904 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4910 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4911 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4915 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4916 area_width
= window_box_width (w
, area
);
4917 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4920 /* Build a doubly-linked list of glyph_string structures between
4921 head and tail from what we have to draw. Note that the macro
4922 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4923 the reason we use a separate variable `i'. */
4925 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4928 x_reached
= tail
->x
+ tail
->background_width
;
4932 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4933 the row, redraw some glyphs in front or following the glyph
4934 strings built above. */
4935 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4938 struct glyph_string
*h
, *t
;
4940 /* Compute overhangs for all glyph strings. */
4941 for (s
= head
; s
; s
= s
->next
)
4942 x_compute_glyph_string_overhangs (s
);
4944 /* Prepend glyph strings for glyphs in front of the first glyph
4945 string that are overwritten because of the first glyph
4946 string's left overhang. The background of all strings
4947 prepended must be drawn because the first glyph string
4949 i
= x_left_overwritten (head
);
4953 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4954 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4958 *real_start
= start
;
4959 x_compute_overhangs_and_x (t
, head
->x
, 1);
4960 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4963 /* Prepend glyph strings for glyphs in front of the first glyph
4964 string that overwrite that glyph string because of their
4965 right overhang. For these strings, only the foreground must
4966 be drawn, because it draws over the glyph string at `head'.
4967 The background must not be drawn because this would overwrite
4968 right overhangs of preceding glyphs for which no glyph
4970 i
= x_left_overwriting (head
);
4973 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4974 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4976 for (s
= h
; s
; s
= s
->next
)
4977 s
->background_filled_p
= 1;
4980 x_compute_overhangs_and_x (t
, head
->x
, 1);
4981 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4984 /* Append glyphs strings for glyphs following the last glyph
4985 string tail that are overwritten by tail. The background of
4986 these strings has to be drawn because tail's foreground draws
4988 i
= x_right_overwritten (tail
);
4991 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4992 DRAW_NORMAL_TEXT
, x
, last_x
,
4994 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4995 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5000 /* Append glyph strings for glyphs following the last glyph
5001 string tail that overwrite tail. The foreground of such
5002 glyphs has to be drawn because it writes into the background
5003 of tail. The background must not be drawn because it could
5004 paint over the foreground of following glyphs. */
5005 i
= x_right_overwriting (tail
);
5008 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5009 DRAW_NORMAL_TEXT
, x
, last_x
,
5011 for (s
= h
; s
; s
= s
->next
)
5012 s
->background_filled_p
= 1;
5013 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5014 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5020 /* Draw all strings. */
5021 for (s
= head
; s
; s
= s
->next
)
5022 x_draw_glyph_string (s
);
5024 /* Value is the x-position up to which drawn, relative to AREA of W.
5025 This doesn't include parts drawn because of overhangs. */
5026 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5027 if (!row
->full_width_p
)
5029 if (area
> LEFT_MARGIN_AREA
)
5030 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5031 if (area
> TEXT_AREA
)
5032 x_reached
-= window_box_width (w
, TEXT_AREA
);
5039 /* Fix the display of area AREA of overlapping row ROW in window W. */
5042 x_fix_overlapping_area (w
, row
, area
)
5044 struct glyph_row
*row
;
5045 enum glyph_row_area area
;
5051 if (area
== LEFT_MARGIN_AREA
)
5053 else if (area
== TEXT_AREA
)
5054 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5056 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5057 + window_box_width (w
, TEXT_AREA
));
5059 for (i
= 0; i
< row
->used
[area
];)
5061 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5063 int start
= i
, start_x
= x
;
5067 x
+= row
->glyphs
[area
][i
].pixel_width
;
5070 while (i
< row
->used
[area
]
5071 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5073 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5075 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5080 x
+= row
->glyphs
[area
][i
].pixel_width
;
5089 /* Output LEN glyphs starting at START at the nominal cursor position.
5090 Advance the nominal cursor over the text. The global variable
5091 updated_window contains the window being updated, updated_row is
5092 the glyph row being updated, and updated_area is the area of that
5093 row being updated. */
5096 x_write_glyphs (start
, len
)
5097 struct glyph
*start
;
5100 int x
, hpos
, real_start
, real_end
;
5102 xassert (updated_window
&& updated_row
);
5107 hpos
= start
- updated_row
->glyphs
[updated_area
];
5108 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5109 updated_row
, updated_area
,
5111 (updated_row
->inverse_p
5112 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5113 &real_start
, &real_end
, 0);
5115 /* If we drew over the cursor, note that it is not visible any more. */
5116 note_overwritten_text_cursor (updated_window
, real_start
,
5117 real_end
- real_start
);
5121 /* Advance the output cursor. */
5122 output_cursor
.hpos
+= len
;
5123 output_cursor
.x
= x
;
5127 /* Insert LEN glyphs from START at the nominal cursor position. */
5130 x_insert_glyphs (start
, len
)
5131 struct glyph
*start
;
5136 int line_height
, shift_by_width
, shifted_region_width
;
5137 struct glyph_row
*row
;
5138 struct glyph
*glyph
;
5139 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
5141 xassert (updated_window
&& updated_row
);
5144 f
= XFRAME (WINDOW_FRAME (w
));
5146 /* Get the height of the line we are in. */
5148 line_height
= row
->height
;
5150 /* Get the width of the glyphs to insert. */
5152 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5153 shift_by_width
+= glyph
->pixel_width
;
5155 /* Get the width of the region to shift right. */
5156 shifted_region_width
= (window_box_width (w
, updated_area
)
5161 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5162 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5163 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5164 f
->output_data
.x
->normal_gc
,
5166 shifted_region_width
, line_height
,
5167 frame_x
+ shift_by_width
, frame_y
);
5169 /* Write the glyphs. */
5170 hpos
= start
- row
->glyphs
[updated_area
];
5171 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5172 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
5173 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5175 /* Advance the output cursor. */
5176 output_cursor
.hpos
+= len
;
5177 output_cursor
.x
+= shift_by_width
;
5182 /* Delete N glyphs at the nominal cursor position. Not implemented
5193 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5194 If they are <= 0, this is probably an error. */
5197 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5204 xassert (width
> 0 && height
> 0);
5205 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5209 /* Erase the current text line from the nominal cursor position
5210 (inclusive) to pixel column TO_X (exclusive). The idea is that
5211 everything from TO_X onward is already erased.
5213 TO_X is a pixel position relative to updated_area of
5214 updated_window. TO_X == -1 means clear to the end of this area. */
5217 x_clear_end_of_line (to_x
)
5221 struct window
*w
= updated_window
;
5222 int max_x
, min_y
, max_y
;
5223 int from_x
, from_y
, to_y
;
5225 xassert (updated_window
&& updated_row
);
5226 f
= XFRAME (w
->frame
);
5228 if (updated_row
->full_width_p
)
5230 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5231 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5232 && !w
->pseudo_window_p
)
5233 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5236 max_x
= window_box_width (w
, updated_area
);
5237 max_y
= window_text_bottom_y (w
);
5239 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5240 of window. For TO_X > 0, truncate to end of drawing area. */
5246 to_x
= min (to_x
, max_x
);
5248 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5250 /* Notice if the cursor will be cleared by this operation. */
5251 if (!updated_row
->full_width_p
)
5252 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5254 from_x
= output_cursor
.x
;
5256 /* Translate to frame coordinates. */
5257 if (updated_row
->full_width_p
)
5259 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5260 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5264 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5265 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5268 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5269 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5270 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5272 /* Prevent inadvertently clearing to end of the X window. */
5273 if (to_x
> from_x
&& to_y
> from_y
)
5276 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5277 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5284 /* Clear entire frame. If updating_frame is non-null, clear that
5285 frame. Otherwise clear the selected frame. */
5295 f
= SELECTED_FRAME ();
5297 /* Clearing the frame will erase any cursor, so mark them all as no
5299 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5300 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5301 output_cursor
.x
= -1;
5303 /* We don't set the output cursor here because there will always
5304 follow an explicit cursor_to. */
5306 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5308 /* We have to clear the scroll bars, too. If we have changed
5309 colors or something like that, then they should be notified. */
5310 x_scroll_bar_clear (f
);
5312 XFlush (FRAME_X_DISPLAY (f
));
5318 /* Invert the middle quarter of the frame for .15 sec. */
5320 /* We use the select system call to do the waiting, so we have to make
5321 sure it's available. If it isn't, we just won't do visual bells. */
5323 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5326 /* Subtract the `struct timeval' values X and Y, storing the result in
5327 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5330 timeval_subtract (result
, x
, y
)
5331 struct timeval
*result
, x
, y
;
5333 /* Perform the carry for the later subtraction by updating y. This
5334 is safer because on some systems the tv_sec member is unsigned. */
5335 if (x
.tv_usec
< y
.tv_usec
)
5337 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5338 y
.tv_usec
-= 1000000 * nsec
;
5342 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5344 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5345 y
.tv_usec
+= 1000000 * nsec
;
5349 /* Compute the time remaining to wait. tv_usec is certainly
5351 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5352 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5354 /* Return indication of whether the result should be considered
5356 return x
.tv_sec
< y
.tv_sec
;
5368 /* Create a GC that will use the GXxor function to flip foreground
5369 pixels into background pixels. */
5373 values
.function
= GXxor
;
5374 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5375 ^ f
->output_data
.x
->background_pixel
);
5377 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5378 GCFunction
| GCForeground
, &values
);
5382 /* Get the height not including a menu bar widget. */
5383 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5384 /* Height of each line to flash. */
5385 int flash_height
= FRAME_LINE_HEIGHT (f
);
5386 /* These will be the left and right margins of the rectangles. */
5387 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5388 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5392 /* Don't flash the area between a scroll bar and the frame
5393 edge it is next to. */
5394 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5396 case vertical_scroll_bar_left
:
5397 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5400 case vertical_scroll_bar_right
:
5401 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5408 width
= flash_right
- flash_left
;
5410 /* If window is tall, flash top and bottom line. */
5411 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5413 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5415 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5416 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5417 width
, flash_height
);
5418 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5420 (height
- flash_height
5421 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5422 width
, flash_height
);
5425 /* If it is short, flash it all. */
5426 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5427 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5428 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5433 struct timeval wakeup
;
5435 EMACS_GET_TIME (wakeup
);
5437 /* Compute time to wait until, propagating carry from usecs. */
5438 wakeup
.tv_usec
+= 150000;
5439 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5440 wakeup
.tv_usec
%= 1000000;
5442 /* Keep waiting until past the time wakeup or any input gets
5444 while (! detect_input_pending ())
5446 struct timeval current
;
5447 struct timeval timeout
;
5449 EMACS_GET_TIME (current
);
5451 /* Break if result would be negative. */
5452 if (timeval_subtract (¤t
, wakeup
, current
))
5455 /* How long `select' should wait. */
5457 timeout
.tv_usec
= 10000;
5459 /* Try to wait that long--but we might wake up sooner. */
5460 select (0, NULL
, NULL
, NULL
, &timeout
);
5464 /* If window is tall, flash top and bottom line. */
5465 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5467 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5469 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5470 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5471 width
, flash_height
);
5472 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5474 (height
- flash_height
5475 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5476 width
, flash_height
);
5479 /* If it is short, flash it all. */
5480 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5481 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5482 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5484 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5492 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5495 /* Make audible bell. */
5500 struct frame
*f
= SELECTED_FRAME ();
5502 if (FRAME_X_DISPLAY (f
))
5504 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5511 XBell (FRAME_X_DISPLAY (f
), 0);
5512 XFlush (FRAME_X_DISPLAY (f
));
5519 /* Specify how many text lines, from the top of the window,
5520 should be affected by insert-lines and delete-lines operations.
5521 This, and those operations, are used only within an update
5522 that is bounded by calls to x_update_begin and x_update_end. */
5525 XTset_terminal_window (n
)
5528 /* This function intentionally left blank. */
5533 /***********************************************************************
5535 ***********************************************************************/
5537 /* Perform an insert-lines or delete-lines operation, inserting N
5538 lines or deleting -N lines at vertical position VPOS. */
5541 x_ins_del_lines (vpos
, n
)
5548 /* Scroll part of the display as described by RUN. */
5551 x_scroll_run (w
, run
)
5555 struct frame
*f
= XFRAME (w
->frame
);
5556 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5558 /* Get frame-relative bounding box of the text display area of W,
5559 without mode lines. Include in this box the flags areas to the
5560 left and right of W. */
5561 window_box (w
, -1, &x
, &y
, &width
, &height
);
5562 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5563 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5565 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5566 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5567 bottom_y
= y
+ height
;
5571 /* Scrolling up. Make sure we don't copy part of the mode
5572 line at the bottom. */
5573 if (from_y
+ run
->height
> bottom_y
)
5574 height
= bottom_y
- from_y
;
5576 height
= run
->height
;
5580 /* Scolling down. Make sure we don't copy over the mode line.
5582 if (to_y
+ run
->height
> bottom_y
)
5583 height
= bottom_y
- to_y
;
5585 height
= run
->height
;
5590 /* Cursor off. Will be switched on again in x_update_window_end. */
5594 XCopyArea (FRAME_X_DISPLAY (f
),
5595 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5596 f
->output_data
.x
->normal_gc
,
5606 /***********************************************************************
5608 ***********************************************************************/
5610 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5611 corner of the exposed rectangle. W and H are width and height of
5612 the exposed area. All are pixel values. W or H zero means redraw
5613 the entire frame. */
5616 expose_frame (f
, x
, y
, w
, h
)
5622 TRACE ((stderr
, "expose_frame "));
5624 /* No need to redraw if frame will be redrawn soon. */
5625 if (FRAME_GARBAGED_P (f
))
5627 TRACE ((stderr
, " garbaged\n"));
5631 /* If basic faces haven't been realized yet, there is no point in
5632 trying to redraw anything. This can happen when we get an expose
5633 event while Emacs is starting, e.g. by moving another window. */
5634 if (FRAME_FACE_CACHE (f
) == NULL
5635 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5637 TRACE ((stderr
, " no faces\n"));
5641 if (w
== 0 || h
== 0)
5644 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5645 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5655 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5656 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5658 if (WINDOWP (f
->tool_bar_window
))
5660 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5661 XRectangle window_rect
;
5662 XRectangle intersection_rect
;
5663 int window_x
, window_y
, window_width
, window_height
;
5666 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5667 window_rect
.x
= window_x
;
5668 window_rect
.y
= window_y
;
5669 window_rect
.width
= window_width
;
5670 window_rect
.height
= window_height
;
5672 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5673 expose_window (w
, &intersection_rect
);
5676 #ifndef USE_X_TOOLKIT
5677 if (WINDOWP (f
->menu_bar_window
))
5679 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5680 XRectangle window_rect
;
5681 XRectangle intersection_rect
;
5682 int window_x
, window_y
, window_width
, window_height
;
5685 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5686 window_rect
.x
= window_x
;
5687 window_rect
.y
= window_y
;
5688 window_rect
.width
= window_width
;
5689 window_rect
.height
= window_height
;
5691 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5692 expose_window (w
, &intersection_rect
);
5694 #endif /* not USE_X_TOOLKIT */
5698 /* Redraw (parts) of all windows in the window tree rooted at W that
5699 intersect R. R contains frame pixel coordinates. */
5702 expose_window_tree (w
, r
)
5708 if (!NILP (w
->hchild
))
5709 expose_window_tree (XWINDOW (w
->hchild
), r
);
5710 else if (!NILP (w
->vchild
))
5711 expose_window_tree (XWINDOW (w
->vchild
), r
);
5714 XRectangle window_rect
;
5715 XRectangle intersection_rect
;
5716 struct frame
*f
= XFRAME (w
->frame
);
5717 int window_x
, window_y
, window_width
, window_height
;
5719 /* Frame-relative pixel rectangle of W. */
5720 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5724 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5725 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5726 window_rect
.y
= window_y
;
5729 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5730 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5732 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5734 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5735 expose_window (w
, &intersection_rect
);
5738 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5743 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5744 which intersects rectangle R. R is in window-relative coordinates. */
5747 expose_area (w
, row
, r
, area
)
5749 struct glyph_row
*row
;
5751 enum glyph_row_area area
;
5753 struct glyph
*first
= row
->glyphs
[area
];
5754 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5756 int first_x
, start_x
, x
;
5758 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5759 /* If row extends face to end of line write the whole line. */
5760 x_draw_glyphs (w
, 0, row
, area
,
5762 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5766 /* Set START_X to the window-relative start position for drawing glyphs of
5767 AREA. The first glyph of the text area can be partially visible.
5768 The first glyphs of other areas cannot. */
5769 if (area
== LEFT_MARGIN_AREA
)
5771 else if (area
== TEXT_AREA
)
5772 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5774 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5775 + window_box_width (w
, TEXT_AREA
));
5778 /* Find the first glyph that must be redrawn. */
5780 && x
+ first
->pixel_width
< r
->x
)
5782 x
+= first
->pixel_width
;
5786 /* Find the last one. */
5790 && x
< r
->x
+ r
->width
)
5792 x
+= last
->pixel_width
;
5798 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5799 first
- row
->glyphs
[area
],
5800 last
- row
->glyphs
[area
],
5801 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5807 /* Redraw the parts of the glyph row ROW on window W intersecting
5808 rectangle R. R is in window-relative coordinates. */
5811 expose_line (w
, row
, r
)
5813 struct glyph_row
*row
;
5816 xassert (row
->enabled_p
);
5818 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5819 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5820 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5824 if (row
->used
[LEFT_MARGIN_AREA
])
5825 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5826 if (row
->used
[TEXT_AREA
])
5827 expose_area (w
, row
, r
, TEXT_AREA
);
5828 if (row
->used
[RIGHT_MARGIN_AREA
])
5829 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5830 x_draw_row_bitmaps (w
, row
);
5835 /* Return non-zero if W's cursor intersects rectangle R. */
5838 x_phys_cursor_in_rect_p (w
, r
)
5842 XRectangle cr
, result
;
5843 struct glyph
*cursor_glyph
;
5845 cursor_glyph
= get_phys_cursor_glyph (w
);
5848 cr
.x
= w
->phys_cursor
.x
;
5849 cr
.y
= w
->phys_cursor
.y
;
5850 cr
.width
= cursor_glyph
->pixel_width
;
5851 cr
.height
= w
->phys_cursor_height
;
5852 return x_intersect_rectangles (&cr
, r
, &result
);
5859 /* Redraw a rectangle of window W. R is a rectangle in window
5860 relative coordinates. Call this function with input blocked. */
5863 expose_window (w
, r
)
5867 struct glyph_row
*row
;
5869 int yb
= window_text_bottom_y (w
);
5870 int cursor_cleared_p
;
5872 /* If window is not yet fully initialized, do nothing. This can
5873 happen when toolkit scroll bars are used and a window is split.
5874 Reconfiguring the scroll bar will generate an expose for a newly
5876 if (w
->current_matrix
== NULL
|| w
== updated_window
)
5879 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5880 r
->x
, r
->y
, r
->width
, r
->height
));
5882 /* Convert to window coordinates. */
5883 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5884 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5886 /* Turn off the cursor. */
5887 if (!w
->pseudo_window_p
5888 && x_phys_cursor_in_rect_p (w
, r
))
5891 cursor_cleared_p
= 1;
5894 cursor_cleared_p
= 0;
5896 /* Find the first row intersecting the rectangle R. */
5897 row
= w
->current_matrix
->rows
;
5899 while (row
->enabled_p
5901 && y
+ row
->height
< r
->y
)
5907 /* Display the text in the rectangle, one text line at a time. */
5908 while (row
->enabled_p
5910 && y
< r
->y
+ r
->height
)
5912 expose_line (w
, row
, r
);
5917 /* Display the mode line if there is one. */
5918 if (WINDOW_WANTS_MODELINE_P (w
)
5919 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5921 && row
->y
< r
->y
+ r
->height
)
5922 expose_line (w
, row
, r
);
5924 if (!w
->pseudo_window_p
)
5926 /* Draw border between windows. */
5927 x_draw_vertical_border (w
);
5929 /* Turn the cursor on again. */
5930 if (cursor_cleared_p
)
5931 x_update_window_cursor (w
, 1);
5936 /* Determine the intersection of two rectangles R1 and R2. Return
5937 the intersection in *RESULT. Value is non-zero if RESULT is not
5941 x_intersect_rectangles (r1
, r2
, result
)
5942 XRectangle
*r1
, *r2
, *result
;
5944 XRectangle
*left
, *right
;
5945 XRectangle
*upper
, *lower
;
5946 int intersection_p
= 0;
5948 /* Rearrange so that R1 is the left-most rectangle. */
5950 left
= r1
, right
= r2
;
5952 left
= r2
, right
= r1
;
5954 /* X0 of the intersection is right.x0, if this is inside R1,
5955 otherwise there is no intersection. */
5956 if (right
->x
<= left
->x
+ left
->width
)
5958 result
->x
= right
->x
;
5960 /* The right end of the intersection is the minimum of the
5961 the right ends of left and right. */
5962 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5965 /* Same game for Y. */
5967 upper
= r1
, lower
= r2
;
5969 upper
= r2
, lower
= r1
;
5971 /* The upper end of the intersection is lower.y0, if this is inside
5972 of upper. Otherwise, there is no intersection. */
5973 if (lower
->y
<= upper
->y
+ upper
->height
)
5975 result
->y
= lower
->y
;
5977 /* The lower end of the intersection is the minimum of the lower
5978 ends of upper and lower. */
5979 result
->height
= (min (lower
->y
+ lower
->height
,
5980 upper
->y
+ upper
->height
)
5986 return intersection_p
;
5997 /* We used to only do this if Vx_no_window_manager was non-nil, but
5998 the ICCCM (section 4.1.6) says that the window's border pixmap
5999 and border pixel are window attributes which are "private to the
6000 client", so we can always change it to whatever we want. */
6002 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6003 f
->output_data
.x
->border_pixel
);
6005 x_update_cursor (f
, 1);
6009 frame_unhighlight (f
)
6012 /* We used to only do this if Vx_no_window_manager was non-nil, but
6013 the ICCCM (section 4.1.6) says that the window's border pixmap
6014 and border pixel are window attributes which are "private to the
6015 client", so we can always change it to whatever we want. */
6017 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6018 f
->output_data
.x
->border_tile
);
6020 x_update_cursor (f
, 1);
6023 /* The focus has changed. Update the frames as necessary to reflect
6024 the new situation. Note that we can't change the selected frame
6025 here, because the Lisp code we are interrupting might become confused.
6026 Each event gets marked with the frame in which it occurred, so the
6027 Lisp code can tell when the switch took place by examining the events. */
6030 x_new_focus_frame (dpyinfo
, frame
)
6031 struct x_display_info
*dpyinfo
;
6032 struct frame
*frame
;
6034 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6036 if (frame
!= dpyinfo
->x_focus_frame
)
6038 /* Set this before calling other routines, so that they see
6039 the correct value of x_focus_frame. */
6040 dpyinfo
->x_focus_frame
= frame
;
6042 if (old_focus
&& old_focus
->auto_lower
)
6043 x_lower_frame (old_focus
);
6046 selected_frame
= frame
;
6047 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6049 Fselect_window (selected_frame
->selected_window
);
6050 choose_minibuf_frame ();
6053 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6054 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6056 pending_autoraise_frame
= 0;
6059 x_frame_rehighlight (dpyinfo
);
6062 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6065 x_mouse_leave (dpyinfo
)
6066 struct x_display_info
*dpyinfo
;
6068 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6071 /* The focus has changed, or we have redirected a frame's focus to
6072 another frame (this happens when a frame uses a surrogate
6073 mini-buffer frame). Shift the highlight as appropriate.
6075 The FRAME argument doesn't necessarily have anything to do with which
6076 frame is being highlighted or un-highlighted; we only use it to find
6077 the appropriate X display info. */
6080 XTframe_rehighlight (frame
)
6081 struct frame
*frame
;
6083 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6087 x_frame_rehighlight (dpyinfo
)
6088 struct x_display_info
*dpyinfo
;
6090 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6092 if (dpyinfo
->x_focus_frame
)
6094 dpyinfo
->x_highlight_frame
6095 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6096 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6097 : dpyinfo
->x_focus_frame
);
6098 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6100 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6101 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6105 dpyinfo
->x_highlight_frame
= 0;
6107 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6110 frame_unhighlight (old_highlight
);
6111 if (dpyinfo
->x_highlight_frame
)
6112 frame_highlight (dpyinfo
->x_highlight_frame
);
6118 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6120 /* Initialize mode_switch_bit and modifier_meaning. */
6122 x_find_modifier_meanings (dpyinfo
)
6123 struct x_display_info
*dpyinfo
;
6125 int min_code
, max_code
;
6128 XModifierKeymap
*mods
;
6130 dpyinfo
->meta_mod_mask
= 0;
6131 dpyinfo
->shift_lock_mask
= 0;
6132 dpyinfo
->alt_mod_mask
= 0;
6133 dpyinfo
->super_mod_mask
= 0;
6134 dpyinfo
->hyper_mod_mask
= 0;
6137 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6139 min_code
= dpyinfo
->display
->min_keycode
;
6140 max_code
= dpyinfo
->display
->max_keycode
;
6143 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6144 min_code
, max_code
- min_code
+ 1,
6146 mods
= XGetModifierMapping (dpyinfo
->display
);
6148 /* Scan the modifier table to see which modifier bits the Meta and
6149 Alt keysyms are on. */
6151 int row
, col
; /* The row and column in the modifier table. */
6153 for (row
= 3; row
< 8; row
++)
6154 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6157 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6159 /* Zeroes are used for filler. Skip them. */
6163 /* Are any of this keycode's keysyms a meta key? */
6167 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6169 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6175 dpyinfo
->meta_mod_mask
|= (1 << row
);
6180 dpyinfo
->alt_mod_mask
|= (1 << row
);
6185 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6190 dpyinfo
->super_mod_mask
|= (1 << row
);
6194 /* Ignore this if it's not on the lock modifier. */
6195 if ((1 << row
) == LockMask
)
6196 dpyinfo
->shift_lock_mask
= LockMask
;
6204 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6205 if (! dpyinfo
->meta_mod_mask
)
6207 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6208 dpyinfo
->alt_mod_mask
= 0;
6211 /* If some keys are both alt and meta,
6212 make them just meta, not alt. */
6213 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6215 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6218 XFree ((char *) syms
);
6219 XFreeModifiermap (mods
);
6222 /* Convert between the modifier bits X uses and the modifier bits
6226 x_x_to_emacs_modifiers (dpyinfo
, state
)
6227 struct x_display_info
*dpyinfo
;
6230 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6231 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6232 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6233 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6234 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6235 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6239 x_emacs_to_x_modifiers (dpyinfo
, state
)
6240 struct x_display_info
*dpyinfo
;
6243 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6244 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6245 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6246 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6247 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6248 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6251 /* Convert a keysym to its name. */
6254 x_get_keysym_name (keysym
)
6260 value
= XKeysymToString (keysym
);
6268 /* Mouse clicks and mouse movement. Rah. */
6270 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6271 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6272 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6273 not force the value into range. */
6276 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6278 register int pix_x
, pix_y
;
6279 register int *x
, *y
;
6283 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6284 even for negative values. */
6286 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6288 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6290 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6291 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6295 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6296 bounds
->height
= f
->output_data
.x
->line_height
;
6297 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6298 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6305 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6306 pix_x
= FRAME_WINDOW_WIDTH (f
);
6310 else if (pix_y
> f
->height
)
6319 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6320 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6321 can't tell the positions because W's display is not up to date,
6325 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6328 int *frame_x
, *frame_y
;
6332 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6333 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6335 if (display_completed
)
6337 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6338 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6339 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6345 *frame_x
+= glyph
->pixel_width
;
6353 *frame_y
= *frame_x
= 0;
6357 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6358 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6363 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6365 If the event is a button press, then note that we have grabbed
6369 construct_mouse_click (result
, event
, f
)
6370 struct input_event
*result
;
6371 XButtonEvent
*event
;
6374 /* Make the event type no_event; we'll change that when we decide
6376 result
->kind
= mouse_click
;
6377 result
->code
= event
->button
- Button1
;
6378 result
->timestamp
= event
->time
;
6379 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6381 | (event
->type
== ButtonRelease
6385 XSETINT (result
->x
, event
->x
);
6386 XSETINT (result
->y
, event
->y
);
6387 XSETFRAME (result
->frame_or_window
, f
);
6393 /* Function to report a mouse movement to the mainstream Emacs code.
6394 The input handler calls this.
6396 We have received a mouse movement event, which is given in *event.
6397 If the mouse is over a different glyph than it was last time, tell
6398 the mainstream emacs code by setting mouse_moved. If not, ask for
6399 another motion event, so we can check again the next time it moves. */
6401 static XMotionEvent last_mouse_motion_event
;
6402 static Lisp_Object last_mouse_motion_frame
;
6405 note_mouse_movement (frame
, event
)
6407 XMotionEvent
*event
;
6409 last_mouse_movement_time
= event
->time
;
6410 last_mouse_motion_event
= *event
;
6411 XSETFRAME (last_mouse_motion_frame
, frame
);
6413 if (event
->window
!= FRAME_X_WINDOW (frame
))
6415 frame
->mouse_moved
= 1;
6416 last_mouse_scroll_bar
= Qnil
;
6417 note_mouse_highlight (frame
, -1, -1);
6420 /* Has the mouse moved off the glyph it was on at the last sighting? */
6421 else if (event
->x
< last_mouse_glyph
.x
6422 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6423 || event
->y
< last_mouse_glyph
.y
6424 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6426 frame
->mouse_moved
= 1;
6427 last_mouse_scroll_bar
= Qnil
;
6428 note_mouse_highlight (frame
, event
->x
, event
->y
);
6432 /* This is used for debugging, to turn off note_mouse_highlight. */
6434 int disable_mouse_highlight
;
6438 /************************************************************************
6440 ************************************************************************/
6442 /* Find the glyph under window-relative coordinates X/Y in window W.
6443 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6444 strings. Return in *HPOS and *VPOS the row and column number of
6445 the glyph found. Return in *AREA the glyph area containing X.
6446 Value is a pointer to the glyph found or null if X/Y is not on
6447 text, or we can't tell because W's current matrix is not up to
6450 static struct glyph
*
6451 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6454 int *hpos
, *vpos
, *area
;
6457 struct glyph
*glyph
, *end
;
6458 struct glyph_row
*row
= NULL
;
6459 int x0
, i
, left_area_width
;
6461 /* Find row containing Y. Give up if some row is not enabled. */
6462 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6464 row
= MATRIX_ROW (w
->current_matrix
, i
);
6465 if (!row
->enabled_p
)
6467 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6474 /* Give up if Y is not in the window. */
6475 if (i
== w
->current_matrix
->nrows
)
6478 /* Get the glyph area containing X. */
6479 if (w
->pseudo_window_p
)
6486 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6487 if (x
< left_area_width
)
6489 *area
= LEFT_MARGIN_AREA
;
6492 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6495 x0
= row
->x
+ left_area_width
;
6499 *area
= RIGHT_MARGIN_AREA
;
6500 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6504 /* Find glyph containing X. */
6505 glyph
= row
->glyphs
[*area
];
6506 end
= glyph
+ row
->used
[*area
];
6509 if (x
< x0
+ glyph
->pixel_width
)
6511 if (w
->pseudo_window_p
)
6513 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6517 x0
+= glyph
->pixel_width
;
6524 *hpos
= glyph
- row
->glyphs
[*area
];
6529 /* Convert frame-relative x/y to coordinates relative to window W.
6530 Takes pseudo-windows into account. */
6533 frame_to_window_pixel_xy (w
, x
, y
)
6537 if (w
->pseudo_window_p
)
6539 /* A pseudo-window is always full-width, and starts at the
6540 left edge of the frame, plus a frame border. */
6541 struct frame
*f
= XFRAME (w
->frame
);
6542 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6543 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6547 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6548 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6553 /* Take proper action when mouse has moved to the mode or header line of
6554 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6555 mode line. X is relative to the start of the text display area of
6556 W, so the width of bitmap areas and scroll bars must be subtracted
6557 to get a position relative to the start of the mode line. */
6560 note_mode_line_highlight (w
, x
, mode_line_p
)
6564 struct frame
*f
= XFRAME (w
->frame
);
6565 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6566 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6567 struct glyph_row
*row
;
6570 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6572 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6576 struct glyph
*glyph
, *end
;
6577 Lisp_Object help
, map
;
6580 /* Find the glyph under X. */
6581 glyph
= row
->glyphs
[TEXT_AREA
];
6582 end
= glyph
+ row
->used
[TEXT_AREA
];
6583 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6584 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6587 && x
>= x0
+ glyph
->pixel_width
)
6589 x0
+= glyph
->pixel_width
;
6594 && STRINGP (glyph
->object
)
6595 && XSTRING (glyph
->object
)->intervals
6596 && glyph
->charpos
>= 0
6597 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6599 /* If we're on a string with `help-echo' text property,
6600 arrange for the help to be displayed. This is done by
6601 setting the global variable help_echo to the help string. */
6602 help
= Fget_text_property (make_number (glyph
->charpos
),
6603 Qhelp_echo
, glyph
->object
);
6607 XSETWINDOW (help_echo_window
, w
);
6608 help_echo_object
= glyph
->object
;
6609 help_echo_pos
= glyph
->charpos
;
6612 /* Change the mouse pointer according to what is under X/Y. */
6613 map
= Fget_text_property (make_number (glyph
->charpos
),
6614 Qlocal_map
, glyph
->object
);
6616 cursor
= f
->output_data
.x
->nontext_cursor
;
6619 map
= Fget_text_property (make_number (glyph
->charpos
),
6620 Qkeymap
, glyph
->object
);
6622 cursor
= f
->output_data
.x
->nontext_cursor
;
6627 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6631 /* Take proper action when the mouse has moved to position X, Y on
6632 frame F as regards highlighting characters that have mouse-face
6633 properties. Also de-highlighting chars where the mouse was before.
6634 X and Y can be negative or out of range. */
6637 note_mouse_highlight (f
, x
, y
)
6641 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6646 /* When a menu is active, don't highlight because this looks odd. */
6647 #ifdef USE_X_TOOLKIT
6648 if (popup_activated ())
6652 if (disable_mouse_highlight
6653 || !f
->glyphs_initialized_p
)
6656 dpyinfo
->mouse_face_mouse_x
= x
;
6657 dpyinfo
->mouse_face_mouse_y
= y
;
6658 dpyinfo
->mouse_face_mouse_frame
= f
;
6660 if (dpyinfo
->mouse_face_defer
)
6665 dpyinfo
->mouse_face_deferred_gc
= 1;
6669 /* Which window is that in? */
6670 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6672 /* If we were displaying active text in another window, clear that. */
6673 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6674 clear_mouse_face (dpyinfo
);
6676 /* Not on a window -> return. */
6677 if (!WINDOWP (window
))
6680 /* Convert to window-relative pixel coordinates. */
6681 w
= XWINDOW (window
);
6682 frame_to_window_pixel_xy (w
, &x
, &y
);
6684 /* Handle tool-bar window differently since it doesn't display a
6686 if (EQ (window
, f
->tool_bar_window
))
6688 note_tool_bar_highlight (f
, x
, y
);
6692 if (portion
== 1 || portion
== 3)
6694 /* Mouse is on the mode or top line. */
6695 note_mode_line_highlight (w
, x
, portion
== 1);
6698 else if (portion
== 2)
6699 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6700 f
->output_data
.x
->horizontal_drag_cursor
);
6702 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6703 f
->output_data
.x
->text_cursor
);
6705 /* Are we in a window whose display is up to date?
6706 And verify the buffer's text has not changed. */
6707 if (/* Within text portion of the window. */
6709 && EQ (w
->window_end_valid
, w
->buffer
)
6710 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6711 && (XFASTINT (w
->last_overlay_modified
)
6712 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6714 int hpos
, vpos
, pos
, i
, area
;
6715 struct glyph
*glyph
;
6718 /* Find the glyph under X/Y. */
6719 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6721 /* Clear mouse face if X/Y not over text. */
6723 || area
!= TEXT_AREA
6724 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6726 clear_mouse_face (dpyinfo
);
6730 pos
= glyph
->charpos
;
6731 object
= glyph
->object
;
6732 if (!STRINGP (object
) && !BUFFERP (object
))
6736 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6737 Lisp_Object
*overlay_vec
= NULL
;
6739 struct buffer
*obuf
;
6742 /* If we get an out-of-range value, return now; avoid an error. */
6743 if (BUFFERP (object
) && pos
> BUF_Z (XBUFFER (w
->buffer
)))
6746 /* Make the window's buffer temporarily current for
6747 overlays_at and compute_char_face. */
6748 obuf
= current_buffer
;
6749 current_buffer
= XBUFFER (w
->buffer
);
6755 /* Is this char mouse-active or does it have help-echo? */
6756 position
= make_number (pos
);
6758 if (BUFFERP (object
))
6760 /* Put all the overlays we want in a vector in overlay_vec.
6761 Store the length in len. If there are more than 10, make
6762 enough space for all, and try again. */
6764 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6765 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6766 if (noverlays
> len
)
6769 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6770 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6773 /* Sort overlays into increasing priority order. */
6774 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6779 /* Check mouse-face highlighting. */
6780 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6781 && vpos
>= dpyinfo
->mouse_face_beg_row
6782 && vpos
<= dpyinfo
->mouse_face_end_row
6783 && (vpos
> dpyinfo
->mouse_face_beg_row
6784 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6785 && (vpos
< dpyinfo
->mouse_face_end_row
6786 || hpos
< dpyinfo
->mouse_face_end_col
6787 || dpyinfo
->mouse_face_past_end
))
6788 /* If there exists an overlay with mouse-face overlapping
6789 the one we are currently highlighting, we have to
6790 check if we enter the overlapping overlay, and then
6791 highlight only that. */
6792 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
6793 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
6796 /* Clear the display of the old active region, if any. */
6797 clear_mouse_face (dpyinfo
);
6799 /* Find the highest priority overlay that has a mouse-face
6802 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
6804 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6805 if (!NILP (mouse_face
))
6806 overlay
= overlay_vec
[i
];
6808 dpyinfo
->mouse_face_overlay
= overlay
;
6810 /* If no overlay applies, get a text property. */
6812 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
6814 /* Handle the overlay case. */
6815 if (!NILP (overlay
))
6817 /* Find the range of text around this char that
6818 should be active. */
6819 Lisp_Object before
, after
;
6822 before
= Foverlay_start (overlay
);
6823 after
= Foverlay_end (overlay
);
6824 /* Record this as the current active region. */
6825 fast_find_position (w
, XFASTINT (before
),
6826 &dpyinfo
->mouse_face_beg_col
,
6827 &dpyinfo
->mouse_face_beg_row
,
6828 &dpyinfo
->mouse_face_beg_x
,
6829 &dpyinfo
->mouse_face_beg_y
);
6830 dpyinfo
->mouse_face_past_end
6831 = !fast_find_position (w
, XFASTINT (after
),
6832 &dpyinfo
->mouse_face_end_col
,
6833 &dpyinfo
->mouse_face_end_row
,
6834 &dpyinfo
->mouse_face_end_x
,
6835 &dpyinfo
->mouse_face_end_y
);
6836 dpyinfo
->mouse_face_window
= window
;
6837 dpyinfo
->mouse_face_face_id
6838 = face_at_buffer_position (w
, pos
, 0, 0,
6839 &ignore
, pos
+ 1, 1);
6841 /* Display it as active. */
6842 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6844 /* Handle the text property case. */
6845 else if (!NILP (mouse_face
) && BUFFERP (object
))
6847 /* Find the range of text around this char that
6848 should be active. */
6849 Lisp_Object before
, after
, beginning
, end
;
6852 beginning
= Fmarker_position (w
->start
);
6853 end
= make_number (BUF_Z (XBUFFER (object
))
6854 - XFASTINT (w
->window_end_pos
));
6856 = Fprevious_single_property_change (make_number (pos
+ 1),
6860 = Fnext_single_property_change (position
, Qmouse_face
,
6863 /* Record this as the current active region. */
6864 fast_find_position (w
, XFASTINT (before
),
6865 &dpyinfo
->mouse_face_beg_col
,
6866 &dpyinfo
->mouse_face_beg_row
,
6867 &dpyinfo
->mouse_face_beg_x
,
6868 &dpyinfo
->mouse_face_beg_y
);
6869 dpyinfo
->mouse_face_past_end
6870 = !fast_find_position (w
, XFASTINT (after
),
6871 &dpyinfo
->mouse_face_end_col
,
6872 &dpyinfo
->mouse_face_end_row
,
6873 &dpyinfo
->mouse_face_end_x
,
6874 &dpyinfo
->mouse_face_end_y
);
6875 dpyinfo
->mouse_face_window
= window
;
6877 if (BUFFERP (object
))
6878 dpyinfo
->mouse_face_face_id
6879 = face_at_buffer_position (w
, pos
, 0, 0,
6880 &ignore
, pos
+ 1, 1);
6882 /* Display it as active. */
6883 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6885 else if (!NILP (mouse_face
) && STRINGP (object
))
6890 b
= Fprevious_single_property_change (make_number (pos
+ 1),
6893 e
= Fnext_single_property_change (position
, Qmouse_face
,
6896 b
= make_number (0);
6898 e
= make_number (XSTRING (object
)->size
) - 1;
6899 fast_find_string_pos (w
, XINT (b
), object
,
6900 &dpyinfo
->mouse_face_beg_col
,
6901 &dpyinfo
->mouse_face_beg_row
,
6902 &dpyinfo
->mouse_face_beg_x
,
6903 &dpyinfo
->mouse_face_beg_y
, 0);
6904 fast_find_string_pos (w
, XINT (e
), object
,
6905 &dpyinfo
->mouse_face_end_col
,
6906 &dpyinfo
->mouse_face_end_row
,
6907 &dpyinfo
->mouse_face_end_x
,
6908 &dpyinfo
->mouse_face_end_y
, 1);
6909 dpyinfo
->mouse_face_past_end
= 0;
6910 dpyinfo
->mouse_face_window
= window
;
6911 dpyinfo
->mouse_face_face_id
6912 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
6914 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6918 /* Look for a `help-echo' property. */
6920 Lisp_Object help
, overlay
;
6922 /* Check overlays first. */
6923 help
= overlay
= Qnil
;
6924 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6926 overlay
= overlay_vec
[i
];
6927 help
= Foverlay_get (overlay
, Qhelp_echo
);
6933 help_echo_window
= window
;
6934 help_echo_object
= overlay
;
6935 help_echo_pos
= pos
;
6939 /* Try text properties. */
6940 if ((STRINGP (glyph
->object
)
6941 && glyph
->charpos
>= 0
6942 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6943 || (BUFFERP (glyph
->object
)
6944 && glyph
->charpos
>= BEGV
6945 && glyph
->charpos
< ZV
))
6946 help
= Fget_text_property (make_number (glyph
->charpos
),
6947 Qhelp_echo
, glyph
->object
);
6952 help_echo_window
= window
;
6953 help_echo_object
= glyph
->object
;
6954 help_echo_pos
= glyph
->charpos
;
6961 current_buffer
= obuf
;
6967 redo_mouse_highlight ()
6969 if (!NILP (last_mouse_motion_frame
)
6970 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6971 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6972 last_mouse_motion_event
.x
,
6973 last_mouse_motion_event
.y
);
6978 /***********************************************************************
6980 ***********************************************************************/
6982 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6983 struct glyph
**, int *, int *, int *));
6985 /* Tool-bar item index of the item on which a mouse button was pressed
6988 static int last_tool_bar_item
;
6991 /* Get information about the tool-bar item at position X/Y on frame F.
6992 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6993 the current matrix of the tool-bar window of F, or NULL if not
6994 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6995 item in F->tool_bar_items. Value is
6997 -1 if X/Y is not on a tool-bar item
6998 0 if X/Y is on the same item that was highlighted before.
7002 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7005 struct glyph
**glyph
;
7006 int *hpos
, *vpos
, *prop_idx
;
7008 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7009 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7012 /* Find the glyph under X/Y. */
7013 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7017 /* Get the start of this tool-bar item's properties in
7018 f->tool_bar_items. */
7019 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7022 /* Is mouse on the highlighted item? */
7023 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7024 && *vpos
>= dpyinfo
->mouse_face_beg_row
7025 && *vpos
<= dpyinfo
->mouse_face_end_row
7026 && (*vpos
> dpyinfo
->mouse_face_beg_row
7027 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7028 && (*vpos
< dpyinfo
->mouse_face_end_row
7029 || *hpos
< dpyinfo
->mouse_face_end_col
7030 || dpyinfo
->mouse_face_past_end
))
7037 /* Handle mouse button event on the tool-bar of frame F, at
7038 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
7042 x_handle_tool_bar_click (f
, button_event
)
7044 XButtonEvent
*button_event
;
7046 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7047 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7048 int hpos
, vpos
, prop_idx
;
7049 struct glyph
*glyph
;
7050 Lisp_Object enabled_p
;
7051 int x
= button_event
->x
;
7052 int y
= button_event
->y
;
7054 /* If not on the highlighted tool-bar item, return. */
7055 frame_to_window_pixel_xy (w
, &x
, &y
);
7056 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7059 /* If item is disabled, do nothing. */
7060 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7061 if (NILP (enabled_p
))
7064 if (button_event
->type
== ButtonPress
)
7066 /* Show item in pressed state. */
7067 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7068 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7069 last_tool_bar_item
= prop_idx
;
7073 Lisp_Object key
, frame
;
7074 struct input_event event
;
7076 /* Show item in released state. */
7077 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7078 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7080 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7082 XSETFRAME (frame
, f
);
7083 event
.kind
= TOOL_BAR_EVENT
;
7084 event
.frame_or_window
= frame
;
7086 kbd_buffer_store_event (&event
);
7088 event
.kind
= TOOL_BAR_EVENT
;
7089 event
.frame_or_window
= frame
;
7091 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7092 button_event
->state
);
7093 kbd_buffer_store_event (&event
);
7094 last_tool_bar_item
= -1;
7099 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7100 tool-bar window-relative coordinates X/Y. Called from
7101 note_mouse_highlight. */
7104 note_tool_bar_highlight (f
, x
, y
)
7108 Lisp_Object window
= f
->tool_bar_window
;
7109 struct window
*w
= XWINDOW (window
);
7110 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7112 struct glyph
*glyph
;
7113 struct glyph_row
*row
;
7115 Lisp_Object enabled_p
;
7117 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
7118 int mouse_down_p
, rc
;
7120 /* Function note_mouse_highlight is called with negative x(y
7121 values when mouse moves outside of the frame. */
7122 if (x
<= 0 || y
<= 0)
7124 clear_mouse_face (dpyinfo
);
7128 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7131 /* Not on tool-bar item. */
7132 clear_mouse_face (dpyinfo
);
7136 /* On same tool-bar item as before. */
7139 clear_mouse_face (dpyinfo
);
7141 /* Mouse is down, but on different tool-bar item? */
7142 mouse_down_p
= (dpyinfo
->grabbed
7143 && f
== last_mouse_frame
7144 && FRAME_LIVE_P (f
));
7146 && last_tool_bar_item
!= prop_idx
)
7149 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7150 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7152 /* If tool-bar item is not enabled, don't highlight it. */
7153 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7154 if (!NILP (enabled_p
))
7156 /* Compute the x-position of the glyph. In front and past the
7157 image is a space. We include this is the highlighted area. */
7158 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7159 for (i
= x
= 0; i
< hpos
; ++i
)
7160 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7162 /* Record this as the current active region. */
7163 dpyinfo
->mouse_face_beg_col
= hpos
;
7164 dpyinfo
->mouse_face_beg_row
= vpos
;
7165 dpyinfo
->mouse_face_beg_x
= x
;
7166 dpyinfo
->mouse_face_beg_y
= row
->y
;
7167 dpyinfo
->mouse_face_past_end
= 0;
7169 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7170 dpyinfo
->mouse_face_end_row
= vpos
;
7171 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7172 dpyinfo
->mouse_face_end_y
= row
->y
;
7173 dpyinfo
->mouse_face_window
= window
;
7174 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7176 /* Display it as active. */
7177 show_mouse_face (dpyinfo
, draw
);
7178 dpyinfo
->mouse_face_image_state
= draw
;
7183 /* Set help_echo to a help string.to display for this tool-bar item.
7184 XTread_socket does the rest. */
7185 help_echo_object
= help_echo_window
= Qnil
;
7187 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7188 if (NILP (help_echo
))
7189 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7194 /* Find the glyph matrix position of buffer position POS in window W.
7195 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7196 current glyphs must be up to date. If POS is above window start
7197 return (0, 0, 0, 0). If POS is after end of W, return end of
7201 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
7204 int *hpos
, *vpos
, *x
, *y
;
7208 int maybe_next_line_p
= 0;
7209 int line_start_position
;
7210 int yb
= window_text_bottom_y (w
);
7211 struct glyph_row
*row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7212 struct glyph_row
*best_row
= row
;
7213 int row_vpos
= 0, best_row_vpos
= 0;
7218 if (row
->used
[TEXT_AREA
])
7219 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7221 line_start_position
= 0;
7223 if (line_start_position
> pos
)
7225 /* If the position sought is the end of the buffer,
7226 don't include the blank lines at the bottom of the window. */
7227 else if (line_start_position
== pos
7228 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7230 maybe_next_line_p
= 1;
7233 else if (line_start_position
> 0)
7236 best_row_vpos
= row_vpos
;
7239 if (row
->y
+ row
->height
>= yb
)
7246 /* Find the right column within BEST_ROW. */
7248 current_x
= best_row
->x
;
7249 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7251 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7254 charpos
= glyph
->charpos
;
7258 *vpos
= best_row_vpos
;
7263 else if (charpos
> pos
)
7265 else if (charpos
> 0)
7268 current_x
+= glyph
->pixel_width
;
7271 /* If we're looking for the end of the buffer,
7272 and we didn't find it in the line we scanned,
7273 use the start of the following line. */
7274 if (maybe_next_line_p
)
7279 current_x
= best_row
->x
;
7282 *vpos
= best_row_vpos
;
7283 *hpos
= lastcol
+ 1;
7290 /* Find the position of the the glyph for position POS in OBJECT in
7291 window W's current matrix, and return in *X/*Y the pixel
7292 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7294 RIGHT_P non-zero means return the position of the right edge of the
7295 glyph, RIGHT_P zero means return the left edge position.
7297 If no glyph for POS exists in the matrix, return the position of
7298 the glyph with the next smaller position that is in the matrix, if
7299 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7300 exists in the matrix, return the position of the glyph with the
7301 next larger position in OBJECT.
7303 Value is non-zero if a glyph was found. */
7306 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7310 int *hpos
, *vpos
, *x
, *y
;
7313 int yb
= window_text_bottom_y (w
);
7314 struct glyph_row
*r
;
7315 struct glyph
*best_glyph
= NULL
;
7316 struct glyph_row
*best_row
= NULL
;
7319 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7320 r
->enabled_p
&& r
->y
< yb
;
7323 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7324 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7327 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7328 if (EQ (g
->object
, object
))
7330 if (g
->charpos
== pos
)
7337 else if (best_glyph
== NULL
7338 || ((abs (g
->charpos
- pos
)
7339 < abs (best_glyph
->charpos
- pos
))
7342 : g
->charpos
> pos
)))
7356 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7360 *x
+= best_glyph
->pixel_width
;
7365 *vpos
= best_row
- w
->current_matrix
->rows
;
7368 return best_glyph
!= NULL
;
7372 /* Display the active region described by mouse_face_*
7373 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7376 show_mouse_face (dpyinfo
, draw
)
7377 struct x_display_info
*dpyinfo
;
7378 enum draw_glyphs_face draw
;
7380 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7381 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7383 int cursor_off_p
= 0;
7384 struct cursor_pos saved_cursor
;
7386 saved_cursor
= output_cursor
;
7388 /* If window is in the process of being destroyed, don't bother
7390 if (w
->current_matrix
== NULL
)
7393 /* Recognize when we are called to operate on rows that don't exist
7394 anymore. This can happen when a window is split. */
7395 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7398 set_output_cursor (&w
->phys_cursor
);
7400 /* Note that mouse_face_beg_row etc. are window relative. */
7401 for (i
= dpyinfo
->mouse_face_beg_row
;
7402 i
<= dpyinfo
->mouse_face_end_row
;
7405 int start_hpos
, end_hpos
, start_x
;
7406 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7408 /* Don't do anything if row doesn't have valid contents. */
7409 if (!row
->enabled_p
)
7412 /* For all but the first row, the highlight starts at column 0. */
7413 if (i
== dpyinfo
->mouse_face_beg_row
)
7415 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7416 start_x
= dpyinfo
->mouse_face_beg_x
;
7424 if (i
== dpyinfo
->mouse_face_end_row
)
7425 end_hpos
= dpyinfo
->mouse_face_end_col
;
7427 end_hpos
= row
->used
[TEXT_AREA
];
7429 /* If the cursor's in the text we are about to rewrite, turn the
7431 if (!w
->pseudo_window_p
7432 && i
== output_cursor
.vpos
7433 && output_cursor
.hpos
>= start_hpos
- 1
7434 && output_cursor
.hpos
<= end_hpos
)
7436 x_update_window_cursor (w
, 0);
7440 if (end_hpos
> start_hpos
)
7442 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7443 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7444 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7448 /* If we turned the cursor off, turn it back on. */
7450 x_display_cursor (w
, 1,
7451 output_cursor
.hpos
, output_cursor
.vpos
,
7452 output_cursor
.x
, output_cursor
.y
);
7454 output_cursor
= saved_cursor
;
7458 /* Change the mouse cursor. */
7459 if (draw
== DRAW_NORMAL_TEXT
)
7460 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7461 f
->output_data
.x
->text_cursor
);
7462 else if (draw
== DRAW_MOUSE_FACE
)
7463 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7464 f
->output_data
.x
->cross_cursor
);
7466 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7467 f
->output_data
.x
->nontext_cursor
);
7470 /* Clear out the mouse-highlighted active region.
7471 Redraw it un-highlighted first. */
7474 clear_mouse_face (dpyinfo
)
7475 struct x_display_info
*dpyinfo
;
7477 #if 0 /* This prevents redrawing tool bar items when changing from one
7478 to another while a tooltip is open, so don't do it. */
7479 if (!NILP (tip_frame
))
7483 if (! NILP (dpyinfo
->mouse_face_window
))
7484 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7486 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7487 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7488 dpyinfo
->mouse_face_window
= Qnil
;
7492 /* Clear any mouse-face on window W. This function is part of the
7493 redisplay interface, and is called from try_window_id and similar
7494 functions to ensure the mouse-highlight is off. */
7497 x_clear_mouse_face (w
)
7500 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7504 XSETWINDOW (window
, w
);
7505 if (EQ (window
, dpyinfo
->mouse_face_window
))
7506 clear_mouse_face (dpyinfo
);
7511 /* Just discard the mouse face information for frame F, if any.
7512 This is used when the size of F is changed. */
7515 cancel_mouse_face (f
)
7519 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7521 window
= dpyinfo
->mouse_face_window
;
7522 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7524 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7525 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7526 dpyinfo
->mouse_face_window
= Qnil
;
7531 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7534 /* Try to determine frame pixel position and size of the glyph under
7535 frame pixel coordinates X/Y on frame F . Return the position and
7536 size in *RECT. Value is non-zero if we could compute these
7540 glyph_rect (f
, x
, y
, rect
)
7546 int part
, found
= 0;
7548 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7551 struct window
*w
= XWINDOW (window
);
7552 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7553 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7556 frame_to_window_pixel_xy (w
, &x
, &y
);
7558 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7561 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7562 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7565 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7568 rect
->width
= g
->pixel_width
;
7569 rect
->height
= r
->height
;
7570 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7571 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7581 /* Return the current position of the mouse.
7582 *FP should be a frame which indicates which display to ask about.
7584 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7585 and *PART to the frame, window, and scroll bar part that the mouse
7586 is over. Set *X and *Y to the portion and whole of the mouse's
7587 position on the scroll bar.
7589 If the mouse movement started elsewhere, set *FP to the frame the
7590 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7593 Set *TIME to the server time-stamp for the time at which the mouse
7594 was at this position.
7596 Don't store anything if we don't have a valid set of values to report.
7598 This clears the mouse_moved flag, so we can wait for the next mouse
7602 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7605 Lisp_Object
*bar_window
;
7606 enum scroll_bar_part
*part
;
7608 unsigned long *time
;
7614 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7615 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7621 Window dummy_window
;
7624 Lisp_Object frame
, tail
;
7626 /* Clear the mouse-moved flag for every frame on this display. */
7627 FOR_EACH_FRAME (tail
, frame
)
7628 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7629 XFRAME (frame
)->mouse_moved
= 0;
7631 last_mouse_scroll_bar
= Qnil
;
7633 /* Figure out which root window we're on. */
7634 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7635 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7637 /* The root window which contains the pointer. */
7640 /* Trash which we can't trust if the pointer is on
7641 a different screen. */
7644 /* The position on that root window. */
7647 /* More trash we can't trust. */
7650 /* Modifier keys and pointer buttons, about which
7652 (unsigned int *) &dummy
);
7654 /* Now we have a position on the root; find the innermost window
7655 containing the pointer. */
7659 int parent_x
= 0, parent_y
= 0;
7664 /* XTranslateCoordinates can get errors if the window
7665 structure is changing at the same time this function
7666 is running. So at least we must not crash from them. */
7668 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7670 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7671 && FRAME_LIVE_P (last_mouse_frame
))
7673 /* If mouse was grabbed on a frame, give coords for that frame
7674 even if the mouse is now outside it. */
7675 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7677 /* From-window, to-window. */
7678 root
, FRAME_X_WINDOW (last_mouse_frame
),
7680 /* From-position, to-position. */
7681 root_x
, root_y
, &win_x
, &win_y
,
7685 f1
= last_mouse_frame
;
7691 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7693 /* From-window, to-window. */
7696 /* From-position, to-position. */
7697 root_x
, root_y
, &win_x
, &win_y
,
7702 if (child
== None
|| child
== win
)
7710 /* Now we know that:
7711 win is the innermost window containing the pointer
7712 (XTC says it has no child containing the pointer),
7713 win_x and win_y are the pointer's position in it
7714 (XTC did this the last time through), and
7715 parent_x and parent_y are the pointer's position in win's parent.
7716 (They are what win_x and win_y were when win was child.
7717 If win is the root window, it has no parent, and
7718 parent_{x,y} are invalid, but that's okay, because we'll
7719 never use them in that case.) */
7721 /* Is win one of our frames? */
7722 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7724 #ifdef USE_X_TOOLKIT
7725 /* If we end up with the menu bar window, say it's not
7728 && f1
->output_data
.x
->menubar_widget
7729 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
7731 #endif /* USE_X_TOOLKIT */
7734 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7737 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7739 /* If not, is it one of our scroll bars? */
7742 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7746 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7752 if (f1
== 0 && insist
> 0)
7753 f1
= SELECTED_FRAME ();
7757 /* Ok, we found a frame. Store all the values.
7758 last_mouse_glyph is a rectangle used to reduce the
7759 generation of mouse events. To not miss any motion
7760 events, we must divide the frame into rectangles of the
7761 size of the smallest character that could be displayed
7762 on it, i.e. into the same rectangles that matrices on
7763 the frame are divided into. */
7765 int width
, height
, gx
, gy
;
7768 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
7769 last_mouse_glyph
= rect
;
7772 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7773 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7777 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7778 round down even for negative values. */
7783 gx
= (gx
+ width
- 1) / width
* width
;
7784 gy
= (gy
+ height
- 1) / height
* height
;
7786 last_mouse_glyph
.width
= width
;
7787 last_mouse_glyph
.height
= height
;
7788 last_mouse_glyph
.x
= gx
;
7789 last_mouse_glyph
.y
= gy
;
7795 XSETINT (*x
, win_x
);
7796 XSETINT (*y
, win_y
);
7797 *time
= last_mouse_movement_time
;
7806 #ifdef USE_X_TOOLKIT
7808 /* Atimer callback function for TIMER. Called every 0.1s to process
7809 Xt timeouts, if needed. We must avoid calling XtAppPending as
7810 much as possible because that function does an implicit XFlush
7811 that slows us down. */
7814 x_process_timeouts (timer
)
7815 struct atimer
*timer
;
7817 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7820 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7821 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7826 #endif /* USE_X_TOOLKIT */
7829 /* Scroll bar support. */
7831 /* Given an X window ID, find the struct scroll_bar which manages it.
7832 This can be called in GC, so we have to make sure to strip off mark
7835 static struct scroll_bar
*
7836 x_window_to_scroll_bar (window_id
)
7841 for (tail
= Vframe_list
;
7842 XGCTYPE (tail
) == Lisp_Cons
;
7845 Lisp_Object frame
, bar
, condemned
;
7847 frame
= XCAR (tail
);
7848 /* All elements of Vframe_list should be frames. */
7849 if (! GC_FRAMEP (frame
))
7852 /* Scan this frame's scroll bar list for a scroll bar with the
7854 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7855 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7856 /* This trick allows us to search both the ordinary and
7857 condemned scroll bar lists with one loop. */
7858 ! GC_NILP (bar
) || (bar
= condemned
,
7861 bar
= XSCROLL_BAR (bar
)->next
)
7862 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7863 return XSCROLL_BAR (bar
);
7871 /************************************************************************
7873 ************************************************************************/
7875 #ifdef USE_TOOLKIT_SCROLL_BARS
7877 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7878 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7879 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7880 struct scroll_bar
*));
7881 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7885 /* Id of action hook installed for scroll bars. */
7887 static XtActionHookId action_hook_id
;
7889 /* Lisp window being scrolled. Set when starting to interact with
7890 a toolkit scroll bar, reset to nil when ending the interaction. */
7892 static Lisp_Object window_being_scrolled
;
7894 /* Last scroll bar part sent in xm_scroll_callback. */
7896 static int last_scroll_bar_part
;
7898 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7899 that movements of 1/20 of the screen size are mapped to up/down. */
7901 static Boolean xaw3d_arrow_scroll
;
7903 /* Whether the drag scrolling maintains the mouse at the top of the
7904 thumb. If not, resizing the thumb needs to be done more carefully
7905 to avoid jerkyness. */
7907 static Boolean xaw3d_pick_top
;
7910 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7911 bars are used.. The hook is responsible for detecting when
7912 the user ends an interaction with the scroll bar, and generates
7913 a `end-scroll' scroll_bar_click' event if so. */
7916 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7919 XtPointer client_data
;
7923 Cardinal
*num_params
;
7929 scroll_bar_p
= XmIsScrollBar (widget
);
7930 end_action
= "Release";
7931 #else /* !USE_MOTIF i.e. use Xaw */
7932 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7933 end_action
= "EndScroll";
7934 #endif /* USE_MOTIF */
7937 && strcmp (action_name
, end_action
) == 0
7938 && WINDOWP (window_being_scrolled
))
7942 x_send_scroll_bar_event (window_being_scrolled
,
7943 scroll_bar_end_scroll
, 0, 0);
7944 w
= XWINDOW (window_being_scrolled
);
7945 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7946 window_being_scrolled
= Qnil
;
7947 last_scroll_bar_part
= -1;
7949 /* Xt timeouts no longer needed. */
7950 toolkit_scroll_bar_interaction
= 0;
7954 /* A vector of windows used for communication between
7955 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
7957 static struct window
**scroll_bar_windows
;
7958 static int scroll_bar_windows_size
;
7961 /* Send a client message with message type Xatom_Scrollbar for a
7962 scroll action to the frame of WINDOW. PART is a value identifying
7963 the part of the scroll bar that was clicked on. PORTION is the
7964 amount to scroll of a whole of WHOLE. */
7967 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7969 int part
, portion
, whole
;
7972 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7973 struct window
*w
= XWINDOW (window
);
7974 struct frame
*f
= XFRAME (w
->frame
);
7979 /* Construct a ClientMessage event to send to the frame. */
7980 ev
->type
= ClientMessage
;
7981 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7982 ev
->display
= FRAME_X_DISPLAY (f
);
7983 ev
->window
= FRAME_X_WINDOW (f
);
7986 /* We can only transfer 32 bits in the XClientMessageEvent, which is
7987 not enough to store a pointer or Lisp_Object on a 64 bit system.
7988 So, store the window in scroll_bar_windows and pass the index
7989 into that array in the event. */
7990 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
7991 if (scroll_bar_windows
[i
] == NULL
)
7994 if (i
== scroll_bar_windows_size
)
7996 int new_size
= max (10, 2 * scroll_bar_windows_size
);
7997 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
7998 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8000 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8002 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8003 scroll_bar_windows_size
= new_size
;
8006 scroll_bar_windows
[i
] = w
;
8007 ev
->data
.l
[0] = (long) i
;
8008 ev
->data
.l
[1] = (long) part
;
8009 ev
->data
.l
[2] = (long) 0;
8010 ev
->data
.l
[3] = (long) portion
;
8011 ev
->data
.l
[4] = (long) whole
;
8013 /* Make Xt timeouts work while the scroll bar is active. */
8014 toolkit_scroll_bar_interaction
= 1;
8016 /* Setting the event mask to zero means that the message will
8017 be sent to the client that created the window, and if that
8018 window no longer exists, no event will be sent. */
8019 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8024 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8028 x_scroll_bar_to_input_event (event
, ievent
)
8030 struct input_event
*ievent
;
8032 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8037 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8038 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8040 XSETWINDOW (window
, w
);
8041 f
= XFRAME (w
->frame
);
8043 ievent
->kind
= scroll_bar_click
;
8044 ievent
->frame_or_window
= window
;
8046 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8047 ievent
->part
= ev
->data
.l
[1];
8048 ievent
->code
= ev
->data
.l
[2];
8049 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8050 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8051 ievent
->modifiers
= 0;
8057 /* Minimum and maximum values used for Motif scroll bars. */
8060 #define XM_SB_MAX 10000000
8061 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8064 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8065 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8066 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
8069 xm_scroll_callback (widget
, client_data
, call_data
)
8071 XtPointer client_data
, call_data
;
8073 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8074 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8076 int part
= -1, whole
= 0, portion
= 0;
8080 case XmCR_DECREMENT
:
8081 bar
->dragging
= Qnil
;
8082 part
= scroll_bar_up_arrow
;
8085 case XmCR_INCREMENT
:
8086 bar
->dragging
= Qnil
;
8087 part
= scroll_bar_down_arrow
;
8090 case XmCR_PAGE_DECREMENT
:
8091 bar
->dragging
= Qnil
;
8092 part
= scroll_bar_above_handle
;
8095 case XmCR_PAGE_INCREMENT
:
8096 bar
->dragging
= Qnil
;
8097 part
= scroll_bar_below_handle
;
8101 bar
->dragging
= Qnil
;
8102 part
= scroll_bar_to_top
;
8105 case XmCR_TO_BOTTOM
:
8106 bar
->dragging
= Qnil
;
8107 part
= scroll_bar_to_bottom
;
8113 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8114 && XINT (bar
->dragging
) <= cs
->value
);
8116 /* Get the slider size. */
8118 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8121 /* At the max position of the scroll bar, do a line-wise
8122 movement. Without doing anything, the LessTif scroll bar
8123 calls us with the same cs->value again and again. If we
8124 want to make sure that we can reach the end of the buffer,
8125 we have to do something.
8127 Implementation note: setting bar->dragging always to
8128 cs->value gives a smoother movement at the max position.
8129 Setting it to nil when doing line-wise movement gives
8130 a better slider behavior. */
8132 if (cs
->value
+ slider_size
== XM_SB_MAX
8134 && last_scroll_bar_part
== scroll_bar_down_arrow
))
8136 part
= scroll_bar_down_arrow
;
8137 bar
->dragging
= Qnil
;
8141 whole
= XM_SB_RANGE
;
8142 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
8143 part
= scroll_bar_handle
;
8144 bar
->dragging
= make_number (cs
->value
);
8149 case XmCR_VALUE_CHANGED
:
8155 window_being_scrolled
= bar
->window
;
8156 last_scroll_bar_part
= part
;
8157 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8162 #else /* !USE_MOTIF, i.e. Xaw. */
8165 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8166 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8167 scroll bar struct. CALL_DATA is a pointer to a float saying where
8171 xaw_jump_callback (widget
, client_data
, call_data
)
8173 XtPointer client_data
, call_data
;
8175 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8176 float top
= *(float *) call_data
;
8178 int whole
, portion
, height
;
8181 /* Get the size of the thumb, a value between 0 and 1. */
8183 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8187 portion
= shown
< 1 ? top
* whole
: 0;
8189 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8190 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8191 the bottom, so we force the scrolling whenever we see that we're
8192 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8193 we try to ensure that we always stay two pixels away from the
8195 part
= scroll_bar_down_arrow
;
8197 part
= scroll_bar_handle
;
8199 window_being_scrolled
= bar
->window
;
8200 bar
->dragging
= make_number (portion
);
8201 last_scroll_bar_part
= part
;
8202 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8206 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8207 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8208 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8209 the scroll bar. CALL_DATA is an integer specifying the action that
8210 has taken place. It's magnitude is in the range 0..height of the
8211 scroll bar. Negative values mean scroll towards buffer start.
8212 Values < height of scroll bar mean line-wise movement. */
8215 xaw_scroll_callback (widget
, client_data
, call_data
)
8217 XtPointer client_data
, call_data
;
8219 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8220 int position
= (int) call_data
;
8224 /* Get the height of the scroll bar. */
8226 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8229 if (abs (position
) >= height
)
8230 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8232 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8233 it maps line-movement to call_data = max(5, height/20). */
8234 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8235 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8237 part
= scroll_bar_move_ratio
;
8239 window_being_scrolled
= bar
->window
;
8240 bar
->dragging
= Qnil
;
8241 last_scroll_bar_part
= part
;
8242 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8246 #endif /* not USE_MOTIF */
8249 /* Create the widget for scroll bar BAR on frame F. Record the widget
8250 and X window of the scroll bar in BAR. */
8253 x_create_toolkit_scroll_bar (f
, bar
)
8255 struct scroll_bar
*bar
;
8261 char *scroll_bar_name
= "verticalScrollBar";
8262 unsigned long pixel
;
8267 /* LessTif 0.85, problems:
8269 1. When the mouse if over the scroll bar, the scroll bar will
8270 get keyboard events. I didn't find a way to turn this off.
8272 2. Do we have to explicitly set the cursor to get an arrow
8273 cursor (see below)? */
8275 /* Set resources. Create the widget. */
8276 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8277 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8278 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8279 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8280 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8281 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8282 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8284 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8287 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8291 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8294 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8298 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8299 scroll_bar_name
, av
, ac
);
8301 /* Add one callback for everything that can happen. */
8302 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8304 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8306 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8308 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8310 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8312 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8314 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8317 /* Realize the widget. Only after that is the X window created. */
8318 XtRealizeWidget (widget
);
8320 /* Set the cursor to an arrow. I didn't find a resource to do that.
8321 And I'm wondering why it hasn't an arrow cursor by default. */
8322 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8323 f
->output_data
.x
->nontext_cursor
);
8325 #else /* !USE_MOTIF i.e. use Xaw */
8327 /* Set resources. Create the widget. The background of the
8328 Xaw3d scroll bar widget is a little bit light for my taste.
8329 We don't alter it here to let users change it according
8330 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8331 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8332 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8333 /* For smoother scrolling with Xaw3d -sm */
8334 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8335 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
8337 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8340 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8344 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8347 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8351 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8352 f
->output_data
.x
->edit_widget
, av
, ac
);
8356 char *val
= initial
;
8357 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8358 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8360 { /* ARROW_SCROLL */
8361 xaw3d_arrow_scroll
= True
;
8362 /* Isn't that just a personal preference ? -sm */
8363 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8367 /* Define callbacks. */
8368 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8369 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8372 /* Realize the widget. Only after that is the X window created. */
8373 XtRealizeWidget (widget
);
8375 #endif /* !USE_MOTIF */
8377 /* Install an action hook that let's us detect when the user
8378 finishes interacting with a scroll bar. */
8379 if (action_hook_id
== 0)
8380 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8382 /* Remember X window and widget in the scroll bar vector. */
8383 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8384 xwindow
= XtWindow (widget
);
8385 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8391 /* Set the thumb size and position of scroll bar BAR. We are currently
8392 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8395 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8396 struct scroll_bar
*bar
;
8397 int portion
, position
, whole
;
8399 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8400 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8407 top
= (float) position
/ whole
;
8408 shown
= (float) portion
/ whole
;
8416 Boolean arrow1_selected
, arrow2_selected
;
8417 unsigned char flags
;
8418 XmScrollBarWidget sb
;
8420 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8421 is the scroll bar's maximum and MIN is the scroll bar's minimum
8423 size
= shown
* XM_SB_RANGE
;
8424 size
= min (size
, XM_SB_RANGE
);
8425 size
= max (size
, 1);
8427 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8428 value
= top
* XM_SB_RANGE
;
8429 value
= min (value
, XM_SB_MAX
- size
);
8430 value
= max (value
, XM_SB_MIN
);
8432 /* LessTif: Calling XmScrollBarSetValues after an increment or
8433 decrement turns off auto-repeat LessTif-internally. This can
8434 be seen in ScrollBar.c which resets Arrow1Selected and
8435 Arrow2Selected. It also sets internal flags so that LessTif
8436 believes the mouse is in the slider. We either have to change
8437 our code, or work around that by accessing private data. */
8439 sb
= (XmScrollBarWidget
) widget
;
8440 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
8441 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
8442 flags
= sb
->scrollBar
.flags
;
8444 if (NILP (bar
->dragging
))
8445 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8446 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8447 /* This has the negative side effect that the slider value is
8448 not what it would be if we scrolled here using line-wise or
8449 page-wise movement. */
8450 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8453 /* If currently dragging, only update the slider size.
8454 This reduces flicker effects. */
8455 int old_value
, old_size
, increment
, page_increment
;
8457 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8458 &increment
, &page_increment
);
8459 XmScrollBarSetValues (widget
, old_value
,
8460 min (size
, XM_SB_RANGE
- old_value
),
8464 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
8465 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
8466 sb
->scrollBar
.flags
= flags
;
8468 #else /* !USE_MOTIF i.e. use Xaw */
8470 float old_top
, old_shown
;
8472 XtVaGetValues (widget
,
8473 XtNtopOfThumb
, &old_top
,
8474 XtNshown
, &old_shown
,
8478 /* Massage the top+shown values. */
8479 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8480 top
= max (0, min (1, top
));
8483 /* Keep two pixels available for moving the thumb down. */
8484 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8486 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8487 check that your system's configuration file contains a define
8488 for `NARROWPROTO'. See s/freebsd.h for an example. */
8489 if (top
!= old_top
|| shown
!= old_shown
)
8491 if (NILP (bar
->dragging
))
8492 XawScrollbarSetThumb (widget
, top
, shown
);
8496 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8497 int scroll_mode
= 0;
8499 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8500 if (xaw3d_arrow_scroll
)
8502 /* Xaw3d stupidly ignores resize requests while dragging
8503 so we have to make it believe it's not in dragging mode. */
8504 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8505 if (scroll_mode
== 2)
8506 sb
->scrollbar
.scroll_mode
= 0;
8509 /* Try to make the scrolling a tad smoother. */
8510 if (!xaw3d_pick_top
)
8511 shown
= min (shown
, old_shown
);
8513 XawScrollbarSetThumb (widget
, top
, shown
);
8516 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8517 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8522 #endif /* !USE_MOTIF */
8527 #endif /* USE_TOOLKIT_SCROLL_BARS */
8531 /************************************************************************
8532 Scroll bars, general
8533 ************************************************************************/
8535 /* Create a scroll bar and return the scroll bar vector for it. W is
8536 the Emacs window on which to create the scroll bar. TOP, LEFT,
8537 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8540 static struct scroll_bar
*
8541 x_scroll_bar_create (w
, top
, left
, width
, height
)
8543 int top
, left
, width
, height
;
8545 struct frame
*f
= XFRAME (w
->frame
);
8546 struct scroll_bar
*bar
8547 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8551 #ifdef USE_TOOLKIT_SCROLL_BARS
8552 x_create_toolkit_scroll_bar (f
, bar
);
8553 #else /* not USE_TOOLKIT_SCROLL_BARS */
8555 XSetWindowAttributes a
;
8559 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8560 if (a
.background_pixel
== -1)
8561 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8563 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8564 | ButtonMotionMask
| PointerMotionHintMask
8566 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8568 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8570 /* Clear the area of W that will serve as a scroll bar. This is
8571 for the case that a window has been split horizontally. In
8572 this case, no clear_frame is generated to reduce flickering. */
8573 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8575 window_box_height (w
), False
);
8577 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8578 /* Position and size of scroll bar. */
8579 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8581 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8583 /* Border width, depth, class, and visual. */
8590 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8592 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8594 XSETWINDOW (bar
->window
, w
);
8595 XSETINT (bar
->top
, top
);
8596 XSETINT (bar
->left
, left
);
8597 XSETINT (bar
->width
, width
);
8598 XSETINT (bar
->height
, height
);
8599 XSETINT (bar
->start
, 0);
8600 XSETINT (bar
->end
, 0);
8601 bar
->dragging
= Qnil
;
8603 /* Add bar to its frame's list of scroll bars. */
8604 bar
->next
= FRAME_SCROLL_BARS (f
);
8606 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8607 if (!NILP (bar
->next
))
8608 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8610 /* Map the window/widget. */
8611 #ifdef USE_TOOLKIT_SCROLL_BARS
8613 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8614 XtConfigureWidget (scroll_bar
,
8615 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8617 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8618 max (height
, 1), 0);
8619 XtMapWidget (scroll_bar
);
8621 #else /* not USE_TOOLKIT_SCROLL_BARS */
8622 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8623 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8630 /* Draw BAR's handle in the proper position.
8632 If the handle is already drawn from START to END, don't bother
8633 redrawing it, unless REBUILD is non-zero; in that case, always
8634 redraw it. (REBUILD is handy for drawing the handle after expose
8637 Normally, we want to constrain the start and end of the handle to
8638 fit inside its rectangle, but if the user is dragging the scroll
8639 bar handle, we want to let them drag it down all the way, so that
8640 the bar's top is as far down as it goes; otherwise, there's no way
8641 to move to the very end of the buffer. */
8643 #ifndef USE_TOOLKIT_SCROLL_BARS
8646 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8647 struct scroll_bar
*bar
;
8651 int dragging
= ! NILP (bar
->dragging
);
8652 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8653 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8654 GC gc
= f
->output_data
.x
->normal_gc
;
8656 /* If the display is already accurate, do nothing. */
8658 && start
== XINT (bar
->start
)
8659 && end
== XINT (bar
->end
))
8665 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8666 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8667 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8669 /* Make sure the values are reasonable, and try to preserve
8670 the distance between start and end. */
8672 int length
= end
- start
;
8676 else if (start
> top_range
)
8678 end
= start
+ length
;
8682 else if (end
> top_range
&& ! dragging
)
8686 /* Store the adjusted setting in the scroll bar. */
8687 XSETINT (bar
->start
, start
);
8688 XSETINT (bar
->end
, end
);
8690 /* Clip the end position, just for display. */
8691 if (end
> top_range
)
8694 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8695 below top positions, to make sure the handle is always at least
8696 that many pixels tall. */
8697 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8699 /* Draw the empty space above the handle. Note that we can't clear
8700 zero-height areas; that means "clear to end of window." */
8702 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8703 /* x, y, width, height, and exposures. */
8704 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8705 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8706 inside_width
, start
,
8709 /* Change to proper foreground color if one is specified. */
8710 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8711 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8712 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8714 /* Draw the handle itself. */
8715 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8717 /* x, y, width, height */
8718 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8719 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8720 inside_width
, end
- start
);
8722 /* Restore the foreground color of the GC if we changed it above. */
8723 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8724 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8725 f
->output_data
.x
->foreground_pixel
);
8727 /* Draw the empty space below the handle. Note that we can't
8728 clear zero-height areas; that means "clear to end of window." */
8729 if (end
< inside_height
)
8730 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8731 /* x, y, width, height, and exposures. */
8732 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8733 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8734 inside_width
, inside_height
- end
,
8742 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8744 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8748 x_scroll_bar_remove (bar
)
8749 struct scroll_bar
*bar
;
8751 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8754 #ifdef USE_TOOLKIT_SCROLL_BARS
8755 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
8757 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8760 /* Disassociate this scroll bar from its window. */
8761 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8767 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8768 that we are displaying PORTION characters out of a total of WHOLE
8769 characters, starting at POSITION. If WINDOW has no scroll bar,
8773 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8775 int portion
, whole
, position
;
8777 struct frame
*f
= XFRAME (w
->frame
);
8778 struct scroll_bar
*bar
;
8779 int top
, height
, left
, sb_left
, width
, sb_width
;
8780 int window_x
, window_y
, window_width
, window_height
;
8782 /* Get window dimensions. */
8783 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8785 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8786 height
= window_height
;
8788 /* Compute the left edge of the scroll bar area. */
8789 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8790 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8792 left
= XFASTINT (w
->left
);
8793 left
*= CANON_X_UNIT (f
);
8794 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8796 /* Compute the width of the scroll bar which might be less than
8797 the width of the area reserved for the scroll bar. */
8798 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8799 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8803 /* Compute the left edge of the scroll bar. */
8804 #ifdef USE_TOOLKIT_SCROLL_BARS
8805 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8806 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8808 sb_left
= left
+ (width
- sb_width
) / 2;
8810 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8811 sb_left
= left
+ width
- sb_width
;
8816 /* Does the scroll bar exist yet? */
8817 if (NILP (w
->vertical_scroll_bar
))
8820 if (width
&& height
)
8821 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8822 left
, top
, width
, height
, False
);
8824 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8828 /* It may just need to be moved and resized. */
8829 unsigned int mask
= 0;
8831 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8835 if (sb_left
!= XINT (bar
->left
))
8837 if (top
!= XINT (bar
->top
))
8839 if (sb_width
!= XINT (bar
->width
))
8841 if (height
!= XINT (bar
->height
))
8844 #ifdef USE_TOOLKIT_SCROLL_BARS
8846 /* Since toolkit scroll bars are smaller than the space reserved
8847 for them on the frame, we have to clear "under" them. */
8848 if (width
&& height
)
8849 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8850 left
, top
, width
, height
, False
);
8852 /* Move/size the scroll bar widget. */
8854 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
8855 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8857 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8858 max (height
, 1), 0);
8860 #else /* not USE_TOOLKIT_SCROLL_BARS */
8862 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8864 /* Clear areas not covered by the scroll bar. This makes sure a
8865 previous mode line display is cleared after C-x 2 C-x 1, for
8866 example. Non-toolkit scroll bars are as wide as the area
8867 reserved for scroll bars - trim at both sides. */
8868 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8869 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8871 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8872 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8873 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8877 /* Move/size the scroll bar window. */
8882 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8884 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8886 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8890 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8892 /* Remember new settings. */
8893 XSETINT (bar
->left
, sb_left
);
8894 XSETINT (bar
->top
, top
);
8895 XSETINT (bar
->width
, sb_width
);
8896 XSETINT (bar
->height
, height
);
8901 #ifdef USE_TOOLKIT_SCROLL_BARS
8902 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8903 #else /* not USE_TOOLKIT_SCROLL_BARS */
8904 /* Set the scroll bar's current state, unless we're currently being
8906 if (NILP (bar
->dragging
))
8908 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8911 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8914 int start
= ((double) position
* top_range
) / whole
;
8915 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8916 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8919 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8921 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8925 /* The following three hooks are used when we're doing a thorough
8926 redisplay of the frame. We don't explicitly know which scroll bars
8927 are going to be deleted, because keeping track of when windows go
8928 away is a real pain - "Can you say set-window-configuration, boys
8929 and girls?" Instead, we just assert at the beginning of redisplay
8930 that *all* scroll bars are to be removed, and then save a scroll bar
8931 from the fiery pit when we actually redisplay its window. */
8933 /* Arrange for all scroll bars on FRAME to be removed at the next call
8934 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8935 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8938 XTcondemn_scroll_bars (frame
)
8941 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8942 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8945 bar
= FRAME_SCROLL_BARS (frame
);
8946 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8947 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8948 XSCROLL_BAR (bar
)->prev
= Qnil
;
8949 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8950 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8951 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8956 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8957 Note that WINDOW isn't necessarily condemned at all. */
8960 XTredeem_scroll_bar (window
)
8961 struct window
*window
;
8963 struct scroll_bar
*bar
;
8966 /* We can't redeem this window's scroll bar if it doesn't have one. */
8967 if (NILP (window
->vertical_scroll_bar
))
8970 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8972 /* Unlink it from the condemned list. */
8973 f
= XFRAME (WINDOW_FRAME (window
));
8974 if (NILP (bar
->prev
))
8976 /* If the prev pointer is nil, it must be the first in one of
8978 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8979 /* It's not condemned. Everything's fine. */
8981 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8982 window
->vertical_scroll_bar
))
8983 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8985 /* If its prev pointer is nil, it must be at the front of
8986 one or the other! */
8990 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8992 if (! NILP (bar
->next
))
8993 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8995 bar
->next
= FRAME_SCROLL_BARS (f
);
8997 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8998 if (! NILP (bar
->next
))
8999 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9002 /* Remove all scroll bars on FRAME that haven't been saved since the
9003 last call to `*condemn_scroll_bars_hook'. */
9006 XTjudge_scroll_bars (f
)
9009 Lisp_Object bar
, next
;
9011 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9013 /* Clear out the condemned list now so we won't try to process any
9014 more events on the hapless scroll bars. */
9015 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9017 for (; ! NILP (bar
); bar
= next
)
9019 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9021 x_scroll_bar_remove (b
);
9024 b
->next
= b
->prev
= Qnil
;
9027 /* Now there should be no references to the condemned scroll bars,
9028 and they should get garbage-collected. */
9032 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9033 is a no-op when using toolkit scroll bars.
9035 This may be called from a signal handler, so we have to ignore GC
9039 x_scroll_bar_expose (bar
, event
)
9040 struct scroll_bar
*bar
;
9043 #ifndef USE_TOOLKIT_SCROLL_BARS
9045 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9046 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9047 GC gc
= f
->output_data
.x
->normal_gc
;
9048 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9052 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9054 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9055 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9057 /* x, y, width, height */
9059 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9060 XINT (bar
->height
) - 1);
9064 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9067 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9068 is set to something other than no_event, it is enqueued.
9070 This may be called from a signal handler, so we have to ignore GC
9073 #ifndef USE_TOOLKIT_SCROLL_BARS
9076 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9077 struct scroll_bar
*bar
;
9079 struct input_event
*emacs_event
;
9081 if (! GC_WINDOWP (bar
->window
))
9084 emacs_event
->kind
= scroll_bar_click
;
9085 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9086 emacs_event
->modifiers
9087 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9088 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9089 event
->xbutton
.state
)
9090 | (event
->type
== ButtonRelease
9093 emacs_event
->frame_or_window
= bar
->window
;
9094 emacs_event
->arg
= Qnil
;
9095 emacs_event
->timestamp
= event
->xbutton
.time
;
9098 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9100 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9103 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9104 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9107 if (y
> top_range
) y
= top_range
;
9109 if (y
< XINT (bar
->start
))
9110 emacs_event
->part
= scroll_bar_above_handle
;
9111 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9112 emacs_event
->part
= scroll_bar_handle
;
9114 emacs_event
->part
= scroll_bar_below_handle
;
9116 /* Just because the user has clicked on the handle doesn't mean
9117 they want to drag it. Lisp code needs to be able to decide
9118 whether or not we're dragging. */
9120 /* If the user has just clicked on the handle, record where they're
9122 if (event
->type
== ButtonPress
9123 && emacs_event
->part
== scroll_bar_handle
)
9124 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9127 /* If the user has released the handle, set it to its final position. */
9128 if (event
->type
== ButtonRelease
9129 && ! NILP (bar
->dragging
))
9131 int new_start
= y
- XINT (bar
->dragging
);
9132 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9134 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9135 bar
->dragging
= Qnil
;
9138 /* Same deal here as the other #if 0. */
9140 /* Clicks on the handle are always reported as occurring at the top of
9142 if (emacs_event
->part
== scroll_bar_handle
)
9143 emacs_event
->x
= bar
->start
;
9145 XSETINT (emacs_event
->x
, y
);
9147 XSETINT (emacs_event
->x
, y
);
9150 XSETINT (emacs_event
->y
, top_range
);
9154 /* Handle some mouse motion while someone is dragging the scroll bar.
9156 This may be called from a signal handler, so we have to ignore GC
9160 x_scroll_bar_note_movement (bar
, event
)
9161 struct scroll_bar
*bar
;
9164 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9166 last_mouse_movement_time
= event
->xmotion
.time
;
9169 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9171 /* If we're dragging the bar, display it. */
9172 if (! GC_NILP (bar
->dragging
))
9174 /* Where should the handle be now? */
9175 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9177 if (new_start
!= XINT (bar
->start
))
9179 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9181 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9186 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9188 /* Return information to the user about the current position of the mouse
9189 on the scroll bar. */
9192 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9194 Lisp_Object
*bar_window
;
9195 enum scroll_bar_part
*part
;
9197 unsigned long *time
;
9199 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9200 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9201 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9203 Window dummy_window
;
9205 unsigned int dummy_mask
;
9209 /* Get the mouse's position relative to the scroll bar window, and
9211 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9213 /* Root, child, root x and root y. */
9214 &dummy_window
, &dummy_window
,
9215 &dummy_coord
, &dummy_coord
,
9217 /* Position relative to scroll bar. */
9220 /* Mouse buttons and modifier keys. */
9227 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9230 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9232 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9234 if (! NILP (bar
->dragging
))
9235 win_y
-= XINT (bar
->dragging
);
9239 if (win_y
> top_range
)
9243 *bar_window
= bar
->window
;
9245 if (! NILP (bar
->dragging
))
9246 *part
= scroll_bar_handle
;
9247 else if (win_y
< XINT (bar
->start
))
9248 *part
= scroll_bar_above_handle
;
9249 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9250 *part
= scroll_bar_handle
;
9252 *part
= scroll_bar_below_handle
;
9254 XSETINT (*x
, win_y
);
9255 XSETINT (*y
, top_range
);
9258 last_mouse_scroll_bar
= Qnil
;
9261 *time
= last_mouse_movement_time
;
9267 /* The screen has been cleared so we may have changed foreground or
9268 background colors, and the scroll bars may need to be redrawn.
9269 Clear out the scroll bars, and ask for expose events, so we can
9273 x_scroll_bar_clear (f
)
9276 #ifndef USE_TOOLKIT_SCROLL_BARS
9279 /* We can have scroll bars even if this is 0,
9280 if we just turned off scroll bar mode.
9281 But in that case we should not clear them. */
9282 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9283 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9284 bar
= XSCROLL_BAR (bar
)->next
)
9285 XClearArea (FRAME_X_DISPLAY (f
),
9286 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9288 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9291 /* This processes Expose events from the menu-bar specific X event
9292 loop in xmenu.c. This allows to redisplay the frame if necessary
9293 when handling menu-bar or pop-up items. */
9296 process_expose_from_menu (event
)
9300 struct x_display_info
*dpyinfo
;
9301 int frame_exposed_p
= 0;
9305 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9306 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9309 if (f
->async_visible
== 0)
9311 f
->async_visible
= 1;
9312 f
->async_iconified
= 0;
9313 f
->output_data
.x
->has_been_visible
= 1;
9314 SET_FRAME_GARBAGED (f
);
9318 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9319 event
.xexpose
.x
, event
.xexpose
.y
,
9320 event
.xexpose
.width
, event
.xexpose
.height
);
9321 frame_exposed_p
= 1;
9326 struct scroll_bar
*bar
9327 = x_window_to_scroll_bar (event
.xexpose
.window
);
9330 x_scroll_bar_expose (bar
, &event
);
9334 return frame_exposed_p
;
9337 /* Define a queue to save up SelectionRequest events for later handling. */
9339 struct selection_event_queue
9342 struct selection_event_queue
*next
;
9345 static struct selection_event_queue
*queue
;
9347 /* Nonzero means queue up certain events--don't process them yet. */
9349 static int x_queue_selection_requests
;
9351 /* Queue up an X event *EVENT, to be processed later. */
9354 x_queue_event (f
, event
)
9358 struct selection_event_queue
*queue_tmp
9359 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9361 if (queue_tmp
!= NULL
)
9363 queue_tmp
->event
= *event
;
9364 queue_tmp
->next
= queue
;
9369 /* Take all the queued events and put them back
9370 so that they get processed afresh. */
9373 x_unqueue_events (display
)
9376 while (queue
!= NULL
)
9378 struct selection_event_queue
*queue_tmp
= queue
;
9379 XPutBackEvent (display
, &queue_tmp
->event
);
9380 queue
= queue_tmp
->next
;
9381 xfree ((char *)queue_tmp
);
9385 /* Start queuing SelectionRequest events. */
9388 x_start_queuing_selection_requests (display
)
9391 x_queue_selection_requests
++;
9394 /* Stop queuing SelectionRequest events. */
9397 x_stop_queuing_selection_requests (display
)
9400 x_queue_selection_requests
--;
9401 x_unqueue_events (display
);
9404 /* The main X event-reading loop - XTread_socket. */
9406 /* Time stamp of enter window event. This is only used by XTread_socket,
9407 but we have to put it out here, since static variables within functions
9408 sometimes don't work. */
9410 static Time enter_timestamp
;
9412 /* This holds the state XLookupString needs to implement dead keys
9413 and other tricks known as "compose processing". _X Window System_
9414 says that a portable program can't use this, but Stephen Gildea assures
9415 me that letting the compiler initialize it to zeros will work okay.
9417 This must be defined outside of XTread_socket, for the same reasons
9418 given for enter_time stamp, above. */
9420 static XComposeStatus compose_status
;
9422 /* Record the last 100 characters stored
9423 to help debug the loss-of-chars-during-GC problem. */
9425 static int temp_index
;
9426 static short temp_buffer
[100];
9428 /* Set this to nonzero to fake an "X I/O error"
9429 on a particular display. */
9431 struct x_display_info
*XTread_socket_fake_io_error
;
9433 /* When we find no input here, we occasionally do a no-op command
9434 to verify that the X server is still running and we can still talk with it.
9435 We try all the open displays, one by one.
9436 This variable is used for cycling thru the displays. */
9438 static struct x_display_info
*next_noop_dpyinfo
;
9440 #define SET_SAVED_MENU_EVENT(size) \
9443 if (f->output_data.x->saved_menu_event == 0) \
9444 f->output_data.x->saved_menu_event \
9445 = (XEvent *) xmalloc (sizeof (XEvent)); \
9446 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9447 if (numchars >= 1) \
9449 bufp->kind = menu_bar_activate_event; \
9450 XSETFRAME (bufp->frame_or_window, f); \
9459 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9460 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9462 /* Read events coming from the X server.
9463 This routine is called by the SIGIO handler.
9464 We return as soon as there are no more events to be read.
9466 Events representing keys are stored in buffer BUFP,
9467 which can hold up to NUMCHARS characters.
9468 We return the number of characters stored into the buffer,
9469 thus pretending to be `read'.
9471 EXPECTED is nonzero if the caller knows input is available. */
9474 XTread_socket (sd
, bufp
, numchars
, expected
)
9476 /* register */ struct input_event
*bufp
;
9477 /* register */ int numchars
;
9484 int event_found
= 0;
9485 struct x_display_info
*dpyinfo
;
9486 struct coding_system coding
;
9488 if (interrupt_input_blocked
)
9490 interrupt_input_pending
= 1;
9494 interrupt_input_pending
= 0;
9497 /* So people can tell when we have read the available input. */
9498 input_signal_count
++;
9501 abort (); /* Don't think this happens. */
9505 /* The input should be decoded if it is from XIM. Currently the
9506 locale of XIM is the same as that of the system. So, we can use
9507 Vlocale_coding_system which is initialized properly at Emacs
9509 setup_coding_system (Vlocale_coding_system
, &coding
);
9510 coding
.src_multibyte
= 0;
9511 coding
.dst_multibyte
= 1;
9512 /* The input is converted to events, thus we can't handle
9513 composition. Anyway, there's no XIM that gives us composition
9515 coding
.composing
= COMPOSITION_DISABLED
;
9517 /* Find the display we are supposed to read input for.
9518 It's the one communicating on descriptor SD. */
9519 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9521 #if 0 /* This ought to be unnecessary; let's verify it. */
9523 /* If available, Xlib uses FIOSNBIO to make the socket
9524 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9525 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9526 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9527 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9528 #endif /* ! defined (FIOSNBIO) */
9531 #if 0 /* This code can't be made to work, with multiple displays,
9532 and appears not to be used on any system any more.
9533 Also keyboard.c doesn't turn O_NDELAY on and off
9534 for X connections. */
9537 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9539 extern int read_alarm_should_throw
;
9540 read_alarm_should_throw
= 1;
9541 XPeekEvent (dpyinfo
->display
, &event
);
9542 read_alarm_should_throw
= 0;
9544 #endif /* HAVE_SELECT */
9548 /* For debugging, this gives a way to fake an I/O error. */
9549 if (dpyinfo
== XTread_socket_fake_io_error
)
9551 XTread_socket_fake_io_error
= 0;
9552 x_io_error_quitter (dpyinfo
->display
);
9555 while (XPending (dpyinfo
->display
))
9557 XNextEvent (dpyinfo
->display
, &event
);
9561 /* Filter events for the current X input method.
9562 XFilterEvent returns non-zero if the input method has
9563 consumed the event. We pass the frame's X window to
9564 XFilterEvent because that's the one for which the IC
9566 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9567 event
.xclient
.window
);
9568 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9578 if (event
.xclient
.message_type
9579 == dpyinfo
->Xatom_wm_protocols
9580 && event
.xclient
.format
== 32)
9582 if (event
.xclient
.data
.l
[0]
9583 == dpyinfo
->Xatom_wm_take_focus
)
9585 /* Use x_any_window_to_frame because this
9586 could be the shell widget window
9587 if the frame has no title bar. */
9588 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9590 /* Not quite sure this is needed -pd */
9591 if (f
&& FRAME_XIC (f
))
9592 XSetICFocus (FRAME_XIC (f
));
9594 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9595 instructs the WM to set the input focus automatically for
9596 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9597 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9598 it has set the focus. So, XSetInputFocus below is not
9601 The call to XSetInputFocus below has also caused trouble. In
9602 cases where the XSetInputFocus done by the WM and the one
9603 below are temporally close (on a fast machine), the call
9604 below can generate additional FocusIn events which confuse
9607 /* Since we set WM_TAKE_FOCUS, we must call
9608 XSetInputFocus explicitly. But not if f is null,
9609 since that might be an event for a deleted frame. */
9612 Display
*d
= event
.xclient
.display
;
9613 /* Catch and ignore errors, in case window has been
9614 iconified by a window manager such as GWM. */
9615 int count
= x_catch_errors (d
);
9616 XSetInputFocus (d
, event
.xclient
.window
,
9617 /* The ICCCM says this is
9618 the only valid choice. */
9620 event
.xclient
.data
.l
[1]);
9621 /* This is needed to detect the error
9622 if there is an error. */
9624 x_uncatch_errors (d
, count
);
9626 /* Not certain about handling scroll bars here */
9629 else if (event
.xclient
.data
.l
[0]
9630 == dpyinfo
->Xatom_wm_save_yourself
)
9632 /* Save state modify the WM_COMMAND property to
9633 something which can reinstate us. This notifies
9634 the session manager, who's looking for such a
9635 PropertyNotify. Can restart processing when
9636 a keyboard or mouse event arrives. */
9639 f
= x_top_window_to_frame (dpyinfo
,
9640 event
.xclient
.window
);
9642 /* This is just so we only give real data once
9643 for a single Emacs process. */
9644 if (f
== SELECTED_FRAME ())
9645 XSetCommand (FRAME_X_DISPLAY (f
),
9646 event
.xclient
.window
,
9647 initial_argv
, initial_argc
);
9649 XSetCommand (FRAME_X_DISPLAY (f
),
9650 event
.xclient
.window
,
9654 else if (event
.xclient
.data
.l
[0]
9655 == dpyinfo
->Xatom_wm_delete_window
)
9658 = x_any_window_to_frame (dpyinfo
,
9659 event
.xclient
.window
);
9666 bufp
->kind
= delete_window_event
;
9667 XSETFRAME (bufp
->frame_or_window
, f
);
9676 else if (event
.xclient
.message_type
9677 == dpyinfo
->Xatom_wm_configure_denied
)
9680 else if (event
.xclient
.message_type
9681 == dpyinfo
->Xatom_wm_window_moved
)
9685 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9687 new_x
= event
.xclient
.data
.s
[0];
9688 new_y
= event
.xclient
.data
.s
[1];
9692 f
->output_data
.x
->left_pos
= new_x
;
9693 f
->output_data
.x
->top_pos
= new_y
;
9697 else if (event
.xclient
.message_type
9698 == dpyinfo
->Xatom_editres
)
9701 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9702 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9705 #endif /* HACK_EDITRES */
9706 else if ((event
.xclient
.message_type
9707 == dpyinfo
->Xatom_DONE
)
9708 || (event
.xclient
.message_type
9709 == dpyinfo
->Xatom_PAGE
))
9711 /* Ghostview job completed. Kill it. We could
9712 reply with "Next" if we received "Page", but we
9713 currently never do because we are interested in
9714 images, only, which should have 1 page. */
9715 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9717 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9718 x_kill_gs_process (pixmap
, f
);
9719 expose_frame (f
, 0, 0, 0, 0);
9721 #ifdef USE_TOOLKIT_SCROLL_BARS
9722 /* Scroll bar callbacks send a ClientMessage from which
9723 we construct an input_event. */
9724 else if (event
.xclient
.message_type
9725 == dpyinfo
->Xatom_Scrollbar
)
9727 x_scroll_bar_to_input_event (&event
, bufp
);
9728 ++bufp
, ++count
, --numchars
;
9731 #endif /* USE_TOOLKIT_SCROLL_BARS */
9737 case SelectionNotify
:
9738 #ifdef USE_X_TOOLKIT
9739 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9741 #endif /* not USE_X_TOOLKIT */
9742 x_handle_selection_notify (&event
.xselection
);
9745 case SelectionClear
: /* Someone has grabbed ownership. */
9746 #ifdef USE_X_TOOLKIT
9747 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9749 #endif /* USE_X_TOOLKIT */
9751 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9756 bufp
->kind
= selection_clear_event
;
9757 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9758 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9759 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9760 bufp
->frame_or_window
= Qnil
;
9769 case SelectionRequest
: /* Someone wants our selection. */
9770 #ifdef USE_X_TOOLKIT
9771 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9773 #endif /* USE_X_TOOLKIT */
9774 if (x_queue_selection_requests
)
9775 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9779 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9784 bufp
->kind
= selection_request_event
;
9785 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9786 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9787 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9788 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9789 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9790 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9791 bufp
->frame_or_window
= Qnil
;
9800 case PropertyNotify
:
9801 #ifdef USE_X_TOOLKIT
9802 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9804 #endif /* not USE_X_TOOLKIT */
9805 x_handle_property_notify (&event
.xproperty
);
9808 case ReparentNotify
:
9809 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9813 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9814 x_real_positions (f
, &x
, &y
);
9815 f
->output_data
.x
->left_pos
= x
;
9816 f
->output_data
.x
->top_pos
= y
;
9821 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9824 if (f
->async_visible
== 0)
9826 f
->async_visible
= 1;
9827 f
->async_iconified
= 0;
9828 f
->output_data
.x
->has_been_visible
= 1;
9829 SET_FRAME_GARBAGED (f
);
9832 expose_frame (x_window_to_frame (dpyinfo
,
9833 event
.xexpose
.window
),
9834 event
.xexpose
.x
, event
.xexpose
.y
,
9835 event
.xexpose
.width
, event
.xexpose
.height
);
9839 #ifdef USE_TOOLKIT_SCROLL_BARS
9840 /* Dispatch event to the widget. */
9842 #else /* not USE_TOOLKIT_SCROLL_BARS */
9843 struct scroll_bar
*bar
9844 = x_window_to_scroll_bar (event
.xexpose
.window
);
9847 x_scroll_bar_expose (bar
, &event
);
9848 #ifdef USE_X_TOOLKIT
9851 #endif /* USE_X_TOOLKIT */
9852 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9856 case GraphicsExpose
: /* This occurs when an XCopyArea's
9857 source area was obscured or not
9859 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9863 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9864 event
.xgraphicsexpose
.width
,
9865 event
.xgraphicsexpose
.height
);
9867 #ifdef USE_X_TOOLKIT
9870 #endif /* USE_X_TOOLKIT */
9873 case NoExpose
: /* This occurs when an XCopyArea's
9874 source area was completely
9879 /* Redo the mouse-highlight after the tooltip has gone. */
9880 if (event
.xmap
.window
== tip_window
)
9883 redo_mouse_highlight ();
9886 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9887 if (f
) /* F may no longer exist if
9888 the frame was deleted. */
9890 /* While a frame is unmapped, display generation is
9891 disabled; you don't want to spend time updating a
9892 display that won't ever be seen. */
9893 f
->async_visible
= 0;
9894 /* We can't distinguish, from the event, whether the window
9895 has become iconified or invisible. So assume, if it
9896 was previously visible, than now it is iconified.
9897 But x_make_frame_invisible clears both
9898 the visible flag and the iconified flag;
9899 and that way, we know the window is not iconified now. */
9900 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9902 f
->async_iconified
= 1;
9904 bufp
->kind
= iconify_event
;
9905 XSETFRAME (bufp
->frame_or_window
, f
);
9915 if (event
.xmap
.window
== tip_window
)
9916 /* The tooltip has been drawn already. Avoid
9917 the SET_FRAME_GARBAGED below. */
9920 /* We use x_top_window_to_frame because map events can
9921 come for sub-windows and they don't mean that the
9922 frame is visible. */
9923 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9926 f
->async_visible
= 1;
9927 f
->async_iconified
= 0;
9928 f
->output_data
.x
->has_been_visible
= 1;
9930 /* wait_reading_process_input will notice this and update
9931 the frame's display structures. */
9932 SET_FRAME_GARBAGED (f
);
9936 bufp
->kind
= deiconify_event
;
9937 XSETFRAME (bufp
->frame_or_window
, f
);
9943 else if (! NILP (Vframe_list
)
9944 && ! NILP (XCDR (Vframe_list
)))
9945 /* Force a redisplay sooner or later
9946 to update the frame titles
9947 in case this is the second frame. */
9948 record_asynch_buffer_change ();
9953 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9955 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
9956 /* I couldn't find a way to prevent LessTif scroll bars
9957 from consuming key events. */
9960 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9962 if (widget
&& XmIsScrollBar (widget
))
9964 widget
= XtParent (widget
);
9965 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9968 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
9972 KeySym keysym
, orig_keysym
;
9973 /* al%imercury@uunet.uu.net says that making this 81
9974 instead of 80 fixed a bug whereby meta chars made
9977 It seems that some version of XmbLookupString has
9978 a bug of not returning XBufferOverflow in
9979 status_return even if the input is too long to
9980 fit in 81 bytes. So, we must prepare sufficient
9981 bytes for copy_buffer. 513 bytes (256 chars for
9982 two-byte character set) seems to be a faily good
9983 approximation. -- 2000.8.10 handa@etl.go.jp */
9984 unsigned char copy_buffer
[513];
9985 unsigned char *copy_bufptr
= copy_buffer
;
9986 int copy_bufsiz
= sizeof (copy_buffer
);
9990 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9991 extra_keyboard_modifiers
);
9992 modifiers
= event
.xkey
.state
;
9994 /* This will have to go some day... */
9996 /* make_lispy_event turns chars into control chars.
9997 Don't do it here because XLookupString is too eager. */
9998 event
.xkey
.state
&= ~ControlMask
;
9999 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10000 | dpyinfo
->super_mod_mask
10001 | dpyinfo
->hyper_mod_mask
10002 | dpyinfo
->alt_mod_mask
);
10004 /* In case Meta is ComposeCharacter,
10005 clear its status. According to Markus Ehrnsperger
10006 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10007 this enables ComposeCharacter to work whether or
10008 not it is combined with Meta. */
10009 if (modifiers
& dpyinfo
->meta_mod_mask
)
10010 bzero (&compose_status
, sizeof (compose_status
));
10015 Status status_return
;
10017 nbytes
= XmbLookupString (FRAME_XIC (f
),
10018 &event
.xkey
, copy_bufptr
,
10019 copy_bufsiz
, &keysym
,
10021 if (status_return
== XBufferOverflow
)
10023 copy_bufsiz
= nbytes
+ 1;
10024 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10025 nbytes
= XmbLookupString (FRAME_XIC (f
),
10026 &event
.xkey
, copy_bufptr
,
10027 copy_bufsiz
, &keysym
,
10031 if (status_return
== XLookupNone
)
10033 else if (status_return
== XLookupChars
)
10038 else if (status_return
!= XLookupKeySym
10039 && status_return
!= XLookupBoth
)
10043 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10044 copy_bufsiz
, &keysym
,
10047 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10048 copy_bufsiz
, &keysym
,
10052 orig_keysym
= keysym
;
10056 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10057 || keysym
== XK_Delete
10058 #ifdef XK_ISO_Left_Tab
10059 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10061 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10062 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10063 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10065 /* This recognizes the "extended function keys".
10066 It seems there's no cleaner way.
10067 Test IsModifierKey to avoid handling mode_switch
10069 || ((unsigned) (keysym
) >= XK_Select
10070 && (unsigned)(keysym
) < XK_KP_Space
)
10072 #ifdef XK_dead_circumflex
10073 || orig_keysym
== XK_dead_circumflex
10075 #ifdef XK_dead_grave
10076 || orig_keysym
== XK_dead_grave
10078 #ifdef XK_dead_tilde
10079 || orig_keysym
== XK_dead_tilde
10081 #ifdef XK_dead_diaeresis
10082 || orig_keysym
== XK_dead_diaeresis
10084 #ifdef XK_dead_macron
10085 || orig_keysym
== XK_dead_macron
10087 #ifdef XK_dead_degree
10088 || orig_keysym
== XK_dead_degree
10090 #ifdef XK_dead_acute
10091 || orig_keysym
== XK_dead_acute
10093 #ifdef XK_dead_cedilla
10094 || orig_keysym
== XK_dead_cedilla
10096 #ifdef XK_dead_breve
10097 || orig_keysym
== XK_dead_breve
10099 #ifdef XK_dead_ogonek
10100 || orig_keysym
== XK_dead_ogonek
10102 #ifdef XK_dead_caron
10103 || orig_keysym
== XK_dead_caron
10105 #ifdef XK_dead_doubleacute
10106 || orig_keysym
== XK_dead_doubleacute
10108 #ifdef XK_dead_abovedot
10109 || orig_keysym
== XK_dead_abovedot
10111 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10112 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10113 /* Any "vendor-specific" key is ok. */
10114 || (orig_keysym
& (1 << 28)))
10115 && ! (IsModifierKey (orig_keysym
)
10117 #ifdef XK_Mode_switch
10118 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10121 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10123 #endif /* not HAVE_X11R5 */
10126 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10128 temp_buffer
[temp_index
++] = keysym
;
10129 bufp
->kind
= non_ascii_keystroke
;
10130 bufp
->code
= keysym
;
10131 XSETFRAME (bufp
->frame_or_window
, f
);
10134 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10136 bufp
->timestamp
= event
.xkey
.time
;
10141 else if (numchars
> nbytes
)
10147 for (i
= 0; i
< nbytes
; i
++)
10149 if (temp_index
== (sizeof temp_buffer
10152 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10155 if (/* If the event is not from XIM, */
10156 event
.xkey
.keycode
!= 0
10157 /* or the current locale doesn't request
10158 decoding of the intup data, ... */
10159 || coding
.type
== coding_type_raw_text
10160 || coding
.type
== coding_type_no_conversion
)
10162 /* ... we can use the input data as is. */
10167 /* We have to decode the input data. */
10171 require
= decoding_buffer_size (&coding
, nbytes
);
10172 p
= (unsigned char *) alloca (require
);
10173 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10174 decode_coding (&coding
, copy_bufptr
, p
,
10176 nbytes
= coding
.produced
;
10177 nchars
= coding
.produced_char
;
10181 /* Convert the input data to a sequence of
10182 character events. */
10183 for (i
= 0; i
< nbytes
; i
+= len
)
10185 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10187 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10189 : multibyte_char_keystroke
);
10191 XSETFRAME (bufp
->frame_or_window
, f
);
10194 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10196 bufp
->timestamp
= event
.xkey
.time
;
10201 numchars
-= nchars
;
10203 if (keysym
== NoSymbol
)
10213 /* Don't dispatch this event since XtDispatchEvent calls
10214 XFilterEvent, and two calls in a row may freeze the
10223 /* Don't dispatch this event since XtDispatchEvent calls
10224 XFilterEvent, and two calls in a row may freeze the
10231 /* Here's a possible interpretation of the whole
10232 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10233 you get a FocusIn event, you have to get a FocusOut
10234 event before you relinquish the focus. If you
10235 haven't received a FocusIn event, then a mere
10236 LeaveNotify is enough to free you. */
10240 int from_menu_bar_p
= 0;
10242 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10244 #ifdef LESSTIF_VERSION
10245 /* When clicking outside of a menu bar popup to close
10246 it, we get a FocusIn/ EnterNotify sequence of
10247 events. The flag event.xcrossing.focus is not set
10248 in the EnterNotify event of that sequence because
10249 the focus is in the menu bar,
10250 event.xcrossing.window is the frame's X window.
10251 Unconditionally setting the focus frame to null in
10252 this case is not the right thing, because no event
10253 follows that could set the focus frame to the right
10256 This could be a LessTif bug, but I wasn't able to
10257 reproduce the behavior in a simple test program.
10258 On the other hand, Motif seems to not have this
10261 (gerd, LessTif 0.92). */
10263 if (!event
.xcrossing
.focus
10265 && f
->output_data
.x
->menubar_widget
)
10270 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
10271 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
10272 from_menu_bar_p
= 1;
10274 #endif /* LESSTIF_VERSION */
10276 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
10278 /* Avoid nasty pop/raise loops. */
10279 if (f
&& (!(f
->auto_raise
)
10280 || !(f
->auto_lower
)
10281 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10283 x_new_focus_frame (dpyinfo
, f
);
10284 enter_timestamp
= event
.xcrossing
.time
;
10287 else if (f
== dpyinfo
->x_focus_frame
)
10288 x_new_focus_frame (dpyinfo
, 0);
10290 /* EnterNotify counts as mouse movement,
10291 so update things that depend on mouse position. */
10292 if (f
&& !f
->output_data
.x
->hourglass_p
)
10293 note_mouse_movement (f
, &event
.xmotion
);
10298 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10299 if (event
.xfocus
.detail
!= NotifyPointer
)
10300 dpyinfo
->x_focus_event_frame
= f
;
10303 x_new_focus_frame (dpyinfo
, f
);
10305 /* Don't stop displaying the initial startup message
10306 for a switch-frame event we don't need. */
10307 if (GC_NILP (Vterminal_frame
)
10308 && GC_CONSP (Vframe_list
)
10309 && !GC_NILP (XCDR (Vframe_list
)))
10311 bufp
->kind
= FOCUS_IN_EVENT
;
10312 XSETFRAME (bufp
->frame_or_window
, f
);
10314 ++bufp
, ++count
, --numchars
;
10319 if (f
&& FRAME_XIC (f
))
10320 XSetICFocus (FRAME_XIC (f
));
10326 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10329 int from_menu_bar_p
= 0;
10331 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10333 /* If we move outside the frame, then we're
10334 certainly no longer on any text in the frame. */
10335 clear_mouse_face (dpyinfo
);
10336 dpyinfo
->mouse_face_mouse_frame
= 0;
10339 /* Generate a nil HELP_EVENT to cancel a help-echo.
10340 Do it only if there's something to cancel.
10341 Otherwise, the startup message is cleared when
10342 the mouse leaves the frame. */
10343 if (any_help_event_p
)
10348 XSETFRAME (frame
, f
);
10350 n
= gen_help_event (bufp
, numchars
,
10351 Qnil
, frame
, Qnil
, Qnil
, 0);
10352 bufp
+= n
, count
+= n
, numchars
-= n
;
10355 #ifdef LESSTIF_VERSION
10356 /* Please see the comment at the start of the
10357 EnterNotify case. */
10358 if (!event
.xcrossing
.focus
10359 && f
->output_data
.x
->menubar_widget
)
10363 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
10364 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
10365 from_menu_bar_p
= 1;
10367 #endif /* LESSTIF_VERSION */
10369 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
10370 x_mouse_leave (dpyinfo
);
10373 if (f
== dpyinfo
->x_focus_event_frame
)
10374 dpyinfo
->x_focus_event_frame
= 0;
10375 if (f
== dpyinfo
->x_focus_frame
)
10376 x_new_focus_frame (dpyinfo
, 0);
10382 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10383 if (event
.xfocus
.detail
!= NotifyPointer
10384 && f
== dpyinfo
->x_focus_event_frame
)
10385 dpyinfo
->x_focus_event_frame
= 0;
10386 if (f
&& f
== dpyinfo
->x_focus_frame
)
10387 x_new_focus_frame (dpyinfo
, 0);
10390 if (f
&& FRAME_XIC (f
))
10391 XUnsetICFocus (FRAME_XIC (f
));
10398 previous_help_echo
= help_echo
;
10399 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10400 help_echo_pos
= -1;
10402 if (dpyinfo
->grabbed
&& last_mouse_frame
10403 && FRAME_LIVE_P (last_mouse_frame
))
10404 f
= last_mouse_frame
;
10406 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10409 note_mouse_movement (f
, &event
.xmotion
);
10412 #ifndef USE_TOOLKIT_SCROLL_BARS
10413 struct scroll_bar
*bar
10414 = x_window_to_scroll_bar (event
.xmotion
.window
);
10417 x_scroll_bar_note_movement (bar
, &event
);
10418 #endif /* USE_TOOLKIT_SCROLL_BARS */
10420 /* If we move outside the frame, then we're
10421 certainly no longer on any text in the frame. */
10422 clear_mouse_face (dpyinfo
);
10425 /* If the contents of the global variable help_echo
10426 has changed, generate a HELP_EVENT. */
10427 if (!NILP (help_echo
)
10428 || !NILP (previous_help_echo
))
10434 XSETFRAME (frame
, f
);
10438 any_help_event_p
= 1;
10439 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10440 help_echo_window
, help_echo_object
,
10442 bufp
+= n
, count
+= n
, numchars
-= n
;
10448 case ConfigureNotify
:
10449 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10452 #ifndef USE_X_TOOLKIT
10453 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10454 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10456 /* In the toolkit version, change_frame_size
10457 is called by the code that handles resizing
10458 of the EmacsFrame widget. */
10460 /* Even if the number of character rows and columns has
10461 not changed, the font size may have changed, so we need
10462 to check the pixel dimensions as well. */
10463 if (columns
!= f
->width
10464 || rows
!= f
->height
10465 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10466 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10468 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10469 SET_FRAME_GARBAGED (f
);
10470 cancel_mouse_face (f
);
10474 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10475 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10477 /* What we have now is the position of Emacs's own window.
10478 Convert that to the position of the window manager window. */
10479 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10480 &f
->output_data
.x
->top_pos
);
10483 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10484 xic_set_statusarea (f
);
10487 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10489 /* Since the WM decorations come below top_pos now,
10490 we must put them below top_pos in the future. */
10491 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10492 x_wm_set_size_hint (f
, (long) 0, 0);
10495 /* Some window managers pass (0,0) as the location of
10496 the window, and the Motif event handler stores it
10497 in the emacs widget, which messes up Motif menus. */
10498 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10500 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10501 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10503 #endif /* USE_MOTIF */
10508 case ButtonRelease
:
10510 /* If we decide we want to generate an event to be seen
10511 by the rest of Emacs, we put it here. */
10512 struct input_event emacs_event
;
10513 int tool_bar_p
= 0;
10515 emacs_event
.kind
= no_event
;
10516 bzero (&compose_status
, sizeof (compose_status
));
10518 if (dpyinfo
->grabbed
10519 && last_mouse_frame
10520 && FRAME_LIVE_P (last_mouse_frame
))
10521 f
= last_mouse_frame
;
10523 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10527 /* Is this in the tool-bar? */
10528 if (WINDOWP (f
->tool_bar_window
)
10529 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10531 Lisp_Object window
;
10534 x
= event
.xbutton
.x
;
10535 y
= event
.xbutton
.y
;
10538 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10539 if (EQ (window
, f
->tool_bar_window
))
10541 x_handle_tool_bar_click (f
, &event
.xbutton
);
10547 if (!dpyinfo
->x_focus_frame
10548 || f
== dpyinfo
->x_focus_frame
)
10549 construct_mouse_click (&emacs_event
, &event
, f
);
10553 #ifndef USE_TOOLKIT_SCROLL_BARS
10554 struct scroll_bar
*bar
10555 = x_window_to_scroll_bar (event
.xbutton
.window
);
10558 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10559 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10562 if (event
.type
== ButtonPress
)
10564 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10565 last_mouse_frame
= f
;
10566 /* Ignore any mouse motion that happened
10567 before this event; any subsequent mouse-movement
10568 Emacs events should reflect only motion after
10569 the ButtonPress. */
10571 f
->mouse_moved
= 0;
10574 last_tool_bar_item
= -1;
10578 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10581 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10583 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10589 #ifdef USE_X_TOOLKIT
10590 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10591 /* For a down-event in the menu bar,
10592 don't pass it to Xt right now.
10593 Instead, save it away
10594 and we will pass it to Xt from kbd_buffer_get_event.
10595 That way, we can run some Lisp code first. */
10596 if (f
&& event
.type
== ButtonPress
10597 /* Verify the event is really within the menu bar
10598 and not just sent to it due to grabbing. */
10599 && event
.xbutton
.x
>= 0
10600 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10601 && event
.xbutton
.y
>= 0
10602 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10603 && event
.xbutton
.same_screen
)
10605 SET_SAVED_BUTTON_EVENT
;
10606 XSETFRAME (last_mouse_press_frame
, f
);
10608 else if (event
.type
== ButtonPress
)
10610 last_mouse_press_frame
= Qnil
;
10614 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10615 but I am trying to be cautious. */
10616 else if (event
.type
== ButtonRelease
)
10618 if (!NILP (last_mouse_press_frame
))
10620 f
= XFRAME (last_mouse_press_frame
);
10621 if (f
->output_data
.x
)
10622 SET_SAVED_BUTTON_EVENT
;
10627 #endif /* USE_MOTIF */
10630 #endif /* USE_X_TOOLKIT */
10634 case CirculateNotify
:
10637 case CirculateRequest
:
10640 case VisibilityNotify
:
10643 case MappingNotify
:
10644 /* Someone has changed the keyboard mapping - update the
10646 switch (event
.xmapping
.request
)
10648 case MappingModifier
:
10649 x_find_modifier_meanings (dpyinfo
);
10650 /* This is meant to fall through. */
10651 case MappingKeyboard
:
10652 XRefreshKeyboardMapping (&event
.xmapping
);
10658 #ifdef USE_X_TOOLKIT
10660 XtDispatchEvent (&event
);
10662 #endif /* USE_X_TOOLKIT */
10670 /* On some systems, an X bug causes Emacs to get no more events
10671 when the window is destroyed. Detect that. (1994.) */
10674 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10675 One XNOOP in 100 loops will make Emacs terminate.
10676 B. Bretthauer, 1994 */
10678 if (x_noop_count
>= 100)
10682 if (next_noop_dpyinfo
== 0)
10683 next_noop_dpyinfo
= x_display_list
;
10685 XNoOp (next_noop_dpyinfo
->display
);
10687 /* Each time we get here, cycle through the displays now open. */
10688 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10692 /* If the focus was just given to an auto-raising frame,
10694 /* ??? This ought to be able to handle more than one such frame. */
10695 if (pending_autoraise_frame
)
10697 x_raise_frame (pending_autoraise_frame
);
10698 pending_autoraise_frame
= 0;
10709 /***********************************************************************
10711 ***********************************************************************/
10713 /* Note if the text cursor of window W has been overwritten by a
10714 drawing operation that outputs N glyphs starting at HPOS in the
10715 line given by output_cursor.vpos. N < 0 means all the rest of the
10716 line after HPOS has been written. */
10719 note_overwritten_text_cursor (w
, hpos
, n
)
10723 if (updated_area
== TEXT_AREA
10724 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10725 && hpos
<= w
->phys_cursor
.hpos
10727 || hpos
+ n
> w
->phys_cursor
.hpos
))
10728 w
->phys_cursor_on_p
= 0;
10732 /* Set clipping for output in glyph row ROW. W is the window in which
10733 we operate. GC is the graphics context to set clipping in.
10734 WHOLE_LINE_P non-zero means include the areas used for truncation
10735 mark display and alike in the clipping rectangle.
10737 ROW may be a text row or, e.g., a mode line. Text rows must be
10738 clipped to the interior of the window dedicated to text display,
10739 mode lines must be clipped to the whole window. */
10742 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10744 struct glyph_row
*row
;
10748 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10749 XRectangle clip_rect
;
10750 int window_x
, window_y
, window_width
, window_height
;
10752 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10754 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10755 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10756 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10757 clip_rect
.width
= window_width
;
10758 clip_rect
.height
= row
->visible_height
;
10760 /* If clipping to the whole line, including trunc marks, extend
10761 the rectangle to the left and increase its width. */
10764 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10765 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10768 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10772 /* Draw a hollow box cursor on window W in glyph row ROW. */
10775 x_draw_hollow_cursor (w
, row
)
10777 struct glyph_row
*row
;
10779 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10780 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10781 Display
*dpy
= FRAME_X_DISPLAY (f
);
10784 struct glyph
*cursor_glyph
;
10787 /* Compute frame-relative coordinates from window-relative
10789 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10790 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10791 + row
->ascent
- w
->phys_cursor_ascent
);
10792 h
= row
->height
- 1;
10794 /* Get the glyph the cursor is on. If we can't tell because
10795 the current matrix is invalid or such, give up. */
10796 cursor_glyph
= get_phys_cursor_glyph (w
);
10797 if (cursor_glyph
== NULL
)
10800 /* Compute the width of the rectangle to draw. If on a stretch
10801 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10802 rectangle as wide as the glyph, but use a canonical character
10804 wd
= cursor_glyph
->pixel_width
- 1;
10805 if (cursor_glyph
->type
== STRETCH_GLYPH
10806 && !x_stretch_cursor_p
)
10807 wd
= min (CANON_X_UNIT (f
), wd
);
10809 /* The foreground of cursor_gc is typically the same as the normal
10810 background color, which can cause the cursor box to be invisible. */
10811 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10812 if (dpyinfo
->scratch_cursor_gc
)
10813 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10815 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10816 GCForeground
, &xgcv
);
10817 gc
= dpyinfo
->scratch_cursor_gc
;
10819 /* Set clipping, draw the rectangle, and reset clipping again. */
10820 x_clip_to_row (w
, row
, gc
, 0);
10821 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10822 XSetClipMask (dpy
, gc
, None
);
10826 /* Draw a bar cursor on window W in glyph row ROW.
10828 Implementation note: One would like to draw a bar cursor with an
10829 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10830 Unfortunately, I didn't find a font yet that has this property set.
10834 x_draw_bar_cursor (w
, row
, width
)
10836 struct glyph_row
*row
;
10839 struct frame
*f
= XFRAME (w
->frame
);
10840 struct glyph
*cursor_glyph
;
10843 unsigned long mask
;
10848 /* If cursor is out of bounds, don't draw garbage. This can happen
10849 in mini-buffer windows when switching between echo area glyphs
10850 and mini-buffer. */
10851 cursor_glyph
= get_phys_cursor_glyph (w
);
10852 if (cursor_glyph
== NULL
)
10855 /* If on an image, draw like a normal cursor. That's usually better
10856 visible than drawing a bar, esp. if the image is large so that
10857 the bar might not be in the window. */
10858 if (cursor_glyph
->type
== IMAGE_GLYPH
)
10860 struct glyph_row
*row
;
10861 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
10862 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
10866 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10867 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10868 xgcv
.graphics_exposures
= 0;
10869 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10870 dpy
= FRAME_X_DISPLAY (f
);
10871 window
= FRAME_X_WINDOW (f
);
10872 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10875 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10878 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10879 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10883 width
= f
->output_data
.x
->cursor_width
;
10885 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10886 x_clip_to_row (w
, row
, gc
, 0);
10887 XFillRectangle (dpy
, window
, gc
,
10889 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10890 min (cursor_glyph
->pixel_width
, width
),
10892 XSetClipMask (dpy
, gc
, None
);
10897 /* Clear the cursor of window W to background color, and mark the
10898 cursor as not shown. This is used when the text where the cursor
10899 is is about to be rewritten. */
10905 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10906 x_update_window_cursor (w
, 0);
10910 /* Draw the cursor glyph of window W in glyph row ROW. See the
10911 comment of x_draw_glyphs for the meaning of HL. */
10914 x_draw_phys_cursor_glyph (w
, row
, hl
)
10916 struct glyph_row
*row
;
10917 enum draw_glyphs_face hl
;
10919 /* If cursor hpos is out of bounds, don't draw garbage. This can
10920 happen in mini-buffer windows when switching between echo area
10921 glyphs and mini-buffer. */
10922 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10924 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10925 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10928 /* When we erase the cursor, and ROW is overlapped by other
10929 rows, make sure that these overlapping parts of other rows
10931 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10933 if (row
> w
->current_matrix
->rows
10934 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10935 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10937 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10938 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10939 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10945 /* Erase the image of a cursor of window W from the screen. */
10948 x_erase_phys_cursor (w
)
10951 struct frame
*f
= XFRAME (w
->frame
);
10952 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10953 int hpos
= w
->phys_cursor
.hpos
;
10954 int vpos
= w
->phys_cursor
.vpos
;
10955 int mouse_face_here_p
= 0;
10956 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10957 struct glyph_row
*cursor_row
;
10958 struct glyph
*cursor_glyph
;
10959 enum draw_glyphs_face hl
;
10961 /* No cursor displayed or row invalidated => nothing to do on the
10963 if (w
->phys_cursor_type
== NO_CURSOR
)
10964 goto mark_cursor_off
;
10966 /* VPOS >= active_glyphs->nrows means that window has been resized.
10967 Don't bother to erase the cursor. */
10968 if (vpos
>= active_glyphs
->nrows
)
10969 goto mark_cursor_off
;
10971 /* If row containing cursor is marked invalid, there is nothing we
10973 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10974 if (!cursor_row
->enabled_p
)
10975 goto mark_cursor_off
;
10977 /* This can happen when the new row is shorter than the old one.
10978 In this case, either x_draw_glyphs or clear_end_of_line
10979 should have cleared the cursor. Note that we wouldn't be
10980 able to erase the cursor in this case because we don't have a
10981 cursor glyph at hand. */
10982 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10983 goto mark_cursor_off
;
10985 /* If the cursor is in the mouse face area, redisplay that when
10986 we clear the cursor. */
10987 if (! NILP (dpyinfo
->mouse_face_window
)
10988 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10989 && (vpos
> dpyinfo
->mouse_face_beg_row
10990 || (vpos
== dpyinfo
->mouse_face_beg_row
10991 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10992 && (vpos
< dpyinfo
->mouse_face_end_row
10993 || (vpos
== dpyinfo
->mouse_face_end_row
10994 && hpos
< dpyinfo
->mouse_face_end_col
))
10995 /* Don't redraw the cursor's spot in mouse face if it is at the
10996 end of a line (on a newline). The cursor appears there, but
10997 mouse highlighting does not. */
10998 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10999 mouse_face_here_p
= 1;
11001 /* Maybe clear the display under the cursor. */
11002 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11005 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11007 cursor_glyph
= get_phys_cursor_glyph (w
);
11008 if (cursor_glyph
== NULL
)
11009 goto mark_cursor_off
;
11011 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11013 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11015 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11017 cursor_glyph
->pixel_width
,
11018 cursor_row
->visible_height
,
11022 /* Erase the cursor by redrawing the character underneath it. */
11023 if (mouse_face_here_p
)
11024 hl
= DRAW_MOUSE_FACE
;
11025 else if (cursor_row
->inverse_p
)
11026 hl
= DRAW_INVERSE_VIDEO
;
11028 hl
= DRAW_NORMAL_TEXT
;
11029 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11032 w
->phys_cursor_on_p
= 0;
11033 w
->phys_cursor_type
= NO_CURSOR
;
11037 /* Display or clear cursor of window W. If ON is zero, clear the
11038 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11039 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11042 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11044 int on
, hpos
, vpos
, x
, y
;
11046 struct frame
*f
= XFRAME (w
->frame
);
11047 int new_cursor_type
;
11048 int new_cursor_width
;
11049 struct glyph_matrix
*current_glyphs
;
11050 struct glyph_row
*glyph_row
;
11051 struct glyph
*glyph
;
11053 /* This is pointless on invisible frames, and dangerous on garbaged
11054 windows and frames; in the latter case, the frame or window may
11055 be in the midst of changing its size, and x and y may be off the
11057 if (! FRAME_VISIBLE_P (f
)
11058 || FRAME_GARBAGED_P (f
)
11059 || vpos
>= w
->current_matrix
->nrows
11060 || hpos
>= w
->current_matrix
->matrix_w
)
11063 /* If cursor is off and we want it off, return quickly. */
11064 if (!on
&& !w
->phys_cursor_on_p
)
11067 current_glyphs
= w
->current_matrix
;
11068 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11069 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11071 /* If cursor row is not enabled, we don't really know where to
11072 display the cursor. */
11073 if (!glyph_row
->enabled_p
)
11075 w
->phys_cursor_on_p
= 0;
11079 xassert (interrupt_input_blocked
);
11081 /* Set new_cursor_type to the cursor we want to be displayed. In a
11082 mini-buffer window, we want the cursor only to appear if we are
11083 reading input from this window. For the selected window, we want
11084 the cursor type given by the frame parameter. If explicitly
11085 marked off, draw no cursor. In all other cases, we want a hollow
11087 new_cursor_width
= -1;
11088 if (cursor_in_echo_area
11089 && FRAME_HAS_MINIBUF_P (f
)
11090 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11092 if (w
== XWINDOW (echo_area_window
))
11093 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11095 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11099 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11100 || w
!= XWINDOW (f
->selected_window
))
11102 extern int cursor_in_non_selected_windows
;
11104 if (MINI_WINDOW_P (w
)
11105 || !cursor_in_non_selected_windows
11106 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11107 new_cursor_type
= NO_CURSOR
;
11109 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11111 else if (w
->cursor_off_p
)
11112 new_cursor_type
= NO_CURSOR
;
11115 struct buffer
*b
= XBUFFER (w
->buffer
);
11117 if (EQ (b
->cursor_type
, Qt
))
11118 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11120 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11121 &new_cursor_width
);
11125 /* If cursor is currently being shown and we don't want it to be or
11126 it is in the wrong place, or the cursor type is not what we want,
11128 if (w
->phys_cursor_on_p
11130 || w
->phys_cursor
.x
!= x
11131 || w
->phys_cursor
.y
!= y
11132 || new_cursor_type
!= w
->phys_cursor_type
))
11133 x_erase_phys_cursor (w
);
11135 /* If the cursor is now invisible and we want it to be visible,
11137 if (on
&& !w
->phys_cursor_on_p
)
11139 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11140 w
->phys_cursor_height
= glyph_row
->height
;
11142 /* Set phys_cursor_.* before x_draw_.* is called because some
11143 of them may need the information. */
11144 w
->phys_cursor
.x
= x
;
11145 w
->phys_cursor
.y
= glyph_row
->y
;
11146 w
->phys_cursor
.hpos
= hpos
;
11147 w
->phys_cursor
.vpos
= vpos
;
11148 w
->phys_cursor_type
= new_cursor_type
;
11149 w
->phys_cursor_on_p
= 1;
11151 switch (new_cursor_type
)
11153 case HOLLOW_BOX_CURSOR
:
11154 x_draw_hollow_cursor (w
, glyph_row
);
11157 case FILLED_BOX_CURSOR
:
11158 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11162 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11173 if (w
== XWINDOW (f
->selected_window
))
11174 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11175 xic_set_preeditarea (w
, x
, y
);
11180 if (updating_frame
!= f
)
11181 XFlush (FRAME_X_DISPLAY (f
));
11186 /* Display the cursor on window W, or clear it. X and Y are window
11187 relative pixel coordinates. HPOS and VPOS are glyph matrix
11188 positions. If W is not the selected window, display a hollow
11189 cursor. ON non-zero means display the cursor at X, Y which
11190 correspond to HPOS, VPOS, otherwise it is cleared. */
11193 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11195 int on
, hpos
, vpos
, x
, y
;
11198 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11203 /* Display the cursor on window W, or clear it, according to ON_P.
11204 Don't change the cursor's position. */
11207 x_update_cursor (f
, on_p
)
11210 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11214 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11215 in the window tree rooted at W. */
11218 x_update_cursor_in_window_tree (w
, on_p
)
11224 if (!NILP (w
->hchild
))
11225 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11226 else if (!NILP (w
->vchild
))
11227 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11229 x_update_window_cursor (w
, on_p
);
11231 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11236 /* Switch the display of W's cursor on or off, according to the value
11240 x_update_window_cursor (w
, on
)
11244 /* Don't update cursor in windows whose frame is in the process
11245 of being deleted. */
11246 if (w
->current_matrix
)
11249 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11250 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11260 /* Refresh bitmap kitchen sink icon for frame F
11261 when we get an expose event for it. */
11267 /* Normally, the window manager handles this function. */
11270 /* Make the x-window of frame F use the gnu icon bitmap. */
11273 x_bitmap_icon (f
, file
)
11279 if (FRAME_X_WINDOW (f
) == 0)
11282 /* Free up our existing icon bitmap if any. */
11283 if (f
->output_data
.x
->icon_bitmap
> 0)
11284 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11285 f
->output_data
.x
->icon_bitmap
= 0;
11287 if (STRINGP (file
))
11288 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11291 /* Create the GNU bitmap if necessary. */
11292 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11293 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11294 = x_create_bitmap_from_data (f
, gnu_bits
,
11295 gnu_width
, gnu_height
);
11297 /* The first time we create the GNU bitmap,
11298 this increments the ref-count one extra time.
11299 As a result, the GNU bitmap is never freed.
11300 That way, we don't have to worry about allocating it again. */
11301 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11303 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11306 x_wm_set_icon_pixmap (f
, bitmap_id
);
11307 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11313 /* Make the x-window of frame F use a rectangle with text.
11314 Use ICON_NAME as the text. */
11317 x_text_icon (f
, icon_name
)
11321 if (FRAME_X_WINDOW (f
) == 0)
11326 XTextProperty text
;
11327 text
.value
= (unsigned char *) icon_name
;
11328 text
.encoding
= XA_STRING
;
11330 text
.nitems
= strlen (icon_name
);
11331 #ifdef USE_X_TOOLKIT
11332 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11334 #else /* not USE_X_TOOLKIT */
11335 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11336 #endif /* not USE_X_TOOLKIT */
11338 #else /* not HAVE_X11R4 */
11339 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11340 #endif /* not HAVE_X11R4 */
11342 if (f
->output_data
.x
->icon_bitmap
> 0)
11343 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11344 f
->output_data
.x
->icon_bitmap
= 0;
11345 x_wm_set_icon_pixmap (f
, 0);
11350 #define X_ERROR_MESSAGE_SIZE 200
11352 /* If non-nil, this should be a string.
11353 It means catch X errors and store the error message in this string. */
11355 static Lisp_Object x_error_message_string
;
11357 /* An X error handler which stores the error message in
11358 x_error_message_string. This is called from x_error_handler if
11359 x_catch_errors is in effect. */
11362 x_error_catcher (display
, error
)
11364 XErrorEvent
*error
;
11366 XGetErrorText (display
, error
->error_code
,
11367 XSTRING (x_error_message_string
)->data
,
11368 X_ERROR_MESSAGE_SIZE
);
11371 /* Begin trapping X errors for display DPY. Actually we trap X errors
11372 for all displays, but DPY should be the display you are actually
11375 After calling this function, X protocol errors no longer cause
11376 Emacs to exit; instead, they are recorded in the string
11377 stored in x_error_message_string.
11379 Calling x_check_errors signals an Emacs error if an X error has
11380 occurred since the last call to x_catch_errors or x_check_errors.
11382 Calling x_uncatch_errors resumes the normal error handling. */
11384 void x_check_errors ();
11385 static Lisp_Object
x_catch_errors_unwind ();
11388 x_catch_errors (dpy
)
11391 int count
= specpdl_ptr
- specpdl
;
11393 /* Make sure any errors from previous requests have been dealt with. */
11394 XSync (dpy
, False
);
11396 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11398 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11399 XSTRING (x_error_message_string
)->data
[0] = 0;
11404 /* Unbind the binding that we made to check for X errors. */
11407 x_catch_errors_unwind (old_val
)
11408 Lisp_Object old_val
;
11410 x_error_message_string
= old_val
;
11414 /* If any X protocol errors have arrived since the last call to
11415 x_catch_errors or x_check_errors, signal an Emacs error using
11416 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11419 x_check_errors (dpy
, format
)
11423 /* Make sure to catch any errors incurred so far. */
11424 XSync (dpy
, False
);
11426 if (XSTRING (x_error_message_string
)->data
[0])
11427 error (format
, XSTRING (x_error_message_string
)->data
);
11430 /* Nonzero if we had any X protocol errors
11431 since we did x_catch_errors on DPY. */
11434 x_had_errors_p (dpy
)
11437 /* Make sure to catch any errors incurred so far. */
11438 XSync (dpy
, False
);
11440 return XSTRING (x_error_message_string
)->data
[0] != 0;
11443 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11446 x_clear_errors (dpy
)
11449 XSTRING (x_error_message_string
)->data
[0] = 0;
11452 /* Stop catching X protocol errors and let them make Emacs die.
11453 DPY should be the display that was passed to x_catch_errors.
11454 COUNT should be the value that was returned by
11455 the corresponding call to x_catch_errors. */
11458 x_uncatch_errors (dpy
, count
)
11462 unbind_to (count
, Qnil
);
11466 static unsigned int x_wire_count
;
11469 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11474 /* Handle SIGPIPE, which can happen when the connection to a server
11475 simply goes away. SIGPIPE is handled by x_connection_signal.
11476 Don't need to do anything, because the write which caused the
11477 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11478 which will do the appropriate cleanup for us. */
11481 x_connection_signal (signalnum
) /* If we don't have an argument, */
11482 int signalnum
; /* some compilers complain in signal calls. */
11485 /* USG systems forget handlers when they are used;
11486 must reestablish each time */
11487 signal (signalnum
, x_connection_signal
);
11492 /************************************************************************
11494 ************************************************************************/
11496 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
11497 the text of an error message that lead to the connection loss. */
11500 x_connection_closed (dpy
, error_message
)
11502 char *error_message
;
11504 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
11505 Lisp_Object frame
, tail
;
11509 msg
= (char *) alloca (strlen (error_message
) + 1);
11510 strcpy (msg
, error_message
);
11511 handling_signal
= 0;
11513 /* Prevent being called recursively because of an error condition
11514 below. Otherwise, we might end up with printing ``can't find per
11515 display information'' in the recursive call instead of printing
11516 the original message here. */
11517 count
= x_catch_errors (dpy
);
11519 /* We have to close the display to inform Xt that it doesn't
11520 exist anymore. If we don't, Xt will continue to wait for
11521 events from the display. As a consequence, a sequence of
11523 M-x make-frame-on-display RET :1 RET
11524 ...kill the new frame, so that we get an IO error...
11525 M-x make-frame-on-display RET :1 RET
11527 will indefinitely wait in Xt for events for display `:1', opened
11528 in the first class to make-frame-on-display.
11530 Closing the display is reported to lead to a bus error on
11531 OpenWindows in certain situations. I suspect that is a bug
11532 in OpenWindows. I don't know how to cicumvent it here. */
11534 #ifdef USE_X_TOOLKIT
11535 /* If DPYINFO is null, this means we didn't open the display
11536 in the first place, so don't try to close it. */
11538 XtCloseDisplay (dpy
);
11541 /* Indicate that this display is dead. */
11543 dpyinfo
->display
= 0;
11545 /* First delete frames whose mini-buffers are on frames
11546 that are on the dead display. */
11547 FOR_EACH_FRAME (tail
, frame
)
11549 Lisp_Object minibuf_frame
;
11551 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11552 if (FRAME_X_P (XFRAME (frame
))
11553 && FRAME_X_P (XFRAME (minibuf_frame
))
11554 && ! EQ (frame
, minibuf_frame
)
11555 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11556 Fdelete_frame (frame
, Qt
);
11559 /* Now delete all remaining frames on the dead display.
11560 We are now sure none of these is used as the mini-buffer
11561 for another frame that we need to delete. */
11562 FOR_EACH_FRAME (tail
, frame
)
11563 if (FRAME_X_P (XFRAME (frame
))
11564 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11566 /* Set this to t so that Fdelete_frame won't get confused
11567 trying to find a replacement. */
11568 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11569 Fdelete_frame (frame
, Qt
);
11573 x_delete_display (dpyinfo
);
11575 x_uncatch_errors (dpy
, count
);
11577 if (x_display_list
== 0)
11579 fprintf (stderr
, "%s\n", msg
);
11580 shut_down_emacs (0, 0, Qnil
);
11584 /* Ordinary stack unwind doesn't deal with these. */
11586 sigunblock (sigmask (SIGIO
));
11588 sigunblock (sigmask (SIGALRM
));
11589 TOTALLY_UNBLOCK_INPUT
;
11591 clear_waiting_for_input ();
11596 /* This is the usual handler for X protocol errors.
11597 It kills all frames on the display that we got the error for.
11598 If that was the only one, it prints an error message and kills Emacs. */
11601 x_error_quitter (display
, error
)
11603 XErrorEvent
*error
;
11605 char buf
[256], buf1
[356];
11607 /* Note that there is no real way portable across R3/R4 to get the
11608 original error handler. */
11610 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11611 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11612 buf
, error
->request_code
);
11613 x_connection_closed (display
, buf1
);
11617 /* This is the first-level handler for X protocol errors.
11618 It calls x_error_quitter or x_error_catcher. */
11621 x_error_handler (display
, error
)
11623 XErrorEvent
*error
;
11625 if (! NILP (x_error_message_string
))
11626 x_error_catcher (display
, error
);
11628 x_error_quitter (display
, error
);
11632 /* This is the handler for X IO errors, always.
11633 It kills all frames on the display that we lost touch with.
11634 If that was the only one, it prints an error message and kills Emacs. */
11637 x_io_error_quitter (display
)
11642 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11643 x_connection_closed (display
, buf
);
11647 /* Changing the font of the frame. */
11649 /* Give frame F the font named FONTNAME as its default font, and
11650 return the full name of that font. FONTNAME may be a wildcard
11651 pattern; in that case, we choose some font that fits the pattern.
11652 The return value shows which font we chose. */
11655 x_new_font (f
, fontname
)
11657 register char *fontname
;
11659 struct font_info
*fontp
11660 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11665 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11666 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11667 f
->output_data
.x
->fontset
= -1;
11669 /* Compute the scroll bar width in character columns. */
11670 if (f
->scroll_bar_pixel_width
> 0)
11672 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11673 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11677 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11678 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11681 /* Now make the frame display the given font. */
11682 if (FRAME_X_WINDOW (f
) != 0)
11684 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11685 f
->output_data
.x
->font
->fid
);
11686 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11687 f
->output_data
.x
->font
->fid
);
11688 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11689 f
->output_data
.x
->font
->fid
);
11691 frame_update_line_height (f
);
11693 /* Don't change the size of a tip frame; there's no point in
11694 doing it because it's done in Fx_show_tip, and it leads to
11695 problems because the tip frame has no widget. */
11696 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
11697 x_set_window_size (f
, 0, f
->width
, f
->height
);
11700 /* If we are setting a new frame's font for the first time,
11701 there are no faces yet, so this font's height is the line height. */
11702 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11704 return build_string (fontp
->full_name
);
11707 /* Give frame F the fontset named FONTSETNAME as its default font, and
11708 return the full name of that fontset. FONTSETNAME may be a wildcard
11709 pattern; in that case, we choose some fontset that fits the pattern.
11710 The return value shows which fontset we chose. */
11713 x_new_fontset (f
, fontsetname
)
11717 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11718 Lisp_Object result
;
11723 if (f
->output_data
.x
->fontset
== fontset
)
11724 /* This fontset is already set in frame F. There's nothing more
11726 return fontset_name (fontset
);
11728 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11730 if (!STRINGP (result
))
11731 /* Can't load ASCII font. */
11734 /* Since x_new_font doesn't update any fontset information, do it now. */
11735 f
->output_data
.x
->fontset
= fontset
;
11739 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11740 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11743 return build_string (fontsetname
);
11747 /***********************************************************************
11749 ***********************************************************************/
11755 /* XIM destroy callback function, which is called whenever the
11756 connection to input method XIM dies. CLIENT_DATA contains a
11757 pointer to the x_display_info structure corresponding to XIM. */
11760 xim_destroy_callback (xim
, client_data
, call_data
)
11762 XPointer client_data
;
11763 XPointer call_data
;
11765 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11766 Lisp_Object frame
, tail
;
11770 /* No need to call XDestroyIC.. */
11771 FOR_EACH_FRAME (tail
, frame
)
11773 struct frame
*f
= XFRAME (frame
);
11774 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11776 FRAME_XIC (f
) = NULL
;
11777 if (FRAME_XIC_FONTSET (f
))
11779 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11780 FRAME_XIC_FONTSET (f
) = NULL
;
11785 /* No need to call XCloseIM. */
11786 dpyinfo
->xim
= NULL
;
11787 XFree (dpyinfo
->xim_styles
);
11791 #endif /* HAVE_X11R6 */
11793 /* Open the connection to the XIM server on display DPYINFO.
11794 RESOURCE_NAME is the resource name Emacs uses. */
11797 xim_open_dpy (dpyinfo
, resource_name
)
11798 struct x_display_info
*dpyinfo
;
11799 char *resource_name
;
11804 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11805 dpyinfo
->xim
= xim
;
11810 XIMCallback destroy
;
11813 /* Get supported styles and XIM values. */
11814 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11817 destroy
.callback
= xim_destroy_callback
;
11818 destroy
.client_data
= (XPointer
)dpyinfo
;
11819 /* This isn't prptotyped in OSF 5.0. */
11820 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11824 #else /* not USE_XIM */
11825 dpyinfo
->xim
= NULL
;
11826 #endif /* not USE_XIM */
11830 #ifdef HAVE_X11R6_XIM
11834 struct x_display_info
*dpyinfo
;
11835 char *resource_name
;
11838 /* XIM instantiate callback function, which is called whenever an XIM
11839 server is available. DISPLAY is teh display of the XIM.
11840 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11841 when the callback was registered. */
11844 xim_instantiate_callback (display
, client_data
, call_data
)
11846 XPointer client_data
;
11847 XPointer call_data
;
11849 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11850 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11852 /* We don't support multiple XIM connections. */
11856 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11858 /* Create XIC for the existing frames on the same display, as long
11859 as they have no XIC. */
11860 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11862 Lisp_Object tail
, frame
;
11865 FOR_EACH_FRAME (tail
, frame
)
11867 struct frame
*f
= XFRAME (frame
);
11869 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11870 if (FRAME_XIC (f
) == NULL
)
11872 create_frame_xic (f
);
11873 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11874 xic_set_statusarea (f
);
11875 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11877 struct window
*w
= XWINDOW (f
->selected_window
);
11878 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11887 #endif /* HAVE_X11R6_XIM */
11890 /* Open a connection to the XIM server on display DPYINFO.
11891 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11892 connection only at the first time. On X11R6, open the connection
11893 in the XIM instantiate callback function. */
11896 xim_initialize (dpyinfo
, resource_name
)
11897 struct x_display_info
*dpyinfo
;
11898 char *resource_name
;
11901 #ifdef HAVE_X11R6_XIM
11902 struct xim_inst_t
*xim_inst
;
11905 dpyinfo
->xim
= NULL
;
11906 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11907 xim_inst
->dpyinfo
= dpyinfo
;
11908 len
= strlen (resource_name
);
11909 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11910 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11911 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11912 resource_name
, EMACS_CLASS
,
11913 xim_instantiate_callback
,
11914 /* Fixme: This is XPointer in
11915 XFree86 but (XPointer *) on
11916 Tru64, at least. */
11917 (XPointer
) xim_inst
);
11918 #else /* not HAVE_X11R6_XIM */
11919 dpyinfo
->xim
= NULL
;
11920 xim_open_dpy (dpyinfo
, resource_name
);
11921 #endif /* not HAVE_X11R6_XIM */
11923 #else /* not USE_XIM */
11924 dpyinfo
->xim
= NULL
;
11925 #endif /* not USE_XIM */
11929 /* Close the connection to the XIM server on display DPYINFO. */
11932 xim_close_dpy (dpyinfo
)
11933 struct x_display_info
*dpyinfo
;
11936 #ifdef HAVE_X11R6_XIM
11937 if (dpyinfo
->display
)
11938 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11940 xim_instantiate_callback
, NULL
);
11941 #endif /* not HAVE_X11R6_XIM */
11942 if (dpyinfo
->display
)
11943 XCloseIM (dpyinfo
->xim
);
11944 dpyinfo
->xim
= NULL
;
11945 XFree (dpyinfo
->xim_styles
);
11946 #endif /* USE_XIM */
11949 #endif /* not HAVE_X11R6_XIM */
11953 /* Calculate the absolute position in frame F
11954 from its current recorded position values and gravity. */
11957 x_calc_absolute_position (f
)
11961 int win_x
= 0, win_y
= 0;
11962 int flags
= f
->output_data
.x
->size_hint_flags
;
11965 /* We have nothing to do if the current position
11966 is already for the top-left corner. */
11967 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11970 #ifdef USE_X_TOOLKIT
11971 this_window
= XtWindow (f
->output_data
.x
->widget
);
11973 this_window
= FRAME_X_WINDOW (f
);
11976 /* Find the position of the outside upper-left corner of
11977 the inner window, with respect to the outer window.
11978 But do this only if we will need the results. */
11979 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11984 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11987 x_clear_errors (FRAME_X_DISPLAY (f
));
11988 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11990 /* From-window, to-window. */
11992 f
->output_data
.x
->parent_desc
,
11994 /* From-position, to-position. */
11995 0, 0, &win_x
, &win_y
,
11997 /* Child of win. */
11999 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12001 Window newroot
, newparent
= 0xdeadbeef;
12002 Window
*newchildren
;
12003 unsigned int nchildren
;
12005 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12006 &newparent
, &newchildren
, &nchildren
))
12009 XFree ((char *) newchildren
);
12011 f
->output_data
.x
->parent_desc
= newparent
;
12017 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12021 /* Treat negative positions as relative to the leftmost bottommost
12022 position that fits on the screen. */
12023 if (flags
& XNegative
)
12024 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12025 - 2 * f
->output_data
.x
->border_width
- win_x
12027 + f
->output_data
.x
->left_pos
);
12030 int height
= PIXEL_HEIGHT (f
);
12032 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12033 /* Something is fishy here. When using Motif, starting Emacs with
12034 `-g -0-0', the frame appears too low by a few pixels.
12036 This seems to be so because initially, while Emacs is starting,
12037 the column widget's height and the frame's pixel height are
12038 different. The column widget's height is the right one. In
12039 later invocations, when Emacs is up, the frame's pixel height
12042 It's not obvious where the initial small difference comes from.
12043 2000-12-01, gerd. */
12045 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12048 if (flags
& YNegative
)
12049 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12050 - 2 * f
->output_data
.x
->border_width
12053 + f
->output_data
.x
->top_pos
);
12056 /* The left_pos and top_pos
12057 are now relative to the top and left screen edges,
12058 so the flags should correspond. */
12059 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12062 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12063 to really change the position, and 0 when calling from
12064 x_make_frame_visible (in that case, XOFF and YOFF are the current
12065 position values). It is -1 when calling from x_set_frame_parameters,
12066 which means, do adjust for borders but don't change the gravity. */
12069 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12071 register int xoff
, yoff
;
12072 int change_gravity
;
12074 int modified_top
, modified_left
;
12076 if (change_gravity
> 0)
12078 f
->output_data
.x
->top_pos
= yoff
;
12079 f
->output_data
.x
->left_pos
= xoff
;
12080 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12082 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12084 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12085 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12087 x_calc_absolute_position (f
);
12090 x_wm_set_size_hint (f
, (long) 0, 0);
12092 modified_left
= f
->output_data
.x
->left_pos
;
12093 modified_top
= f
->output_data
.x
->top_pos
;
12094 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12095 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12096 /* It is a mystery why we need to add the border_width here
12097 when the frame is already visible, but experiment says we do. */
12098 if (change_gravity
!= 0)
12100 modified_left
+= f
->output_data
.x
->border_width
;
12101 modified_top
+= f
->output_data
.x
->border_width
;
12105 #ifdef USE_X_TOOLKIT
12106 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12107 modified_left
, modified_top
);
12108 #else /* not USE_X_TOOLKIT */
12109 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12110 modified_left
, modified_top
);
12111 #endif /* not USE_X_TOOLKIT */
12116 /* Change the size of frame F's X window to COLS/ROWS in the case F
12117 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12118 top-left-corner window gravity for this size change and subsequent
12119 size changes. Otherwise we leave the window gravity unchanged. */
12122 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12124 int change_gravity
;
12127 int pixelwidth
, pixelheight
;
12129 check_frame_size (f
, &rows
, &cols
);
12130 f
->output_data
.x
->vertical_scroll_bar_extra
12131 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12133 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12134 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12135 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12136 f
->output_data
.x
->flags_areas_extra
12137 = FRAME_FLAGS_AREA_WIDTH (f
);
12138 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12139 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12141 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12142 x_wm_set_size_hint (f
, (long) 0, 0);
12144 XSync (FRAME_X_DISPLAY (f
), False
);
12145 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12146 pixelwidth
, pixelheight
);
12148 /* Now, strictly speaking, we can't be sure that this is accurate,
12149 but the window manager will get around to dealing with the size
12150 change request eventually, and we'll hear how it went when the
12151 ConfigureNotify event gets here.
12153 We could just not bother storing any of this information here,
12154 and let the ConfigureNotify event set everything up, but that
12155 might be kind of confusing to the Lisp code, since size changes
12156 wouldn't be reported in the frame parameters until some random
12157 point in the future when the ConfigureNotify event arrives.
12159 We pass 1 for DELAY since we can't run Lisp code inside of
12161 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12162 PIXEL_WIDTH (f
) = pixelwidth
;
12163 PIXEL_HEIGHT (f
) = pixelheight
;
12165 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12166 receive in the ConfigureNotify event; if we get what we asked
12167 for, then the event won't cause the screen to become garbaged, so
12168 we have to make sure to do it here. */
12169 SET_FRAME_GARBAGED (f
);
12171 XFlush (FRAME_X_DISPLAY (f
));
12175 /* Call this to change the size of frame F's x-window.
12176 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12177 for this size change and subsequent size changes.
12178 Otherwise we leave the window gravity unchanged. */
12181 x_set_window_size (f
, change_gravity
, cols
, rows
)
12183 int change_gravity
;
12188 #ifdef USE_X_TOOLKIT
12190 if (f
->output_data
.x
->widget
!= NULL
)
12192 /* The x and y position of the widget is clobbered by the
12193 call to XtSetValues within EmacsFrameSetCharSize.
12194 This is a real kludge, but I don't understand Xt so I can't
12195 figure out a correct fix. Can anyone else tell me? -- rms. */
12196 int xpos
= f
->output_data
.x
->widget
->core
.x
;
12197 int ypos
= f
->output_data
.x
->widget
->core
.y
;
12198 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
12199 f
->output_data
.x
->widget
->core
.x
= xpos
;
12200 f
->output_data
.x
->widget
->core
.y
= ypos
;
12203 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12205 #else /* not USE_X_TOOLKIT */
12207 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12209 #endif /* not USE_X_TOOLKIT */
12211 /* If cursor was outside the new size, mark it as off. */
12212 mark_window_cursors_off (XWINDOW (f
->root_window
));
12214 /* Clear out any recollection of where the mouse highlighting was,
12215 since it might be in a place that's outside the new frame size.
12216 Actually checking whether it is outside is a pain in the neck,
12217 so don't try--just let the highlighting be done afresh with new size. */
12218 cancel_mouse_face (f
);
12223 /* Mouse warping. */
12226 x_set_mouse_position (f
, x
, y
)
12232 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
12233 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
12235 if (pix_x
< 0) pix_x
= 0;
12236 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
12238 if (pix_y
< 0) pix_y
= 0;
12239 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
12243 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12244 0, 0, 0, 0, pix_x
, pix_y
);
12248 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
12251 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
12257 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12258 0, 0, 0, 0, pix_x
, pix_y
);
12262 /* focus shifting, raising and lowering. */
12265 x_focus_on_frame (f
)
12268 #if 0 /* This proves to be unpleasant. */
12272 /* I don't think that the ICCCM allows programs to do things like this
12273 without the interaction of the window manager. Whatever you end up
12274 doing with this code, do it to x_unfocus_frame too. */
12275 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12276 RevertToPointerRoot
, CurrentTime
);
12281 x_unfocus_frame (f
)
12285 /* Look at the remarks in x_focus_on_frame. */
12286 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
12287 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
12288 RevertToPointerRoot
, CurrentTime
);
12292 /* Raise frame F. */
12298 if (f
->async_visible
)
12301 #ifdef USE_X_TOOLKIT
12302 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12303 #else /* not USE_X_TOOLKIT */
12304 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12305 #endif /* not USE_X_TOOLKIT */
12306 XFlush (FRAME_X_DISPLAY (f
));
12311 /* Lower frame F. */
12317 if (f
->async_visible
)
12320 #ifdef USE_X_TOOLKIT
12321 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12322 #else /* not USE_X_TOOLKIT */
12323 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12324 #endif /* not USE_X_TOOLKIT */
12325 XFlush (FRAME_X_DISPLAY (f
));
12331 XTframe_raise_lower (f
, raise_flag
)
12341 /* Change of visibility. */
12343 /* This tries to wait until the frame is really visible.
12344 However, if the window manager asks the user where to position
12345 the frame, this will return before the user finishes doing that.
12346 The frame will not actually be visible at that time,
12347 but it will become visible later when the window manager
12348 finishes with it. */
12351 x_make_frame_visible (f
)
12355 int original_top
, original_left
;
12356 int retry_count
= 2;
12362 type
= x_icon_type (f
);
12364 x_bitmap_icon (f
, type
);
12366 if (! FRAME_VISIBLE_P (f
))
12368 /* We test FRAME_GARBAGED_P here to make sure we don't
12369 call x_set_offset a second time
12370 if we get to x_make_frame_visible a second time
12371 before the window gets really visible. */
12372 if (! FRAME_ICONIFIED_P (f
)
12373 && ! f
->output_data
.x
->asked_for_visible
)
12374 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12376 f
->output_data
.x
->asked_for_visible
= 1;
12378 if (! EQ (Vx_no_window_manager
, Qt
))
12379 x_wm_set_window_state (f
, NormalState
);
12380 #ifdef USE_X_TOOLKIT
12381 /* This was XtPopup, but that did nothing for an iconified frame. */
12382 XtMapWidget (f
->output_data
.x
->widget
);
12383 #else /* not USE_X_TOOLKIT */
12384 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12385 #endif /* not USE_X_TOOLKIT */
12386 #if 0 /* This seems to bring back scroll bars in the wrong places
12387 if the window configuration has changed. They seem
12388 to come back ok without this. */
12389 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
12390 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12394 XFlush (FRAME_X_DISPLAY (f
));
12396 /* Synchronize to ensure Emacs knows the frame is visible
12397 before we do anything else. We do this loop with input not blocked
12398 so that incoming events are handled. */
12402 /* This must be before UNBLOCK_INPUT
12403 since events that arrive in response to the actions above
12404 will set it when they are handled. */
12405 int previously_visible
= f
->output_data
.x
->has_been_visible
;
12407 original_left
= f
->output_data
.x
->left_pos
;
12408 original_top
= f
->output_data
.x
->top_pos
;
12410 /* This must come after we set COUNT. */
12413 /* We unblock here so that arriving X events are processed. */
12415 /* Now move the window back to where it was "supposed to be".
12416 But don't do it if the gravity is negative.
12417 When the gravity is negative, this uses a position
12418 that is 3 pixels too low. Perhaps that's really the border width.
12420 Don't do this if the window has never been visible before,
12421 because the window manager may choose the position
12422 and we don't want to override it. */
12424 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
12425 && f
->output_data
.x
->win_gravity
== NorthWestGravity
12426 && previously_visible
)
12430 unsigned int width
, height
, border
, depth
;
12434 /* On some window managers (such as FVWM) moving an existing
12435 window, even to the same place, causes the window manager
12436 to introduce an offset. This can cause the window to move
12437 to an unexpected location. Check the geometry (a little
12438 slow here) and then verify that the window is in the right
12439 place. If the window is not in the right place, move it
12440 there, and take the potential window manager hit. */
12441 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12442 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
12444 if (original_left
!= x
|| original_top
!= y
)
12445 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12446 original_left
, original_top
);
12451 XSETFRAME (frame
, f
);
12453 /* Wait until the frame is visible. Process X events until a
12454 MapNotify event has been seen, or until we think we won't get a
12455 MapNotify at all.. */
12456 for (count
= input_signal_count
+ 10;
12457 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
12459 /* Force processing of queued events. */
12462 /* Machines that do polling rather than SIGIO have been
12463 observed to go into a busy-wait here. So we'll fake an
12464 alarm signal to let the handler know that there's something
12465 to be read. We used to raise a real alarm, but it seems
12466 that the handler isn't always enabled here. This is
12468 if (input_polling_used ())
12470 /* It could be confusing if a real alarm arrives while
12471 processing the fake one. Turn it off and let the
12472 handler reset it. */
12473 extern void poll_for_input_1
P_ ((void));
12474 int old_poll_suppress_count
= poll_suppress_count
;
12475 poll_suppress_count
= 1;
12476 poll_for_input_1 ();
12477 poll_suppress_count
= old_poll_suppress_count
;
12480 /* See if a MapNotify event has been processed. */
12481 FRAME_SAMPLE_VISIBILITY (f
);
12486 (let ((f (selected-frame)))
12490 the frame is not raised with various window managers on
12491 FreeBSD, Linux and Solaris. It turns out that, for some
12492 unknown reason, the call to XtMapWidget is completely ignored.
12493 Mapping the widget a second time works. */
12495 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
12500 /* Change from mapped state to withdrawn state. */
12502 /* Make the frame visible (mapped and not iconified). */
12505 x_make_frame_invisible (f
)
12510 #ifdef USE_X_TOOLKIT
12511 /* Use the frame's outermost window, not the one we normally draw on. */
12512 window
= XtWindow (f
->output_data
.x
->widget
);
12513 #else /* not USE_X_TOOLKIT */
12514 window
= FRAME_X_WINDOW (f
);
12515 #endif /* not USE_X_TOOLKIT */
12517 /* Don't keep the highlight on an invisible frame. */
12518 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12519 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12521 #if 0/* This might add unreliability; I don't trust it -- rms. */
12522 if (! f
->async_visible
&& ! f
->async_iconified
)
12528 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12529 that the current position of the window is user-specified, rather than
12530 program-specified, so that when the window is mapped again, it will be
12531 placed at the same location, without forcing the user to position it
12532 by hand again (they have already done that once for this window.) */
12533 x_wm_set_size_hint (f
, (long) 0, 1);
12537 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12538 DefaultScreen (FRAME_X_DISPLAY (f
))))
12540 UNBLOCK_INPUT_RESIGNAL
;
12541 error ("Can't notify window manager of window withdrawal");
12543 #else /* ! defined (HAVE_X11R4) */
12545 /* Tell the window manager what we're going to do. */
12546 if (! EQ (Vx_no_window_manager
, Qt
))
12550 unmap
.xunmap
.type
= UnmapNotify
;
12551 unmap
.xunmap
.window
= window
;
12552 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12553 unmap
.xunmap
.from_configure
= False
;
12554 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12555 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12557 SubstructureRedirectMaskSubstructureNotifyMask
,
12560 UNBLOCK_INPUT_RESIGNAL
;
12561 error ("Can't notify window manager of withdrawal");
12565 /* Unmap the window ourselves. Cheeky! */
12566 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12567 #endif /* ! defined (HAVE_X11R4) */
12569 /* We can't distinguish this from iconification
12570 just by the event that we get from the server.
12571 So we can't win using the usual strategy of letting
12572 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12573 and synchronize with the server to make sure we agree. */
12575 FRAME_ICONIFIED_P (f
) = 0;
12576 f
->async_visible
= 0;
12577 f
->async_iconified
= 0;
12584 /* Change window state from mapped to iconified. */
12587 x_iconify_frame (f
)
12593 /* Don't keep the highlight on an invisible frame. */
12594 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12595 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12597 if (f
->async_iconified
)
12602 FRAME_SAMPLE_VISIBILITY (f
);
12604 type
= x_icon_type (f
);
12606 x_bitmap_icon (f
, type
);
12608 #ifdef USE_X_TOOLKIT
12610 if (! FRAME_VISIBLE_P (f
))
12612 if (! EQ (Vx_no_window_manager
, Qt
))
12613 x_wm_set_window_state (f
, IconicState
);
12614 /* This was XtPopup, but that did nothing for an iconified frame. */
12615 XtMapWidget (f
->output_data
.x
->widget
);
12616 /* The server won't give us any event to indicate
12617 that an invisible frame was changed to an icon,
12618 so we have to record it here. */
12621 f
->async_iconified
= 1;
12622 f
->async_visible
= 0;
12627 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12628 XtWindow (f
->output_data
.x
->widget
),
12629 DefaultScreen (FRAME_X_DISPLAY (f
)));
12633 error ("Can't notify window manager of iconification");
12635 f
->async_iconified
= 1;
12636 f
->async_visible
= 0;
12640 XFlush (FRAME_X_DISPLAY (f
));
12642 #else /* not USE_X_TOOLKIT */
12644 /* Make sure the X server knows where the window should be positioned,
12645 in case the user deiconifies with the window manager. */
12646 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12647 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12649 /* Since we don't know which revision of X we're running, we'll use both
12650 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12652 /* X11R4: send a ClientMessage to the window manager using the
12653 WM_CHANGE_STATE type. */
12657 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12658 message
.xclient
.type
= ClientMessage
;
12659 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12660 message
.xclient
.format
= 32;
12661 message
.xclient
.data
.l
[0] = IconicState
;
12663 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12664 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12666 SubstructureRedirectMask
| SubstructureNotifyMask
,
12669 UNBLOCK_INPUT_RESIGNAL
;
12670 error ("Can't notify window manager of iconification");
12674 /* X11R3: set the initial_state field of the window manager hints to
12676 x_wm_set_window_state (f
, IconicState
);
12678 if (!FRAME_VISIBLE_P (f
))
12680 /* If the frame was withdrawn, before, we must map it. */
12681 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12684 f
->async_iconified
= 1;
12685 f
->async_visible
= 0;
12687 XFlush (FRAME_X_DISPLAY (f
));
12689 #endif /* not USE_X_TOOLKIT */
12693 /* Free X resources of frame F. */
12696 x_free_frame_resources (f
)
12699 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12703 /* If a display connection is dead, don't try sending more
12704 commands to the X server. */
12705 if (dpyinfo
->display
)
12707 if (f
->output_data
.x
->icon_desc
)
12708 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12712 free_frame_xic (f
);
12715 if (FRAME_X_WINDOW (f
))
12716 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12718 #ifdef USE_X_TOOLKIT
12719 if (f
->output_data
.x
->widget
)
12720 XtDestroyWidget (f
->output_data
.x
->widget
);
12721 free_frame_menubar (f
);
12722 #endif /* USE_X_TOOLKIT */
12724 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12725 unload_color (f
, f
->output_data
.x
->background_pixel
);
12726 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12727 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12728 unload_color (f
, f
->output_data
.x
->border_pixel
);
12729 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12731 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12732 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12733 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12734 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12735 if (f
->output_data
.x
->white_relief
.allocated_p
)
12736 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12737 if (f
->output_data
.x
->black_relief
.allocated_p
)
12738 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12740 if (FRAME_FACE_CACHE (f
))
12741 free_frame_faces (f
);
12744 XFlush (FRAME_X_DISPLAY (f
));
12747 if (f
->output_data
.x
->saved_menu_event
)
12748 xfree (f
->output_data
.x
->saved_menu_event
);
12750 xfree (f
->output_data
.x
);
12751 f
->output_data
.x
= NULL
;
12753 if (f
== dpyinfo
->x_focus_frame
)
12754 dpyinfo
->x_focus_frame
= 0;
12755 if (f
== dpyinfo
->x_focus_event_frame
)
12756 dpyinfo
->x_focus_event_frame
= 0;
12757 if (f
== dpyinfo
->x_highlight_frame
)
12758 dpyinfo
->x_highlight_frame
= 0;
12760 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12762 dpyinfo
->mouse_face_beg_row
12763 = dpyinfo
->mouse_face_beg_col
= -1;
12764 dpyinfo
->mouse_face_end_row
12765 = dpyinfo
->mouse_face_end_col
= -1;
12766 dpyinfo
->mouse_face_window
= Qnil
;
12767 dpyinfo
->mouse_face_deferred_gc
= 0;
12768 dpyinfo
->mouse_face_mouse_frame
= 0;
12775 /* Destroy the X window of frame F. */
12778 x_destroy_window (f
)
12781 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12783 /* If a display connection is dead, don't try sending more
12784 commands to the X server. */
12785 if (dpyinfo
->display
!= 0)
12786 x_free_frame_resources (f
);
12788 dpyinfo
->reference_count
--;
12792 /* Setting window manager hints. */
12794 /* Set the normal size hints for the window manager, for frame F.
12795 FLAGS is the flags word to use--or 0 meaning preserve the flags
12796 that the window now has.
12797 If USER_POSITION is nonzero, we set the USPosition
12798 flag (this is useful when FLAGS is 0). */
12801 x_wm_set_size_hint (f
, flags
, user_position
)
12806 XSizeHints size_hints
;
12808 #ifdef USE_X_TOOLKIT
12811 Dimension widget_width
, widget_height
;
12812 Window window
= XtWindow (f
->output_data
.x
->widget
);
12813 #else /* not USE_X_TOOLKIT */
12814 Window window
= FRAME_X_WINDOW (f
);
12815 #endif /* not USE_X_TOOLKIT */
12817 /* Setting PMaxSize caused various problems. */
12818 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12820 size_hints
.x
= f
->output_data
.x
->left_pos
;
12821 size_hints
.y
= f
->output_data
.x
->top_pos
;
12823 #ifdef USE_X_TOOLKIT
12824 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12825 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12826 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12827 size_hints
.height
= widget_height
;
12828 size_hints
.width
= widget_width
;
12829 #else /* not USE_X_TOOLKIT */
12830 size_hints
.height
= PIXEL_HEIGHT (f
);
12831 size_hints
.width
= PIXEL_WIDTH (f
);
12832 #endif /* not USE_X_TOOLKIT */
12834 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12835 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12836 size_hints
.max_width
12837 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12838 size_hints
.max_height
12839 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12841 /* Calculate the base and minimum sizes.
12843 (When we use the X toolkit, we don't do it here.
12844 Instead we copy the values that the widgets are using, below.) */
12845 #ifndef USE_X_TOOLKIT
12847 int base_width
, base_height
;
12848 int min_rows
= 0, min_cols
= 0;
12850 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12851 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12853 check_frame_size (f
, &min_rows
, &min_cols
);
12855 /* The window manager uses the base width hints to calculate the
12856 current number of rows and columns in the frame while
12857 resizing; min_width and min_height aren't useful for this
12858 purpose, since they might not give the dimensions for a
12859 zero-row, zero-column frame.
12861 We use the base_width and base_height members if we have
12862 them; otherwise, we set the min_width and min_height members
12863 to the size for a zero x zero frame. */
12866 size_hints
.flags
|= PBaseSize
;
12867 size_hints
.base_width
= base_width
;
12868 size_hints
.base_height
= base_height
;
12869 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12870 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12872 size_hints
.min_width
= base_width
;
12873 size_hints
.min_height
= base_height
;
12877 /* If we don't need the old flags, we don't need the old hint at all. */
12880 size_hints
.flags
|= flags
;
12883 #endif /* not USE_X_TOOLKIT */
12886 XSizeHints hints
; /* Sometimes I hate X Windows... */
12887 long supplied_return
;
12891 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12894 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12897 #ifdef USE_X_TOOLKIT
12898 size_hints
.base_height
= hints
.base_height
;
12899 size_hints
.base_width
= hints
.base_width
;
12900 size_hints
.min_height
= hints
.min_height
;
12901 size_hints
.min_width
= hints
.min_width
;
12905 size_hints
.flags
|= flags
;
12910 if (hints
.flags
& PSize
)
12911 size_hints
.flags
|= PSize
;
12912 if (hints
.flags
& PPosition
)
12913 size_hints
.flags
|= PPosition
;
12914 if (hints
.flags
& USPosition
)
12915 size_hints
.flags
|= USPosition
;
12916 if (hints
.flags
& USSize
)
12917 size_hints
.flags
|= USSize
;
12921 #ifndef USE_X_TOOLKIT
12926 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12927 size_hints
.flags
|= PWinGravity
;
12931 size_hints
.flags
&= ~ PPosition
;
12932 size_hints
.flags
|= USPosition
;
12934 #endif /* PWinGravity */
12937 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12939 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12943 /* Used for IconicState or NormalState */
12946 x_wm_set_window_state (f
, state
)
12950 #ifdef USE_X_TOOLKIT
12953 XtSetArg (al
[0], XtNinitialState
, state
);
12954 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12955 #else /* not USE_X_TOOLKIT */
12956 Window window
= FRAME_X_WINDOW (f
);
12958 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12959 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12961 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12962 #endif /* not USE_X_TOOLKIT */
12966 x_wm_set_icon_pixmap (f
, pixmap_id
)
12970 Pixmap icon_pixmap
;
12972 #ifndef USE_X_TOOLKIT
12973 Window window
= FRAME_X_WINDOW (f
);
12978 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12979 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12983 /* It seems there is no way to turn off use of an icon pixmap.
12984 The following line does it, only if no icon has yet been created,
12985 for some window managers. But with mwm it crashes.
12986 Some people say it should clear the IconPixmapHint bit in this case,
12987 but that doesn't work, and the X consortium said it isn't the
12988 right thing at all. Since there is no way to win,
12989 best to explicitly give up. */
12991 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12997 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
13001 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
13002 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13005 #else /* not USE_X_TOOLKIT */
13007 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
13008 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13010 #endif /* not USE_X_TOOLKIT */
13014 x_wm_set_icon_position (f
, icon_x
, icon_y
)
13016 int icon_x
, icon_y
;
13018 #ifdef USE_X_TOOLKIT
13019 Window window
= XtWindow (f
->output_data
.x
->widget
);
13021 Window window
= FRAME_X_WINDOW (f
);
13024 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
13025 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
13026 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
13028 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13032 /***********************************************************************
13034 ***********************************************************************/
13036 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
13039 x_get_font_info (f
, font_idx
)
13043 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
13047 /* Return a list of names of available fonts matching PATTERN on frame F.
13049 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13052 SIZE < 0 means include scalable fonts.
13054 Frame F null means we have not yet created any frame on X, and
13055 consult the first display in x_display_list. MAXNAMES sets a limit
13056 on how many fonts to match. */
13059 x_list_fonts (f
, pattern
, size
, maxnames
)
13061 Lisp_Object pattern
;
13065 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13066 Lisp_Object tem
, second_best
;
13067 struct x_display_info
*dpyinfo
13068 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13069 Display
*dpy
= dpyinfo
->display
;
13070 int try_XLoadQueryFont
= 0;
13072 int allow_scalable_fonts_p
= 0;
13076 allow_scalable_fonts_p
= 1;
13080 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13081 if (NILP (patterns
))
13082 patterns
= Fcons (pattern
, Qnil
);
13084 if (maxnames
== 1 && !size
)
13085 /* We can return any single font matching PATTERN. */
13086 try_XLoadQueryFont
= 1;
13088 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13091 char **names
= NULL
;
13093 pattern
= XCAR (patterns
);
13094 /* See if we cached the result for this particular query.
13095 The cache is an alist of the form:
13096 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13097 tem
= XCDR (dpyinfo
->name_list_element
);
13098 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13099 allow_scalable_fonts_p
? Qt
: Qnil
);
13100 list
= Fassoc (key
, tem
);
13103 list
= Fcdr_safe (list
);
13104 /* We have a cashed list. Don't have to get the list again. */
13108 /* At first, put PATTERN in the cache. */
13111 count
= x_catch_errors (dpy
);
13113 if (try_XLoadQueryFont
)
13116 unsigned long value
;
13118 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13119 if (x_had_errors_p (dpy
))
13121 /* This error is perhaps due to insufficient memory on X
13122 server. Let's just ignore it. */
13124 x_clear_errors (dpy
);
13128 && XGetFontProperty (font
, XA_FONT
, &value
))
13130 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13131 int len
= strlen (name
);
13134 /* If DXPC (a Differential X Protocol Compressor)
13135 Ver.3.7 is running, XGetAtomName will return null
13136 string. We must avoid such a name. */
13138 try_XLoadQueryFont
= 0;
13142 names
= (char **) alloca (sizeof (char *));
13143 /* Some systems only allow alloca assigned to a
13145 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13146 bcopy (name
, names
[0], len
+ 1);
13151 try_XLoadQueryFont
= 0;
13154 XFreeFont (dpy
, font
);
13157 if (!try_XLoadQueryFont
)
13159 /* We try at least 10 fonts because XListFonts will return
13160 auto-scaled fonts at the head. */
13161 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
13163 if (x_had_errors_p (dpy
))
13165 /* This error is perhaps due to insufficient memory on X
13166 server. Let's just ignore it. */
13168 x_clear_errors (dpy
);
13172 x_uncatch_errors (dpy
, count
);
13179 /* Make a list of all the fonts we got back.
13180 Store that in the font cache for the display. */
13181 for (i
= 0; i
< num_fonts
; i
++)
13184 char *p
= names
[i
];
13185 int average_width
= -1, dashes
= 0;
13187 /* Count the number of dashes in NAMES[I]. If there are
13188 14 dashes, and the field value following 12th dash
13189 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
13190 is usually too ugly to be used for editing. Let's
13196 if (dashes
== 7) /* PIXEL_SIZE field */
13198 else if (dashes
== 12) /* AVERAGE_WIDTH field */
13199 average_width
= atoi (p
);
13202 if (allow_scalable_fonts_p
13203 || dashes
< 14 || average_width
!= 0)
13205 tem
= build_string (names
[i
]);
13206 if (NILP (Fassoc (tem
, list
)))
13208 if (STRINGP (Vx_pixel_size_width_font_regexp
)
13209 && ((fast_c_string_match_ignore_case
13210 (Vx_pixel_size_width_font_regexp
, names
[i
]))
13212 /* We can set the value of PIXEL_SIZE to the
13213 width of this font. */
13214 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
13216 /* For the moment, width is not known. */
13217 list
= Fcons (Fcons (tem
, Qnil
), list
);
13221 if (!try_XLoadQueryFont
)
13222 XFreeFontNames (names
);
13225 /* Now store the result in the cache. */
13226 XCDR (dpyinfo
->name_list_element
)
13227 = Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
));
13230 if (NILP (list
)) continue; /* Try the remaining alternatives. */
13232 newlist
= second_best
= Qnil
;
13233 /* Make a list of the fonts that have the right width. */
13234 for (; CONSP (list
); list
= XCDR (list
))
13240 if (!CONSP (tem
) || NILP (XCAR (tem
)))
13244 newlist
= Fcons (XCAR (tem
), newlist
);
13248 if (!INTEGERP (XCDR (tem
)))
13250 /* Since we have not yet known the size of this font, we
13251 must try slow function call XLoadQueryFont. */
13252 XFontStruct
*thisinfo
;
13255 count
= x_catch_errors (dpy
);
13256 thisinfo
= XLoadQueryFont (dpy
,
13257 XSTRING (XCAR (tem
))->data
);
13258 if (x_had_errors_p (dpy
))
13260 /* This error is perhaps due to insufficient memory on X
13261 server. Let's just ignore it. */
13263 x_clear_errors (dpy
);
13265 x_uncatch_errors (dpy
, count
);
13271 = (thisinfo
->min_bounds
.width
== 0
13273 : make_number (thisinfo
->max_bounds
.width
));
13274 XFreeFont (dpy
, thisinfo
);
13277 /* For unknown reason, the previous call of XListFont had
13278 returned a font which can't be opened. Record the size
13279 as 0 not to try to open it again. */
13280 XCDR (tem
) = make_number (0);
13283 found_size
= XINT (XCDR (tem
));
13284 if (found_size
== size
)
13285 newlist
= Fcons (XCAR (tem
), newlist
);
13286 else if (found_size
> 0)
13288 if (NILP (second_best
))
13290 else if (found_size
< size
)
13292 if (XINT (XCDR (second_best
)) > size
13293 || XINT (XCDR (second_best
)) < found_size
)
13298 if (XINT (XCDR (second_best
)) > size
13299 && XINT (XCDR (second_best
)) > found_size
)
13304 if (!NILP (newlist
))
13306 else if (!NILP (second_best
))
13308 newlist
= Fcons (XCAR (second_best
), Qnil
);
13319 /* Check that FONT is valid on frame F. It is if it can be found in F's
13323 x_check_font (f
, font
)
13328 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13330 xassert (font
!= NULL
);
13332 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13333 if (dpyinfo
->font_table
[i
].name
13334 && font
== dpyinfo
->font_table
[i
].font
)
13337 xassert (i
< dpyinfo
->n_fonts
);
13340 #endif /* GLYPH_DEBUG != 0 */
13342 /* Set *W to the minimum width, *H to the minimum font height of FONT.
13343 Note: There are (broken) X fonts out there with invalid XFontStruct
13344 min_bounds contents. For example, handa@etl.go.jp reports that
13345 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
13346 have font->min_bounds.width == 0. */
13349 x_font_min_bounds (font
, w
, h
)
13353 *h
= FONT_HEIGHT (font
);
13354 *w
= font
->min_bounds
.width
;
13356 /* Try to handle the case where FONT->min_bounds has invalid
13357 contents. Since the only font known to have invalid min_bounds
13358 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
13360 *w
= font
->max_bounds
.width
;
13364 /* Compute the smallest character width and smallest font height over
13365 all fonts available on frame F. Set the members smallest_char_width
13366 and smallest_font_height in F's x_display_info structure to
13367 the values computed. Value is non-zero if smallest_font_height or
13368 smallest_char_width become smaller than they were before. */
13371 x_compute_min_glyph_bounds (f
)
13375 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13377 int old_width
= dpyinfo
->smallest_char_width
;
13378 int old_height
= dpyinfo
->smallest_font_height
;
13380 dpyinfo
->smallest_font_height
= 100000;
13381 dpyinfo
->smallest_char_width
= 100000;
13383 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13384 if (dpyinfo
->font_table
[i
].name
)
13386 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
13389 font
= (XFontStruct
*) fontp
->font
;
13390 xassert (font
!= (XFontStruct
*) ~0);
13391 x_font_min_bounds (font
, &w
, &h
);
13393 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
13394 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
13397 xassert (dpyinfo
->smallest_char_width
> 0
13398 && dpyinfo
->smallest_font_height
> 0);
13400 return (dpyinfo
->n_fonts
== 1
13401 || dpyinfo
->smallest_char_width
< old_width
13402 || dpyinfo
->smallest_font_height
< old_height
);
13406 /* Load font named FONTNAME of the size SIZE for frame F, and return a
13407 pointer to the structure font_info while allocating it dynamically.
13408 If SIZE is 0, load any size of font.
13409 If loading is failed, return NULL. */
13412 x_load_font (f
, fontname
, size
)
13414 register char *fontname
;
13417 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13418 Lisp_Object font_names
;
13421 /* Get a list of all the fonts that match this name. Once we
13422 have a list of matching fonts, we compare them against the fonts
13423 we already have by comparing names. */
13424 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
13426 if (!NILP (font_names
))
13431 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13432 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
13433 if (dpyinfo
->font_table
[i
].name
13434 && (!strcmp (dpyinfo
->font_table
[i
].name
,
13435 XSTRING (XCAR (tail
))->data
)
13436 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
13437 XSTRING (XCAR (tail
))->data
)))
13438 return (dpyinfo
->font_table
+ i
);
13441 /* Load the font and add it to the table. */
13445 struct font_info
*fontp
;
13446 unsigned long value
;
13449 /* If we have found fonts by x_list_font, load one of them. If
13450 not, we still try to load a font by the name given as FONTNAME
13451 because XListFonts (called in x_list_font) of some X server has
13452 a bug of not finding a font even if the font surely exists and
13453 is loadable by XLoadQueryFont. */
13454 if (size
> 0 && !NILP (font_names
))
13455 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
13458 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
13459 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
13460 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
13462 /* This error is perhaps due to insufficient memory on X
13463 server. Let's just ignore it. */
13465 x_clear_errors (FRAME_X_DISPLAY (f
));
13467 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
13472 /* Find a free slot in the font table. */
13473 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13474 if (dpyinfo
->font_table
[i
].name
== NULL
)
13477 /* If no free slot found, maybe enlarge the font table. */
13478 if (i
== dpyinfo
->n_fonts
13479 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
13482 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
13483 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
13484 dpyinfo
->font_table
13485 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
13488 fontp
= dpyinfo
->font_table
+ i
;
13489 if (i
== dpyinfo
->n_fonts
)
13490 ++dpyinfo
->n_fonts
;
13492 /* Now fill in the slots of *FONTP. */
13494 fontp
->font
= font
;
13495 fontp
->font_idx
= i
;
13496 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
13497 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
13499 /* Try to get the full name of FONT. Put it in FULL_NAME. */
13501 if (XGetFontProperty (font
, XA_FONT
, &value
))
13503 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
13507 /* Count the number of dashes in the "full name".
13508 If it is too few, this isn't really the font's full name,
13510 In X11R4, the fonts did not come with their canonical names
13521 full_name
= (char *) xmalloc (p
- name
+ 1);
13522 bcopy (name
, full_name
, p
- name
+ 1);
13528 if (full_name
!= 0)
13529 fontp
->full_name
= full_name
;
13531 fontp
->full_name
= fontp
->name
;
13533 fontp
->size
= font
->max_bounds
.width
;
13534 fontp
->height
= FONT_HEIGHT (font
);
13536 if (NILP (font_names
))
13538 /* We come here because of a bug of XListFonts mentioned at
13539 the head of this block. Let's store this information in
13540 the cache for x_list_fonts. */
13541 Lisp_Object lispy_name
= build_string (fontname
);
13542 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13543 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
13546 XCDR (dpyinfo
->name_list_element
)
13547 = Fcons (Fcons (key
,
13548 Fcons (Fcons (lispy_full_name
,
13549 make_number (fontp
->size
)),
13551 XCDR (dpyinfo
->name_list_element
));
13554 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
13556 XCDR (dpyinfo
->name_list_element
)
13557 = Fcons (Fcons (key
,
13558 Fcons (Fcons (lispy_full_name
,
13559 make_number (fontp
->size
)),
13561 XCDR (dpyinfo
->name_list_element
));
13565 /* The slot `encoding' specifies how to map a character
13566 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13567 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13568 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13569 2:0xA020..0xFF7F). For the moment, we don't know which charset
13570 uses this font. So, we set information in fontp->encoding[1]
13571 which is never used by any charset. If mapping can't be
13572 decided, set FONT_ENCODING_NOT_DECIDED. */
13574 = (font
->max_byte1
== 0
13576 ? (font
->min_char_or_byte2
< 0x80
13577 ? (font
->max_char_or_byte2
< 0x80
13578 ? 0 /* 0x20..0x7F */
13579 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13580 : 1) /* 0xA0..0xFF */
13582 : (font
->min_byte1
< 0x80
13583 ? (font
->max_byte1
< 0x80
13584 ? (font
->min_char_or_byte2
< 0x80
13585 ? (font
->max_char_or_byte2
< 0x80
13586 ? 0 /* 0x2020..0x7F7F */
13587 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13588 : 3) /* 0x20A0..0x7FFF */
13589 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13590 : (font
->min_char_or_byte2
< 0x80
13591 ? (font
->max_char_or_byte2
< 0x80
13592 ? 2 /* 0xA020..0xFF7F */
13593 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13594 : 1))); /* 0xA0A0..0xFFFF */
13596 fontp
->baseline_offset
13597 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13598 ? (long) value
: 0);
13599 fontp
->relative_compose
13600 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13601 ? (long) value
: 0);
13602 fontp
->default_ascent
13603 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13604 ? (long) value
: 0);
13606 /* Set global flag fonts_changed_p to non-zero if the font loaded
13607 has a character with a smaller width than any other character
13608 before, or if the font loaded has a smalle>r height than any
13609 other font loaded before. If this happens, it will make a
13610 glyph matrix reallocation necessary. */
13611 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13618 /* Return a pointer to struct font_info of a font named FONTNAME for
13619 frame F. If no such font is loaded, return NULL. */
13622 x_query_font (f
, fontname
)
13624 register char *fontname
;
13626 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13629 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13630 if (dpyinfo
->font_table
[i
].name
13631 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13632 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13633 return (dpyinfo
->font_table
+ i
);
13638 /* Find a CCL program for a font specified by FONTP, and set the member
13639 `encoder' of the structure. */
13642 x_find_ccl_program (fontp
)
13643 struct font_info
*fontp
;
13645 Lisp_Object list
, elt
;
13648 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13652 && STRINGP (XCAR (elt
))
13653 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13655 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
13662 struct ccl_program
*ccl
13663 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13665 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13668 fontp
->font_encoder
= ccl
;
13674 /***********************************************************************
13676 ***********************************************************************/
13678 #ifdef USE_X_TOOLKIT
13679 static XrmOptionDescRec emacs_options
[] = {
13680 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13681 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13683 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13684 XrmoptionSepArg
, NULL
},
13685 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13687 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13688 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13689 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13690 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13691 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13692 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13693 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13695 #endif /* USE_X_TOOLKIT */
13697 static int x_initialized
;
13699 #ifdef MULTI_KBOARD
13700 /* Test whether two display-name strings agree up to the dot that separates
13701 the screen number from the server number. */
13703 same_x_server (name1
, name2
)
13704 char *name1
, *name2
;
13706 int seen_colon
= 0;
13707 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13708 int system_name_length
= strlen (system_name
);
13709 int length_until_period
= 0;
13711 while (system_name
[length_until_period
] != 0
13712 && system_name
[length_until_period
] != '.')
13713 length_until_period
++;
13715 /* Treat `unix' like an empty host name. */
13716 if (! strncmp (name1
, "unix:", 5))
13718 if (! strncmp (name2
, "unix:", 5))
13720 /* Treat this host's name like an empty host name. */
13721 if (! strncmp (name1
, system_name
, system_name_length
)
13722 && name1
[system_name_length
] == ':')
13723 name1
+= system_name_length
;
13724 if (! strncmp (name2
, system_name
, system_name_length
)
13725 && name2
[system_name_length
] == ':')
13726 name2
+= system_name_length
;
13727 /* Treat this host's domainless name like an empty host name. */
13728 if (! strncmp (name1
, system_name
, length_until_period
)
13729 && name1
[length_until_period
] == ':')
13730 name1
+= length_until_period
;
13731 if (! strncmp (name2
, system_name
, length_until_period
)
13732 && name2
[length_until_period
] == ':')
13733 name2
+= length_until_period
;
13735 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13739 if (seen_colon
&& *name1
== '.')
13743 && (*name1
== '.' || *name1
== '\0')
13744 && (*name2
== '.' || *name2
== '\0'));
13748 struct x_display_info
*
13749 x_term_init (display_name
, xrm_option
, resource_name
)
13750 Lisp_Object display_name
;
13752 char *resource_name
;
13756 struct x_display_info
*dpyinfo
;
13761 if (!x_initialized
)
13767 #ifdef USE_X_TOOLKIT
13768 /* weiner@footloose.sps.mot.com reports that this causes
13770 X protocol error: BadAtom (invalid Atom parameter)
13771 on protocol request 18skiloaf.
13772 So let's not use it until R6. */
13773 #ifdef HAVE_X11XTR6
13774 XtSetLanguageProc (NULL
, NULL
, NULL
);
13785 argv
[argc
++] = "-xrm";
13786 argv
[argc
++] = xrm_option
;
13788 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13789 resource_name
, EMACS_CLASS
,
13790 emacs_options
, XtNumber (emacs_options
),
13793 #ifdef HAVE_X11XTR6
13794 /* I think this is to compensate for XtSetLanguageProc. */
13799 #else /* not USE_X_TOOLKIT */
13801 XSetLocaleModifiers ("");
13803 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13804 #endif /* not USE_X_TOOLKIT */
13806 /* Detect failure. */
13813 /* We have definitely succeeded. Record the new connection. */
13815 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13816 bzero (dpyinfo
, sizeof *dpyinfo
);
13818 #ifdef MULTI_KBOARD
13820 struct x_display_info
*share
;
13823 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13824 share
= share
->next
, tail
= XCDR (tail
))
13825 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13826 XSTRING (display_name
)->data
))
13829 dpyinfo
->kboard
= share
->kboard
;
13832 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13833 init_kboard (dpyinfo
->kboard
);
13834 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13836 char *vendor
= ServerVendor (dpy
);
13838 dpyinfo
->kboard
->Vsystem_key_alist
13839 = call1 (Qvendor_specific_keysyms
,
13840 build_string (vendor
? vendor
: ""));
13844 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13845 all_kboards
= dpyinfo
->kboard
;
13846 /* Don't let the initial kboard remain current longer than necessary.
13847 That would cause problems if a file loaded on startup tries to
13848 prompt in the mini-buffer. */
13849 if (current_kboard
== initial_kboard
)
13850 current_kboard
= dpyinfo
->kboard
;
13852 dpyinfo
->kboard
->reference_count
++;
13856 /* Put this display on the chain. */
13857 dpyinfo
->next
= x_display_list
;
13858 x_display_list
= dpyinfo
;
13860 /* Put it on x_display_name_list as well, to keep them parallel. */
13861 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13862 x_display_name_list
);
13863 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13865 dpyinfo
->display
= dpy
;
13868 XSetAfterFunction (x_current_display
, x_trace_wire
);
13872 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13873 + STRING_BYTES (XSTRING (Vsystem_name
))
13875 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13876 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13878 /* Figure out which modifier bits mean what. */
13879 x_find_modifier_meanings (dpyinfo
);
13881 /* Get the scroll bar cursor. */
13882 dpyinfo
->vertical_scroll_bar_cursor
13883 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13885 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13886 resource_name
, EMACS_CLASS
);
13887 #ifdef HAVE_XRMSETDATABASE
13888 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13890 dpyinfo
->display
->db
= xrdb
;
13892 /* Put the rdb where we can find it in a way that works on
13894 dpyinfo
->xrdb
= xrdb
;
13896 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13897 DefaultScreen (dpyinfo
->display
));
13898 select_visual (dpyinfo
);
13899 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13900 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13901 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13902 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13903 dpyinfo
->grabbed
= 0;
13904 dpyinfo
->reference_count
= 0;
13905 dpyinfo
->icon_bitmap_id
= -1;
13906 dpyinfo
->font_table
= NULL
;
13907 dpyinfo
->n_fonts
= 0;
13908 dpyinfo
->font_table_size
= 0;
13909 dpyinfo
->bitmaps
= 0;
13910 dpyinfo
->bitmaps_size
= 0;
13911 dpyinfo
->bitmaps_last
= 0;
13912 dpyinfo
->scratch_cursor_gc
= 0;
13913 dpyinfo
->mouse_face_mouse_frame
= 0;
13914 dpyinfo
->mouse_face_deferred_gc
= 0;
13915 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13916 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13917 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13918 dpyinfo
->mouse_face_window
= Qnil
;
13919 dpyinfo
->mouse_face_overlay
= Qnil
;
13920 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13921 dpyinfo
->mouse_face_defer
= 0;
13922 dpyinfo
->x_focus_frame
= 0;
13923 dpyinfo
->x_focus_event_frame
= 0;
13924 dpyinfo
->x_highlight_frame
= 0;
13925 dpyinfo
->image_cache
= make_image_cache ();
13927 /* See if a private colormap is requested. */
13928 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13930 if (dpyinfo
->visual
->class == PseudoColor
)
13933 value
= display_x_get_resource (dpyinfo
,
13934 build_string ("privateColormap"),
13935 build_string ("PrivateColormap"),
13937 if (STRINGP (value
)
13938 && (!strcmp (XSTRING (value
)->data
, "true")
13939 || !strcmp (XSTRING (value
)->data
, "on")))
13940 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13944 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13945 dpyinfo
->visual
, AllocNone
);
13948 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13949 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13950 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13951 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13952 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13953 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13954 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13957 dpyinfo
->Xatom_wm_protocols
13958 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13959 dpyinfo
->Xatom_wm_take_focus
13960 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13961 dpyinfo
->Xatom_wm_save_yourself
13962 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13963 dpyinfo
->Xatom_wm_delete_window
13964 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13965 dpyinfo
->Xatom_wm_change_state
13966 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13967 dpyinfo
->Xatom_wm_configure_denied
13968 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13969 dpyinfo
->Xatom_wm_window_moved
13970 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13971 dpyinfo
->Xatom_editres
13972 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13973 dpyinfo
->Xatom_CLIPBOARD
13974 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13975 dpyinfo
->Xatom_TIMESTAMP
13976 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13977 dpyinfo
->Xatom_TEXT
13978 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13979 dpyinfo
->Xatom_COMPOUND_TEXT
13980 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13981 dpyinfo
->Xatom_DELETE
13982 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13983 dpyinfo
->Xatom_MULTIPLE
13984 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13985 dpyinfo
->Xatom_INCR
13986 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13987 dpyinfo
->Xatom_EMACS_TMP
13988 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13989 dpyinfo
->Xatom_TARGETS
13990 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13991 dpyinfo
->Xatom_NULL
13992 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13993 dpyinfo
->Xatom_ATOM_PAIR
13994 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13995 /* For properties of font. */
13996 dpyinfo
->Xatom_PIXEL_SIZE
13997 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13998 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13999 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
14000 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
14001 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
14002 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
14003 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
14005 /* Ghostscript support. */
14006 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
14007 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
14009 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
14012 dpyinfo
->cut_buffers_initialized
= 0;
14014 connection
= ConnectionNumber (dpyinfo
->display
);
14015 dpyinfo
->connection
= connection
;
14020 null_bits
[0] = 0x00;
14022 dpyinfo
->null_pixel
14023 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14024 null_bits
, 1, 1, (long) 0, (long) 0,
14029 extern int gray_bitmap_width
, gray_bitmap_height
;
14030 extern char *gray_bitmap_bits
;
14032 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14034 gray_bitmap_width
, gray_bitmap_height
,
14035 (unsigned long) 1, (unsigned long) 0, 1);
14039 xim_initialize (dpyinfo
, resource_name
);
14042 #ifdef subprocesses
14043 /* This is only needed for distinguishing keyboard and process input. */
14044 if (connection
!= 0)
14045 add_keyboard_wait_descriptor (connection
);
14048 #ifndef F_SETOWN_BUG
14050 #ifdef F_SETOWN_SOCK_NEG
14051 /* stdin is a socket here */
14052 fcntl (connection
, F_SETOWN
, -getpid ());
14053 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14054 fcntl (connection
, F_SETOWN
, getpid ());
14055 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14056 #endif /* ! defined (F_SETOWN) */
14057 #endif /* F_SETOWN_BUG */
14060 if (interrupt_input
)
14061 init_sigio (connection
);
14062 #endif /* ! defined (SIGIO) */
14065 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
14066 /* Make sure that we have a valid font for dialog boxes
14067 so that Xt does not crash. */
14069 Display
*dpy
= dpyinfo
->display
;
14070 XrmValue d
, fr
, to
;
14074 d
.addr
= (XPointer
)&dpy
;
14075 d
.size
= sizeof (Display
*);
14076 fr
.addr
= XtDefaultFont
;
14077 fr
.size
= sizeof (XtDefaultFont
);
14078 to
.size
= sizeof (Font
*);
14079 to
.addr
= (XPointer
)&font
;
14080 count
= x_catch_errors (dpy
);
14081 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
14083 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
14084 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
14085 x_uncatch_errors (dpy
, count
);
14090 /* See if we should run in synchronous mode. This is useful
14091 for debugging X code. */
14094 value
= display_x_get_resource (dpyinfo
,
14095 build_string ("synchronous"),
14096 build_string ("Synchronous"),
14098 if (STRINGP (value
)
14099 && (!strcmp (XSTRING (value
)->data
, "true")
14100 || !strcmp (XSTRING (value
)->data
, "on")))
14101 XSynchronize (dpyinfo
->display
, True
);
14109 /* Get rid of display DPYINFO, assuming all frames are already gone,
14110 and without sending any more commands to the X server. */
14113 x_delete_display (dpyinfo
)
14114 struct x_display_info
*dpyinfo
;
14116 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
14118 /* Discard this display from x_display_name_list and x_display_list.
14119 We can't use Fdelq because that can quit. */
14120 if (! NILP (x_display_name_list
)
14121 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
14122 x_display_name_list
= XCDR (x_display_name_list
);
14127 tail
= x_display_name_list
;
14128 while (CONSP (tail
) && CONSP (XCDR (tail
)))
14130 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
14132 XCDR (tail
) = XCDR (XCDR (tail
));
14135 tail
= XCDR (tail
);
14139 if (next_noop_dpyinfo
== dpyinfo
)
14140 next_noop_dpyinfo
= dpyinfo
->next
;
14142 if (x_display_list
== dpyinfo
)
14143 x_display_list
= dpyinfo
->next
;
14146 struct x_display_info
*tail
;
14148 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
14149 if (tail
->next
== dpyinfo
)
14150 tail
->next
= tail
->next
->next
;
14153 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
14154 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
14155 XrmDestroyDatabase (dpyinfo
->xrdb
);
14158 #ifdef MULTI_KBOARD
14159 if (--dpyinfo
->kboard
->reference_count
== 0)
14160 delete_kboard (dpyinfo
->kboard
);
14164 xim_close_dpy (dpyinfo
);
14167 xfree (dpyinfo
->font_table
);
14168 xfree (dpyinfo
->x_id_name
);
14169 xfree (dpyinfo
->color_cells
);
14174 /* Set up use of X before we make the first connection. */
14176 static struct redisplay_interface x_redisplay_interface
=
14181 x_clear_end_of_line
,
14183 x_after_update_window_line
,
14184 x_update_window_begin
,
14185 x_update_window_end
,
14188 x_clear_mouse_face
,
14189 x_get_glyph_overhangs
,
14190 x_fix_overlapping_area
14196 rif
= &x_redisplay_interface
;
14198 clear_frame_hook
= x_clear_frame
;
14199 ins_del_lines_hook
= x_ins_del_lines
;
14200 change_line_highlight_hook
= x_change_line_highlight
;
14201 delete_glyphs_hook
= x_delete_glyphs
;
14202 ring_bell_hook
= XTring_bell
;
14203 reset_terminal_modes_hook
= XTreset_terminal_modes
;
14204 set_terminal_modes_hook
= XTset_terminal_modes
;
14205 update_begin_hook
= x_update_begin
;
14206 update_end_hook
= x_update_end
;
14207 set_terminal_window_hook
= XTset_terminal_window
;
14208 read_socket_hook
= XTread_socket
;
14209 frame_up_to_date_hook
= XTframe_up_to_date
;
14210 reassert_line_highlight_hook
= XTreassert_line_highlight
;
14211 mouse_position_hook
= XTmouse_position
;
14212 frame_rehighlight_hook
= XTframe_rehighlight
;
14213 frame_raise_lower_hook
= XTframe_raise_lower
;
14214 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
14215 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
14216 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
14217 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
14218 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
14220 scroll_region_ok
= 1; /* we'll scroll partial frames */
14221 char_ins_del_ok
= 1;
14222 line_ins_del_ok
= 1; /* we'll just blt 'em */
14223 fast_clear_end_of_line
= 1; /* X does this well */
14224 memory_below_frame
= 0; /* we don't remember what scrolls
14229 last_tool_bar_item
= -1;
14230 any_help_event_p
= 0;
14232 /* Try to use interrupt input; if we can't, then start polling. */
14233 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
14235 #ifdef USE_X_TOOLKIT
14236 XtToolkitInitialize ();
14237 Xt_app_con
= XtCreateApplicationContext ();
14238 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
14240 /* Install an asynchronous timer that processes Xt timeout events
14241 every 0.1s. This is necessary because some widget sets use
14242 timeouts internally, for example the LessTif menu bar, or the
14243 Xaw3d scroll bar. When Xt timouts aren't processed, these
14244 widgets don't behave normally. */
14246 EMACS_TIME interval
;
14247 EMACS_SET_SECS_USECS (interval
, 0, 100000);
14248 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
14252 #ifdef USE_TOOLKIT_SCROLL_BARS
14253 xaw3d_arrow_scroll
= False
;
14254 xaw3d_pick_top
= True
;
14257 /* Note that there is no real way portable across R3/R4 to get the
14258 original error handler. */
14259 XSetErrorHandler (x_error_handler
);
14260 XSetIOErrorHandler (x_io_error_quitter
);
14262 /* Disable Window Change signals; they are handled by X events. */
14264 signal (SIGWINCH
, SIG_DFL
);
14265 #endif /* ! defined (SIGWINCH) */
14267 signal (SIGPIPE
, x_connection_signal
);
14274 staticpro (&x_error_message_string
);
14275 x_error_message_string
= Qnil
;
14277 staticpro (&x_display_name_list
);
14278 x_display_name_list
= Qnil
;
14280 staticpro (&last_mouse_scroll_bar
);
14281 last_mouse_scroll_bar
= Qnil
;
14283 staticpro (&Qvendor_specific_keysyms
);
14284 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
14286 staticpro (&last_mouse_press_frame
);
14287 last_mouse_press_frame
= Qnil
;
14290 staticpro (&help_echo
);
14291 help_echo_object
= Qnil
;
14292 staticpro (&help_echo_object
);
14293 help_echo_window
= Qnil
;
14294 staticpro (&help_echo_window
);
14295 previous_help_echo
= Qnil
;
14296 staticpro (&previous_help_echo
);
14297 help_echo_pos
= -1;
14299 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
14300 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
14301 For example, if a block cursor is over a tab, it will be drawn as\n\
14302 wide as that tab on the display.");
14303 x_stretch_cursor_p
= 0;
14305 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
14306 "What X toolkit scroll bars Emacs uses.\n\
14307 A value of nil means Emacs doesn't use X toolkit scroll bars.\n\
14308 Otherwise, value is a symbol describing the X toolkit.");
14309 #ifdef USE_TOOLKIT_SCROLL_BARS
14311 Vx_toolkit_scroll_bars
= intern ("motif");
14312 #elif defined HAVE_XAW3D
14313 Vx_toolkit_scroll_bars
= intern ("xaw3d");
14315 Vx_toolkit_scroll_bars
= intern ("xaw");
14318 Vx_toolkit_scroll_bars
= Qnil
;
14321 staticpro (&last_mouse_motion_frame
);
14322 last_mouse_motion_frame
= Qnil
;
14325 #endif /* not HAVE_X_WINDOWS */