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 #else /* !USE_MOTIF i.e. use Xaw */
123 #include <X11/Xaw3d/Simple.h>
124 #include <X11/Xaw3d/Scrollbar.h>
125 #define ARROW_SCROLLBAR
126 #include <X11/Xaw3d/ScrollbarP.h>
127 #else /* !HAVE_XAW3D */
128 #include <X11/Xaw/Simple.h>
129 #include <X11/Xaw/Scrollbar.h>
130 #endif /* !HAVE_XAW3D */
132 #define XtNpickTop "pickTop"
133 #endif /* !XtNpickTop */
134 #endif /* !USE_MOTIF */
135 #endif /* USE_TOOLKIT_SCROLL_BARS */
137 #endif /* USE_X_TOOLKIT */
139 #ifndef USE_X_TOOLKIT
140 #define x_any_window_to_frame x_window_to_frame
141 #define x_top_window_to_frame x_window_to_frame
146 #ifndef XtNinitialState
147 #define XtNinitialState "initialState"
152 #define min(a,b) ((a) < (b) ? (a) : (b))
155 #define max(a,b) ((a) > (b) ? (a) : (b))
158 #define abs(x) ((x) < 0 ? -(x) : (x))
160 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
163 /* Bitmaps for truncated lines. */
168 LEFT_TRUNCATION_BITMAP
,
169 RIGHT_TRUNCATION_BITMAP
,
170 OVERLAY_ARROW_BITMAP
,
171 CONTINUED_LINE_BITMAP
,
172 CONTINUATION_LINE_BITMAP
,
176 /* Bitmap drawn to indicate lines not displaying text if
177 `indicate-empty-lines' is non-nil. */
181 static unsigned char zv_bits
[] = {
182 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
184 /* An arrow like this: `<-'. */
187 #define left_height 8
188 static unsigned char left_bits
[] = {
189 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
191 /* Right truncation arrow bitmap `->'. */
193 #define right_width 8
194 #define right_height 8
195 static unsigned char right_bits
[] = {
196 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
198 /* Marker for continued lines. */
200 #define continued_width 8
201 #define continued_height 8
202 static unsigned char continued_bits
[] = {
203 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
205 /* Marker for continuation lines. */
207 #define continuation_width 8
208 #define continuation_height 8
209 static unsigned char continuation_bits
[] = {
210 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
212 /* Overlay arrow bitmap. */
218 static unsigned char ov_bits
[] = {
219 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
221 /* A triangular arrow. */
224 static unsigned char ov_bits
[] = {
225 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
229 extern Lisp_Object Qhelp_echo
;
232 /* Non-nil means Emacs uses toolkit scroll bars. */
234 Lisp_Object Vx_toolkit_scroll_bars
;
236 /* If a string, XTread_socket generates an event to display that string.
237 (The display is done in read_char.) */
239 static Lisp_Object help_echo
;
240 static Lisp_Object help_echo_window
;
241 static Lisp_Object help_echo_object
;
242 static int help_echo_pos
;
244 /* Temporary variable for XTread_socket. */
246 static Lisp_Object previous_help_echo
;
248 /* Non-zero means that a HELP_EVENT has been generated since Emacs
251 static int any_help_event_p
;
253 /* Non-zero means draw block and hollow cursor as wide as the glyph
254 under it. For example, if a block cursor is over a tab, it will be
255 drawn as wide as that tab on the display. */
257 int x_stretch_cursor_p
;
259 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
261 int x_use_underline_position_properties
;
263 /* This is a chain of structures for all the X displays currently in
266 struct x_display_info
*x_display_list
;
268 /* This is a list of cons cells, each of the form (NAME
269 . FONT-LIST-CACHE), one for each element of x_display_list and in
270 the same order. NAME is the name of the frame. FONT-LIST-CACHE
271 records previous values returned by x-list-fonts. */
273 Lisp_Object x_display_name_list
;
275 /* Frame being updated by update_frame. This is declared in term.c.
276 This is set by update_begin and looked at by all the XT functions.
277 It is zero while not inside an update. In that case, the XT
278 functions assume that `selected_frame' is the frame to apply to. */
280 extern struct frame
*updating_frame
;
282 extern int waiting_for_input
;
284 /* This is a frame waiting to be auto-raised, within XTread_socket. */
286 struct frame
*pending_autoraise_frame
;
289 /* The application context for Xt use. */
290 XtAppContext Xt_app_con
;
291 static String Xt_default_resources
[] = {0};
292 #endif /* USE_X_TOOLKIT */
294 /* Nominal cursor position -- where to draw output.
295 HPOS and VPOS are window relative glyph matrix coordinates.
296 X and Y are window relative pixel coordinates. */
298 struct cursor_pos output_cursor
;
300 /* Non-zero means user is interacting with a toolkit scroll bar. */
302 static int toolkit_scroll_bar_interaction
;
306 Formerly, we used PointerMotionHintMask (in standard_event_mask)
307 so that we would have to call XQueryPointer after each MotionNotify
308 event to ask for another such event. However, this made mouse tracking
309 slow, and there was a bug that made it eventually stop.
311 Simply asking for MotionNotify all the time seems to work better.
313 In order to avoid asking for motion events and then throwing most
314 of them away or busy-polling the server for mouse positions, we ask
315 the server for pointer motion hints. This means that we get only
316 one event per group of mouse movements. "Groups" are delimited by
317 other kinds of events (focus changes and button clicks, for
318 example), or by XQueryPointer calls; when one of these happens, we
319 get another MotionNotify event the next time the mouse moves. This
320 is at least as efficient as getting motion events when mouse
321 tracking is on, and I suspect only negligibly worse when tracking
324 /* Where the mouse was last time we reported a mouse event. */
326 FRAME_PTR last_mouse_frame
;
327 static XRectangle last_mouse_glyph
;
328 static Lisp_Object last_mouse_press_frame
;
330 /* The scroll bar in which the last X motion event occurred.
332 If the last X motion event occurred in a scroll bar, we set this so
333 XTmouse_position can know whether to report a scroll bar motion or
336 If the last X motion event didn't occur in a scroll bar, we set
337 this to Qnil, to tell XTmouse_position to return an ordinary motion
340 static Lisp_Object last_mouse_scroll_bar
;
342 /* This is a hack. We would really prefer that XTmouse_position would
343 return the time associated with the position it returns, but there
344 doesn't seem to be any way to wrest the time-stamp from the server
345 along with the position query. So, we just keep track of the time
346 of the last movement we received, and return that in hopes that
347 it's somewhat accurate. */
349 static Time last_mouse_movement_time
;
351 /* Incremented by XTread_socket whenever it really tries to read
355 static int volatile input_signal_count
;
357 static int input_signal_count
;
360 /* Used locally within XTread_socket. */
362 static int x_noop_count
;
364 /* Initial values of argv and argc. */
366 extern char **initial_argv
;
367 extern int initial_argc
;
369 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
371 /* Tells if a window manager is present or not. */
373 extern Lisp_Object Vx_no_window_manager
;
375 extern Lisp_Object Qface
, Qmouse_face
;
379 /* A mask of extra modifier bits to put into every keyboard char. */
381 extern int extra_keyboard_modifiers
;
383 static Lisp_Object Qvendor_specific_keysyms
;
385 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
386 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
389 /* Enumeration for overriding/changing the face to use for drawing
390 glyphs in x_draw_glyphs. */
392 enum draw_glyphs_face
402 static int cursor_in_mouse_face_p
P_ ((struct window
*));
403 static int clear_mouse_face
P_ ((struct x_display_info
*));
404 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
405 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
406 static const XColor
*x_color_cells
P_ ((Display
*, int *));
407 static void x_update_window_end
P_ ((struct window
*, int, int));
408 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
409 void x_delete_display
P_ ((struct x_display_info
*));
410 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
412 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
414 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
415 int *, int *, int *, int *, int));
416 static void set_output_cursor
P_ ((struct cursor_pos
*));
417 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
418 int *, int *, int *, int));
419 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
420 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
421 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
422 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
423 static void show_mouse_face
P_ ((struct x_display_info
*,
424 enum draw_glyphs_face
));
425 static int x_io_error_quitter
P_ ((Display
*));
426 int x_catch_errors
P_ ((Display
*));
427 void x_uncatch_errors
P_ ((Display
*, int));
428 void x_lower_frame
P_ ((struct frame
*));
429 void x_scroll_bar_clear
P_ ((struct frame
*));
430 int x_had_errors_p
P_ ((Display
*));
431 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
432 void x_raise_frame
P_ ((struct frame
*));
433 void x_set_window_size
P_ ((struct frame
*, int, int, int));
434 void x_wm_set_window_state
P_ ((struct frame
*, int));
435 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
436 void x_initialize
P_ ((void));
437 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
438 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
439 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
441 enum draw_glyphs_face
));
442 static void x_update_end
P_ ((struct frame
*));
443 static void XTframe_up_to_date
P_ ((struct frame
*));
444 static void XTreassert_line_highlight
P_ ((int, int));
445 static void x_change_line_highlight
P_ ((int, int, int, int));
446 static void XTset_terminal_modes
P_ ((void));
447 static void XTreset_terminal_modes
P_ ((void));
448 static void XTcursor_to
P_ ((int, int, int, int));
449 static void x_write_glyphs
P_ ((struct glyph
*, int));
450 static void x_clear_end_of_line
P_ ((int));
451 static void x_clear_frame
P_ ((void));
452 static void x_clear_cursor
P_ ((struct window
*));
453 static void frame_highlight
P_ ((struct frame
*));
454 static void frame_unhighlight
P_ ((struct frame
*));
455 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
456 static void XTframe_rehighlight
P_ ((struct frame
*));
457 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
458 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
459 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
460 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
462 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
463 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
464 static int expose_window
P_ ((struct window
*, XRectangle
*));
465 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
466 XRectangle
*, enum glyph_row_area
));
467 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
469 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
470 static void x_update_window_cursor
P_ ((struct window
*, int));
471 static void x_erase_phys_cursor
P_ ((struct window
*));
472 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
473 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
476 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
478 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
479 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
480 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
481 static void x_flush
P_ ((struct frame
*f
));
482 static void x_update_begin
P_ ((struct frame
*));
483 static void x_update_window_begin
P_ ((struct window
*));
484 static void x_draw_vertical_border
P_ ((struct window
*));
485 static void x_after_update_window_line
P_ ((struct glyph_row
*));
486 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
487 static void x_produce_stretch_glyph
P_ ((struct it
*));
488 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
489 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
490 enum scroll_bar_part
*,
491 Lisp_Object
*, Lisp_Object
*,
494 /* Flush display of frame F, or of all frames if F is null. */
503 Lisp_Object rest
, frame
;
504 FOR_EACH_FRAME (rest
, frame
)
505 x_flush (XFRAME (frame
));
507 else if (FRAME_X_P (f
))
508 XFlush (FRAME_X_DISPLAY (f
));
513 /* Remove calls to XFlush by defining XFlush to an empty replacement.
514 Calls to XFlush should be unnecessary because the X output buffer
515 is flushed automatically as needed by calls to XPending,
516 XNextEvent, or XWindowEvent according to the XFlush man page.
517 XTread_socket calls XPending. Removing XFlush improves
520 #define XFlush(DISPLAY) (void) 0
523 /***********************************************************************
525 ***********************************************************************/
529 /* This is a function useful for recording debugging information about
530 the sequence of occurrences in this file. */
538 struct record event_record
[100];
540 int event_record_index
;
542 record_event (locus
, type
)
546 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
547 event_record_index
= 0;
549 event_record
[event_record_index
].locus
= locus
;
550 event_record
[event_record_index
].type
= type
;
551 event_record_index
++;
558 /* Return the struct x_display_info corresponding to DPY. */
560 struct x_display_info
*
561 x_display_info_for_display (dpy
)
564 struct x_display_info
*dpyinfo
;
566 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
567 if (dpyinfo
->display
== dpy
)
575 /***********************************************************************
576 Starting and ending an update
577 ***********************************************************************/
579 /* Start an update of frame F. This function is installed as a hook
580 for update_begin, i.e. it is called when update_begin is called.
581 This function is called prior to calls to x_update_window_begin for
582 each window being updated. Currently, there is nothing to do here
583 because all interesting stuff is done on a window basis. */
593 /* Start update of window W. Set the global variable updated_window
594 to the window being updated and set output_cursor to the cursor
598 x_update_window_begin (w
)
601 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
602 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
605 set_output_cursor (&w
->cursor
);
609 if (f
== display_info
->mouse_face_mouse_frame
)
611 /* Don't do highlighting for mouse motion during the update. */
612 display_info
->mouse_face_defer
= 1;
614 /* If F needs to be redrawn, simply forget about any prior mouse
616 if (FRAME_GARBAGED_P (f
))
617 display_info
->mouse_face_window
= Qnil
;
619 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
620 their mouse_face_p flag set, which means that they are always
621 unequal to rows in a desired matrix which never have that
622 flag set. So, rows containing mouse-face glyphs are never
623 scrolled, and we don't have to switch the mouse highlight off
624 here to prevent it from being scrolled. */
626 /* Can we tell that this update does not affect the window
627 where the mouse highlight is? If so, no need to turn off.
628 Likewise, don't do anything if the frame is garbaged;
629 in that case, the frame's current matrix that we would use
630 is all wrong, and we will redisplay that line anyway. */
631 if (!NILP (display_info
->mouse_face_window
)
632 && w
== XWINDOW (display_info
->mouse_face_window
))
636 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
637 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
640 if (i
< w
->desired_matrix
->nrows
)
641 clear_mouse_face (display_info
);
650 /* Draw a vertical window border to the right of window W if W doesn't
651 have vertical scroll bars. */
654 x_draw_vertical_border (w
)
657 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
659 /* Redraw borders between horizontally adjacent windows. Don't
660 do it for frames with vertical scroll bars because either the
661 right scroll bar of a window, or the left scroll bar of its
662 neighbor will suffice as a border. */
663 if (!WINDOW_RIGHTMOST_P (w
)
664 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
668 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
669 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
672 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
673 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
678 /* End update of window W (which is equal to updated_window).
680 Draw vertical borders between horizontally adjacent windows, and
681 display W's cursor if CURSOR_ON_P is non-zero.
683 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
684 glyphs in mouse-face were overwritten. In that case we have to
685 make sure that the mouse-highlight is properly redrawn.
687 W may be a menu bar pseudo-window in case we don't have X toolkit
688 support. Such windows don't have a cursor, so don't display it
692 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
694 int cursor_on_p
, mouse_face_overwritten_p
;
696 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
698 if (!w
->pseudo_window_p
)
703 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
705 output_cursor
.x
, output_cursor
.y
);
707 x_draw_vertical_border (w
);
711 /* If a row with mouse-face was overwritten, arrange for
712 XTframe_up_to_date to redisplay the mouse highlight. */
713 if (mouse_face_overwritten_p
)
715 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
716 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
717 dpyinfo
->mouse_face_window
= Qnil
;
720 updated_window
= NULL
;
724 /* End update of frame F. This function is installed as a hook in
731 /* Mouse highlight may be displayed again. */
732 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
735 XFlush (FRAME_X_DISPLAY (f
));
740 /* This function is called from various places in xdisp.c whenever a
741 complete update has been performed. The global variable
742 updated_window is not available here. */
745 XTframe_up_to_date (f
)
750 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
752 if (dpyinfo
->mouse_face_deferred_gc
753 || f
== dpyinfo
->mouse_face_mouse_frame
)
756 if (dpyinfo
->mouse_face_mouse_frame
)
757 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
758 dpyinfo
->mouse_face_mouse_x
,
759 dpyinfo
->mouse_face_mouse_y
);
760 dpyinfo
->mouse_face_deferred_gc
= 0;
767 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
768 arrow bitmaps, or clear the areas where they would be displayed
769 before DESIRED_ROW is made current. The window being updated is
770 found in updated_window. This function It is called from
771 update_window_line only if it is known that there are differences
772 between bitmaps to be drawn between current row and DESIRED_ROW. */
775 x_after_update_window_line (desired_row
)
776 struct glyph_row
*desired_row
;
778 struct window
*w
= updated_window
;
782 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
788 x_draw_row_bitmaps (w
, desired_row
);
790 /* When a window has disappeared, make sure that no rest of
791 full-width rows stays visible in the internal border. */
792 if (windows_or_buffers_changed
793 && (f
= XFRAME (w
->frame
),
794 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
797 int height
= desired_row
->visible_height
;
798 int x
= (window_box_right (w
, -1)
799 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
800 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
802 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
803 x
, y
, width
, height
, False
);
811 /* Draw the bitmap WHICH in one of the areas to the left or right of
812 window W. ROW is the glyph row for which to display the bitmap; it
813 determines the vertical position at which the bitmap has to be
817 x_draw_bitmap (w
, row
, which
)
819 struct glyph_row
*row
;
820 enum bitmap_type which
;
822 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
823 Display
*display
= FRAME_X_DISPLAY (f
);
824 Window window
= FRAME_X_WINDOW (f
);
828 GC gc
= f
->output_data
.x
->normal_gc
;
830 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
832 /* Must clip because of partially visible lines. */
833 x_clip_to_row (w
, row
, gc
, 1);
837 case LEFT_TRUNCATION_BITMAP
:
841 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
843 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
846 case OVERLAY_ARROW_BITMAP
:
850 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
852 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
855 case RIGHT_TRUNCATION_BITMAP
:
859 x
= window_box_right (w
, -1);
860 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
863 case CONTINUED_LINE_BITMAP
:
866 bits
= continued_bits
;
867 x
= window_box_right (w
, -1);
868 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
871 case CONTINUATION_LINE_BITMAP
:
872 wd
= continuation_width
;
873 h
= continuation_height
;
874 bits
= continuation_bits
;
875 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
877 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
884 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
886 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
893 /* Convert to frame coordinates. Set dy to the offset in the row to
894 start drawing the bitmap. */
895 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
896 dy
= (row
->height
- h
) / 2;
898 /* Draw the bitmap. I believe these small pixmaps can be cached
900 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
901 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
903 face
->background
, depth
);
904 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
905 XFreePixmap (display
, pixmap
);
906 XSetClipMask (display
, gc
, None
);
910 /* Draw flags bitmaps for glyph row ROW on window W. Call this
911 function with input blocked. */
914 x_draw_row_bitmaps (w
, row
)
916 struct glyph_row
*row
;
918 struct frame
*f
= XFRAME (w
->frame
);
919 enum bitmap_type bitmap
;
921 int header_line_height
= -1;
923 xassert (interrupt_input_blocked
);
925 /* If row is completely invisible, because of vscrolling, we
926 don't have to draw anything. */
927 if (row
->visible_height
<= 0)
930 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
931 PREPARE_FACE_FOR_DISPLAY (f
, face
);
933 /* Decide which bitmap to draw at the left side. */
934 if (row
->overlay_arrow_p
)
935 bitmap
= OVERLAY_ARROW_BITMAP
;
936 else if (row
->truncated_on_left_p
)
937 bitmap
= LEFT_TRUNCATION_BITMAP
;
938 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
939 bitmap
= CONTINUATION_LINE_BITMAP
;
940 else if (row
->indicate_empty_line_p
)
941 bitmap
= ZV_LINE_BITMAP
;
945 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
947 if (bitmap
== NO_BITMAP
948 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
949 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
951 /* If W has a vertical border to its left, don't draw over it. */
952 int border
= ((XFASTINT (w
->left
) > 0
953 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
955 int left
= window_box_left (w
, -1);
957 if (header_line_height
< 0)
958 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
960 /* In case the same realized face is used for bitmap areas and
961 for something displayed in the text (e.g. face `region' on
962 mono-displays, the fill style may have been changed to
963 FillSolid in x_draw_glyph_string_background. */
965 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
967 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
969 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
972 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
974 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
976 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
977 row
->visible_height
);
979 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
982 /* Draw the left bitmap. */
983 if (bitmap
!= NO_BITMAP
)
984 x_draw_bitmap (w
, row
, bitmap
);
986 /* Decide which bitmap to draw at the right side. */
987 if (row
->truncated_on_right_p
)
988 bitmap
= RIGHT_TRUNCATION_BITMAP
;
989 else if (row
->continued_p
)
990 bitmap
= CONTINUED_LINE_BITMAP
;
994 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
996 if (bitmap
== NO_BITMAP
997 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
998 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
1000 int right
= window_box_right (w
, -1);
1002 if (header_line_height
< 0)
1003 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1005 /* In case the same realized face is used for bitmap areas and
1006 for something displayed in the text (e.g. face `region' on
1007 mono-displays, the fill style may have been changed to
1008 FillSolid in x_draw_glyph_string_background. */
1010 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1012 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1013 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1016 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1018 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
1019 row
->visible_height
);
1021 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1024 /* Draw the right bitmap. */
1025 if (bitmap
!= NO_BITMAP
)
1026 x_draw_bitmap (w
, row
, bitmap
);
1030 /***********************************************************************
1032 ***********************************************************************/
1034 /* External interface to control of standout mode. Not used for X
1035 frames. Aborts when called. */
1038 XTreassert_line_highlight (new, vpos
)
1045 /* Call this when about to modify line at position VPOS and change
1046 whether it is highlighted. Not used for X frames. Aborts when
1050 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1051 int new_highlight
, vpos
, y
, first_unused_hpos
;
1057 /* This is called when starting Emacs and when restarting after
1058 suspend. When starting Emacs, no X window is mapped. And nothing
1059 must be done to Emacs's own window if it is suspended (though that
1063 XTset_terminal_modes ()
1067 /* This is called when exiting or suspending Emacs. Exiting will make
1068 the X-windows go away, and suspending requires no action. */
1071 XTreset_terminal_modes ()
1077 /***********************************************************************
1079 ***********************************************************************/
1081 /* Set the global variable output_cursor to CURSOR. All cursor
1082 positions are relative to updated_window. */
1085 set_output_cursor (cursor
)
1086 struct cursor_pos
*cursor
;
1088 output_cursor
.hpos
= cursor
->hpos
;
1089 output_cursor
.vpos
= cursor
->vpos
;
1090 output_cursor
.x
= cursor
->x
;
1091 output_cursor
.y
= cursor
->y
;
1095 /* Set a nominal cursor position.
1097 HPOS and VPOS are column/row positions in a window glyph matrix. X
1098 and Y are window text area relative pixel positions.
1100 If this is done during an update, updated_window will contain the
1101 window that is being updated and the position is the future output
1102 cursor position for that window. If updated_window is null, use
1103 selected_window and display the cursor at the given position. */
1106 XTcursor_to (vpos
, hpos
, y
, x
)
1107 int vpos
, hpos
, y
, x
;
1111 /* If updated_window is not set, work on selected_window. */
1115 w
= XWINDOW (selected_window
);
1117 /* Set the output cursor. */
1118 output_cursor
.hpos
= hpos
;
1119 output_cursor
.vpos
= vpos
;
1120 output_cursor
.x
= x
;
1121 output_cursor
.y
= y
;
1123 /* If not called as part of an update, really display the cursor.
1124 This will also set the cursor position of W. */
1125 if (updated_window
== NULL
)
1128 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1129 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1136 /***********************************************************************
1138 ***********************************************************************/
1140 /* Function prototypes of this page. */
1142 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1146 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1147 int, XChar2b
*, int));
1148 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1149 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1150 static void x_append_glyph
P_ ((struct it
*));
1151 static void x_append_composite_glyph
P_ ((struct it
*));
1152 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1154 static void x_produce_glyphs
P_ ((struct it
*));
1155 static void x_produce_image_glyph
P_ ((struct it
*it
));
1158 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1159 is not contained in the font. */
1161 static INLINE XCharStruct
*
1162 x_per_char_metric (font
, char2b
)
1166 /* The result metric information. */
1167 XCharStruct
*pcm
= NULL
;
1169 xassert (font
&& char2b
);
1171 if (font
->per_char
!= NULL
)
1173 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1175 /* min_char_or_byte2 specifies the linear character index
1176 corresponding to the first element of the per_char array,
1177 max_char_or_byte2 is the index of the last character. A
1178 character with non-zero CHAR2B->byte1 is not in the font.
1179 A character with byte2 less than min_char_or_byte2 or
1180 greater max_char_or_byte2 is not in the font. */
1181 if (char2b
->byte1
== 0
1182 && char2b
->byte2
>= font
->min_char_or_byte2
1183 && char2b
->byte2
<= font
->max_char_or_byte2
)
1184 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1188 /* If either min_byte1 or max_byte1 are nonzero, both
1189 min_char_or_byte2 and max_char_or_byte2 are less than
1190 256, and the 2-byte character index values corresponding
1191 to the per_char array element N (counting from 0) are:
1193 byte1 = N/D + min_byte1
1194 byte2 = N\D + min_char_or_byte2
1198 D = max_char_or_byte2 - min_char_or_byte2 + 1
1199 / = integer division
1200 \ = integer modulus */
1201 if (char2b
->byte1
>= font
->min_byte1
1202 && char2b
->byte1
<= font
->max_byte1
1203 && char2b
->byte2
>= font
->min_char_or_byte2
1204 && char2b
->byte2
<= font
->max_char_or_byte2
)
1206 pcm
= (font
->per_char
1207 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1208 * (char2b
->byte1
- font
->min_byte1
))
1209 + (char2b
->byte2
- font
->min_char_or_byte2
));
1215 /* If the per_char pointer is null, all glyphs between the first
1216 and last character indexes inclusive have the same
1217 information, as given by both min_bounds and max_bounds. */
1218 if (char2b
->byte2
>= font
->min_char_or_byte2
1219 && char2b
->byte2
<= font
->max_char_or_byte2
)
1220 pcm
= &font
->max_bounds
;
1223 return ((pcm
== NULL
1224 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1229 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1230 the two-byte form of C. Encoding is returned in *CHAR2B. */
1233 x_encode_char (c
, char2b
, font_info
)
1236 struct font_info
*font_info
;
1238 int charset
= CHAR_CHARSET (c
);
1239 XFontStruct
*font
= font_info
->font
;
1241 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1242 This may be either a program in a special encoder language or a
1244 if (font_info
->font_encoder
)
1246 /* It's a program. */
1247 struct ccl_program
*ccl
= font_info
->font_encoder
;
1249 if (CHARSET_DIMENSION (charset
) == 1)
1251 ccl
->reg
[0] = charset
;
1252 ccl
->reg
[1] = char2b
->byte2
;
1256 ccl
->reg
[0] = charset
;
1257 ccl
->reg
[1] = char2b
->byte1
;
1258 ccl
->reg
[2] = char2b
->byte2
;
1261 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1263 /* We assume that MSBs are appropriately set/reset by CCL
1265 if (font
->max_byte1
== 0) /* 1-byte font */
1266 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1268 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1270 else if (font_info
->encoding
[charset
])
1272 /* Fixed encoding scheme. See fontset.h for the meaning of the
1273 encoding numbers. */
1274 int enc
= font_info
->encoding
[charset
];
1276 if ((enc
== 1 || enc
== 2)
1277 && CHARSET_DIMENSION (charset
) == 2)
1278 char2b
->byte1
|= 0x80;
1280 if (enc
== 1 || enc
== 3)
1281 char2b
->byte2
|= 0x80;
1286 /* Get face and two-byte form of character C in face FACE_ID on frame
1287 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1288 means we want to display multibyte text. Value is a pointer to a
1289 realized face that is ready for display. */
1291 static INLINE
struct face
*
1292 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1298 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1302 /* Unibyte case. We don't have to encode, but we have to make
1303 sure to use a face suitable for unibyte. */
1306 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1307 face
= FACE_FROM_ID (f
, face_id
);
1309 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1311 /* Case of ASCII in a face known to fit ASCII. */
1317 int c1
, c2
, charset
;
1319 /* Split characters into bytes. If c2 is -1 afterwards, C is
1320 really a one-byte character so that byte1 is zero. */
1321 SPLIT_CHAR (c
, charset
, c1
, c2
);
1323 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1325 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1327 /* Maybe encode the character in *CHAR2B. */
1328 if (face
->font
!= NULL
)
1330 struct font_info
*font_info
1331 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1333 x_encode_char (c
, char2b
, font_info
);
1337 /* Make sure X resources of the face are allocated. */
1338 xassert (face
!= NULL
);
1339 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1345 /* Get face and two-byte form of character glyph GLYPH on frame F.
1346 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1347 a pointer to a realized face that is ready for display. */
1349 static INLINE
struct face
*
1350 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1352 struct glyph
*glyph
;
1358 xassert (glyph
->type
== CHAR_GLYPH
);
1359 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1364 if (!glyph
->multibyte_p
)
1366 /* Unibyte case. We don't have to encode, but we have to make
1367 sure to use a face suitable for unibyte. */
1369 char2b
->byte2
= glyph
->u
.ch
;
1371 else if (glyph
->u
.ch
< 128
1372 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1374 /* Case of ASCII in a face known to fit ASCII. */
1376 char2b
->byte2
= glyph
->u
.ch
;
1380 int c1
, c2
, charset
;
1382 /* Split characters into bytes. If c2 is -1 afterwards, C is
1383 really a one-byte character so that byte1 is zero. */
1384 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1386 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1388 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1390 /* Maybe encode the character in *CHAR2B. */
1391 if (charset
!= CHARSET_ASCII
)
1393 struct font_info
*font_info
1394 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1397 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1400 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1405 /* Make sure X resources of the face are allocated. */
1406 xassert (face
!= NULL
);
1407 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1412 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1413 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1419 struct glyph
*glyph
;
1420 enum glyph_row_area area
= it
->area
;
1422 xassert (it
->glyph_row
);
1423 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1425 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1426 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1428 glyph
->charpos
= CHARPOS (it
->position
);
1429 glyph
->object
= it
->object
;
1430 glyph
->pixel_width
= it
->pixel_width
;
1431 glyph
->voffset
= it
->voffset
;
1432 glyph
->type
= CHAR_GLYPH
;
1433 glyph
->multibyte_p
= it
->multibyte_p
;
1434 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1435 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1436 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1437 || it
->phys_descent
> it
->descent
);
1438 glyph
->padding_p
= 0;
1439 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1440 glyph
->face_id
= it
->face_id
;
1441 glyph
->u
.ch
= it
->char_to_display
;
1442 ++it
->glyph_row
->used
[area
];
1446 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1447 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1450 x_append_composite_glyph (it
)
1453 struct glyph
*glyph
;
1454 enum glyph_row_area area
= it
->area
;
1456 xassert (it
->glyph_row
);
1458 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1459 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1461 glyph
->charpos
= CHARPOS (it
->position
);
1462 glyph
->object
= it
->object
;
1463 glyph
->pixel_width
= it
->pixel_width
;
1464 glyph
->voffset
= it
->voffset
;
1465 glyph
->type
= COMPOSITE_GLYPH
;
1466 glyph
->multibyte_p
= it
->multibyte_p
;
1467 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1468 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1469 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1470 || it
->phys_descent
> it
->descent
);
1471 glyph
->padding_p
= 0;
1472 glyph
->glyph_not_available_p
= 0;
1473 glyph
->face_id
= it
->face_id
;
1474 glyph
->u
.cmp_id
= it
->cmp_id
;
1475 ++it
->glyph_row
->used
[area
];
1480 /* Change IT->ascent and IT->height according to the setting of
1484 take_vertical_position_into_account (it
)
1489 if (it
->voffset
< 0)
1490 /* Increase the ascent so that we can display the text higher
1492 it
->ascent
+= abs (it
->voffset
);
1494 /* Increase the descent so that we can display the text lower
1496 it
->descent
+= it
->voffset
;
1501 /* Produce glyphs/get display metrics for the image IT is loaded with.
1502 See the description of struct display_iterator in dispextern.h for
1503 an overview of struct display_iterator. */
1506 x_produce_image_glyph (it
)
1512 xassert (it
->what
== IT_IMAGE
);
1514 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1515 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1518 /* Make sure X resources of the face and image are loaded. */
1519 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1520 prepare_image_for_display (it
->f
, img
);
1522 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1523 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1524 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1528 if (face
->box
!= FACE_NO_BOX
)
1530 if (face
->box_line_width
> 0)
1532 it
->ascent
+= face
->box_line_width
;
1533 it
->descent
+= face
->box_line_width
;
1536 if (it
->start_of_box_run_p
)
1537 it
->pixel_width
+= abs (face
->box_line_width
);
1538 if (it
->end_of_box_run_p
)
1539 it
->pixel_width
+= abs (face
->box_line_width
);
1542 take_vertical_position_into_account (it
);
1546 struct glyph
*glyph
;
1547 enum glyph_row_area area
= it
->area
;
1549 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1550 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1552 glyph
->charpos
= CHARPOS (it
->position
);
1553 glyph
->object
= it
->object
;
1554 glyph
->pixel_width
= it
->pixel_width
;
1555 glyph
->voffset
= it
->voffset
;
1556 glyph
->type
= IMAGE_GLYPH
;
1557 glyph
->multibyte_p
= it
->multibyte_p
;
1558 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1559 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1560 glyph
->overlaps_vertically_p
= 0;
1561 glyph
->padding_p
= 0;
1562 glyph
->glyph_not_available_p
= 0;
1563 glyph
->face_id
= it
->face_id
;
1564 glyph
->u
.img_id
= img
->id
;
1565 ++it
->glyph_row
->used
[area
];
1571 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1572 of the glyph, WIDTH and HEIGHT are the width and height of the
1573 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1574 ascent of the glyph (0 <= ASCENT <= 1). */
1577 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1583 struct glyph
*glyph
;
1584 enum glyph_row_area area
= it
->area
;
1586 xassert (ascent
>= 0 && ascent
<= 1);
1588 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1589 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1591 glyph
->charpos
= CHARPOS (it
->position
);
1592 glyph
->object
= object
;
1593 glyph
->pixel_width
= width
;
1594 glyph
->voffset
= it
->voffset
;
1595 glyph
->type
= STRETCH_GLYPH
;
1596 glyph
->multibyte_p
= it
->multibyte_p
;
1597 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1598 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1599 glyph
->overlaps_vertically_p
= 0;
1600 glyph
->padding_p
= 0;
1601 glyph
->glyph_not_available_p
= 0;
1602 glyph
->face_id
= it
->face_id
;
1603 glyph
->u
.stretch
.ascent
= height
* ascent
;
1604 glyph
->u
.stretch
.height
= height
;
1605 ++it
->glyph_row
->used
[area
];
1610 /* Produce a stretch glyph for iterator IT. IT->object is the value
1611 of the glyph property displayed. The value must be a list
1612 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1615 1. `:width WIDTH' specifies that the space should be WIDTH *
1616 canonical char width wide. WIDTH may be an integer or floating
1619 2. `:relative-width FACTOR' specifies that the width of the stretch
1620 should be computed from the width of the first character having the
1621 `glyph' property, and should be FACTOR times that width.
1623 3. `:align-to HPOS' specifies that the space should be wide enough
1624 to reach HPOS, a value in canonical character units.
1626 Exactly one of the above pairs must be present.
1628 4. `:height HEIGHT' specifies that the height of the stretch produced
1629 should be HEIGHT, measured in canonical character units.
1631 5. `:relative-height FACTOR' specifies that the height of the the
1632 stretch should be FACTOR times the height of the characters having
1635 Either none or exactly one of 4 or 5 must be present.
1637 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1638 of the stretch should be used for the ascent of the stretch.
1639 ASCENT must be in the range 0 <= ASCENT <= 100. */
1642 ((INTEGERP (X) || FLOATP (X)) \
1648 x_produce_stretch_glyph (it
)
1651 /* (space :width WIDTH :height HEIGHT. */
1653 extern Lisp_Object Qspace
;
1655 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1656 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1657 extern Lisp_Object QCalign_to
;
1658 Lisp_Object prop
, plist
;
1659 double width
= 0, height
= 0, ascent
= 0;
1660 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1661 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1663 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1665 /* List should start with `space'. */
1666 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1667 plist
= XCDR (it
->object
);
1669 /* Compute the width of the stretch. */
1670 if (prop
= Fplist_get (plist
, QCwidth
),
1672 /* Absolute width `:width WIDTH' specified and valid. */
1673 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1674 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1677 /* Relative width `:relative-width FACTOR' specified and valid.
1678 Compute the width of the characters having the `glyph'
1681 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1684 if (it
->multibyte_p
)
1686 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1687 - IT_BYTEPOS (*it
));
1688 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1691 it2
.c
= *p
, it2
.len
= 1;
1693 it2
.glyph_row
= NULL
;
1694 it2
.what
= IT_CHARACTER
;
1695 x_produce_glyphs (&it2
);
1696 width
= NUMVAL (prop
) * it2
.pixel_width
;
1698 else if (prop
= Fplist_get (plist
, QCalign_to
),
1700 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1702 /* Nothing specified -> width defaults to canonical char width. */
1703 width
= CANON_X_UNIT (it
->f
);
1705 /* Compute height. */
1706 if (prop
= Fplist_get (plist
, QCheight
),
1708 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1709 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1711 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1713 height
= FONT_HEIGHT (font
);
1715 /* Compute percentage of height used for ascent. If
1716 `:ascent ASCENT' is present and valid, use that. Otherwise,
1717 derive the ascent from the font in use. */
1718 if (prop
= Fplist_get (plist
, QCascent
),
1719 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1720 ascent
= NUMVAL (prop
) / 100.0;
1722 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1731 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1732 if (!STRINGP (object
))
1733 object
= it
->w
->buffer
;
1734 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1737 it
->pixel_width
= width
;
1738 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1739 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1742 if (face
->box
!= FACE_NO_BOX
)
1744 if (face
->box_line_width
> 0)
1746 it
->ascent
+= face
->box_line_width
;
1747 it
->descent
+= face
->box_line_width
;
1750 if (it
->start_of_box_run_p
)
1751 it
->pixel_width
+= abs (face
->box_line_width
);
1752 if (it
->end_of_box_run_p
)
1753 it
->pixel_width
+= abs (face
->box_line_width
);
1756 take_vertical_position_into_account (it
);
1759 /* Return proper value to be used as baseline offset of font that has
1760 ASCENT and DESCENT to draw characters by the font at the vertical
1761 center of the line of frame F.
1763 Here, out task is to find the value of BOFF in the following figure;
1765 -------------------------+-----------+-
1766 -+-+---------+-+ | |
1768 | | | | F_ASCENT F_HEIGHT
1771 | | |-|-+------+-----------|------- baseline
1773 | |---------|-+-+ | |
1775 -+-+---------+-+ F_DESCENT |
1776 -------------------------+-----------+-
1778 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1779 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1780 DESCENT = FONT->descent
1781 HEIGHT = FONT_HEIGHT (FONT)
1782 F_DESCENT = (F->output_data.x->font->descent
1783 - F->output_data.x->baseline_offset)
1784 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1787 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1789 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1790 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1791 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1793 /* Produce glyphs/get display metrics for the display element IT is
1794 loaded with. See the description of struct display_iterator in
1795 dispextern.h for an overview of struct display_iterator. */
1798 x_produce_glyphs (it
)
1801 it
->glyph_not_available_p
= 0;
1803 if (it
->what
== IT_CHARACTER
)
1807 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1809 int font_not_found_p
;
1810 struct font_info
*font_info
;
1811 int boff
; /* baseline offset */
1812 /* We may change it->multibyte_p upon unibyte<->multibyte
1813 conversion. So, save the current value now and restore it
1816 Note: It seems that we don't have to record multibyte_p in
1817 struct glyph because the character code itself tells if or
1818 not the character is multibyte. Thus, in the future, we must
1819 consider eliminating the field `multibyte_p' in the struct
1822 int saved_multibyte_p
= it
->multibyte_p
;
1824 /* Maybe translate single-byte characters to multibyte, or the
1826 it
->char_to_display
= it
->c
;
1827 if (!ASCII_BYTE_P (it
->c
))
1829 if (unibyte_display_via_language_environment
1830 && SINGLE_BYTE_CHAR_P (it
->c
)
1832 || !NILP (Vnonascii_translation_table
)))
1834 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1835 it
->multibyte_p
= 1;
1836 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1837 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1839 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1840 && !it
->multibyte_p
)
1842 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1843 it
->multibyte_p
= 0;
1844 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1845 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1849 /* Get font to use. Encode IT->char_to_display. */
1850 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1851 it
->face_id
, &char2b
,
1855 /* When no suitable font found, use the default font. */
1856 font_not_found_p
= font
== NULL
;
1857 if (font_not_found_p
)
1859 font
= FRAME_FONT (it
->f
);
1860 boff
= it
->f
->output_data
.x
->baseline_offset
;
1865 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1866 boff
= font_info
->baseline_offset
;
1867 if (font_info
->vertical_centering
)
1868 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1871 if (it
->char_to_display
>= ' '
1872 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1874 /* Either unibyte or ASCII. */
1879 pcm
= x_per_char_metric (font
, &char2b
);
1880 it
->ascent
= font
->ascent
+ boff
;
1881 it
->descent
= font
->descent
- boff
;
1885 it
->phys_ascent
= pcm
->ascent
+ boff
;
1886 it
->phys_descent
= pcm
->descent
- boff
;
1887 it
->pixel_width
= pcm
->width
;
1891 it
->glyph_not_available_p
= 1;
1892 it
->phys_ascent
= font
->ascent
+ boff
;
1893 it
->phys_descent
= font
->descent
- boff
;
1894 it
->pixel_width
= FONT_WIDTH (font
);
1897 /* If this is a space inside a region of text with
1898 `space-width' property, change its width. */
1899 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1901 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1903 /* If face has a box, add the box thickness to the character
1904 height. If character has a box line to the left and/or
1905 right, add the box line width to the character's width. */
1906 if (face
->box
!= FACE_NO_BOX
)
1908 int thick
= face
->box_line_width
;
1912 it
->ascent
+= thick
;
1913 it
->descent
+= thick
;
1918 if (it
->start_of_box_run_p
)
1919 it
->pixel_width
+= thick
;
1920 if (it
->end_of_box_run_p
)
1921 it
->pixel_width
+= thick
;
1924 /* If face has an overline, add the height of the overline
1925 (1 pixel) and a 1 pixel margin to the character height. */
1926 if (face
->overline_p
)
1929 take_vertical_position_into_account (it
);
1931 /* If we have to actually produce glyphs, do it. */
1936 /* Translate a space with a `space-width' property
1937 into a stretch glyph. */
1938 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1939 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1940 it
->ascent
+ it
->descent
, ascent
);
1943 x_append_glyph (it
);
1945 /* If characters with lbearing or rbearing are displayed
1946 in this line, record that fact in a flag of the
1947 glyph row. This is used to optimize X output code. */
1948 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1949 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1952 else if (it
->char_to_display
== '\n')
1954 /* A newline has no width but we need the height of the line. */
1955 it
->pixel_width
= 0;
1957 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1958 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1960 if (face
->box
!= FACE_NO_BOX
1961 && face
->box_line_width
> 0)
1963 it
->ascent
+= face
->box_line_width
;
1964 it
->descent
+= face
->box_line_width
;
1967 else if (it
->char_to_display
== '\t')
1969 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1970 int x
= it
->current_x
+ it
->continuation_lines_width
;
1971 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1973 /* If the distance from the current position to the next tab
1974 stop is less than a canonical character width, use the
1975 tab stop after that. */
1976 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1977 next_tab_x
+= tab_width
;
1979 it
->pixel_width
= next_tab_x
- x
;
1981 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1982 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1986 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1987 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1988 it
->ascent
+ it
->descent
, ascent
);
1993 /* A multi-byte character. Assume that the display width of the
1994 character is the width of the character multiplied by the
1995 width of the font. */
1997 /* If we found a font, this font should give us the right
1998 metrics. If we didn't find a font, use the frame's
1999 default font and calculate the width of the character
2000 from the charset width; this is what old redisplay code
2002 pcm
= x_per_char_metric (font
, &char2b
);
2003 if (font_not_found_p
|| !pcm
)
2005 int charset
= CHAR_CHARSET (it
->char_to_display
);
2007 it
->glyph_not_available_p
= 1;
2008 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2009 * CHARSET_WIDTH (charset
));
2010 it
->phys_ascent
= font
->ascent
+ boff
;
2011 it
->phys_descent
= font
->descent
- boff
;
2015 it
->pixel_width
= pcm
->width
;
2016 it
->phys_ascent
= pcm
->ascent
+ boff
;
2017 it
->phys_descent
= pcm
->descent
- boff
;
2019 && (pcm
->lbearing
< 0
2020 || pcm
->rbearing
> pcm
->width
))
2021 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2024 it
->ascent
= font
->ascent
+ boff
;
2025 it
->descent
= font
->descent
- boff
;
2026 if (face
->box
!= FACE_NO_BOX
)
2028 int thick
= face
->box_line_width
;
2032 it
->ascent
+= thick
;
2033 it
->descent
+= thick
;
2038 if (it
->start_of_box_run_p
)
2039 it
->pixel_width
+= thick
;
2040 if (it
->end_of_box_run_p
)
2041 it
->pixel_width
+= thick
;
2044 /* If face has an overline, add the height of the overline
2045 (1 pixel) and a 1 pixel margin to the character height. */
2046 if (face
->overline_p
)
2049 take_vertical_position_into_account (it
);
2052 x_append_glyph (it
);
2054 it
->multibyte_p
= saved_multibyte_p
;
2056 else if (it
->what
== IT_COMPOSITION
)
2058 /* Note: A composition is represented as one glyph in the
2059 glyph matrix. There are no padding glyphs. */
2062 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2064 int font_not_found_p
;
2065 struct font_info
*font_info
;
2066 int boff
; /* baseline offset */
2067 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2069 /* Maybe translate single-byte characters to multibyte. */
2070 it
->char_to_display
= it
->c
;
2071 if (unibyte_display_via_language_environment
2072 && SINGLE_BYTE_CHAR_P (it
->c
)
2075 && !NILP (Vnonascii_translation_table
))))
2077 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2080 /* Get face and font to use. Encode IT->char_to_display. */
2081 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2082 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2083 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2084 it
->face_id
, &char2b
, it
->multibyte_p
);
2087 /* When no suitable font found, use the default font. */
2088 font_not_found_p
= font
== NULL
;
2089 if (font_not_found_p
)
2091 font
= FRAME_FONT (it
->f
);
2092 boff
= it
->f
->output_data
.x
->baseline_offset
;
2097 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2098 boff
= font_info
->baseline_offset
;
2099 if (font_info
->vertical_centering
)
2100 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2103 /* There are no padding glyphs, so there is only one glyph to
2104 produce for the composition. Important is that pixel_width,
2105 ascent and descent are the values of what is drawn by
2106 draw_glyphs (i.e. the values of the overall glyphs composed). */
2109 /* If we have not yet calculated pixel size data of glyphs of
2110 the composition for the current face font, calculate them
2111 now. Theoretically, we have to check all fonts for the
2112 glyphs, but that requires much time and memory space. So,
2113 here we check only the font of the first glyph. This leads
2114 to incorrect display very rarely, and C-l (recenter) can
2115 correct the display anyway. */
2116 if (cmp
->font
!= (void *) font
)
2118 /* Ascent and descent of the font of the first character of
2119 this composition (adjusted by baseline offset). Ascent
2120 and descent of overall glyphs should not be less than
2121 them respectively. */
2122 int font_ascent
= font
->ascent
+ boff
;
2123 int font_descent
= font
->descent
- boff
;
2124 /* Bounding box of the overall glyphs. */
2125 int leftmost
, rightmost
, lowest
, highest
;
2126 int i
, width
, ascent
, descent
;
2128 cmp
->font
= (void *) font
;
2130 /* Initialize the bounding box. */
2132 && (pcm
= x_per_char_metric (font
, &char2b
)))
2135 ascent
= pcm
->ascent
;
2136 descent
= pcm
->descent
;
2140 width
= FONT_WIDTH (font
);
2141 ascent
= font
->ascent
;
2142 descent
= font
->descent
;
2146 lowest
= - descent
+ boff
;
2147 highest
= ascent
+ boff
;
2151 && font_info
->default_ascent
2152 && CHAR_TABLE_P (Vuse_default_ascent
)
2153 && !NILP (Faref (Vuse_default_ascent
,
2154 make_number (it
->char_to_display
))))
2155 highest
= font_info
->default_ascent
+ boff
;
2157 /* Draw the first glyph at the normal position. It may be
2158 shifted to right later if some other glyphs are drawn at
2160 cmp
->offsets
[0] = 0;
2161 cmp
->offsets
[1] = boff
;
2163 /* Set cmp->offsets for the remaining glyphs. */
2164 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2166 int left
, right
, btm
, top
;
2167 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2168 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2170 face
= FACE_FROM_ID (it
->f
, face_id
);
2171 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2176 font
= FRAME_FONT (it
->f
);
2177 boff
= it
->f
->output_data
.x
->baseline_offset
;
2183 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2184 boff
= font_info
->baseline_offset
;
2185 if (font_info
->vertical_centering
)
2186 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2190 && (pcm
= x_per_char_metric (font
, &char2b
)))
2193 ascent
= pcm
->ascent
;
2194 descent
= pcm
->descent
;
2198 width
= FONT_WIDTH (font
);
2203 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2205 /* Relative composition with or without
2207 left
= (leftmost
+ rightmost
- width
) / 2;
2208 btm
= - descent
+ boff
;
2209 if (font_info
&& font_info
->relative_compose
2210 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2211 || NILP (Faref (Vignore_relative_composition
,
2212 make_number (ch
)))))
2215 if (- descent
>= font_info
->relative_compose
)
2216 /* One extra pixel between two glyphs. */
2218 else if (ascent
<= 0)
2219 /* One extra pixel between two glyphs. */
2220 btm
= lowest
- 1 - ascent
- descent
;
2225 /* A composition rule is specified by an integer
2226 value that encodes global and new reference
2227 points (GREF and NREF). GREF and NREF are
2228 specified by numbers as below:
2236 ---3---4---5--- baseline
2238 6---7---8 -- descent
2240 int rule
= COMPOSITION_RULE (cmp
, i
);
2241 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2243 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2244 grefx
= gref
% 3, nrefx
= nref
% 3;
2245 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2248 + grefx
* (rightmost
- leftmost
) / 2
2249 - nrefx
* width
/ 2);
2250 btm
= ((grefy
== 0 ? highest
2252 : grefy
== 2 ? lowest
2253 : (highest
+ lowest
) / 2)
2254 - (nrefy
== 0 ? ascent
+ descent
2255 : nrefy
== 1 ? descent
- boff
2257 : (ascent
+ descent
) / 2));
2260 cmp
->offsets
[i
* 2] = left
;
2261 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2263 /* Update the bounding box of the overall glyphs. */
2264 right
= left
+ width
;
2265 top
= btm
+ descent
+ ascent
;
2266 if (left
< leftmost
)
2268 if (right
> rightmost
)
2276 /* If there are glyphs whose x-offsets are negative,
2277 shift all glyphs to the right and make all x-offsets
2281 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2282 cmp
->offsets
[i
* 2] -= leftmost
;
2283 rightmost
-= leftmost
;
2286 cmp
->pixel_width
= rightmost
;
2287 cmp
->ascent
= highest
;
2288 cmp
->descent
= - lowest
;
2289 if (cmp
->ascent
< font_ascent
)
2290 cmp
->ascent
= font_ascent
;
2291 if (cmp
->descent
< font_descent
)
2292 cmp
->descent
= font_descent
;
2295 it
->pixel_width
= cmp
->pixel_width
;
2296 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2297 it
->descent
= it
->phys_descent
= cmp
->descent
;
2299 if (face
->box
!= FACE_NO_BOX
)
2301 int thick
= face
->box_line_width
;
2305 it
->ascent
+= thick
;
2306 it
->descent
+= thick
;
2311 if (it
->start_of_box_run_p
)
2312 it
->pixel_width
+= thick
;
2313 if (it
->end_of_box_run_p
)
2314 it
->pixel_width
+= thick
;
2317 /* If face has an overline, add the height of the overline
2318 (1 pixel) and a 1 pixel margin to the character height. */
2319 if (face
->overline_p
)
2322 take_vertical_position_into_account (it
);
2325 x_append_composite_glyph (it
);
2327 else if (it
->what
== IT_IMAGE
)
2328 x_produce_image_glyph (it
);
2329 else if (it
->what
== IT_STRETCH
)
2330 x_produce_stretch_glyph (it
);
2332 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2333 because this isn't true for images with `:ascent 100'. */
2334 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2335 if (it
->area
== TEXT_AREA
)
2336 it
->current_x
+= it
->pixel_width
;
2338 it
->descent
+= it
->extra_line_spacing
;
2340 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2341 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2342 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2343 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2347 /* Estimate the pixel height of the mode or top line on frame F.
2348 FACE_ID specifies what line's height to estimate. */
2351 x_estimate_mode_line_height (f
, face_id
)
2353 enum face_id face_id
;
2355 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2357 /* This function is called so early when Emacs starts that the face
2358 cache and mode line face are not yet initialized. */
2359 if (FRAME_FACE_CACHE (f
))
2361 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2365 height
= FONT_HEIGHT (face
->font
);
2366 if (face
->box_line_width
> 0)
2367 height
+= 2 * face
->box_line_width
;
2375 /***********************************************************************
2377 ***********************************************************************/
2379 /* A sequence of glyphs to be drawn in the same face.
2381 This data structure is not really completely X specific, so it
2382 could possibly, at least partially, be useful for other systems. It
2383 is currently not part of the external redisplay interface because
2384 it's not clear what other systems will need. */
2388 /* X-origin of the string. */
2391 /* Y-origin and y-position of the base line of this string. */
2394 /* The width of the string, not including a face extension. */
2397 /* The width of the string, including a face extension. */
2398 int background_width
;
2400 /* The height of this string. This is the height of the line this
2401 string is drawn in, and can be different from the height of the
2402 font the string is drawn in. */
2405 /* Number of pixels this string overwrites in front of its x-origin.
2406 This number is zero if the string has an lbearing >= 0; it is
2407 -lbearing, if the string has an lbearing < 0. */
2410 /* Number of pixels this string overwrites past its right-most
2411 nominal x-position, i.e. x + width. Zero if the string's
2412 rbearing is <= its nominal width, rbearing - width otherwise. */
2415 /* The frame on which the glyph string is drawn. */
2418 /* The window on which the glyph string is drawn. */
2421 /* X display and window for convenience. */
2425 /* The glyph row for which this string was built. It determines the
2426 y-origin and height of the string. */
2427 struct glyph_row
*row
;
2429 /* The area within row. */
2430 enum glyph_row_area area
;
2432 /* Characters to be drawn, and number of characters. */
2436 /* A face-override for drawing cursors, mouse face and similar. */
2437 enum draw_glyphs_face hl
;
2439 /* Face in which this string is to be drawn. */
2442 /* Font in which this string is to be drawn. */
2445 /* Font info for this string. */
2446 struct font_info
*font_info
;
2448 /* Non-null means this string describes (part of) a composition.
2449 All characters from char2b are drawn composed. */
2450 struct composition
*cmp
;
2452 /* Index of this glyph string's first character in the glyph
2453 definition of CMP. If this is zero, this glyph string describes
2454 the first character of a composition. */
2457 /* 1 means this glyph strings face has to be drawn to the right end
2458 of the window's drawing area. */
2459 unsigned extends_to_end_of_line_p
: 1;
2461 /* 1 means the background of this string has been drawn. */
2462 unsigned background_filled_p
: 1;
2464 /* 1 means glyph string must be drawn with 16-bit functions. */
2465 unsigned two_byte_p
: 1;
2467 /* 1 means that the original font determined for drawing this glyph
2468 string could not be loaded. The member `font' has been set to
2469 the frame's default font in this case. */
2470 unsigned font_not_found_p
: 1;
2472 /* 1 means that the face in which this glyph string is drawn has a
2474 unsigned stippled_p
: 1;
2476 /* 1 means only the foreground of this glyph string must be drawn,
2477 and we should use the physical height of the line this glyph
2478 string appears in as clip rect. */
2479 unsigned for_overlaps_p
: 1;
2481 /* The GC to use for drawing this glyph string. */
2484 /* A pointer to the first glyph in the string. This glyph
2485 corresponds to char2b[0]. Needed to draw rectangles if
2486 font_not_found_p is 1. */
2487 struct glyph
*first_glyph
;
2489 /* Image, if any. */
2492 struct glyph_string
*next
, *prev
;
2499 x_dump_glyph_string (s
)
2500 struct glyph_string
*s
;
2502 fprintf (stderr
, "glyph string\n");
2503 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2504 s
->x
, s
->y
, s
->width
, s
->height
);
2505 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2506 fprintf (stderr
, " hl = %d\n", s
->hl
);
2507 fprintf (stderr
, " left overhang = %d, right = %d\n",
2508 s
->left_overhang
, s
->right_overhang
);
2509 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2510 fprintf (stderr
, " extends to end of line = %d\n",
2511 s
->extends_to_end_of_line_p
);
2512 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2513 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2516 #endif /* GLYPH_DEBUG */
2520 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2521 struct glyph_string
**,
2522 struct glyph_string
*,
2523 struct glyph_string
*));
2524 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2525 struct glyph_string
**,
2526 struct glyph_string
*,
2527 struct glyph_string
*));
2528 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2529 struct glyph_string
**,
2530 struct glyph_string
*));
2531 static int x_left_overwritten
P_ ((struct glyph_string
*));
2532 static int x_left_overwriting
P_ ((struct glyph_string
*));
2533 static int x_right_overwritten
P_ ((struct glyph_string
*));
2534 static int x_right_overwriting
P_ ((struct glyph_string
*));
2535 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2537 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2538 XChar2b
*, struct window
*,
2540 enum glyph_row_area
, int,
2541 enum draw_glyphs_face
));
2542 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2543 enum glyph_row_area
, int, int,
2544 enum draw_glyphs_face
, int *, int *, int));
2545 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2546 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2547 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2549 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2550 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2551 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2552 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2553 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2554 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2555 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2556 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2557 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2559 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2560 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2561 unsigned long *, double, int));
2562 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2563 double, int, unsigned long));
2564 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2565 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2566 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2567 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2568 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2569 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2570 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2572 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2573 int, int, int, int, XRectangle
*));
2574 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2575 int, int, int, XRectangle
*));
2576 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2577 enum glyph_row_area
));
2578 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2580 enum glyph_row_area
, int, int));
2583 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2587 /* Append the list of glyph strings with head H and tail T to the list
2588 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2591 x_append_glyph_string_lists (head
, tail
, h
, t
)
2592 struct glyph_string
**head
, **tail
;
2593 struct glyph_string
*h
, *t
;
2607 /* Prepend the list of glyph strings with head H and tail T to the
2608 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2612 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2613 struct glyph_string
**head
, **tail
;
2614 struct glyph_string
*h
, *t
;
2628 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2629 Set *HEAD and *TAIL to the resulting list. */
2632 x_append_glyph_string (head
, tail
, s
)
2633 struct glyph_string
**head
, **tail
;
2634 struct glyph_string
*s
;
2636 s
->next
= s
->prev
= NULL
;
2637 x_append_glyph_string_lists (head
, tail
, s
, s
);
2641 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2646 struct glyph_string
*s
;
2648 if (s
->font
== FRAME_FONT (s
->f
)
2649 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2650 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2652 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2655 /* Cursor on non-default face: must merge. */
2659 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2660 xgcv
.foreground
= s
->face
->background
;
2662 /* If the glyph would be invisible, try a different foreground. */
2663 if (xgcv
.foreground
== xgcv
.background
)
2664 xgcv
.foreground
= s
->face
->foreground
;
2665 if (xgcv
.foreground
== xgcv
.background
)
2666 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2667 if (xgcv
.foreground
== xgcv
.background
)
2668 xgcv
.foreground
= s
->face
->foreground
;
2670 /* Make sure the cursor is distinct from text in this face. */
2671 if (xgcv
.background
== s
->face
->background
2672 && xgcv
.foreground
== s
->face
->foreground
)
2674 xgcv
.background
= s
->face
->foreground
;
2675 xgcv
.foreground
= s
->face
->background
;
2678 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2679 xgcv
.font
= s
->font
->fid
;
2680 xgcv
.graphics_exposures
= False
;
2681 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2683 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2684 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2687 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2688 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2690 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2695 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2698 x_set_mouse_face_gc (s
)
2699 struct glyph_string
*s
;
2704 /* What face has to be used last for the mouse face? */
2705 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2706 face
= FACE_FROM_ID (s
->f
, face_id
);
2708 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2710 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2711 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2713 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2714 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2715 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2717 /* If font in this face is same as S->font, use it. */
2718 if (s
->font
== s
->face
->font
)
2719 s
->gc
= s
->face
->gc
;
2722 /* Otherwise construct scratch_cursor_gc with values from FACE
2727 xgcv
.background
= s
->face
->background
;
2728 xgcv
.foreground
= s
->face
->foreground
;
2729 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2730 xgcv
.font
= s
->font
->fid
;
2731 xgcv
.graphics_exposures
= False
;
2732 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2734 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2735 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2738 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2739 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2741 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2744 xassert (s
->gc
!= 0);
2748 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2749 Faces to use in the mode line have already been computed when the
2750 matrix was built, so there isn't much to do, here. */
2753 x_set_mode_line_face_gc (s
)
2754 struct glyph_string
*s
;
2756 s
->gc
= s
->face
->gc
;
2760 /* Set S->gc of glyph string S for drawing that glyph string. Set
2761 S->stippled_p to a non-zero value if the face of S has a stipple
2765 x_set_glyph_string_gc (s
)
2766 struct glyph_string
*s
;
2768 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2770 if (s
->hl
== DRAW_NORMAL_TEXT
)
2772 s
->gc
= s
->face
->gc
;
2773 s
->stippled_p
= s
->face
->stipple
!= 0;
2775 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2777 x_set_mode_line_face_gc (s
);
2778 s
->stippled_p
= s
->face
->stipple
!= 0;
2780 else if (s
->hl
== DRAW_CURSOR
)
2782 x_set_cursor_gc (s
);
2785 else if (s
->hl
== DRAW_MOUSE_FACE
)
2787 x_set_mouse_face_gc (s
);
2788 s
->stippled_p
= s
->face
->stipple
!= 0;
2790 else if (s
->hl
== DRAW_IMAGE_RAISED
2791 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2793 s
->gc
= s
->face
->gc
;
2794 s
->stippled_p
= s
->face
->stipple
!= 0;
2798 s
->gc
= s
->face
->gc
;
2799 s
->stippled_p
= s
->face
->stipple
!= 0;
2802 /* GC must have been set. */
2803 xassert (s
->gc
!= 0);
2807 /* Return in *R the clipping rectangle for glyph string S. */
2810 x_get_glyph_string_clip_rect (s
, r
)
2811 struct glyph_string
*s
;
2814 if (s
->row
->full_width_p
)
2816 /* Draw full-width. X coordinates are relative to S->w->left. */
2817 int canon_x
= CANON_X_UNIT (s
->f
);
2819 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2820 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2822 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2824 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2825 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2829 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2831 /* Unless displaying a mode or menu bar line, which are always
2832 fully visible, clip to the visible part of the row. */
2833 if (s
->w
->pseudo_window_p
)
2834 r
->height
= s
->row
->visible_height
;
2836 r
->height
= s
->height
;
2840 /* This is a text line that may be partially visible. */
2841 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2842 r
->width
= window_box_width (s
->w
, s
->area
);
2843 r
->height
= s
->row
->visible_height
;
2846 /* Don't use S->y for clipping because it doesn't take partially
2847 visible lines into account. For example, it can be negative for
2848 partially visible lines at the top of a window. */
2849 if (!s
->row
->full_width_p
2850 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2851 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2853 r
->y
= max (0, s
->row
->y
);
2855 /* If drawing a tool-bar window, draw it over the internal border
2856 at the top of the window. */
2857 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2858 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2860 /* If S draws overlapping rows, it's sufficient to use the top and
2861 bottom of the window for clipping because this glyph string
2862 intentionally draws over other lines. */
2863 if (s
->for_overlaps_p
)
2865 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2866 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2869 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2873 /* Set clipping for output of glyph string S. S may be part of a mode
2874 line or menu if we don't have X toolkit support. */
2877 x_set_glyph_string_clipping (s
)
2878 struct glyph_string
*s
;
2881 x_get_glyph_string_clip_rect (s
, &r
);
2882 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2886 /* Compute left and right overhang of glyph string S. If S is a glyph
2887 string for a composition, assume overhangs don't exist. */
2890 x_compute_glyph_string_overhangs (s
)
2891 struct glyph_string
*s
;
2894 && s
->first_glyph
->type
== CHAR_GLYPH
)
2897 int direction
, font_ascent
, font_descent
;
2898 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2899 &font_ascent
, &font_descent
, &cs
);
2900 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2901 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2906 /* Compute overhangs and x-positions for glyph string S and its
2907 predecessors, or successors. X is the starting x-position for S.
2908 BACKWARD_P non-zero means process predecessors. */
2911 x_compute_overhangs_and_x (s
, x
, backward_p
)
2912 struct glyph_string
*s
;
2920 x_compute_glyph_string_overhangs (s
);
2930 x_compute_glyph_string_overhangs (s
);
2939 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2940 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2941 assumed to be zero. */
2944 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2945 struct glyph
*glyph
;
2951 if (glyph
->type
== CHAR_GLYPH
)
2955 struct font_info
*font_info
;
2959 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2961 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2963 && (pcm
= x_per_char_metric (font
, &char2b
)))
2965 if (pcm
->rbearing
> pcm
->width
)
2966 *right
= pcm
->rbearing
- pcm
->width
;
2967 if (pcm
->lbearing
< 0)
2968 *left
= -pcm
->lbearing
;
2974 /* Return the index of the first glyph preceding glyph string S that
2975 is overwritten by S because of S's left overhang. Value is -1
2976 if no glyphs are overwritten. */
2979 x_left_overwritten (s
)
2980 struct glyph_string
*s
;
2984 if (s
->left_overhang
)
2987 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2988 int first
= s
->first_glyph
- glyphs
;
2990 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2991 x
-= glyphs
[i
].pixel_width
;
3002 /* Return the index of the first glyph preceding glyph string S that
3003 is overwriting S because of its right overhang. Value is -1 if no
3004 glyph in front of S overwrites S. */
3007 x_left_overwriting (s
)
3008 struct glyph_string
*s
;
3011 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3012 int first
= s
->first_glyph
- glyphs
;
3016 for (i
= first
- 1; i
>= 0; --i
)
3019 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3022 x
-= glyphs
[i
].pixel_width
;
3029 /* Return the index of the last glyph following glyph string S that is
3030 not overwritten by S because of S's right overhang. Value is -1 if
3031 no such glyph is found. */
3034 x_right_overwritten (s
)
3035 struct glyph_string
*s
;
3039 if (s
->right_overhang
)
3042 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3043 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3044 int end
= s
->row
->used
[s
->area
];
3046 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3047 x
+= glyphs
[i
].pixel_width
;
3056 /* Return the index of the last glyph following glyph string S that
3057 overwrites S because of its left overhang. Value is negative
3058 if no such glyph is found. */
3061 x_right_overwriting (s
)
3062 struct glyph_string
*s
;
3065 int end
= s
->row
->used
[s
->area
];
3066 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3067 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3071 for (i
= first
; i
< end
; ++i
)
3074 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3077 x
+= glyphs
[i
].pixel_width
;
3084 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3087 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3088 struct glyph_string
*s
;
3092 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3093 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3094 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3095 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3099 /* Draw the background of glyph_string S. If S->background_filled_p
3100 is non-zero don't draw it. FORCE_P non-zero means draw the
3101 background even if it wouldn't be drawn normally. This is used
3102 when a string preceding S draws into the background of S, or S
3103 contains the first component of a composition. */
3106 x_draw_glyph_string_background (s
, force_p
)
3107 struct glyph_string
*s
;
3110 /* Nothing to do if background has already been drawn or if it
3111 shouldn't be drawn in the first place. */
3112 if (!s
->background_filled_p
)
3114 int box_line_width
= max (s
->face
->box_line_width
, 0);
3118 /* Fill background with a stipple pattern. */
3119 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3120 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3121 s
->y
+ box_line_width
,
3122 s
->background_width
,
3123 s
->height
- 2 * box_line_width
);
3124 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3125 s
->background_filled_p
= 1;
3127 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3128 || s
->font_not_found_p
3129 || s
->extends_to_end_of_line_p
3132 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3133 s
->background_width
,
3134 s
->height
- 2 * box_line_width
);
3135 s
->background_filled_p
= 1;
3141 /* Draw the foreground of glyph string S. */
3144 x_draw_glyph_string_foreground (s
)
3145 struct glyph_string
*s
;
3149 /* If first glyph of S has a left box line, start drawing the text
3150 of S to the right of that box line. */
3151 if (s
->face
->box
!= FACE_NO_BOX
3152 && s
->first_glyph
->left_box_line_p
)
3153 x
= s
->x
+ abs (s
->face
->box_line_width
);
3157 /* Draw characters of S as rectangles if S's font could not be
3159 if (s
->font_not_found_p
)
3161 for (i
= 0; i
< s
->nchars
; ++i
)
3163 struct glyph
*g
= s
->first_glyph
+ i
;
3164 XDrawRectangle (s
->display
, s
->window
,
3165 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3167 x
+= g
->pixel_width
;
3172 char *char1b
= (char *) s
->char2b
;
3173 int boff
= s
->font_info
->baseline_offset
;
3175 if (s
->font_info
->vertical_centering
)
3176 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3178 /* If we can use 8-bit functions, condense S->char2b. */
3180 for (i
= 0; i
< s
->nchars
; ++i
)
3181 char1b
[i
] = s
->char2b
[i
].byte2
;
3183 /* Draw text with XDrawString if background has already been
3184 filled. Otherwise, use XDrawImageString. (Note that
3185 XDrawImageString is usually faster than XDrawString.) Always
3186 use XDrawImageString when drawing the cursor so that there is
3187 no chance that characters under a box cursor are invisible. */
3188 if (s
->for_overlaps_p
3189 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3191 /* Draw characters with 16-bit or 8-bit functions. */
3193 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3194 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3196 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3197 s
->ybase
- boff
, char1b
, s
->nchars
);
3202 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3203 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3205 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3206 s
->ybase
- boff
, char1b
, s
->nchars
);
3211 /* Draw the foreground of composite glyph string S. */
3214 x_draw_composite_glyph_string_foreground (s
)
3215 struct glyph_string
*s
;
3219 /* If first glyph of S has a left box line, start drawing the text
3220 of S to the right of that box line. */
3221 if (s
->face
->box
!= FACE_NO_BOX
3222 && s
->first_glyph
->left_box_line_p
)
3223 x
= s
->x
+ abs (s
->face
->box_line_width
);
3227 /* S is a glyph string for a composition. S->gidx is the index of
3228 the first character drawn for glyphs of this composition.
3229 S->gidx == 0 means we are drawing the very first character of
3230 this composition. */
3232 /* Draw a rectangle for the composition if the font for the very
3233 first character of the composition could not be loaded. */
3234 if (s
->font_not_found_p
)
3237 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3238 s
->width
- 1, s
->height
- 1);
3242 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3243 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3244 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3245 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3251 #ifdef USE_X_TOOLKIT
3253 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3254 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3255 XrmValue
*, XrmValue
*, XtPointer
*));
3256 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3257 XrmValue
*, Cardinal
*));
3260 /* Return the frame on which widget WIDGET is used.. Abort if frame
3261 cannot be determined. */
3263 static struct frame
*
3264 x_frame_of_widget (widget
)
3267 struct x_display_info
*dpyinfo
;
3271 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3273 /* Find the top-level shell of the widget. Note that this function
3274 can be called when the widget is not yet realized, so XtWindow
3275 (widget) == 0. That's the reason we can't simply use
3276 x_any_window_to_frame. */
3277 while (!XtIsTopLevelShell (widget
))
3278 widget
= XtParent (widget
);
3280 /* Look for a frame with that top-level widget. Allocate the color
3281 on that frame to get the right gamma correction value. */
3282 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3283 if (GC_FRAMEP (XCAR (tail
))
3284 && (f
= XFRAME (XCAR (tail
)),
3285 (f
->output_data
.nothing
!= 1
3286 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3287 && f
->output_data
.x
->widget
== widget
)
3294 /* Allocate the color COLOR->pixel on the screen and display of
3295 widget WIDGET in colormap CMAP. If an exact match cannot be
3296 allocated, try the nearest color available. Value is non-zero
3297 if successful. This is called from lwlib. */
3300 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3305 struct frame
*f
= x_frame_of_widget (widget
);
3306 return x_alloc_nearest_color (f
, cmap
, color
);
3310 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3311 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3312 If this produces the same color as PIXEL, try a color where all RGB
3313 values have DELTA added. Return the allocated color in *PIXEL.
3314 DISPLAY is the X display, CMAP is the colormap to operate on.
3315 Value is non-zero if successful. */
3318 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3322 unsigned long *pixel
;
3326 struct frame
*f
= x_frame_of_widget (widget
);
3327 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3331 /* Structure specifying which arguments should be passed by Xt to
3332 cvt_string_to_pixel. We want the widget's screen and colormap. */
3334 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3336 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3338 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3343 /* The address of this variable is returned by
3344 cvt_string_to_pixel. */
3346 static Pixel cvt_string_to_pixel_value
;
3349 /* Convert a color name to a pixel color.
3351 DPY is the display we are working on.
3353 ARGS is an array of *NARGS XrmValue structures holding additional
3354 information about the widget for which the conversion takes place.
3355 The contents of this array are determined by the specification
3356 in cvt_string_to_pixel_args.
3358 FROM is a pointer to an XrmValue which points to the color name to
3359 convert. TO is an XrmValue in which to return the pixel color.
3361 CLOSURE_RET is a pointer to user-data, in which we record if
3362 we allocated the color or not.
3364 Value is True if successful, False otherwise. */
3367 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3371 XrmValue
*from
, *to
;
3372 XtPointer
*closure_ret
;
3382 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3383 "wrongParameters", "cvt_string_to_pixel",
3385 "Screen and colormap args required", NULL
, NULL
);
3389 screen
= *(Screen
**) args
[0].addr
;
3390 cmap
= *(Colormap
*) args
[1].addr
;
3391 color_name
= (String
) from
->addr
;
3393 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3395 *closure_ret
= (XtPointer
) False
;
3396 pixel
= WhitePixelOfScreen (screen
);
3398 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3400 *closure_ret
= (XtPointer
) False
;
3401 pixel
= BlackPixelOfScreen (screen
);
3403 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3404 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3406 pixel
= color
.pixel
;
3407 *closure_ret
= (XtPointer
) True
;
3412 Cardinal nparams
= 1;
3414 params
[0] = color_name
;
3415 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3416 "badValue", "cvt_string_to_pixel",
3417 "XtToolkitError", "Invalid color `%s'",
3422 if (to
->addr
!= NULL
)
3424 if (to
->size
< sizeof (Pixel
))
3426 to
->size
= sizeof (Pixel
);
3430 *(Pixel
*) to
->addr
= pixel
;
3434 cvt_string_to_pixel_value
= pixel
;
3435 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3438 to
->size
= sizeof (Pixel
);
3443 /* Free a pixel color which was previously allocated via
3444 cvt_string_to_pixel. This is registered as the destructor
3445 for this type of resource via XtSetTypeConverter.
3447 APP is the application context in which we work.
3449 TO is a pointer to an XrmValue holding the color to free.
3450 CLOSURE is the value we stored in CLOSURE_RET for this color
3451 in cvt_string_to_pixel.
3453 ARGS and NARGS are like for cvt_string_to_pixel. */
3456 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3465 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3467 "Screen and colormap arguments required",
3470 else if (closure
!= NULL
)
3472 /* We did allocate the pixel, so free it. */
3473 Screen
*screen
= *(Screen
**) args
[0].addr
;
3474 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3475 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3476 (Pixel
*) to
->addr
, 1, 0);
3481 #endif /* USE_X_TOOLKIT */
3484 /* Value is an array of XColor structures for the contents of the
3485 color map of display DPY. Set *NCELLS to the size of the array.
3486 Note that this probably shouldn't be called for large color maps,
3487 say a 24-bit TrueColor map. */
3489 static const XColor
*
3490 x_color_cells (dpy
, ncells
)
3494 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3496 if (dpyinfo
->color_cells
== NULL
)
3498 Screen
*screen
= dpyinfo
->screen
;
3501 dpyinfo
->ncolor_cells
3502 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3503 dpyinfo
->color_cells
3504 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3505 * sizeof *dpyinfo
->color_cells
);
3507 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3508 dpyinfo
->color_cells
[i
].pixel
= i
;
3510 XQueryColors (dpy
, dpyinfo
->cmap
,
3511 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3514 *ncells
= dpyinfo
->ncolor_cells
;
3515 return dpyinfo
->color_cells
;
3519 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3520 colors in COLORS. Use cached information, if available. */
3523 x_query_colors (f
, colors
, ncolors
)
3528 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3530 if (dpyinfo
->color_cells
)
3533 for (i
= 0; i
< ncolors
; ++i
)
3535 unsigned long pixel
= colors
[i
].pixel
;
3536 xassert (pixel
< dpyinfo
->ncolor_cells
);
3537 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3538 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3542 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3546 /* On frame F, translate pixel color to RGB values for the color in
3547 COLOR. Use cached information, if available. */
3550 x_query_color (f
, color
)
3554 x_query_colors (f
, color
, 1);
3558 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3559 exact match can't be allocated, try the nearest color available.
3560 Value is non-zero if successful. Set *COLOR to the color
3564 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3571 rc
= XAllocColor (dpy
, cmap
, color
);
3574 /* If we got to this point, the colormap is full, so we're going
3575 to try to get the next closest color. The algorithm used is
3576 a least-squares matching, which is what X uses for closest
3577 color matching with StaticColor visuals. */
3579 unsigned long nearest_delta
= ~0;
3581 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3583 for (nearest
= i
= 0; i
< ncells
; ++i
)
3585 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3586 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3587 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3588 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3590 if (delta
< nearest_delta
)
3593 nearest_delta
= delta
;
3597 color
->red
= cells
[nearest
].red
;
3598 color
->green
= cells
[nearest
].green
;
3599 color
->blue
= cells
[nearest
].blue
;
3600 rc
= XAllocColor (dpy
, cmap
, color
);
3604 /* If allocation succeeded, and the allocated pixel color is not
3605 equal to a cached pixel color recorded earlier, there was a
3606 change in the colormap, so clear the color cache. */
3607 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3608 XColor
*cached_color
;
3610 if (dpyinfo
->color_cells
3611 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3612 (cached_color
->red
!= color
->red
3613 || cached_color
->blue
!= color
->blue
3614 || cached_color
->green
!= color
->green
)))
3616 xfree (dpyinfo
->color_cells
);
3617 dpyinfo
->color_cells
= NULL
;
3618 dpyinfo
->ncolor_cells
= 0;
3622 #ifdef DEBUG_X_COLORS
3624 register_color (color
->pixel
);
3625 #endif /* DEBUG_X_COLORS */
3631 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3632 exact match can't be allocated, try the nearest color available.
3633 Value is non-zero if successful. Set *COLOR to the color
3637 x_alloc_nearest_color (f
, cmap
, color
)
3642 gamma_correct (f
, color
);
3643 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3647 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3648 It's necessary to do this instead of just using PIXEL directly to
3649 get color reference counts right. */
3652 x_copy_color (f
, pixel
)
3654 unsigned long pixel
;
3658 color
.pixel
= pixel
;
3660 x_query_color (f
, &color
);
3661 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3663 #ifdef DEBUG_X_COLORS
3664 register_color (pixel
);
3670 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3671 It's necessary to do this instead of just using PIXEL directly to
3672 get color reference counts right. */
3675 x_copy_dpy_color (dpy
, cmap
, pixel
)
3678 unsigned long pixel
;
3682 color
.pixel
= pixel
;
3684 XQueryColor (dpy
, cmap
, &color
);
3685 XAllocColor (dpy
, cmap
, &color
);
3687 #ifdef DEBUG_X_COLORS
3688 register_color (pixel
);
3694 /* Brightness beyond which a color won't have its highlight brightness
3697 Nominally, highlight colors for `3d' faces are calculated by
3698 brightening an object's color by a constant scale factor, but this
3699 doesn't yield good results for dark colors, so for colors who's
3700 brightness is less than this value (on a scale of 0-65535) have an
3701 use an additional additive factor.
3703 The value here is set so that the default menu-bar/mode-line color
3704 (grey75) will not have its highlights changed at all. */
3705 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3708 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3709 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3710 If this produces the same color as PIXEL, try a color where all RGB
3711 values have DELTA added. Return the allocated color in *PIXEL.
3712 DISPLAY is the X display, CMAP is the colormap to operate on.
3713 Value is non-zero if successful. */
3716 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3720 unsigned long *pixel
;
3728 /* Get RGB color values. */
3729 color
.pixel
= *pixel
;
3730 x_query_color (f
, &color
);
3732 /* Change RGB values by specified FACTOR. Avoid overflow! */
3733 xassert (factor
>= 0);
3734 new.red
= min (0xffff, factor
* color
.red
);
3735 new.green
= min (0xffff, factor
* color
.green
);
3736 new.blue
= min (0xffff, factor
* color
.blue
);
3738 /* Calculate brightness of COLOR. */
3739 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3741 /* We only boost colors that are darker than
3742 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3743 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3744 /* Make an additive adjustment to NEW, because it's dark enough so
3745 that scaling by FACTOR alone isn't enough. */
3747 /* How far below the limit this color is (0 - 1, 1 being darker). */
3748 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3749 /* The additive adjustment. */
3750 int min_delta
= delta
* dimness
* factor
/ 2;
3754 new.red
= max (0, new.red
- min_delta
);
3755 new.green
= max (0, new.green
- min_delta
);
3756 new.blue
= max (0, new.blue
- min_delta
);
3760 new.red
= min (0xffff, min_delta
+ new.red
);
3761 new.green
= min (0xffff, min_delta
+ new.green
);
3762 new.blue
= min (0xffff, min_delta
+ new.blue
);
3766 /* Try to allocate the color. */
3767 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3770 if (new.pixel
== *pixel
)
3772 /* If we end up with the same color as before, try adding
3773 delta to the RGB values. */
3774 x_free_colors (f
, &new.pixel
, 1);
3776 new.red
= min (0xffff, delta
+ color
.red
);
3777 new.green
= min (0xffff, delta
+ color
.green
);
3778 new.blue
= min (0xffff, delta
+ color
.blue
);
3779 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3790 /* Set up the foreground color for drawing relief lines of glyph
3791 string S. RELIEF is a pointer to a struct relief containing the GC
3792 with which lines will be drawn. Use a color that is FACTOR or
3793 DELTA lighter or darker than the relief's background which is found
3794 in S->f->output_data.x->relief_background. If such a color cannot
3795 be allocated, use DEFAULT_PIXEL, instead. */
3798 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3800 struct relief
*relief
;
3803 unsigned long default_pixel
;
3806 struct x_output
*di
= f
->output_data
.x
;
3807 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3808 unsigned long pixel
;
3809 unsigned long background
= di
->relief_background
;
3810 Colormap cmap
= FRAME_X_COLORMAP (f
);
3811 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3812 Display
*dpy
= FRAME_X_DISPLAY (f
);
3814 xgcv
.graphics_exposures
= False
;
3815 xgcv
.line_width
= 1;
3817 /* Free previously allocated color. The color cell will be reused
3818 when it has been freed as many times as it was allocated, so this
3819 doesn't affect faces using the same colors. */
3821 && relief
->allocated_p
)
3823 x_free_colors (f
, &relief
->pixel
, 1);
3824 relief
->allocated_p
= 0;
3827 /* Allocate new color. */
3828 xgcv
.foreground
= default_pixel
;
3830 if (dpyinfo
->n_planes
!= 1
3831 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3833 relief
->allocated_p
= 1;
3834 xgcv
.foreground
= relief
->pixel
= pixel
;
3837 if (relief
->gc
== 0)
3839 xgcv
.stipple
= dpyinfo
->gray
;
3841 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3844 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3848 /* Set up colors for the relief lines around glyph string S. */
3851 x_setup_relief_colors (s
)
3852 struct glyph_string
*s
;
3854 struct x_output
*di
= s
->f
->output_data
.x
;
3855 unsigned long color
;
3857 if (s
->face
->use_box_color_for_shadows_p
)
3858 color
= s
->face
->box_color
;
3863 /* Get the background color of the face. */
3864 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3865 color
= xgcv
.background
;
3868 if (di
->white_relief
.gc
== 0
3869 || color
!= di
->relief_background
)
3871 di
->relief_background
= color
;
3872 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3873 WHITE_PIX_DEFAULT (s
->f
));
3874 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3875 BLACK_PIX_DEFAULT (s
->f
));
3880 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3881 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3882 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3883 relief. LEFT_P non-zero means draw a relief on the left side of
3884 the rectangle. RIGHT_P non-zero means draw a relief on the right
3885 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3889 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3890 raised_p
, left_p
, right_p
, clip_rect
)
3892 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3893 XRectangle
*clip_rect
;
3899 gc
= f
->output_data
.x
->white_relief
.gc
;
3901 gc
= f
->output_data
.x
->black_relief
.gc
;
3902 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3905 for (i
= 0; i
< width
; ++i
)
3906 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3907 left_x
+ i
* left_p
, top_y
+ i
,
3908 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3912 for (i
= 0; i
< width
; ++i
)
3913 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3914 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3916 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3918 gc
= f
->output_data
.x
->black_relief
.gc
;
3920 gc
= f
->output_data
.x
->white_relief
.gc
;
3921 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3924 for (i
= 0; i
< width
; ++i
)
3925 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3926 left_x
+ i
* left_p
+ 1, bottom_y
- i
,
3927 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3931 for (i
= 0; i
< width
; ++i
)
3932 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3933 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3935 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3939 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3940 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3941 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3942 left side of the rectangle. RIGHT_P non-zero means draw a line
3943 on the right side of the rectangle. CLIP_RECT is the clipping
3944 rectangle to use when drawing. */
3947 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3948 left_p
, right_p
, clip_rect
)
3949 struct glyph_string
*s
;
3950 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3951 XRectangle
*clip_rect
;
3955 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3956 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3957 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3960 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3961 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3965 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3966 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3969 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3970 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3974 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3975 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3977 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3978 XSetClipMask (s
->display
, s
->gc
, None
);
3982 /* Draw a box around glyph string S. */
3985 x_draw_glyph_string_box (s
)
3986 struct glyph_string
*s
;
3988 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3989 int left_p
, right_p
;
3990 struct glyph
*last_glyph
;
3991 XRectangle clip_rect
;
3993 last_x
= window_box_right (s
->w
, s
->area
);
3994 if (s
->row
->full_width_p
3995 && !s
->w
->pseudo_window_p
)
3997 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3998 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3999 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
4002 /* The glyph that may have a right box line. */
4003 last_glyph
= (s
->cmp
|| s
->img
4005 : s
->first_glyph
+ s
->nchars
- 1);
4007 width
= abs (s
->face
->box_line_width
);
4008 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
4010 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
4012 : min (last_x
, s
->x
+ s
->background_width
) - 1);
4014 bottom_y
= top_y
+ s
->height
- 1;
4016 left_p
= (s
->first_glyph
->left_box_line_p
4017 || (s
->hl
== DRAW_MOUSE_FACE
4019 || s
->prev
->hl
!= s
->hl
)));
4020 right_p
= (last_glyph
->right_box_line_p
4021 || (s
->hl
== DRAW_MOUSE_FACE
4023 || s
->next
->hl
!= s
->hl
)));
4025 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4027 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4028 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4029 left_p
, right_p
, &clip_rect
);
4032 x_setup_relief_colors (s
);
4033 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4034 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4039 /* Draw foreground of image glyph string S. */
4042 x_draw_image_foreground (s
)
4043 struct glyph_string
*s
;
4046 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4048 /* If first glyph of S has a left box line, start drawing it to the
4049 right of that line. */
4050 if (s
->face
->box
!= FACE_NO_BOX
4051 && s
->first_glyph
->left_box_line_p
)
4052 x
= s
->x
+ abs (s
->face
->box_line_width
);
4056 /* If there is a margin around the image, adjust x- and y-position
4058 x
+= s
->img
->hmargin
;
4059 y
+= s
->img
->vmargin
;
4065 /* We can't set both a clip mask and use XSetClipRectangles
4066 because the latter also sets a clip mask. We also can't
4067 trust on the shape extension to be available
4068 (XShapeCombineRegion). So, compute the rectangle to draw
4070 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4073 XRectangle clip_rect
, image_rect
, r
;
4075 xgcv
.clip_mask
= s
->img
->mask
;
4076 xgcv
.clip_x_origin
= x
;
4077 xgcv
.clip_y_origin
= y
;
4078 xgcv
.function
= GXcopy
;
4079 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4081 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4084 image_rect
.width
= s
->img
->width
;
4085 image_rect
.height
= s
->img
->height
;
4086 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4087 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4088 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4092 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
4094 XRectangle clip_rect
, image_rect
, r
;
4096 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4099 image_rect
.width
= s
->img
->width
;
4100 image_rect
.height
= s
->img
->height
;
4101 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4102 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4103 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4105 /* When the image has a mask, we can expect that at
4106 least part of a mouse highlight or a block cursor will
4107 be visible. If the image doesn't have a mask, make
4108 a block cursor visible by drawing a rectangle around
4109 the image. I believe it's looking better if we do
4110 nothing here for mouse-face. */
4111 if (s
->hl
== DRAW_CURSOR
)
4112 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4113 s
->img
->width
- 1, s
->img
->height
- 1);
4117 /* Draw a rectangle if image could not be loaded. */
4118 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4119 s
->img
->width
- 1, s
->img
->height
- 1);
4123 /* Draw a relief around the image glyph string S. */
4126 x_draw_image_relief (s
)
4127 struct glyph_string
*s
;
4129 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4132 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4134 /* If first glyph of S has a left box line, start drawing it to the
4135 right of that line. */
4136 if (s
->face
->box
!= FACE_NO_BOX
4137 && s
->first_glyph
->left_box_line_p
)
4138 x
= s
->x
+ abs (s
->face
->box_line_width
);
4142 /* If there is a margin around the image, adjust x- and y-position
4144 x
+= s
->img
->hmargin
;
4145 y
+= s
->img
->vmargin
;
4147 if (s
->hl
== DRAW_IMAGE_SUNKEN
4148 || s
->hl
== DRAW_IMAGE_RAISED
)
4150 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
4151 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4155 thick
= abs (s
->img
->relief
);
4156 raised_p
= s
->img
->relief
> 0;
4161 x1
= x
+ s
->img
->width
+ thick
- 1;
4162 y1
= y
+ s
->img
->height
+ thick
- 1;
4164 x_setup_relief_colors (s
);
4165 x_get_glyph_string_clip_rect (s
, &r
);
4166 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4170 /* Draw the foreground of image glyph string S to PIXMAP. */
4173 x_draw_image_foreground_1 (s
, pixmap
)
4174 struct glyph_string
*s
;
4178 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4180 /* If first glyph of S has a left box line, start drawing it to the
4181 right of that line. */
4182 if (s
->face
->box
!= FACE_NO_BOX
4183 && s
->first_glyph
->left_box_line_p
)
4184 x
= abs (s
->face
->box_line_width
);
4188 /* If there is a margin around the image, adjust x- and y-position
4190 x
+= s
->img
->hmargin
;
4191 y
+= s
->img
->vmargin
;
4197 /* We can't set both a clip mask and use XSetClipRectangles
4198 because the latter also sets a clip mask. We also can't
4199 trust on the shape extension to be available
4200 (XShapeCombineRegion). So, compute the rectangle to draw
4202 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4206 xgcv
.clip_mask
= s
->img
->mask
;
4207 xgcv
.clip_x_origin
= x
;
4208 xgcv
.clip_y_origin
= y
;
4209 xgcv
.function
= GXcopy
;
4210 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4212 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4213 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4214 XSetClipMask (s
->display
, s
->gc
, None
);
4218 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4219 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4221 /* When the image has a mask, we can expect that at
4222 least part of a mouse highlight or a block cursor will
4223 be visible. If the image doesn't have a mask, make
4224 a block cursor visible by drawing a rectangle around
4225 the image. I believe it's looking better if we do
4226 nothing here for mouse-face. */
4227 if (s
->hl
== DRAW_CURSOR
)
4228 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4229 s
->img
->width
- 1, s
->img
->height
- 1);
4233 /* Draw a rectangle if image could not be loaded. */
4234 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4235 s
->img
->width
- 1, s
->img
->height
- 1);
4239 /* Draw part of the background of glyph string S. X, Y, W, and H
4240 give the rectangle to draw. */
4243 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4244 struct glyph_string
*s
;
4249 /* Fill background with a stipple pattern. */
4250 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4251 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4252 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4255 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4259 /* Draw image glyph string S.
4262 s->x +-------------------------
4265 | +-------------------------
4268 | | +-------------------
4274 x_draw_image_glyph_string (s
)
4275 struct glyph_string
*s
;
4278 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4279 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4281 Pixmap pixmap
= None
;
4283 height
= s
->height
- 2 * box_line_vwidth
;
4285 /* Fill background with face under the image. Do it only if row is
4286 taller than image or if image has a clip mask to reduce
4288 s
->stippled_p
= s
->face
->stipple
!= 0;
4289 if (height
> s
->img
->height
4293 || s
->img
->pixmap
== 0
4294 || s
->width
!= s
->background_width
)
4296 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4297 x
= s
->x
+ box_line_hwidth
;
4301 y
= s
->y
+ box_line_vwidth
;
4305 /* Create a pixmap as large as the glyph string. Fill it
4306 with the background color. Copy the image to it, using
4307 its mask. Copy the temporary pixmap to the display. */
4308 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4309 int depth
= DefaultDepthOfScreen (screen
);
4311 /* Create a pixmap as large as the glyph string. */
4312 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4313 s
->background_width
,
4316 /* Don't clip in the following because we're working on the
4318 XSetClipMask (s
->display
, s
->gc
, None
);
4320 /* Fill the pixmap with the background color/stipple. */
4323 /* Fill background with a stipple pattern. */
4324 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4325 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4326 0, 0, s
->background_width
, s
->height
);
4327 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4332 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4334 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4335 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4336 0, 0, s
->background_width
, s
->height
);
4337 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4341 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4343 s
->background_filled_p
= 1;
4346 /* Draw the foreground. */
4349 x_draw_image_foreground_1 (s
, pixmap
);
4350 x_set_glyph_string_clipping (s
);
4351 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4352 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4353 XFreePixmap (s
->display
, pixmap
);
4356 x_draw_image_foreground (s
);
4358 /* If we must draw a relief around the image, do it. */
4360 || s
->hl
== DRAW_IMAGE_RAISED
4361 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4362 x_draw_image_relief (s
);
4366 /* Draw stretch glyph string S. */
4369 x_draw_stretch_glyph_string (s
)
4370 struct glyph_string
*s
;
4372 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4373 s
->stippled_p
= s
->face
->stipple
!= 0;
4375 if (s
->hl
== DRAW_CURSOR
4376 && !x_stretch_cursor_p
)
4378 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4379 as wide as the stretch glyph. */
4380 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4383 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4385 /* Clear rest using the GC of the original non-cursor face. */
4386 if (width
< s
->background_width
)
4388 int x
= s
->x
+ width
, y
= s
->y
;
4389 int w
= s
->background_width
- width
, h
= s
->height
;
4393 if (s
->row
->mouse_face_p
4394 && cursor_in_mouse_face_p (s
->w
))
4396 x_set_mouse_face_gc (s
);
4402 x_get_glyph_string_clip_rect (s
, &r
);
4403 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4405 if (s
->face
->stipple
)
4407 /* Fill background with a stipple pattern. */
4408 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4409 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4410 XSetFillStyle (s
->display
, gc
, FillSolid
);
4415 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4416 XSetForeground (s
->display
, gc
, xgcv
.background
);
4417 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4418 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4422 else if (!s
->background_filled_p
)
4423 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4426 s
->background_filled_p
= 1;
4430 /* Draw glyph string S. */
4433 x_draw_glyph_string (s
)
4434 struct glyph_string
*s
;
4436 int relief_drawn_p
= 0;
4438 /* If S draws into the background of its successor, draw the
4439 background of the successor first so that S can draw into it.
4440 This makes S->next use XDrawString instead of XDrawImageString. */
4441 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4443 xassert (s
->next
->img
== NULL
);
4444 x_set_glyph_string_gc (s
->next
);
4445 x_set_glyph_string_clipping (s
->next
);
4446 x_draw_glyph_string_background (s
->next
, 1);
4449 /* Set up S->gc, set clipping and draw S. */
4450 x_set_glyph_string_gc (s
);
4451 x_set_glyph_string_clipping (s
);
4453 /* Draw relief (if any) in advance for char/composition so that the
4454 glyph string can be drawn over it. */
4455 if (!s
->for_overlaps_p
4456 && s
->face
->box
!= FACE_NO_BOX
4457 && (s
->first_glyph
->type
== CHAR_GLYPH
4458 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4461 x_draw_glyph_string_background (s
, 1);
4462 x_draw_glyph_string_box (s
);
4466 switch (s
->first_glyph
->type
)
4469 x_draw_image_glyph_string (s
);
4473 x_draw_stretch_glyph_string (s
);
4477 if (s
->for_overlaps_p
)
4478 s
->background_filled_p
= 1;
4480 x_draw_glyph_string_background (s
, 0);
4481 x_draw_glyph_string_foreground (s
);
4484 case COMPOSITE_GLYPH
:
4485 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4486 s
->background_filled_p
= 1;
4488 x_draw_glyph_string_background (s
, 1);
4489 x_draw_composite_glyph_string_foreground (s
);
4496 if (!s
->for_overlaps_p
)
4498 /* Draw underline. */
4499 if (s
->face
->underline_p
)
4501 unsigned long tem
, h
;
4504 /* Get the underline thickness. Default is 1 pixel. */
4505 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4508 /* Get the underline position. This is the recommended
4509 vertical offset in pixels from the baseline to the top of
4510 the underline. This is a signed value according to the
4511 specs, and its default is
4513 ROUND ((maximum descent) / 2), with
4514 ROUND(x) = floor (x + 0.5) */
4516 if (x_use_underline_position_properties
4517 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4518 y
= s
->ybase
+ (long) tem
;
4519 else if (s
->face
->font
)
4520 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4522 y
= s
->y
+ s
->height
- h
;
4524 if (s
->face
->underline_defaulted_p
)
4525 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4526 s
->x
, y
, s
->width
, h
);
4530 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4531 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4532 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4533 s
->x
, y
, s
->width
, h
);
4534 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4538 /* Draw overline. */
4539 if (s
->face
->overline_p
)
4541 unsigned long dy
= 0, h
= 1;
4543 if (s
->face
->overline_color_defaulted_p
)
4544 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4549 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4550 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4551 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4553 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4557 /* Draw strike-through. */
4558 if (s
->face
->strike_through_p
)
4560 unsigned long h
= 1;
4561 unsigned long dy
= (s
->height
- h
) / 2;
4563 if (s
->face
->strike_through_color_defaulted_p
)
4564 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4569 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4570 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4571 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4573 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4577 /* Draw relief if not yet drawn. */
4578 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4579 x_draw_glyph_string_box (s
);
4582 /* Reset clipping. */
4583 XSetClipMask (s
->display
, s
->gc
, None
);
4587 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4588 struct face
**, int));
4591 /* Fill glyph string S with composition components specified by S->cmp.
4593 FACES is an array of faces for all components of this composition.
4594 S->gidx is the index of the first component for S.
4595 OVERLAPS_P non-zero means S should draw the foreground only, and
4596 use its physical height for clipping.
4598 Value is the index of a component not in S. */
4601 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4602 struct glyph_string
*s
;
4603 struct face
**faces
;
4610 s
->for_overlaps_p
= overlaps_p
;
4612 s
->face
= faces
[s
->gidx
];
4613 s
->font
= s
->face
->font
;
4614 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4616 /* For all glyphs of this composition, starting at the offset
4617 S->gidx, until we reach the end of the definition or encounter a
4618 glyph that requires the different face, add it to S. */
4620 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4623 /* All glyph strings for the same composition has the same width,
4624 i.e. the width set for the first component of the composition. */
4626 s
->width
= s
->first_glyph
->pixel_width
;
4628 /* If the specified font could not be loaded, use the frame's
4629 default font, but record the fact that we couldn't load it in
4630 the glyph string so that we can draw rectangles for the
4631 characters of the glyph string. */
4632 if (s
->font
== NULL
)
4634 s
->font_not_found_p
= 1;
4635 s
->font
= FRAME_FONT (s
->f
);
4638 /* Adjust base line for subscript/superscript text. */
4639 s
->ybase
+= s
->first_glyph
->voffset
;
4641 xassert (s
->face
&& s
->face
->gc
);
4643 /* This glyph string must always be drawn with 16-bit functions. */
4646 return s
->gidx
+ s
->nchars
;
4650 /* Fill glyph string S from a sequence of character glyphs.
4652 FACE_ID is the face id of the string. START is the index of the
4653 first glyph to consider, END is the index of the last + 1.
4654 OVERLAPS_P non-zero means S should draw the foreground only, and
4655 use its physical height for clipping.
4657 Value is the index of the first glyph not in S. */
4660 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4661 struct glyph_string
*s
;
4663 int start
, end
, overlaps_p
;
4665 struct glyph
*glyph
, *last
;
4667 int glyph_not_available_p
;
4669 xassert (s
->f
== XFRAME (s
->w
->frame
));
4670 xassert (s
->nchars
== 0);
4671 xassert (start
>= 0 && end
> start
);
4673 s
->for_overlaps_p
= overlaps_p
,
4674 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4675 last
= s
->row
->glyphs
[s
->area
] + end
;
4676 voffset
= glyph
->voffset
;
4678 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4681 && glyph
->type
== CHAR_GLYPH
4682 && glyph
->voffset
== voffset
4683 /* Same face id implies same font, nowadays. */
4684 && glyph
->face_id
== face_id
4685 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4689 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4690 s
->char2b
+ s
->nchars
,
4692 s
->two_byte_p
= two_byte_p
;
4694 xassert (s
->nchars
<= end
- start
);
4695 s
->width
+= glyph
->pixel_width
;
4699 s
->font
= s
->face
->font
;
4700 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4702 /* If the specified font could not be loaded, use the frame's font,
4703 but record the fact that we couldn't load it in
4704 S->font_not_found_p so that we can draw rectangles for the
4705 characters of the glyph string. */
4706 if (s
->font
== NULL
|| glyph_not_available_p
)
4708 s
->font_not_found_p
= 1;
4709 s
->font
= FRAME_FONT (s
->f
);
4712 /* Adjust base line for subscript/superscript text. */
4713 s
->ybase
+= voffset
;
4715 xassert (s
->face
&& s
->face
->gc
);
4716 return glyph
- s
->row
->glyphs
[s
->area
];
4720 /* Fill glyph string S from image glyph S->first_glyph. */
4723 x_fill_image_glyph_string (s
)
4724 struct glyph_string
*s
;
4726 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4727 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4729 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4730 s
->font
= s
->face
->font
;
4731 s
->width
= s
->first_glyph
->pixel_width
;
4733 /* Adjust base line for subscript/superscript text. */
4734 s
->ybase
+= s
->first_glyph
->voffset
;
4738 /* Fill glyph string S from a sequence of stretch glyphs.
4740 ROW is the glyph row in which the glyphs are found, AREA is the
4741 area within the row. START is the index of the first glyph to
4742 consider, END is the index of the last + 1.
4744 Value is the index of the first glyph not in S. */
4747 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4748 struct glyph_string
*s
;
4749 struct glyph_row
*row
;
4750 enum glyph_row_area area
;
4753 struct glyph
*glyph
, *last
;
4754 int voffset
, face_id
;
4756 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4758 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4759 last
= s
->row
->glyphs
[s
->area
] + end
;
4760 face_id
= glyph
->face_id
;
4761 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4762 s
->font
= s
->face
->font
;
4763 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4764 s
->width
= glyph
->pixel_width
;
4765 voffset
= glyph
->voffset
;
4769 && glyph
->type
== STRETCH_GLYPH
4770 && glyph
->voffset
== voffset
4771 && glyph
->face_id
== face_id
);
4773 s
->width
+= glyph
->pixel_width
;
4775 /* Adjust base line for subscript/superscript text. */
4776 s
->ybase
+= voffset
;
4778 xassert (s
->face
&& s
->face
->gc
);
4779 return glyph
- s
->row
->glyphs
[s
->area
];
4783 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4784 of XChar2b structures for S; it can't be allocated in
4785 x_init_glyph_string because it must be allocated via `alloca'. W
4786 is the window on which S is drawn. ROW and AREA are the glyph row
4787 and area within the row from which S is constructed. START is the
4788 index of the first glyph structure covered by S. HL is a
4789 face-override for drawing S. */
4792 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4793 struct glyph_string
*s
;
4796 struct glyph_row
*row
;
4797 enum glyph_row_area area
;
4799 enum draw_glyphs_face hl
;
4801 bzero (s
, sizeof *s
);
4803 s
->f
= XFRAME (w
->frame
);
4804 s
->display
= FRAME_X_DISPLAY (s
->f
);
4805 s
->window
= FRAME_X_WINDOW (s
->f
);
4810 s
->first_glyph
= row
->glyphs
[area
] + start
;
4811 s
->height
= row
->height
;
4812 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4814 /* Display the internal border below the tool-bar window. */
4815 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4816 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4818 s
->ybase
= s
->y
+ row
->ascent
;
4822 /* Set background width of glyph string S. START is the index of the
4823 first glyph following S. LAST_X is the right-most x-position + 1
4824 in the drawing area. */
4827 x_set_glyph_string_background_width (s
, start
, last_x
)
4828 struct glyph_string
*s
;
4832 /* If the face of this glyph string has to be drawn to the end of
4833 the drawing area, set S->extends_to_end_of_line_p. */
4834 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4836 if (start
== s
->row
->used
[s
->area
]
4837 && s
->hl
== DRAW_NORMAL_TEXT
4838 && s
->area
== TEXT_AREA
4839 && (s
->row
->fill_line_p
4840 || s
->face
->background
!= default_face
->background
4841 || s
->face
->stipple
!= default_face
->stipple
))
4842 s
->extends_to_end_of_line_p
= 1;
4844 /* If S extends its face to the end of the line, set its
4845 background_width to the distance to the right edge of the drawing
4847 if (s
->extends_to_end_of_line_p
)
4848 s
->background_width
= last_x
- s
->x
+ 1;
4850 s
->background_width
= s
->width
;
4854 /* Add a glyph string for a stretch glyph to the list of strings
4855 between HEAD and TAIL. START is the index of the stretch glyph in
4856 row area AREA of glyph row ROW. END is the index of the last glyph
4857 in that glyph row area. X is the current output position assigned
4858 to the new glyph string constructed. HL overrides that face of the
4859 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4860 is the right-most x-position of the drawing area. */
4862 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4863 and below -- keep them on one line. */
4864 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4867 s = (struct glyph_string *) alloca (sizeof *s); \
4868 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4869 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4870 x_append_glyph_string (&HEAD, &TAIL, s); \
4876 /* Add a glyph string for an image glyph to the list of strings
4877 between HEAD and TAIL. START is the index of the image glyph in
4878 row area AREA of glyph row ROW. END is the index of the last glyph
4879 in that glyph row area. X is the current output position assigned
4880 to the new glyph string constructed. HL overrides that face of the
4881 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4882 is the right-most x-position of the drawing area. */
4884 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4887 s = (struct glyph_string *) alloca (sizeof *s); \
4888 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4889 x_fill_image_glyph_string (s); \
4890 x_append_glyph_string (&HEAD, &TAIL, s); \
4897 /* Add a glyph string for a sequence of character glyphs to the list
4898 of strings between HEAD and TAIL. START is the index of the first
4899 glyph in row area AREA of glyph row ROW that is part of the new
4900 glyph string. END is the index of the last glyph in that glyph row
4901 area. X is the current output position assigned to the new glyph
4902 string constructed. HL overrides that face of the glyph; e.g. it
4903 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4904 right-most x-position of the drawing area. */
4906 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4912 c = (ROW)->glyphs[AREA][START].u.ch; \
4913 face_id = (ROW)->glyphs[AREA][START].face_id; \
4915 s = (struct glyph_string *) alloca (sizeof *s); \
4916 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4917 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4918 x_append_glyph_string (&HEAD, &TAIL, s); \
4920 START = x_fill_glyph_string (s, face_id, START, END, \
4926 /* Add a glyph string for a composite sequence to the list of strings
4927 between HEAD and TAIL. START is the index of the first glyph in
4928 row area AREA of glyph row ROW that is part of the new glyph
4929 string. END is the index of the last glyph in that glyph row area.
4930 X is the current output position assigned to the new glyph string
4931 constructed. HL overrides that face of the glyph; e.g. it is
4932 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4933 x-position of the drawing area. */
4935 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4937 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4938 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4939 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4940 struct composition *cmp = composition_table[cmp_id]; \
4941 int glyph_len = cmp->glyph_len; \
4943 struct face **faces; \
4944 struct glyph_string *first_s = NULL; \
4947 base_face = base_face->ascii_face; \
4948 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4949 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4950 /* At first, fill in `char2b' and `faces'. */ \
4951 for (n = 0; n < glyph_len; n++) \
4953 int c = COMPOSITION_GLYPH (cmp, n); \
4954 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4955 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4956 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4957 this_face_id, char2b + n, 1); \
4960 /* Make glyph_strings for each glyph sequence that is drawable by \
4961 the same face, and append them to HEAD/TAIL. */ \
4962 for (n = 0; n < cmp->glyph_len;) \
4964 s = (struct glyph_string *) alloca (sizeof *s); \
4965 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4966 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4974 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4982 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4983 of AREA of glyph row ROW on window W between indices START and END.
4984 HL overrides the face for drawing glyph strings, e.g. it is
4985 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4986 x-positions of the drawing area.
4988 This is an ugly monster macro construct because we must use alloca
4989 to allocate glyph strings (because x_draw_glyphs can be called
4992 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4995 HEAD = TAIL = NULL; \
4996 while (START < END) \
4998 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4999 switch (first_glyph->type) \
5002 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
5003 TAIL, HL, X, LAST_X, \
5007 case COMPOSITE_GLYPH: \
5008 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
5009 HEAD, TAIL, HL, X, LAST_X,\
5013 case STRETCH_GLYPH: \
5014 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5015 HEAD, TAIL, HL, X, LAST_X); \
5019 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5020 TAIL, HL, X, LAST_X); \
5027 x_set_glyph_string_background_width (s, START, LAST_X); \
5034 /* Draw glyphs between START and END in AREA of ROW on window W,
5035 starting at x-position X. X is relative to AREA in W. HL is a
5036 face-override with the following meaning:
5038 DRAW_NORMAL_TEXT draw normally
5039 DRAW_CURSOR draw in cursor face
5040 DRAW_MOUSE_FACE draw in mouse face.
5041 DRAW_INVERSE_VIDEO draw in mode line face
5042 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5043 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5045 If REAL_START is non-null, return in *REAL_START the real starting
5046 position for display. This can be different from START in case
5047 overlapping glyphs must be displayed. If REAL_END is non-null,
5048 return in *REAL_END the real end position for display. This can be
5049 different from END in case overlapping glyphs must be displayed.
5051 If OVERLAPS_P is non-zero, draw only the foreground of characters
5052 and clip to the physical height of ROW.
5054 Value is the x-position reached, relative to AREA of W. */
5057 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
5061 struct glyph_row
*row
;
5062 enum glyph_row_area area
;
5064 enum draw_glyphs_face hl
;
5065 int *real_start
, *real_end
;
5068 struct glyph_string
*head
, *tail
;
5069 struct glyph_string
*s
;
5070 int last_x
, area_width
;
5074 /* Let's rather be paranoid than getting a SEGV. */
5075 end
= min (end
, row
->used
[area
]);
5076 start
= max (0, start
);
5077 start
= min (end
, start
);
5079 *real_start
= start
;
5083 /* Translate X to frame coordinates. Set last_x to the right
5084 end of the drawing area. */
5085 if (row
->full_width_p
)
5087 /* X is relative to the left edge of W, without scroll bars
5089 struct frame
*f
= XFRAME (w
->frame
);
5090 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
5091 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5094 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5095 last_x
= window_left_x
+ area_width
;
5097 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5099 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5100 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5106 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5107 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5111 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5112 area_width
= window_box_width (w
, area
);
5113 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5116 /* Build a doubly-linked list of glyph_string structures between
5117 head and tail from what we have to draw. Note that the macro
5118 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5119 the reason we use a separate variable `i'. */
5121 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5124 x_reached
= tail
->x
+ tail
->background_width
;
5128 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5129 the row, redraw some glyphs in front or following the glyph
5130 strings built above. */
5131 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5134 struct glyph_string
*h
, *t
;
5136 /* Compute overhangs for all glyph strings. */
5137 for (s
= head
; s
; s
= s
->next
)
5138 x_compute_glyph_string_overhangs (s
);
5140 /* Prepend glyph strings for glyphs in front of the first glyph
5141 string that are overwritten because of the first glyph
5142 string's left overhang. The background of all strings
5143 prepended must be drawn because the first glyph string
5145 i
= x_left_overwritten (head
);
5149 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5150 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5154 *real_start
= start
;
5155 x_compute_overhangs_and_x (t
, head
->x
, 1);
5156 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5159 /* Prepend glyph strings for glyphs in front of the first glyph
5160 string that overwrite that glyph string because of their
5161 right overhang. For these strings, only the foreground must
5162 be drawn, because it draws over the glyph string at `head'.
5163 The background must not be drawn because this would overwrite
5164 right overhangs of preceding glyphs for which no glyph
5166 i
= x_left_overwriting (head
);
5169 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5170 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5172 for (s
= h
; s
; s
= s
->next
)
5173 s
->background_filled_p
= 1;
5176 x_compute_overhangs_and_x (t
, head
->x
, 1);
5177 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5180 /* Append glyphs strings for glyphs following the last glyph
5181 string tail that are overwritten by tail. The background of
5182 these strings has to be drawn because tail's foreground draws
5184 i
= x_right_overwritten (tail
);
5187 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5188 DRAW_NORMAL_TEXT
, x
, last_x
,
5190 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5191 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5196 /* Append glyph strings for glyphs following the last glyph
5197 string tail that overwrite tail. The foreground of such
5198 glyphs has to be drawn because it writes into the background
5199 of tail. The background must not be drawn because it could
5200 paint over the foreground of following glyphs. */
5201 i
= x_right_overwriting (tail
);
5204 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5205 DRAW_NORMAL_TEXT
, x
, last_x
,
5207 for (s
= h
; s
; s
= s
->next
)
5208 s
->background_filled_p
= 1;
5209 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5210 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5216 /* Draw all strings. */
5217 for (s
= head
; s
; s
= s
->next
)
5218 x_draw_glyph_string (s
);
5220 /* Value is the x-position up to which drawn, relative to AREA of W.
5221 This doesn't include parts drawn because of overhangs. */
5222 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5223 if (!row
->full_width_p
)
5225 if (area
> LEFT_MARGIN_AREA
)
5226 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5227 if (area
> TEXT_AREA
)
5228 x_reached
-= window_box_width (w
, TEXT_AREA
);
5235 /* Fix the display of area AREA of overlapping row ROW in window W. */
5238 x_fix_overlapping_area (w
, row
, area
)
5240 struct glyph_row
*row
;
5241 enum glyph_row_area area
;
5247 if (area
== LEFT_MARGIN_AREA
)
5249 else if (area
== TEXT_AREA
)
5250 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5252 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5253 + window_box_width (w
, TEXT_AREA
));
5255 for (i
= 0; i
< row
->used
[area
];)
5257 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5259 int start
= i
, start_x
= x
;
5263 x
+= row
->glyphs
[area
][i
].pixel_width
;
5266 while (i
< row
->used
[area
]
5267 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5269 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5271 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5276 x
+= row
->glyphs
[area
][i
].pixel_width
;
5285 /* Output LEN glyphs starting at START at the nominal cursor position.
5286 Advance the nominal cursor over the text. The global variable
5287 updated_window contains the window being updated, updated_row is
5288 the glyph row being updated, and updated_area is the area of that
5289 row being updated. */
5292 x_write_glyphs (start
, len
)
5293 struct glyph
*start
;
5296 int x
, hpos
, real_start
, real_end
;
5298 xassert (updated_window
&& updated_row
);
5303 hpos
= start
- updated_row
->glyphs
[updated_area
];
5304 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5305 updated_row
, updated_area
,
5307 (updated_row
->inverse_p
5308 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5309 &real_start
, &real_end
, 0);
5311 /* If we drew over the cursor, note that it is not visible any more. */
5312 note_overwritten_text_cursor (updated_window
, real_start
,
5313 real_end
- real_start
);
5317 /* Advance the output cursor. */
5318 output_cursor
.hpos
+= len
;
5319 output_cursor
.x
= x
;
5323 /* Insert LEN glyphs from START at the nominal cursor position. */
5326 x_insert_glyphs (start
, len
)
5327 struct glyph
*start
;
5332 int line_height
, shift_by_width
, shifted_region_width
;
5333 struct glyph_row
*row
;
5334 struct glyph
*glyph
;
5335 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
5337 xassert (updated_window
&& updated_row
);
5340 f
= XFRAME (WINDOW_FRAME (w
));
5342 /* Get the height of the line we are in. */
5344 line_height
= row
->height
;
5346 /* Get the width of the glyphs to insert. */
5348 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5349 shift_by_width
+= glyph
->pixel_width
;
5351 /* Get the width of the region to shift right. */
5352 shifted_region_width
= (window_box_width (w
, updated_area
)
5357 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5358 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5359 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5360 f
->output_data
.x
->normal_gc
,
5362 shifted_region_width
, line_height
,
5363 frame_x
+ shift_by_width
, frame_y
);
5365 /* Write the glyphs. */
5366 hpos
= start
- row
->glyphs
[updated_area
];
5367 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5368 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
5369 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5371 /* Advance the output cursor. */
5372 output_cursor
.hpos
+= len
;
5373 output_cursor
.x
+= shift_by_width
;
5378 /* Delete N glyphs at the nominal cursor position. Not implemented
5389 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5390 If they are <= 0, this is probably an error. */
5393 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5400 xassert (width
> 0 && height
> 0);
5401 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5405 /* Erase the current text line from the nominal cursor position
5406 (inclusive) to pixel column TO_X (exclusive). The idea is that
5407 everything from TO_X onward is already erased.
5409 TO_X is a pixel position relative to updated_area of
5410 updated_window. TO_X == -1 means clear to the end of this area. */
5413 x_clear_end_of_line (to_x
)
5417 struct window
*w
= updated_window
;
5418 int max_x
, min_y
, max_y
;
5419 int from_x
, from_y
, to_y
;
5421 xassert (updated_window
&& updated_row
);
5422 f
= XFRAME (w
->frame
);
5424 if (updated_row
->full_width_p
)
5426 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5427 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5428 && !w
->pseudo_window_p
)
5429 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5432 max_x
= window_box_width (w
, updated_area
);
5433 max_y
= window_text_bottom_y (w
);
5435 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5436 of window. For TO_X > 0, truncate to end of drawing area. */
5442 to_x
= min (to_x
, max_x
);
5444 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5446 /* Notice if the cursor will be cleared by this operation. */
5447 if (!updated_row
->full_width_p
)
5448 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5450 from_x
= output_cursor
.x
;
5452 /* Translate to frame coordinates. */
5453 if (updated_row
->full_width_p
)
5455 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5456 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5460 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5461 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5464 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5465 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5466 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5468 /* Prevent inadvertently clearing to end of the X window. */
5469 if (to_x
> from_x
&& to_y
> from_y
)
5472 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5473 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5480 /* Clear entire frame. If updating_frame is non-null, clear that
5481 frame. Otherwise clear the selected frame. */
5491 f
= SELECTED_FRAME ();
5493 /* Clearing the frame will erase any cursor, so mark them all as no
5495 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5496 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5497 output_cursor
.x
= -1;
5499 /* We don't set the output cursor here because there will always
5500 follow an explicit cursor_to. */
5502 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5504 /* We have to clear the scroll bars, too. If we have changed
5505 colors or something like that, then they should be notified. */
5506 x_scroll_bar_clear (f
);
5508 XFlush (FRAME_X_DISPLAY (f
));
5514 /* Invert the middle quarter of the frame for .15 sec. */
5516 /* We use the select system call to do the waiting, so we have to make
5517 sure it's available. If it isn't, we just won't do visual bells. */
5519 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5522 /* Subtract the `struct timeval' values X and Y, storing the result in
5523 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5526 timeval_subtract (result
, x
, y
)
5527 struct timeval
*result
, x
, y
;
5529 /* Perform the carry for the later subtraction by updating y. This
5530 is safer because on some systems the tv_sec member is unsigned. */
5531 if (x
.tv_usec
< y
.tv_usec
)
5533 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5534 y
.tv_usec
-= 1000000 * nsec
;
5538 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5540 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5541 y
.tv_usec
+= 1000000 * nsec
;
5545 /* Compute the time remaining to wait. tv_usec is certainly
5547 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5548 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5550 /* Return indication of whether the result should be considered
5552 return x
.tv_sec
< y
.tv_sec
;
5564 /* Create a GC that will use the GXxor function to flip foreground
5565 pixels into background pixels. */
5569 values
.function
= GXxor
;
5570 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5571 ^ f
->output_data
.x
->background_pixel
);
5573 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5574 GCFunction
| GCForeground
, &values
);
5578 /* Get the height not including a menu bar widget. */
5579 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5580 /* Height of each line to flash. */
5581 int flash_height
= FRAME_LINE_HEIGHT (f
);
5582 /* These will be the left and right margins of the rectangles. */
5583 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5584 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5588 /* Don't flash the area between a scroll bar and the frame
5589 edge it is next to. */
5590 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5592 case vertical_scroll_bar_left
:
5593 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5596 case vertical_scroll_bar_right
:
5597 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5604 width
= flash_right
- flash_left
;
5606 /* If window is tall, flash top and bottom line. */
5607 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5609 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5611 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5612 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5613 width
, flash_height
);
5614 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5616 (height
- flash_height
5617 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5618 width
, flash_height
);
5621 /* If it is short, flash it all. */
5622 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5623 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5624 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5629 struct timeval wakeup
;
5631 EMACS_GET_TIME (wakeup
);
5633 /* Compute time to wait until, propagating carry from usecs. */
5634 wakeup
.tv_usec
+= 150000;
5635 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5636 wakeup
.tv_usec
%= 1000000;
5638 /* Keep waiting until past the time wakeup or any input gets
5640 while (! detect_input_pending ())
5642 struct timeval current
;
5643 struct timeval timeout
;
5645 EMACS_GET_TIME (current
);
5647 /* Break if result would be negative. */
5648 if (timeval_subtract (¤t
, wakeup
, current
))
5651 /* How long `select' should wait. */
5653 timeout
.tv_usec
= 10000;
5655 /* Try to wait that long--but we might wake up sooner. */
5656 select (0, NULL
, NULL
, NULL
, &timeout
);
5660 /* If window is tall, flash top and bottom line. */
5661 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5663 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5665 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5666 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5667 width
, flash_height
);
5668 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5670 (height
- flash_height
5671 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5672 width
, flash_height
);
5675 /* If it is short, flash it all. */
5676 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5677 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5678 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5680 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5688 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5691 /* Make audible bell. */
5696 struct frame
*f
= SELECTED_FRAME ();
5698 if (FRAME_X_DISPLAY (f
))
5700 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5707 XBell (FRAME_X_DISPLAY (f
), 0);
5708 XFlush (FRAME_X_DISPLAY (f
));
5715 /* Specify how many text lines, from the top of the window,
5716 should be affected by insert-lines and delete-lines operations.
5717 This, and those operations, are used only within an update
5718 that is bounded by calls to x_update_begin and x_update_end. */
5721 XTset_terminal_window (n
)
5724 /* This function intentionally left blank. */
5729 /***********************************************************************
5731 ***********************************************************************/
5733 /* Perform an insert-lines or delete-lines operation, inserting N
5734 lines or deleting -N lines at vertical position VPOS. */
5737 x_ins_del_lines (vpos
, n
)
5744 /* Scroll part of the display as described by RUN. */
5747 x_scroll_run (w
, run
)
5751 struct frame
*f
= XFRAME (w
->frame
);
5752 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5754 /* Get frame-relative bounding box of the text display area of W,
5755 without mode lines. Include in this box the flags areas to the
5756 left and right of W. */
5757 window_box (w
, -1, &x
, &y
, &width
, &height
);
5758 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5759 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5761 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5762 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5763 bottom_y
= y
+ height
;
5767 /* Scrolling up. Make sure we don't copy part of the mode
5768 line at the bottom. */
5769 if (from_y
+ run
->height
> bottom_y
)
5770 height
= bottom_y
- from_y
;
5772 height
= run
->height
;
5776 /* Scolling down. Make sure we don't copy over the mode line.
5778 if (to_y
+ run
->height
> bottom_y
)
5779 height
= bottom_y
- to_y
;
5781 height
= run
->height
;
5786 /* Cursor off. Will be switched on again in x_update_window_end. */
5790 XCopyArea (FRAME_X_DISPLAY (f
),
5791 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5792 f
->output_data
.x
->normal_gc
,
5802 /***********************************************************************
5804 ***********************************************************************/
5806 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5807 corner of the exposed rectangle. W and H are width and height of
5808 the exposed area. All are pixel values. W or H zero means redraw
5809 the entire frame. */
5812 expose_frame (f
, x
, y
, w
, h
)
5818 TRACE ((stderr
, "expose_frame "));
5820 /* No need to redraw if frame will be redrawn soon. */
5821 if (FRAME_GARBAGED_P (f
))
5823 TRACE ((stderr
, " garbaged\n"));
5827 /* If basic faces haven't been realized yet, there is no point in
5828 trying to redraw anything. This can happen when we get an expose
5829 event while Emacs is starting, e.g. by moving another window. */
5830 if (FRAME_FACE_CACHE (f
) == NULL
5831 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5833 TRACE ((stderr
, " no faces\n"));
5837 if (w
== 0 || h
== 0)
5840 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5841 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5851 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5852 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5854 if (WINDOWP (f
->tool_bar_window
))
5855 expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5857 #ifndef USE_X_TOOLKIT
5858 if (WINDOWP (f
->menu_bar_window
))
5859 expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5860 #endif /* not USE_X_TOOLKIT */
5864 /* Redraw (parts) of all windows in the window tree rooted at W that
5865 intersect R. R contains frame pixel coordinates. */
5868 expose_window_tree (w
, r
)
5874 if (!NILP (w
->hchild
))
5875 expose_window_tree (XWINDOW (w
->hchild
), r
);
5876 else if (!NILP (w
->vchild
))
5877 expose_window_tree (XWINDOW (w
->vchild
), r
);
5878 else if (expose_window (w
, r
) == 0)
5880 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5885 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5886 which intersects rectangle R. R is in window-relative coordinates. */
5889 expose_area (w
, row
, r
, area
)
5891 struct glyph_row
*row
;
5893 enum glyph_row_area area
;
5895 struct glyph
*first
= row
->glyphs
[area
];
5896 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5898 int first_x
, start_x
, x
;
5900 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5901 /* If row extends face to end of line write the whole line. */
5902 x_draw_glyphs (w
, 0, row
, area
,
5904 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5908 /* Set START_X to the window-relative start position for drawing glyphs of
5909 AREA. The first glyph of the text area can be partially visible.
5910 The first glyphs of other areas cannot. */
5911 if (area
== LEFT_MARGIN_AREA
)
5913 else if (area
== TEXT_AREA
)
5914 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5916 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5917 + window_box_width (w
, TEXT_AREA
));
5920 /* Find the first glyph that must be redrawn. */
5922 && x
+ first
->pixel_width
< r
->x
)
5924 x
+= first
->pixel_width
;
5928 /* Find the last one. */
5932 && x
< r
->x
+ r
->width
)
5934 x
+= last
->pixel_width
;
5940 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5941 first
- row
->glyphs
[area
],
5942 last
- row
->glyphs
[area
],
5943 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5949 /* Redraw the parts of the glyph row ROW on window W intersecting
5950 rectangle R. R is in window-relative coordinates. */
5953 expose_line (w
, row
, r
)
5955 struct glyph_row
*row
;
5958 xassert (row
->enabled_p
);
5960 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5961 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5962 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5966 if (row
->used
[LEFT_MARGIN_AREA
])
5967 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5968 if (row
->used
[TEXT_AREA
])
5969 expose_area (w
, row
, r
, TEXT_AREA
);
5970 if (row
->used
[RIGHT_MARGIN_AREA
])
5971 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5972 x_draw_row_bitmaps (w
, row
);
5977 /* Return non-zero if W's cursor intersects rectangle R. */
5980 x_phys_cursor_in_rect_p (w
, r
)
5984 XRectangle cr
, result
;
5985 struct glyph
*cursor_glyph
;
5987 cursor_glyph
= get_phys_cursor_glyph (w
);
5990 cr
.x
= w
->phys_cursor
.x
;
5991 cr
.y
= w
->phys_cursor
.y
;
5992 cr
.width
= cursor_glyph
->pixel_width
;
5993 cr
.height
= w
->phys_cursor_height
;
5994 return x_intersect_rectangles (&cr
, r
, &result
);
6001 /* Redraw the part of window W intersection rectangle FR. Pixel
6002 coordinates in FR are frame-relative. Call this function with
6006 expose_window (w
, fr
)
6010 struct frame
*f
= XFRAME (w
->frame
);
6013 /* If window is not yet fully initialized, do nothing. This can
6014 happen when toolkit scroll bars are used and a window is split.
6015 Reconfiguring the scroll bar will generate an expose for a newly
6017 if (w
->current_matrix
== NULL
)
6020 /* When we're currently updating the window, display and current
6021 matrix usually don't agree. Arrange for a thorough display
6023 if (w
== updated_window
)
6025 SET_FRAME_GARBAGED (f
);
6029 /* Frame-relative pixel rectangle of W. */
6030 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6031 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6032 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6033 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6035 if (x_intersect_rectangles (fr
, &wr
, &r
))
6037 int yb
= window_text_bottom_y (w
);
6038 struct glyph_row
*row
;
6039 int cursor_cleared_p
;
6041 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6042 r
.x
, r
.y
, r
.width
, r
.height
));
6044 /* Convert to window coordinates. */
6045 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
6046 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
6048 /* Turn off the cursor. */
6049 if (!w
->pseudo_window_p
6050 && x_phys_cursor_in_rect_p (w
, &r
))
6053 cursor_cleared_p
= 1;
6056 cursor_cleared_p
= 0;
6058 /* Find the first row intersecting the rectangle R. */
6059 for (row
= w
->current_matrix
->rows
;
6064 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6066 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
6067 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
6068 || (r
.y
>= y0
&& r
.y
< y1
)
6069 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
6070 expose_line (w
, row
, &r
);
6076 /* Display the mode line if there is one. */
6077 if (WINDOW_WANTS_MODELINE_P (w
)
6078 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6080 && row
->y
< r
.y
+ r
.height
)
6081 expose_line (w
, row
, &r
);
6083 if (!w
->pseudo_window_p
)
6085 /* Draw border between windows. */
6086 x_draw_vertical_border (w
);
6088 /* Turn the cursor on again. */
6089 if (cursor_cleared_p
)
6090 x_update_window_cursor (w
, 1);
6098 /* Determine the intersection of two rectangles R1 and R2. Return
6099 the intersection in *RESULT. Value is non-zero if RESULT is not
6103 x_intersect_rectangles (r1
, r2
, result
)
6104 XRectangle
*r1
, *r2
, *result
;
6106 XRectangle
*left
, *right
;
6107 XRectangle
*upper
, *lower
;
6108 int intersection_p
= 0;
6110 /* Rearrange so that R1 is the left-most rectangle. */
6112 left
= r1
, right
= r2
;
6114 left
= r2
, right
= r1
;
6116 /* X0 of the intersection is right.x0, if this is inside R1,
6117 otherwise there is no intersection. */
6118 if (right
->x
<= left
->x
+ left
->width
)
6120 result
->x
= right
->x
;
6122 /* The right end of the intersection is the minimum of the
6123 the right ends of left and right. */
6124 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6127 /* Same game for Y. */
6129 upper
= r1
, lower
= r2
;
6131 upper
= r2
, lower
= r1
;
6133 /* The upper end of the intersection is lower.y0, if this is inside
6134 of upper. Otherwise, there is no intersection. */
6135 if (lower
->y
<= upper
->y
+ upper
->height
)
6137 result
->y
= lower
->y
;
6139 /* The lower end of the intersection is the minimum of the lower
6140 ends of upper and lower. */
6141 result
->height
= (min (lower
->y
+ lower
->height
,
6142 upper
->y
+ upper
->height
)
6148 return intersection_p
;
6159 /* We used to only do this if Vx_no_window_manager was non-nil, but
6160 the ICCCM (section 4.1.6) says that the window's border pixmap
6161 and border pixel are window attributes which are "private to the
6162 client", so we can always change it to whatever we want. */
6164 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6165 f
->output_data
.x
->border_pixel
);
6167 x_update_cursor (f
, 1);
6171 frame_unhighlight (f
)
6174 /* We used to only do this if Vx_no_window_manager was non-nil, but
6175 the ICCCM (section 4.1.6) says that the window's border pixmap
6176 and border pixel are window attributes which are "private to the
6177 client", so we can always change it to whatever we want. */
6179 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6180 f
->output_data
.x
->border_tile
);
6182 x_update_cursor (f
, 1);
6185 /* The focus has changed. Update the frames as necessary to reflect
6186 the new situation. Note that we can't change the selected frame
6187 here, because the Lisp code we are interrupting might become confused.
6188 Each event gets marked with the frame in which it occurred, so the
6189 Lisp code can tell when the switch took place by examining the events. */
6192 x_new_focus_frame (dpyinfo
, frame
)
6193 struct x_display_info
*dpyinfo
;
6194 struct frame
*frame
;
6196 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6198 if (frame
!= dpyinfo
->x_focus_frame
)
6200 /* Set this before calling other routines, so that they see
6201 the correct value of x_focus_frame. */
6202 dpyinfo
->x_focus_frame
= frame
;
6204 if (old_focus
&& old_focus
->auto_lower
)
6205 x_lower_frame (old_focus
);
6208 selected_frame
= frame
;
6209 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6211 Fselect_window (selected_frame
->selected_window
);
6212 choose_minibuf_frame ();
6215 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6216 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6218 pending_autoraise_frame
= 0;
6221 x_frame_rehighlight (dpyinfo
);
6224 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6227 x_mouse_leave (dpyinfo
)
6228 struct x_display_info
*dpyinfo
;
6230 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6233 /* The focus has changed, or we have redirected a frame's focus to
6234 another frame (this happens when a frame uses a surrogate
6235 mini-buffer frame). Shift the highlight as appropriate.
6237 The FRAME argument doesn't necessarily have anything to do with which
6238 frame is being highlighted or un-highlighted; we only use it to find
6239 the appropriate X display info. */
6242 XTframe_rehighlight (frame
)
6243 struct frame
*frame
;
6245 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6249 x_frame_rehighlight (dpyinfo
)
6250 struct x_display_info
*dpyinfo
;
6252 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6254 if (dpyinfo
->x_focus_frame
)
6256 dpyinfo
->x_highlight_frame
6257 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6258 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6259 : dpyinfo
->x_focus_frame
);
6260 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6262 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6263 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6267 dpyinfo
->x_highlight_frame
= 0;
6269 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6272 frame_unhighlight (old_highlight
);
6273 if (dpyinfo
->x_highlight_frame
)
6274 frame_highlight (dpyinfo
->x_highlight_frame
);
6280 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6282 /* Initialize mode_switch_bit and modifier_meaning. */
6284 x_find_modifier_meanings (dpyinfo
)
6285 struct x_display_info
*dpyinfo
;
6287 int min_code
, max_code
;
6290 XModifierKeymap
*mods
;
6292 dpyinfo
->meta_mod_mask
= 0;
6293 dpyinfo
->shift_lock_mask
= 0;
6294 dpyinfo
->alt_mod_mask
= 0;
6295 dpyinfo
->super_mod_mask
= 0;
6296 dpyinfo
->hyper_mod_mask
= 0;
6299 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6301 min_code
= dpyinfo
->display
->min_keycode
;
6302 max_code
= dpyinfo
->display
->max_keycode
;
6305 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6306 min_code
, max_code
- min_code
+ 1,
6308 mods
= XGetModifierMapping (dpyinfo
->display
);
6310 /* Scan the modifier table to see which modifier bits the Meta and
6311 Alt keysyms are on. */
6313 int row
, col
; /* The row and column in the modifier table. */
6315 for (row
= 3; row
< 8; row
++)
6316 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6319 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6321 /* Zeroes are used for filler. Skip them. */
6325 /* Are any of this keycode's keysyms a meta key? */
6329 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6331 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6337 dpyinfo
->meta_mod_mask
|= (1 << row
);
6342 dpyinfo
->alt_mod_mask
|= (1 << row
);
6347 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6352 dpyinfo
->super_mod_mask
|= (1 << row
);
6356 /* Ignore this if it's not on the lock modifier. */
6357 if ((1 << row
) == LockMask
)
6358 dpyinfo
->shift_lock_mask
= LockMask
;
6366 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6367 if (! dpyinfo
->meta_mod_mask
)
6369 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6370 dpyinfo
->alt_mod_mask
= 0;
6373 /* If some keys are both alt and meta,
6374 make them just meta, not alt. */
6375 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6377 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6380 XFree ((char *) syms
);
6381 XFreeModifiermap (mods
);
6384 /* Convert between the modifier bits X uses and the modifier bits
6388 x_x_to_emacs_modifiers (dpyinfo
, state
)
6389 struct x_display_info
*dpyinfo
;
6392 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6393 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6394 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6395 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6396 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6397 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6401 x_emacs_to_x_modifiers (dpyinfo
, state
)
6402 struct x_display_info
*dpyinfo
;
6405 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6406 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6407 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6408 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6409 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6410 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6413 /* Convert a keysym to its name. */
6416 x_get_keysym_name (keysym
)
6422 value
= XKeysymToString (keysym
);
6430 /* Mouse clicks and mouse movement. Rah. */
6432 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6433 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6434 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6435 not force the value into range. */
6438 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6440 register int pix_x
, pix_y
;
6441 register int *x
, *y
;
6445 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6446 even for negative values. */
6448 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6450 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6452 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6453 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6457 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6458 bounds
->height
= f
->output_data
.x
->line_height
;
6459 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6460 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6467 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6468 pix_x
= FRAME_WINDOW_WIDTH (f
);
6472 else if (pix_y
> f
->height
)
6481 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6482 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6483 can't tell the positions because W's display is not up to date,
6487 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6490 int *frame_x
, *frame_y
;
6494 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6495 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6497 if (display_completed
)
6499 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6500 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6501 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6507 *frame_x
+= glyph
->pixel_width
;
6515 *frame_y
= *frame_x
= 0;
6519 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6520 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6525 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6527 If the event is a button press, then note that we have grabbed
6531 construct_mouse_click (result
, event
, f
)
6532 struct input_event
*result
;
6533 XButtonEvent
*event
;
6536 /* Make the event type no_event; we'll change that when we decide
6538 result
->kind
= mouse_click
;
6539 result
->code
= event
->button
- Button1
;
6540 result
->timestamp
= event
->time
;
6541 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6543 | (event
->type
== ButtonRelease
6547 XSETINT (result
->x
, event
->x
);
6548 XSETINT (result
->y
, event
->y
);
6549 XSETFRAME (result
->frame_or_window
, f
);
6555 /* Function to report a mouse movement to the mainstream Emacs code.
6556 The input handler calls this.
6558 We have received a mouse movement event, which is given in *event.
6559 If the mouse is over a different glyph than it was last time, tell
6560 the mainstream emacs code by setting mouse_moved. If not, ask for
6561 another motion event, so we can check again the next time it moves. */
6563 static XMotionEvent last_mouse_motion_event
;
6564 static Lisp_Object last_mouse_motion_frame
;
6567 note_mouse_movement (frame
, event
)
6569 XMotionEvent
*event
;
6571 last_mouse_movement_time
= event
->time
;
6572 last_mouse_motion_event
= *event
;
6573 XSETFRAME (last_mouse_motion_frame
, frame
);
6575 if (event
->window
!= FRAME_X_WINDOW (frame
))
6577 frame
->mouse_moved
= 1;
6578 last_mouse_scroll_bar
= Qnil
;
6579 note_mouse_highlight (frame
, -1, -1);
6582 /* Has the mouse moved off the glyph it was on at the last sighting? */
6583 else if (event
->x
< last_mouse_glyph
.x
6584 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6585 || event
->y
< last_mouse_glyph
.y
6586 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6588 frame
->mouse_moved
= 1;
6589 last_mouse_scroll_bar
= Qnil
;
6590 note_mouse_highlight (frame
, event
->x
, event
->y
);
6594 /* This is used for debugging, to turn off note_mouse_highlight. */
6596 int disable_mouse_highlight
;
6600 /************************************************************************
6602 ************************************************************************/
6604 /* Find the glyph under window-relative coordinates X/Y in window W.
6605 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6606 strings. Return in *HPOS and *VPOS the row and column number of
6607 the glyph found. Return in *AREA the glyph area containing X.
6608 Value is a pointer to the glyph found or null if X/Y is not on
6609 text, or we can't tell because W's current matrix is not up to
6612 static struct glyph
*
6613 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6616 int *hpos
, *vpos
, *area
;
6619 struct glyph
*glyph
, *end
;
6620 struct glyph_row
*row
= NULL
;
6621 int x0
, i
, left_area_width
;
6623 /* Find row containing Y. Give up if some row is not enabled. */
6624 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6626 row
= MATRIX_ROW (w
->current_matrix
, i
);
6627 if (!row
->enabled_p
)
6629 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6636 /* Give up if Y is not in the window. */
6637 if (i
== w
->current_matrix
->nrows
)
6640 /* Get the glyph area containing X. */
6641 if (w
->pseudo_window_p
)
6648 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6649 if (x
< left_area_width
)
6651 *area
= LEFT_MARGIN_AREA
;
6654 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6657 x0
= row
->x
+ left_area_width
;
6661 *area
= RIGHT_MARGIN_AREA
;
6662 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6666 /* Find glyph containing X. */
6667 glyph
= row
->glyphs
[*area
];
6668 end
= glyph
+ row
->used
[*area
];
6671 if (x
< x0
+ glyph
->pixel_width
)
6673 if (w
->pseudo_window_p
)
6675 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6679 x0
+= glyph
->pixel_width
;
6686 *hpos
= glyph
- row
->glyphs
[*area
];
6691 /* Convert frame-relative x/y to coordinates relative to window W.
6692 Takes pseudo-windows into account. */
6695 frame_to_window_pixel_xy (w
, x
, y
)
6699 if (w
->pseudo_window_p
)
6701 /* A pseudo-window is always full-width, and starts at the
6702 left edge of the frame, plus a frame border. */
6703 struct frame
*f
= XFRAME (w
->frame
);
6704 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6705 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6709 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6710 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6715 /* Take proper action when mouse has moved to the mode or header line of
6716 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6717 mode line. X is relative to the start of the text display area of
6718 W, so the width of bitmap areas and scroll bars must be subtracted
6719 to get a position relative to the start of the mode line. */
6722 note_mode_line_highlight (w
, x
, mode_line_p
)
6726 struct frame
*f
= XFRAME (w
->frame
);
6727 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6728 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6729 struct glyph_row
*row
;
6732 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6734 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6738 struct glyph
*glyph
, *end
;
6739 Lisp_Object help
, map
;
6742 /* Find the glyph under X. */
6743 glyph
= row
->glyphs
[TEXT_AREA
];
6744 end
= glyph
+ row
->used
[TEXT_AREA
];
6745 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6746 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6749 && x
>= x0
+ glyph
->pixel_width
)
6751 x0
+= glyph
->pixel_width
;
6756 && STRINGP (glyph
->object
)
6757 && XSTRING (glyph
->object
)->intervals
6758 && glyph
->charpos
>= 0
6759 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6761 /* If we're on a string with `help-echo' text property,
6762 arrange for the help to be displayed. This is done by
6763 setting the global variable help_echo to the help string. */
6764 help
= Fget_text_property (make_number (glyph
->charpos
),
6765 Qhelp_echo
, glyph
->object
);
6769 XSETWINDOW (help_echo_window
, w
);
6770 help_echo_object
= glyph
->object
;
6771 help_echo_pos
= glyph
->charpos
;
6774 /* Change the mouse pointer according to what is under X/Y. */
6775 map
= Fget_text_property (make_number (glyph
->charpos
),
6776 Qlocal_map
, glyph
->object
);
6778 cursor
= f
->output_data
.x
->nontext_cursor
;
6781 map
= Fget_text_property (make_number (glyph
->charpos
),
6782 Qkeymap
, glyph
->object
);
6784 cursor
= f
->output_data
.x
->nontext_cursor
;
6789 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6793 /* Take proper action when the mouse has moved to position X, Y on
6794 frame F as regards highlighting characters that have mouse-face
6795 properties. Also de-highlighting chars where the mouse was before.
6796 X and Y can be negative or out of range. */
6799 note_mouse_highlight (f
, x
, y
)
6803 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6807 Cursor cursor
= None
;
6810 /* When a menu is active, don't highlight because this looks odd. */
6811 #ifdef USE_X_TOOLKIT
6812 if (popup_activated ())
6816 if (disable_mouse_highlight
6817 || !f
->glyphs_initialized_p
)
6820 dpyinfo
->mouse_face_mouse_x
= x
;
6821 dpyinfo
->mouse_face_mouse_y
= y
;
6822 dpyinfo
->mouse_face_mouse_frame
= f
;
6824 if (dpyinfo
->mouse_face_defer
)
6829 dpyinfo
->mouse_face_deferred_gc
= 1;
6833 /* Which window is that in? */
6834 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6836 /* If we were displaying active text in another window, clear that. */
6837 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6838 clear_mouse_face (dpyinfo
);
6840 /* Not on a window -> return. */
6841 if (!WINDOWP (window
))
6844 /* Convert to window-relative pixel coordinates. */
6845 w
= XWINDOW (window
);
6846 frame_to_window_pixel_xy (w
, &x
, &y
);
6848 /* Handle tool-bar window differently since it doesn't display a
6850 if (EQ (window
, f
->tool_bar_window
))
6852 note_tool_bar_highlight (f
, x
, y
);
6856 /* Mouse is on the mode or header line? */
6857 if (portion
== 1 || portion
== 3)
6859 note_mode_line_highlight (w
, x
, portion
== 1);
6864 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6866 cursor
= f
->output_data
.x
->text_cursor
;
6868 /* Are we in a window whose display is up to date?
6869 And verify the buffer's text has not changed. */
6870 b
= XBUFFER (w
->buffer
);
6871 if (/* Within text portion of the window. */
6873 && EQ (w
->window_end_valid
, w
->buffer
)
6874 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6875 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6877 int hpos
, vpos
, pos
, i
, area
;
6878 struct glyph
*glyph
;
6880 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6881 Lisp_Object
*overlay_vec
= NULL
;
6883 struct buffer
*obuf
;
6884 int obegv
, ozv
, same_region
;
6886 /* Find the glyph under X/Y. */
6887 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6889 /* Clear mouse face if X/Y not over text. */
6891 || area
!= TEXT_AREA
6892 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6894 if (clear_mouse_face (dpyinfo
))
6899 pos
= glyph
->charpos
;
6900 object
= glyph
->object
;
6901 if (!STRINGP (object
) && !BUFFERP (object
))
6904 /* If we get an out-of-range value, return now; avoid an error. */
6905 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6908 /* Make the window's buffer temporarily current for
6909 overlays_at and compute_char_face. */
6910 obuf
= current_buffer
;
6917 /* Is this char mouse-active or does it have help-echo? */
6918 position
= make_number (pos
);
6920 if (BUFFERP (object
))
6922 /* Put all the overlays we want in a vector in overlay_vec.
6923 Store the length in len. If there are more than 10, make
6924 enough space for all, and try again. */
6926 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6927 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6928 if (noverlays
> len
)
6931 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6932 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6935 /* Sort overlays into increasing priority order. */
6936 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6941 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
6942 && vpos
>= dpyinfo
->mouse_face_beg_row
6943 && vpos
<= dpyinfo
->mouse_face_end_row
6944 && (vpos
> dpyinfo
->mouse_face_beg_row
6945 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6946 && (vpos
< dpyinfo
->mouse_face_end_row
6947 || hpos
< dpyinfo
->mouse_face_end_col
6948 || dpyinfo
->mouse_face_past_end
));
6953 /* Check mouse-face highlighting. */
6955 /* If there exists an overlay with mouse-face overlapping
6956 the one we are currently highlighting, we have to
6957 check if we enter the overlapping overlay, and then
6958 highlight only that. */
6959 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
6960 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
6962 /* Find the highest priority overlay that has a mouse-face
6965 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
6967 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6968 if (!NILP (mouse_face
))
6969 overlay
= overlay_vec
[i
];
6972 /* If we're actually highlighting the same overlay as
6973 before, there's no need to do that again. */
6975 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
6976 goto check_help_echo
;
6978 dpyinfo
->mouse_face_overlay
= overlay
;
6980 /* Clear the display of the old active region, if any. */
6981 if (clear_mouse_face (dpyinfo
))
6984 /* If no overlay applies, get a text property. */
6986 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
6988 /* Handle the overlay case. */
6989 if (!NILP (overlay
))
6991 /* Find the range of text around this char that
6992 should be active. */
6993 Lisp_Object before
, after
;
6996 before
= Foverlay_start (overlay
);
6997 after
= Foverlay_end (overlay
);
6998 /* Record this as the current active region. */
6999 fast_find_position (w
, XFASTINT (before
),
7000 &dpyinfo
->mouse_face_beg_col
,
7001 &dpyinfo
->mouse_face_beg_row
,
7002 &dpyinfo
->mouse_face_beg_x
,
7003 &dpyinfo
->mouse_face_beg_y
);
7004 dpyinfo
->mouse_face_past_end
7005 = !fast_find_position (w
, XFASTINT (after
),
7006 &dpyinfo
->mouse_face_end_col
,
7007 &dpyinfo
->mouse_face_end_row
,
7008 &dpyinfo
->mouse_face_end_x
,
7009 &dpyinfo
->mouse_face_end_y
);
7010 dpyinfo
->mouse_face_window
= window
;
7011 dpyinfo
->mouse_face_face_id
7012 = face_at_buffer_position (w
, pos
, 0, 0,
7013 &ignore
, pos
+ 1, 1);
7015 /* Display it as active. */
7016 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7019 /* Handle the text property case. */
7020 else if (!NILP (mouse_face
) && BUFFERP (object
))
7022 /* Find the range of text around this char that
7023 should be active. */
7024 Lisp_Object before
, after
, beginning
, end
;
7027 beginning
= Fmarker_position (w
->start
);
7028 end
= make_number (BUF_Z (XBUFFER (object
))
7029 - XFASTINT (w
->window_end_pos
));
7031 = Fprevious_single_property_change (make_number (pos
+ 1),
7035 = Fnext_single_property_change (position
, Qmouse_face
,
7038 /* Record this as the current active region. */
7039 fast_find_position (w
, XFASTINT (before
),
7040 &dpyinfo
->mouse_face_beg_col
,
7041 &dpyinfo
->mouse_face_beg_row
,
7042 &dpyinfo
->mouse_face_beg_x
,
7043 &dpyinfo
->mouse_face_beg_y
);
7044 dpyinfo
->mouse_face_past_end
7045 = !fast_find_position (w
, XFASTINT (after
),
7046 &dpyinfo
->mouse_face_end_col
,
7047 &dpyinfo
->mouse_face_end_row
,
7048 &dpyinfo
->mouse_face_end_x
,
7049 &dpyinfo
->mouse_face_end_y
);
7050 dpyinfo
->mouse_face_window
= window
;
7052 if (BUFFERP (object
))
7053 dpyinfo
->mouse_face_face_id
7054 = face_at_buffer_position (w
, pos
, 0, 0,
7055 &ignore
, pos
+ 1, 1);
7057 /* Display it as active. */
7058 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7061 else if (!NILP (mouse_face
) && STRINGP (object
))
7066 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7069 e
= Fnext_single_property_change (position
, Qmouse_face
,
7072 b
= make_number (0);
7074 e
= make_number (XSTRING (object
)->size
- 1);
7075 fast_find_string_pos (w
, XINT (b
), object
,
7076 &dpyinfo
->mouse_face_beg_col
,
7077 &dpyinfo
->mouse_face_beg_row
,
7078 &dpyinfo
->mouse_face_beg_x
,
7079 &dpyinfo
->mouse_face_beg_y
, 0);
7080 fast_find_string_pos (w
, XINT (e
), object
,
7081 &dpyinfo
->mouse_face_end_col
,
7082 &dpyinfo
->mouse_face_end_row
,
7083 &dpyinfo
->mouse_face_end_x
,
7084 &dpyinfo
->mouse_face_end_y
, 1);
7085 dpyinfo
->mouse_face_past_end
= 0;
7086 dpyinfo
->mouse_face_window
= window
;
7087 dpyinfo
->mouse_face_face_id
7088 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7090 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7097 /* Look for a `help-echo' property. */
7099 Lisp_Object help
, overlay
;
7101 /* Check overlays first. */
7102 help
= overlay
= Qnil
;
7103 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7105 overlay
= overlay_vec
[i
];
7106 help
= Foverlay_get (overlay
, Qhelp_echo
);
7112 help_echo_window
= window
;
7113 help_echo_object
= overlay
;
7114 help_echo_pos
= pos
;
7118 Lisp_Object object
= glyph
->object
;
7119 int charpos
= glyph
->charpos
;
7121 /* Try text properties. */
7122 if (STRINGP (object
)
7124 && charpos
< XSTRING (object
)->size
)
7126 help
= Fget_text_property (make_number (charpos
),
7127 Qhelp_echo
, object
);
7130 /* If the string itself doesn't specify a help-echo,
7131 see if the buffer text ``under'' it does. */
7133 = MATRIX_ROW (w
->current_matrix
, vpos
);
7134 int start
= MATRIX_ROW_START_CHARPOS (r
);
7135 int pos
= string_buffer_position (w
, object
, start
);
7138 help
= Fget_text_property (make_number (pos
),
7139 Qhelp_echo
, w
->buffer
);
7148 else if (BUFFERP (object
)
7151 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7157 help_echo_window
= window
;
7158 help_echo_object
= object
;
7159 help_echo_pos
= charpos
;
7166 current_buffer
= obuf
;
7172 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7176 redo_mouse_highlight ()
7178 if (!NILP (last_mouse_motion_frame
)
7179 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7180 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7181 last_mouse_motion_event
.x
,
7182 last_mouse_motion_event
.y
);
7187 /***********************************************************************
7189 ***********************************************************************/
7191 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7192 struct glyph
**, int *, int *, int *));
7194 /* Tool-bar item index of the item on which a mouse button was pressed
7197 static int last_tool_bar_item
;
7200 /* Get information about the tool-bar item at position X/Y on frame F.
7201 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7202 the current matrix of the tool-bar window of F, or NULL if not
7203 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7204 item in F->tool_bar_items. Value is
7206 -1 if X/Y is not on a tool-bar item
7207 0 if X/Y is on the same item that was highlighted before.
7211 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7214 struct glyph
**glyph
;
7215 int *hpos
, *vpos
, *prop_idx
;
7217 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7218 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7221 /* Find the glyph under X/Y. */
7222 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7226 /* Get the start of this tool-bar item's properties in
7227 f->tool_bar_items. */
7228 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7231 /* Is mouse on the highlighted item? */
7232 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7233 && *vpos
>= dpyinfo
->mouse_face_beg_row
7234 && *vpos
<= dpyinfo
->mouse_face_end_row
7235 && (*vpos
> dpyinfo
->mouse_face_beg_row
7236 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7237 && (*vpos
< dpyinfo
->mouse_face_end_row
7238 || *hpos
< dpyinfo
->mouse_face_end_col
7239 || dpyinfo
->mouse_face_past_end
))
7246 /* Handle mouse button event on the tool-bar of frame F, at
7247 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
7251 x_handle_tool_bar_click (f
, button_event
)
7253 XButtonEvent
*button_event
;
7255 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7256 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7257 int hpos
, vpos
, prop_idx
;
7258 struct glyph
*glyph
;
7259 Lisp_Object enabled_p
;
7260 int x
= button_event
->x
;
7261 int y
= button_event
->y
;
7263 /* If not on the highlighted tool-bar item, return. */
7264 frame_to_window_pixel_xy (w
, &x
, &y
);
7265 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7268 /* If item is disabled, do nothing. */
7269 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7270 if (NILP (enabled_p
))
7273 if (button_event
->type
== ButtonPress
)
7275 /* Show item in pressed state. */
7276 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7277 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7278 last_tool_bar_item
= prop_idx
;
7282 Lisp_Object key
, frame
;
7283 struct input_event event
;
7285 /* Show item in released state. */
7286 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7287 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7289 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7291 XSETFRAME (frame
, f
);
7292 event
.kind
= TOOL_BAR_EVENT
;
7293 event
.frame_or_window
= frame
;
7295 kbd_buffer_store_event (&event
);
7297 event
.kind
= TOOL_BAR_EVENT
;
7298 event
.frame_or_window
= frame
;
7300 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7301 button_event
->state
);
7302 kbd_buffer_store_event (&event
);
7303 last_tool_bar_item
= -1;
7308 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7309 tool-bar window-relative coordinates X/Y. Called from
7310 note_mouse_highlight. */
7313 note_tool_bar_highlight (f
, x
, y
)
7317 Lisp_Object window
= f
->tool_bar_window
;
7318 struct window
*w
= XWINDOW (window
);
7319 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7321 struct glyph
*glyph
;
7322 struct glyph_row
*row
;
7324 Lisp_Object enabled_p
;
7326 enum draw_glyphs_face draw
;
7327 int mouse_down_p
, rc
;
7329 /* Function note_mouse_highlight is called with negative x(y
7330 values when mouse moves outside of the frame. */
7331 if (x
<= 0 || y
<= 0)
7333 clear_mouse_face (dpyinfo
);
7337 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7340 /* Not on tool-bar item. */
7341 clear_mouse_face (dpyinfo
);
7347 clear_mouse_face (dpyinfo
);
7349 /* Mouse is down, but on different tool-bar item? */
7350 mouse_down_p
= (dpyinfo
->grabbed
7351 && f
== last_mouse_frame
7352 && FRAME_LIVE_P (f
));
7354 && last_tool_bar_item
!= prop_idx
)
7357 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7358 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7360 /* If tool-bar item is not enabled, don't highlight it. */
7361 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7362 if (!NILP (enabled_p
))
7364 /* Compute the x-position of the glyph. In front and past the
7365 image is a space. We include this is the highlighted area. */
7366 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7367 for (i
= x
= 0; i
< hpos
; ++i
)
7368 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7370 /* Record this as the current active region. */
7371 dpyinfo
->mouse_face_beg_col
= hpos
;
7372 dpyinfo
->mouse_face_beg_row
= vpos
;
7373 dpyinfo
->mouse_face_beg_x
= x
;
7374 dpyinfo
->mouse_face_beg_y
= row
->y
;
7375 dpyinfo
->mouse_face_past_end
= 0;
7377 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7378 dpyinfo
->mouse_face_end_row
= vpos
;
7379 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7380 dpyinfo
->mouse_face_end_y
= row
->y
;
7381 dpyinfo
->mouse_face_window
= window
;
7382 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7384 /* Display it as active. */
7385 show_mouse_face (dpyinfo
, draw
);
7386 dpyinfo
->mouse_face_image_state
= draw
;
7391 /* Set help_echo to a help string.to display for this tool-bar item.
7392 XTread_socket does the rest. */
7393 help_echo_object
= help_echo_window
= Qnil
;
7395 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7396 if (NILP (help_echo
))
7397 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7402 /* Find the glyph matrix position of buffer position POS in window W.
7403 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7404 current glyphs must be up to date. If POS is above window start
7405 return (0, 0, 0, 0). If POS is after end of W, return end of
7409 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
7412 int *hpos
, *vpos
, *x
, *y
;
7416 int maybe_next_line_p
= 0;
7417 int line_start_position
;
7418 int yb
= window_text_bottom_y (w
);
7419 struct glyph_row
*row
, *best_row
;
7420 int row_vpos
, best_row_vpos
;
7423 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7424 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7428 if (row
->used
[TEXT_AREA
])
7429 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7431 line_start_position
= 0;
7433 if (line_start_position
> pos
)
7435 /* If the position sought is the end of the buffer,
7436 don't include the blank lines at the bottom of the window. */
7437 else if (line_start_position
== pos
7438 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7440 maybe_next_line_p
= 1;
7443 else if (line_start_position
> 0)
7446 best_row_vpos
= row_vpos
;
7449 if (row
->y
+ row
->height
>= yb
)
7456 /* Find the right column within BEST_ROW. */
7458 current_x
= best_row
->x
;
7459 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7461 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7464 charpos
= glyph
->charpos
;
7468 *vpos
= best_row_vpos
;
7473 else if (charpos
> pos
)
7475 else if (charpos
> 0)
7478 current_x
+= glyph
->pixel_width
;
7481 /* If we're looking for the end of the buffer,
7482 and we didn't find it in the line we scanned,
7483 use the start of the following line. */
7484 if (maybe_next_line_p
)
7489 current_x
= best_row
->x
;
7492 *vpos
= best_row_vpos
;
7493 *hpos
= lastcol
+ 1;
7500 /* Find the position of the the glyph for position POS in OBJECT in
7501 window W's current matrix, and return in *X/*Y the pixel
7502 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7504 RIGHT_P non-zero means return the position of the right edge of the
7505 glyph, RIGHT_P zero means return the left edge position.
7507 If no glyph for POS exists in the matrix, return the position of
7508 the glyph with the next smaller position that is in the matrix, if
7509 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7510 exists in the matrix, return the position of the glyph with the
7511 next larger position in OBJECT.
7513 Value is non-zero if a glyph was found. */
7516 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7520 int *hpos
, *vpos
, *x
, *y
;
7523 int yb
= window_text_bottom_y (w
);
7524 struct glyph_row
*r
;
7525 struct glyph
*best_glyph
= NULL
;
7526 struct glyph_row
*best_row
= NULL
;
7529 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7530 r
->enabled_p
&& r
->y
< yb
;
7533 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7534 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7537 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7538 if (EQ (g
->object
, object
))
7540 if (g
->charpos
== pos
)
7547 else if (best_glyph
== NULL
7548 || ((abs (g
->charpos
- pos
)
7549 < abs (best_glyph
->charpos
- pos
))
7552 : g
->charpos
> pos
)))
7566 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7570 *x
+= best_glyph
->pixel_width
;
7575 *vpos
= best_row
- w
->current_matrix
->rows
;
7578 return best_glyph
!= NULL
;
7582 /* Display the active region described by mouse_face_*
7583 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7586 show_mouse_face (dpyinfo
, draw
)
7587 struct x_display_info
*dpyinfo
;
7588 enum draw_glyphs_face draw
;
7590 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7591 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7593 int cursor_off_p
= 0;
7594 struct cursor_pos saved_cursor
;
7596 saved_cursor
= output_cursor
;
7598 /* If window is in the process of being destroyed, don't bother
7600 if (w
->current_matrix
== NULL
)
7603 /* Recognize when we are called to operate on rows that don't exist
7604 anymore. This can happen when a window is split. */
7605 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7608 set_output_cursor (&w
->phys_cursor
);
7610 /* Note that mouse_face_beg_row etc. are window relative. */
7611 for (i
= dpyinfo
->mouse_face_beg_row
;
7612 i
<= dpyinfo
->mouse_face_end_row
;
7615 int start_hpos
, end_hpos
, start_x
;
7616 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7618 /* Don't do anything if row doesn't have valid contents. */
7619 if (!row
->enabled_p
)
7622 /* For all but the first row, the highlight starts at column 0. */
7623 if (i
== dpyinfo
->mouse_face_beg_row
)
7625 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7626 start_x
= dpyinfo
->mouse_face_beg_x
;
7634 if (i
== dpyinfo
->mouse_face_end_row
)
7635 end_hpos
= dpyinfo
->mouse_face_end_col
;
7637 end_hpos
= row
->used
[TEXT_AREA
];
7639 /* If the cursor's in the text we are about to rewrite, turn the
7641 if (!w
->pseudo_window_p
7642 && i
== output_cursor
.vpos
7643 && output_cursor
.hpos
>= start_hpos
- 1
7644 && output_cursor
.hpos
<= end_hpos
)
7646 x_update_window_cursor (w
, 0);
7650 if (end_hpos
> start_hpos
)
7652 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
|| DRAW_IMAGE_RAISED
;
7653 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7654 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7658 /* If we turned the cursor off, turn it back on. */
7660 x_display_cursor (w
, 1,
7661 output_cursor
.hpos
, output_cursor
.vpos
,
7662 output_cursor
.x
, output_cursor
.y
);
7664 output_cursor
= saved_cursor
;
7668 /* Change the mouse cursor. */
7669 if (draw
== DRAW_NORMAL_TEXT
)
7670 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7671 f
->output_data
.x
->text_cursor
);
7672 else if (draw
== DRAW_MOUSE_FACE
)
7673 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7674 f
->output_data
.x
->cross_cursor
);
7676 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7677 f
->output_data
.x
->nontext_cursor
);
7680 /* Clear out the mouse-highlighted active region.
7681 Redraw it un-highlighted first. Value is non-zero if mouse
7682 face was actually drawn unhighlighted. */
7685 clear_mouse_face (dpyinfo
)
7686 struct x_display_info
*dpyinfo
;
7690 if (!NILP (dpyinfo
->mouse_face_window
))
7692 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7696 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7697 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7698 dpyinfo
->mouse_face_window
= Qnil
;
7703 /* Clear any mouse-face on window W. This function is part of the
7704 redisplay interface, and is called from try_window_id and similar
7705 functions to ensure the mouse-highlight is off. */
7708 x_clear_mouse_face (w
)
7711 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7715 XSETWINDOW (window
, w
);
7716 if (EQ (window
, dpyinfo
->mouse_face_window
))
7717 clear_mouse_face (dpyinfo
);
7722 /* Just discard the mouse face information for frame F, if any.
7723 This is used when the size of F is changed. */
7726 cancel_mouse_face (f
)
7730 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7732 window
= dpyinfo
->mouse_face_window
;
7733 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7735 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7736 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7737 dpyinfo
->mouse_face_window
= Qnil
;
7742 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7745 /* Try to determine frame pixel position and size of the glyph under
7746 frame pixel coordinates X/Y on frame F . Return the position and
7747 size in *RECT. Value is non-zero if we could compute these
7751 glyph_rect (f
, x
, y
, rect
)
7757 int part
, found
= 0;
7759 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7762 struct window
*w
= XWINDOW (window
);
7763 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7764 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7767 frame_to_window_pixel_xy (w
, &x
, &y
);
7769 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7772 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7773 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7776 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7779 rect
->width
= g
->pixel_width
;
7780 rect
->height
= r
->height
;
7781 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7782 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7792 /* Return the current position of the mouse.
7793 *FP should be a frame which indicates which display to ask about.
7795 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7796 and *PART to the frame, window, and scroll bar part that the mouse
7797 is over. Set *X and *Y to the portion and whole of the mouse's
7798 position on the scroll bar.
7800 If the mouse movement started elsewhere, set *FP to the frame the
7801 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7804 Set *TIME to the server time-stamp for the time at which the mouse
7805 was at this position.
7807 Don't store anything if we don't have a valid set of values to report.
7809 This clears the mouse_moved flag, so we can wait for the next mouse
7813 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7816 Lisp_Object
*bar_window
;
7817 enum scroll_bar_part
*part
;
7819 unsigned long *time
;
7825 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7826 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7832 Window dummy_window
;
7835 Lisp_Object frame
, tail
;
7837 /* Clear the mouse-moved flag for every frame on this display. */
7838 FOR_EACH_FRAME (tail
, frame
)
7839 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7840 XFRAME (frame
)->mouse_moved
= 0;
7842 last_mouse_scroll_bar
= Qnil
;
7844 /* Figure out which root window we're on. */
7845 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7846 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7848 /* The root window which contains the pointer. */
7851 /* Trash which we can't trust if the pointer is on
7852 a different screen. */
7855 /* The position on that root window. */
7858 /* More trash we can't trust. */
7861 /* Modifier keys and pointer buttons, about which
7863 (unsigned int *) &dummy
);
7865 /* Now we have a position on the root; find the innermost window
7866 containing the pointer. */
7870 int parent_x
= 0, parent_y
= 0;
7875 /* XTranslateCoordinates can get errors if the window
7876 structure is changing at the same time this function
7877 is running. So at least we must not crash from them. */
7879 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7881 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7882 && FRAME_LIVE_P (last_mouse_frame
))
7884 /* If mouse was grabbed on a frame, give coords for that frame
7885 even if the mouse is now outside it. */
7886 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7888 /* From-window, to-window. */
7889 root
, FRAME_X_WINDOW (last_mouse_frame
),
7891 /* From-position, to-position. */
7892 root_x
, root_y
, &win_x
, &win_y
,
7896 f1
= last_mouse_frame
;
7902 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7904 /* From-window, to-window. */
7907 /* From-position, to-position. */
7908 root_x
, root_y
, &win_x
, &win_y
,
7913 if (child
== None
|| child
== win
)
7921 /* Now we know that:
7922 win is the innermost window containing the pointer
7923 (XTC says it has no child containing the pointer),
7924 win_x and win_y are the pointer's position in it
7925 (XTC did this the last time through), and
7926 parent_x and parent_y are the pointer's position in win's parent.
7927 (They are what win_x and win_y were when win was child.
7928 If win is the root window, it has no parent, and
7929 parent_{x,y} are invalid, but that's okay, because we'll
7930 never use them in that case.) */
7932 /* Is win one of our frames? */
7933 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7935 #ifdef USE_X_TOOLKIT
7936 /* If we end up with the menu bar window, say it's not
7939 && f1
->output_data
.x
->menubar_widget
7940 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
7942 #endif /* USE_X_TOOLKIT */
7945 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7948 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7950 /* If not, is it one of our scroll bars? */
7953 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7957 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7963 if (f1
== 0 && insist
> 0)
7964 f1
= SELECTED_FRAME ();
7968 /* Ok, we found a frame. Store all the values.
7969 last_mouse_glyph is a rectangle used to reduce the
7970 generation of mouse events. To not miss any motion
7971 events, we must divide the frame into rectangles of the
7972 size of the smallest character that could be displayed
7973 on it, i.e. into the same rectangles that matrices on
7974 the frame are divided into. */
7976 int width
, height
, gx
, gy
;
7979 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
7980 last_mouse_glyph
= rect
;
7983 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7984 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7988 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7989 round down even for negative values. */
7994 gx
= (gx
+ width
- 1) / width
* width
;
7995 gy
= (gy
+ height
- 1) / height
* height
;
7997 last_mouse_glyph
.width
= width
;
7998 last_mouse_glyph
.height
= height
;
7999 last_mouse_glyph
.x
= gx
;
8000 last_mouse_glyph
.y
= gy
;
8006 XSETINT (*x
, win_x
);
8007 XSETINT (*y
, win_y
);
8008 *time
= last_mouse_movement_time
;
8017 #ifdef USE_X_TOOLKIT
8019 /* Atimer callback function for TIMER. Called every 0.1s to process
8020 Xt timeouts, if needed. We must avoid calling XtAppPending as
8021 much as possible because that function does an implicit XFlush
8022 that slows us down. */
8025 x_process_timeouts (timer
)
8026 struct atimer
*timer
;
8028 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
8031 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8032 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8037 #endif /* USE_X_TOOLKIT */
8040 /* Scroll bar support. */
8042 /* Given an X window ID, find the struct scroll_bar which manages it.
8043 This can be called in GC, so we have to make sure to strip off mark
8046 static struct scroll_bar
*
8047 x_window_to_scroll_bar (window_id
)
8052 for (tail
= Vframe_list
;
8053 XGCTYPE (tail
) == Lisp_Cons
;
8056 Lisp_Object frame
, bar
, condemned
;
8058 frame
= XCAR (tail
);
8059 /* All elements of Vframe_list should be frames. */
8060 if (! GC_FRAMEP (frame
))
8063 /* Scan this frame's scroll bar list for a scroll bar with the
8065 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8066 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8067 /* This trick allows us to search both the ordinary and
8068 condemned scroll bar lists with one loop. */
8069 ! GC_NILP (bar
) || (bar
= condemned
,
8072 bar
= XSCROLL_BAR (bar
)->next
)
8073 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8074 return XSCROLL_BAR (bar
);
8081 #if defined USE_X_TOOLKIT && defined USE_LUCID
8083 /* Return the Lucid menu bar WINDOW is part of. Return null
8084 if WINDOW is not part of a menu bar. */
8087 x_window_to_menu_bar (window
)
8092 for (tail
= Vframe_list
;
8093 XGCTYPE (tail
) == Lisp_Cons
;
8096 Lisp_Object frame
= XCAR (tail
);
8097 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8099 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8106 #endif /* USE_X_TOOLKIT && USE_LUCID */
8109 /************************************************************************
8111 ************************************************************************/
8113 #ifdef USE_TOOLKIT_SCROLL_BARS
8115 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8116 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8117 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8118 struct scroll_bar
*));
8119 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8123 /* Id of action hook installed for scroll bars. */
8125 static XtActionHookId action_hook_id
;
8127 /* Lisp window being scrolled. Set when starting to interact with
8128 a toolkit scroll bar, reset to nil when ending the interaction. */
8130 static Lisp_Object window_being_scrolled
;
8132 /* Last scroll bar part sent in xm_scroll_callback. */
8134 static int last_scroll_bar_part
;
8136 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8137 that movements of 1/20 of the screen size are mapped to up/down. */
8139 static Boolean xaw3d_arrow_scroll
;
8141 /* Whether the drag scrolling maintains the mouse at the top of the
8142 thumb. If not, resizing the thumb needs to be done more carefully
8143 to avoid jerkyness. */
8145 static Boolean xaw3d_pick_top
;
8148 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8149 bars are used.. The hook is responsible for detecting when
8150 the user ends an interaction with the scroll bar, and generates
8151 a `end-scroll' scroll_bar_click' event if so. */
8154 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8157 XtPointer client_data
;
8161 Cardinal
*num_params
;
8167 scroll_bar_p
= XmIsScrollBar (widget
);
8168 end_action
= "Release";
8169 #else /* !USE_MOTIF i.e. use Xaw */
8170 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8171 end_action
= "EndScroll";
8172 #endif /* USE_MOTIF */
8175 && strcmp (action_name
, end_action
) == 0
8176 && WINDOWP (window_being_scrolled
))
8180 x_send_scroll_bar_event (window_being_scrolled
,
8181 scroll_bar_end_scroll
, 0, 0);
8182 w
= XWINDOW (window_being_scrolled
);
8183 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8184 window_being_scrolled
= Qnil
;
8185 last_scroll_bar_part
= -1;
8187 /* Xt timeouts no longer needed. */
8188 toolkit_scroll_bar_interaction
= 0;
8192 /* A vector of windows used for communication between
8193 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8195 static struct window
**scroll_bar_windows
;
8196 static int scroll_bar_windows_size
;
8199 /* Send a client message with message type Xatom_Scrollbar for a
8200 scroll action to the frame of WINDOW. PART is a value identifying
8201 the part of the scroll bar that was clicked on. PORTION is the
8202 amount to scroll of a whole of WHOLE. */
8205 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8207 int part
, portion
, whole
;
8210 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8211 struct window
*w
= XWINDOW (window
);
8212 struct frame
*f
= XFRAME (w
->frame
);
8217 /* Construct a ClientMessage event to send to the frame. */
8218 ev
->type
= ClientMessage
;
8219 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8220 ev
->display
= FRAME_X_DISPLAY (f
);
8221 ev
->window
= FRAME_X_WINDOW (f
);
8224 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8225 not enough to store a pointer or Lisp_Object on a 64 bit system.
8226 So, store the window in scroll_bar_windows and pass the index
8227 into that array in the event. */
8228 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8229 if (scroll_bar_windows
[i
] == NULL
)
8232 if (i
== scroll_bar_windows_size
)
8234 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8235 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8236 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8238 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8240 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8241 scroll_bar_windows_size
= new_size
;
8244 scroll_bar_windows
[i
] = w
;
8245 ev
->data
.l
[0] = (long) i
;
8246 ev
->data
.l
[1] = (long) part
;
8247 ev
->data
.l
[2] = (long) 0;
8248 ev
->data
.l
[3] = (long) portion
;
8249 ev
->data
.l
[4] = (long) whole
;
8251 /* Make Xt timeouts work while the scroll bar is active. */
8252 toolkit_scroll_bar_interaction
= 1;
8254 /* Setting the event mask to zero means that the message will
8255 be sent to the client that created the window, and if that
8256 window no longer exists, no event will be sent. */
8257 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8262 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8266 x_scroll_bar_to_input_event (event
, ievent
)
8268 struct input_event
*ievent
;
8270 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8275 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8276 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8278 XSETWINDOW (window
, w
);
8279 f
= XFRAME (w
->frame
);
8281 ievent
->kind
= scroll_bar_click
;
8282 ievent
->frame_or_window
= window
;
8284 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8285 ievent
->part
= ev
->data
.l
[1];
8286 ievent
->code
= ev
->data
.l
[2];
8287 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8288 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8289 ievent
->modifiers
= 0;
8295 /* Minimum and maximum values used for Motif scroll bars. */
8298 #define XM_SB_MAX 10000000
8299 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8302 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8303 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8304 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
8307 xm_scroll_callback (widget
, client_data
, call_data
)
8309 XtPointer client_data
, call_data
;
8311 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8312 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8314 int part
= -1, whole
= 0, portion
= 0;
8318 case XmCR_DECREMENT
:
8319 bar
->dragging
= Qnil
;
8320 part
= scroll_bar_up_arrow
;
8323 case XmCR_INCREMENT
:
8324 bar
->dragging
= Qnil
;
8325 part
= scroll_bar_down_arrow
;
8328 case XmCR_PAGE_DECREMENT
:
8329 bar
->dragging
= Qnil
;
8330 part
= scroll_bar_above_handle
;
8333 case XmCR_PAGE_INCREMENT
:
8334 bar
->dragging
= Qnil
;
8335 part
= scroll_bar_below_handle
;
8339 bar
->dragging
= Qnil
;
8340 part
= scroll_bar_to_top
;
8343 case XmCR_TO_BOTTOM
:
8344 bar
->dragging
= Qnil
;
8345 part
= scroll_bar_to_bottom
;
8351 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8352 && XINT (bar
->dragging
) <= cs
->value
);
8354 /* Get the slider size. */
8356 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8359 /* At the max position of the scroll bar, do a line-wise
8360 movement. Without doing anything, we would be called with
8361 the same cs->value again and again. If we want to make
8362 sure that we can reach the end of the buffer, we have to do
8365 Implementation note: setting bar->dragging always to
8366 cs->value gives a smoother movement at the max position.
8367 Setting it to nil when doing line-wise movement gives
8368 a better slider behavior. */
8370 if (cs
->value
+ slider_size
== XM_SB_MAX
8372 && last_scroll_bar_part
== scroll_bar_down_arrow
))
8374 part
= scroll_bar_down_arrow
;
8375 bar
->dragging
= Qnil
;
8379 whole
= XM_SB_RANGE
;
8380 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
8381 part
= scroll_bar_handle
;
8382 bar
->dragging
= make_number (cs
->value
);
8387 case XmCR_VALUE_CHANGED
:
8393 window_being_scrolled
= bar
->window
;
8394 last_scroll_bar_part
= part
;
8395 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8400 #else /* !USE_MOTIF, i.e. Xaw. */
8403 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8404 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8405 scroll bar struct. CALL_DATA is a pointer to a float saying where
8409 xaw_jump_callback (widget
, client_data
, call_data
)
8411 XtPointer client_data
, call_data
;
8413 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8414 float top
= *(float *) call_data
;
8416 int whole
, portion
, height
;
8419 /* Get the size of the thumb, a value between 0 and 1. */
8421 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8425 portion
= shown
< 1 ? top
* whole
: 0;
8427 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8428 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8429 the bottom, so we force the scrolling whenever we see that we're
8430 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8431 we try to ensure that we always stay two pixels away from the
8433 part
= scroll_bar_down_arrow
;
8435 part
= scroll_bar_handle
;
8437 window_being_scrolled
= bar
->window
;
8438 bar
->dragging
= make_number (portion
);
8439 last_scroll_bar_part
= part
;
8440 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8444 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8445 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8446 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8447 the scroll bar. CALL_DATA is an integer specifying the action that
8448 has taken place. It's magnitude is in the range 0..height of the
8449 scroll bar. Negative values mean scroll towards buffer start.
8450 Values < height of scroll bar mean line-wise movement. */
8453 xaw_scroll_callback (widget
, client_data
, call_data
)
8455 XtPointer client_data
, call_data
;
8457 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8458 int position
= (int) call_data
;
8462 /* Get the height of the scroll bar. */
8464 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8467 if (abs (position
) >= height
)
8468 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8470 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8471 it maps line-movement to call_data = max(5, height/20). */
8472 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8473 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8475 part
= scroll_bar_move_ratio
;
8477 window_being_scrolled
= bar
->window
;
8478 bar
->dragging
= Qnil
;
8479 last_scroll_bar_part
= part
;
8480 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8484 #endif /* not USE_MOTIF */
8487 /* Create the widget for scroll bar BAR on frame F. Record the widget
8488 and X window of the scroll bar in BAR. */
8491 x_create_toolkit_scroll_bar (f
, bar
)
8493 struct scroll_bar
*bar
;
8499 char *scroll_bar_name
= "verticalScrollBar";
8500 unsigned long pixel
;
8505 /* Set resources. Create the widget. */
8506 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8507 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8508 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8509 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8510 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8511 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8512 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8514 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8517 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8521 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8524 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8528 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8529 scroll_bar_name
, av
, ac
);
8531 /* Add one callback for everything that can happen. */
8532 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8534 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8536 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8538 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8540 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8542 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8544 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8547 /* Realize the widget. Only after that is the X window created. */
8548 XtRealizeWidget (widget
);
8550 /* Set the cursor to an arrow. I didn't find a resource to do that.
8551 And I'm wondering why it hasn't an arrow cursor by default. */
8552 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8553 f
->output_data
.x
->nontext_cursor
);
8555 #else /* !USE_MOTIF i.e. use Xaw */
8557 /* Set resources. Create the widget. The background of the
8558 Xaw3d scroll bar widget is a little bit light for my taste.
8559 We don't alter it here to let users change it according
8560 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8561 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8562 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8563 /* For smoother scrolling with Xaw3d -sm */
8564 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8565 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
8567 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8570 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8574 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8577 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8581 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8582 f
->output_data
.x
->edit_widget
, av
, ac
);
8586 char *val
= initial
;
8587 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8588 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8590 { /* ARROW_SCROLL */
8591 xaw3d_arrow_scroll
= True
;
8592 /* Isn't that just a personal preference ? -sm */
8593 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8597 /* Define callbacks. */
8598 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8599 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8602 /* Realize the widget. Only after that is the X window created. */
8603 XtRealizeWidget (widget
);
8605 #endif /* !USE_MOTIF */
8607 /* Install an action hook that let's us detect when the user
8608 finishes interacting with a scroll bar. */
8609 if (action_hook_id
== 0)
8610 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8612 /* Remember X window and widget in the scroll bar vector. */
8613 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8614 xwindow
= XtWindow (widget
);
8615 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8621 /* Set the thumb size and position of scroll bar BAR. We are currently
8622 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8625 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8626 struct scroll_bar
*bar
;
8627 int portion
, position
, whole
;
8629 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8630 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8637 top
= (float) position
/ whole
;
8638 shown
= (float) portion
/ whole
;
8646 XmScrollBarWidget sb
;
8648 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8649 is the scroll bar's maximum and MIN is the scroll bar's minimum
8651 size
= shown
* XM_SB_RANGE
;
8652 size
= min (size
, XM_SB_RANGE
);
8653 size
= max (size
, 1);
8655 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8656 value
= top
* XM_SB_RANGE
;
8657 value
= min (value
, XM_SB_MAX
- size
);
8658 value
= max (value
, XM_SB_MIN
);
8660 if (NILP (bar
->dragging
))
8661 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8662 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8663 /* This has the negative side effect that the slider value is
8664 not what it would be if we scrolled here using line-wise or
8665 page-wise movement. */
8666 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8669 /* If currently dragging, only update the slider size.
8670 This reduces flicker effects. */
8671 int old_value
, old_size
, increment
, page_increment
;
8673 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8674 &increment
, &page_increment
);
8675 XmScrollBarSetValues (widget
, old_value
,
8676 min (size
, XM_SB_RANGE
- old_value
),
8680 #else /* !USE_MOTIF i.e. use Xaw */
8682 float old_top
, old_shown
;
8684 XtVaGetValues (widget
,
8685 XtNtopOfThumb
, &old_top
,
8686 XtNshown
, &old_shown
,
8690 /* Massage the top+shown values. */
8691 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8692 top
= max (0, min (1, top
));
8695 /* Keep two pixels available for moving the thumb down. */
8696 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8698 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8699 check that your system's configuration file contains a define
8700 for `NARROWPROTO'. See s/freebsd.h for an example. */
8701 if (top
!= old_top
|| shown
!= old_shown
)
8703 if (NILP (bar
->dragging
))
8704 XawScrollbarSetThumb (widget
, top
, shown
);
8708 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8709 int scroll_mode
= 0;
8711 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8712 if (xaw3d_arrow_scroll
)
8714 /* Xaw3d stupidly ignores resize requests while dragging
8715 so we have to make it believe it's not in dragging mode. */
8716 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8717 if (scroll_mode
== 2)
8718 sb
->scrollbar
.scroll_mode
= 0;
8721 /* Try to make the scrolling a tad smoother. */
8722 if (!xaw3d_pick_top
)
8723 shown
= min (shown
, old_shown
);
8725 XawScrollbarSetThumb (widget
, top
, shown
);
8728 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8729 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8734 #endif /* !USE_MOTIF */
8739 #endif /* USE_TOOLKIT_SCROLL_BARS */
8743 /************************************************************************
8744 Scroll bars, general
8745 ************************************************************************/
8747 /* Create a scroll bar and return the scroll bar vector for it. W is
8748 the Emacs window on which to create the scroll bar. TOP, LEFT,
8749 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8752 static struct scroll_bar
*
8753 x_scroll_bar_create (w
, top
, left
, width
, height
)
8755 int top
, left
, width
, height
;
8757 struct frame
*f
= XFRAME (w
->frame
);
8758 struct scroll_bar
*bar
8759 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8763 #ifdef USE_TOOLKIT_SCROLL_BARS
8764 x_create_toolkit_scroll_bar (f
, bar
);
8765 #else /* not USE_TOOLKIT_SCROLL_BARS */
8767 XSetWindowAttributes a
;
8771 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8772 if (a
.background_pixel
== -1)
8773 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8775 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8776 | ButtonMotionMask
| PointerMotionHintMask
8778 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8780 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8782 /* Clear the area of W that will serve as a scroll bar. This is
8783 for the case that a window has been split horizontally. In
8784 this case, no clear_frame is generated to reduce flickering. */
8785 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8787 window_box_height (w
), False
);
8789 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8790 /* Position and size of scroll bar. */
8791 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8793 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8795 /* Border width, depth, class, and visual. */
8802 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8804 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8806 XSETWINDOW (bar
->window
, w
);
8807 XSETINT (bar
->top
, top
);
8808 XSETINT (bar
->left
, left
);
8809 XSETINT (bar
->width
, width
);
8810 XSETINT (bar
->height
, height
);
8811 XSETINT (bar
->start
, 0);
8812 XSETINT (bar
->end
, 0);
8813 bar
->dragging
= Qnil
;
8815 /* Add bar to its frame's list of scroll bars. */
8816 bar
->next
= FRAME_SCROLL_BARS (f
);
8818 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8819 if (!NILP (bar
->next
))
8820 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8822 /* Map the window/widget. */
8823 #ifdef USE_TOOLKIT_SCROLL_BARS
8825 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8826 XtConfigureWidget (scroll_bar
,
8827 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8829 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8830 max (height
, 1), 0);
8831 XtMapWidget (scroll_bar
);
8833 #else /* not USE_TOOLKIT_SCROLL_BARS */
8834 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8835 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8842 /* Draw BAR's handle in the proper position.
8844 If the handle is already drawn from START to END, don't bother
8845 redrawing it, unless REBUILD is non-zero; in that case, always
8846 redraw it. (REBUILD is handy for drawing the handle after expose
8849 Normally, we want to constrain the start and end of the handle to
8850 fit inside its rectangle, but if the user is dragging the scroll
8851 bar handle, we want to let them drag it down all the way, so that
8852 the bar's top is as far down as it goes; otherwise, there's no way
8853 to move to the very end of the buffer. */
8855 #ifndef USE_TOOLKIT_SCROLL_BARS
8858 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8859 struct scroll_bar
*bar
;
8863 int dragging
= ! NILP (bar
->dragging
);
8864 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8865 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8866 GC gc
= f
->output_data
.x
->normal_gc
;
8868 /* If the display is already accurate, do nothing. */
8870 && start
== XINT (bar
->start
)
8871 && end
== XINT (bar
->end
))
8877 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8878 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8879 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8881 /* Make sure the values are reasonable, and try to preserve
8882 the distance between start and end. */
8884 int length
= end
- start
;
8888 else if (start
> top_range
)
8890 end
= start
+ length
;
8894 else if (end
> top_range
&& ! dragging
)
8898 /* Store the adjusted setting in the scroll bar. */
8899 XSETINT (bar
->start
, start
);
8900 XSETINT (bar
->end
, end
);
8902 /* Clip the end position, just for display. */
8903 if (end
> top_range
)
8906 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8907 below top positions, to make sure the handle is always at least
8908 that many pixels tall. */
8909 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8911 /* Draw the empty space above the handle. Note that we can't clear
8912 zero-height areas; that means "clear to end of window." */
8914 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8915 /* x, y, width, height, and exposures. */
8916 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8917 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8918 inside_width
, start
,
8921 /* Change to proper foreground color if one is specified. */
8922 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8923 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8924 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8926 /* Draw the handle itself. */
8927 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8928 /* x, y, width, height */
8929 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8930 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8931 inside_width
, end
- start
);
8933 /* Restore the foreground color of the GC if we changed it above. */
8934 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8935 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8936 f
->output_data
.x
->foreground_pixel
);
8938 /* Draw the empty space below the handle. Note that we can't
8939 clear zero-height areas; that means "clear to end of window." */
8940 if (end
< inside_height
)
8941 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8942 /* x, y, width, height, and exposures. */
8943 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8944 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8945 inside_width
, inside_height
- end
,
8953 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8955 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8959 x_scroll_bar_remove (bar
)
8960 struct scroll_bar
*bar
;
8962 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8965 #ifdef USE_TOOLKIT_SCROLL_BARS
8966 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
8968 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8971 /* Disassociate this scroll bar from its window. */
8972 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8978 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8979 that we are displaying PORTION characters out of a total of WHOLE
8980 characters, starting at POSITION. If WINDOW has no scroll bar,
8984 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8986 int portion
, whole
, position
;
8988 struct frame
*f
= XFRAME (w
->frame
);
8989 struct scroll_bar
*bar
;
8990 int top
, height
, left
, sb_left
, width
, sb_width
;
8991 int window_x
, window_y
, window_width
, window_height
;
8993 /* Get window dimensions. */
8994 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8996 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8997 height
= window_height
;
8999 /* Compute the left edge of the scroll bar area. */
9000 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9001 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
9003 left
= XFASTINT (w
->left
);
9004 left
*= CANON_X_UNIT (f
);
9005 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
9007 /* Compute the width of the scroll bar which might be less than
9008 the width of the area reserved for the scroll bar. */
9009 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
9010 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
9014 /* Compute the left edge of the scroll bar. */
9015 #ifdef USE_TOOLKIT_SCROLL_BARS
9016 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9017 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
9019 sb_left
= left
+ (width
- sb_width
) / 2;
9021 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9022 sb_left
= left
+ width
- sb_width
;
9027 /* Does the scroll bar exist yet? */
9028 if (NILP (w
->vertical_scroll_bar
))
9031 if (width
&& height
)
9032 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9033 left
, top
, width
, height
, False
);
9035 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9039 /* It may just need to be moved and resized. */
9040 unsigned int mask
= 0;
9042 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9046 if (sb_left
!= XINT (bar
->left
))
9048 if (top
!= XINT (bar
->top
))
9050 if (sb_width
!= XINT (bar
->width
))
9052 if (height
!= XINT (bar
->height
))
9055 #ifdef USE_TOOLKIT_SCROLL_BARS
9057 /* Since toolkit scroll bars are smaller than the space reserved
9058 for them on the frame, we have to clear "under" them. */
9059 if (width
&& height
)
9060 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9061 left
, top
, width
, height
, False
);
9063 /* Move/size the scroll bar widget. */
9065 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9066 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9068 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9069 max (height
, 1), 0);
9071 #else /* not USE_TOOLKIT_SCROLL_BARS */
9073 /* Clear areas not covered by the scroll bar because of
9074 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9075 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9077 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9078 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9080 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9081 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9082 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9086 /* Clear areas not covered by the scroll bar because it's not as
9087 wide as the area reserved for it . This makes sure a
9088 previous mode line display is cleared after C-x 2 C-x 1, for
9091 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9092 int rest
= area_width
- sb_width
;
9094 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9095 left
+ area_width
- rest
, 0,
9096 rest
, max (height
, 1), False
);
9099 /* Move/size the scroll bar window. */
9104 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9106 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9108 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9112 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9114 /* Remember new settings. */
9115 XSETINT (bar
->left
, sb_left
);
9116 XSETINT (bar
->top
, top
);
9117 XSETINT (bar
->width
, sb_width
);
9118 XSETINT (bar
->height
, height
);
9123 #ifdef USE_TOOLKIT_SCROLL_BARS
9124 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9125 #else /* not USE_TOOLKIT_SCROLL_BARS */
9126 /* Set the scroll bar's current state, unless we're currently being
9128 if (NILP (bar
->dragging
))
9130 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9133 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9136 int start
= ((double) position
* top_range
) / whole
;
9137 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9138 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9141 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9143 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9147 /* The following three hooks are used when we're doing a thorough
9148 redisplay of the frame. We don't explicitly know which scroll bars
9149 are going to be deleted, because keeping track of when windows go
9150 away is a real pain - "Can you say set-window-configuration, boys
9151 and girls?" Instead, we just assert at the beginning of redisplay
9152 that *all* scroll bars are to be removed, and then save a scroll bar
9153 from the fiery pit when we actually redisplay its window. */
9155 /* Arrange for all scroll bars on FRAME to be removed at the next call
9156 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9157 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9160 XTcondemn_scroll_bars (frame
)
9163 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9164 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9167 bar
= FRAME_SCROLL_BARS (frame
);
9168 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9169 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9170 XSCROLL_BAR (bar
)->prev
= Qnil
;
9171 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9172 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9173 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9178 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9179 Note that WINDOW isn't necessarily condemned at all. */
9182 XTredeem_scroll_bar (window
)
9183 struct window
*window
;
9185 struct scroll_bar
*bar
;
9188 /* We can't redeem this window's scroll bar if it doesn't have one. */
9189 if (NILP (window
->vertical_scroll_bar
))
9192 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9194 /* Unlink it from the condemned list. */
9195 f
= XFRAME (WINDOW_FRAME (window
));
9196 if (NILP (bar
->prev
))
9198 /* If the prev pointer is nil, it must be the first in one of
9200 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9201 /* It's not condemned. Everything's fine. */
9203 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9204 window
->vertical_scroll_bar
))
9205 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9207 /* If its prev pointer is nil, it must be at the front of
9208 one or the other! */
9212 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9214 if (! NILP (bar
->next
))
9215 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9217 bar
->next
= FRAME_SCROLL_BARS (f
);
9219 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9220 if (! NILP (bar
->next
))
9221 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9224 /* Remove all scroll bars on FRAME that haven't been saved since the
9225 last call to `*condemn_scroll_bars_hook'. */
9228 XTjudge_scroll_bars (f
)
9231 Lisp_Object bar
, next
;
9233 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9235 /* Clear out the condemned list now so we won't try to process any
9236 more events on the hapless scroll bars. */
9237 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9239 for (; ! NILP (bar
); bar
= next
)
9241 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9243 x_scroll_bar_remove (b
);
9246 b
->next
= b
->prev
= Qnil
;
9249 /* Now there should be no references to the condemned scroll bars,
9250 and they should get garbage-collected. */
9254 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9255 is a no-op when using toolkit scroll bars.
9257 This may be called from a signal handler, so we have to ignore GC
9261 x_scroll_bar_expose (bar
, event
)
9262 struct scroll_bar
*bar
;
9265 #ifndef USE_TOOLKIT_SCROLL_BARS
9267 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9268 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9269 GC gc
= f
->output_data
.x
->normal_gc
;
9270 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9274 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9276 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9277 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9279 /* x, y, width, height */
9281 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9282 XINT (bar
->height
) - 1);
9286 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9289 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9290 is set to something other than no_event, it is enqueued.
9292 This may be called from a signal handler, so we have to ignore GC
9295 #ifndef USE_TOOLKIT_SCROLL_BARS
9298 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9299 struct scroll_bar
*bar
;
9301 struct input_event
*emacs_event
;
9303 if (! GC_WINDOWP (bar
->window
))
9306 emacs_event
->kind
= scroll_bar_click
;
9307 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9308 emacs_event
->modifiers
9309 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9310 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9311 event
->xbutton
.state
)
9312 | (event
->type
== ButtonRelease
9315 emacs_event
->frame_or_window
= bar
->window
;
9316 emacs_event
->arg
= Qnil
;
9317 emacs_event
->timestamp
= event
->xbutton
.time
;
9320 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9322 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9325 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9326 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9329 if (y
> top_range
) y
= top_range
;
9331 if (y
< XINT (bar
->start
))
9332 emacs_event
->part
= scroll_bar_above_handle
;
9333 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9334 emacs_event
->part
= scroll_bar_handle
;
9336 emacs_event
->part
= scroll_bar_below_handle
;
9338 /* Just because the user has clicked on the handle doesn't mean
9339 they want to drag it. Lisp code needs to be able to decide
9340 whether or not we're dragging. */
9342 /* If the user has just clicked on the handle, record where they're
9344 if (event
->type
== ButtonPress
9345 && emacs_event
->part
== scroll_bar_handle
)
9346 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9349 /* If the user has released the handle, set it to its final position. */
9350 if (event
->type
== ButtonRelease
9351 && ! NILP (bar
->dragging
))
9353 int new_start
= y
- XINT (bar
->dragging
);
9354 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9356 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9357 bar
->dragging
= Qnil
;
9360 /* Same deal here as the other #if 0. */
9362 /* Clicks on the handle are always reported as occurring at the top of
9364 if (emacs_event
->part
== scroll_bar_handle
)
9365 emacs_event
->x
= bar
->start
;
9367 XSETINT (emacs_event
->x
, y
);
9369 XSETINT (emacs_event
->x
, y
);
9372 XSETINT (emacs_event
->y
, top_range
);
9376 /* Handle some mouse motion while someone is dragging the scroll bar.
9378 This may be called from a signal handler, so we have to ignore GC
9382 x_scroll_bar_note_movement (bar
, event
)
9383 struct scroll_bar
*bar
;
9386 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9388 last_mouse_movement_time
= event
->xmotion
.time
;
9391 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9393 /* If we're dragging the bar, display it. */
9394 if (! GC_NILP (bar
->dragging
))
9396 /* Where should the handle be now? */
9397 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9399 if (new_start
!= XINT (bar
->start
))
9401 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9403 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9408 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9410 /* Return information to the user about the current position of the mouse
9411 on the scroll bar. */
9414 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9416 Lisp_Object
*bar_window
;
9417 enum scroll_bar_part
*part
;
9419 unsigned long *time
;
9421 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9422 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9423 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9425 Window dummy_window
;
9427 unsigned int dummy_mask
;
9431 /* Get the mouse's position relative to the scroll bar window, and
9433 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9435 /* Root, child, root x and root y. */
9436 &dummy_window
, &dummy_window
,
9437 &dummy_coord
, &dummy_coord
,
9439 /* Position relative to scroll bar. */
9442 /* Mouse buttons and modifier keys. */
9449 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9452 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9454 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9456 if (! NILP (bar
->dragging
))
9457 win_y
-= XINT (bar
->dragging
);
9461 if (win_y
> top_range
)
9465 *bar_window
= bar
->window
;
9467 if (! NILP (bar
->dragging
))
9468 *part
= scroll_bar_handle
;
9469 else if (win_y
< XINT (bar
->start
))
9470 *part
= scroll_bar_above_handle
;
9471 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9472 *part
= scroll_bar_handle
;
9474 *part
= scroll_bar_below_handle
;
9476 XSETINT (*x
, win_y
);
9477 XSETINT (*y
, top_range
);
9480 last_mouse_scroll_bar
= Qnil
;
9483 *time
= last_mouse_movement_time
;
9489 /* The screen has been cleared so we may have changed foreground or
9490 background colors, and the scroll bars may need to be redrawn.
9491 Clear out the scroll bars, and ask for expose events, so we can
9495 x_scroll_bar_clear (f
)
9498 #ifndef USE_TOOLKIT_SCROLL_BARS
9501 /* We can have scroll bars even if this is 0,
9502 if we just turned off scroll bar mode.
9503 But in that case we should not clear them. */
9504 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9505 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9506 bar
= XSCROLL_BAR (bar
)->next
)
9507 XClearArea (FRAME_X_DISPLAY (f
),
9508 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9510 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9513 /* This processes Expose events from the menu-bar specific X event
9514 loop in xmenu.c. This allows to redisplay the frame if necessary
9515 when handling menu-bar or pop-up items. */
9518 process_expose_from_menu (event
)
9522 struct x_display_info
*dpyinfo
;
9523 int frame_exposed_p
= 0;
9527 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9528 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9531 if (f
->async_visible
== 0)
9533 f
->async_visible
= 1;
9534 f
->async_iconified
= 0;
9535 f
->output_data
.x
->has_been_visible
= 1;
9536 SET_FRAME_GARBAGED (f
);
9540 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9541 event
.xexpose
.x
, event
.xexpose
.y
,
9542 event
.xexpose
.width
, event
.xexpose
.height
);
9543 frame_exposed_p
= 1;
9548 struct scroll_bar
*bar
9549 = x_window_to_scroll_bar (event
.xexpose
.window
);
9552 x_scroll_bar_expose (bar
, &event
);
9556 return frame_exposed_p
;
9559 /* Define a queue to save up SelectionRequest events for later handling. */
9561 struct selection_event_queue
9564 struct selection_event_queue
*next
;
9567 static struct selection_event_queue
*queue
;
9569 /* Nonzero means queue up certain events--don't process them yet. */
9571 static int x_queue_selection_requests
;
9573 /* Queue up an X event *EVENT, to be processed later. */
9576 x_queue_event (f
, event
)
9580 struct selection_event_queue
*queue_tmp
9581 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9583 if (queue_tmp
!= NULL
)
9585 queue_tmp
->event
= *event
;
9586 queue_tmp
->next
= queue
;
9591 /* Take all the queued events and put them back
9592 so that they get processed afresh. */
9595 x_unqueue_events (display
)
9598 while (queue
!= NULL
)
9600 struct selection_event_queue
*queue_tmp
= queue
;
9601 XPutBackEvent (display
, &queue_tmp
->event
);
9602 queue
= queue_tmp
->next
;
9603 xfree ((char *)queue_tmp
);
9607 /* Start queuing SelectionRequest events. */
9610 x_start_queuing_selection_requests (display
)
9613 x_queue_selection_requests
++;
9616 /* Stop queuing SelectionRequest events. */
9619 x_stop_queuing_selection_requests (display
)
9622 x_queue_selection_requests
--;
9623 x_unqueue_events (display
);
9626 /* The main X event-reading loop - XTread_socket. */
9628 /* Time stamp of enter window event. This is only used by XTread_socket,
9629 but we have to put it out here, since static variables within functions
9630 sometimes don't work. */
9632 static Time enter_timestamp
;
9634 /* This holds the state XLookupString needs to implement dead keys
9635 and other tricks known as "compose processing". _X Window System_
9636 says that a portable program can't use this, but Stephen Gildea assures
9637 me that letting the compiler initialize it to zeros will work okay.
9639 This must be defined outside of XTread_socket, for the same reasons
9640 given for enter_time stamp, above. */
9642 static XComposeStatus compose_status
;
9644 /* Record the last 100 characters stored
9645 to help debug the loss-of-chars-during-GC problem. */
9647 static int temp_index
;
9648 static short temp_buffer
[100];
9650 /* Set this to nonzero to fake an "X I/O error"
9651 on a particular display. */
9653 struct x_display_info
*XTread_socket_fake_io_error
;
9655 /* When we find no input here, we occasionally do a no-op command
9656 to verify that the X server is still running and we can still talk with it.
9657 We try all the open displays, one by one.
9658 This variable is used for cycling thru the displays. */
9660 static struct x_display_info
*next_noop_dpyinfo
;
9662 #define SET_SAVED_MENU_EVENT(size) \
9665 if (f->output_data.x->saved_menu_event == 0) \
9666 f->output_data.x->saved_menu_event \
9667 = (XEvent *) xmalloc (sizeof (XEvent)); \
9668 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9669 if (numchars >= 1) \
9671 bufp->kind = menu_bar_activate_event; \
9672 XSETFRAME (bufp->frame_or_window, f); \
9681 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9682 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9684 /* Read events coming from the X server.
9685 This routine is called by the SIGIO handler.
9686 We return as soon as there are no more events to be read.
9688 Events representing keys are stored in buffer BUFP,
9689 which can hold up to NUMCHARS characters.
9690 We return the number of characters stored into the buffer,
9691 thus pretending to be `read'.
9693 EXPECTED is nonzero if the caller knows input is available. */
9696 XTread_socket (sd
, bufp
, numchars
, expected
)
9698 /* register */ struct input_event
*bufp
;
9699 /* register */ int numchars
;
9706 int event_found
= 0;
9707 struct x_display_info
*dpyinfo
;
9708 struct coding_system coding
;
9710 if (interrupt_input_blocked
)
9712 interrupt_input_pending
= 1;
9716 interrupt_input_pending
= 0;
9719 /* So people can tell when we have read the available input. */
9720 input_signal_count
++;
9723 abort (); /* Don't think this happens. */
9727 /* The input should be decoded if it is from XIM. Currently the
9728 locale of XIM is the same as that of the system. So, we can use
9729 Vlocale_coding_system which is initialized properly at Emacs
9731 setup_coding_system (Vlocale_coding_system
, &coding
);
9732 coding
.src_multibyte
= 0;
9733 coding
.dst_multibyte
= 1;
9734 /* The input is converted to events, thus we can't handle
9735 composition. Anyway, there's no XIM that gives us composition
9737 coding
.composing
= COMPOSITION_DISABLED
;
9739 /* Find the display we are supposed to read input for.
9740 It's the one communicating on descriptor SD. */
9741 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9743 #if 0 /* This ought to be unnecessary; let's verify it. */
9745 /* If available, Xlib uses FIOSNBIO to make the socket
9746 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9747 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9748 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9749 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9750 #endif /* ! defined (FIOSNBIO) */
9753 #if 0 /* This code can't be made to work, with multiple displays,
9754 and appears not to be used on any system any more.
9755 Also keyboard.c doesn't turn O_NDELAY on and off
9756 for X connections. */
9759 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9761 extern int read_alarm_should_throw
;
9762 read_alarm_should_throw
= 1;
9763 XPeekEvent (dpyinfo
->display
, &event
);
9764 read_alarm_should_throw
= 0;
9766 #endif /* HAVE_SELECT */
9770 /* For debugging, this gives a way to fake an I/O error. */
9771 if (dpyinfo
== XTread_socket_fake_io_error
)
9773 XTread_socket_fake_io_error
= 0;
9774 x_io_error_quitter (dpyinfo
->display
);
9777 while (XPending (dpyinfo
->display
))
9779 XNextEvent (dpyinfo
->display
, &event
);
9783 /* Filter events for the current X input method.
9784 XFilterEvent returns non-zero if the input method has
9785 consumed the event. We pass the frame's X window to
9786 XFilterEvent because that's the one for which the IC
9788 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9789 event
.xclient
.window
);
9790 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9800 if (event
.xclient
.message_type
9801 == dpyinfo
->Xatom_wm_protocols
9802 && event
.xclient
.format
== 32)
9804 if (event
.xclient
.data
.l
[0]
9805 == dpyinfo
->Xatom_wm_take_focus
)
9807 /* Use x_any_window_to_frame because this
9808 could be the shell widget window
9809 if the frame has no title bar. */
9810 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9812 /* Not quite sure this is needed -pd */
9813 if (f
&& FRAME_XIC (f
))
9814 XSetICFocus (FRAME_XIC (f
));
9816 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9817 instructs the WM to set the input focus automatically for
9818 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9819 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9820 it has set the focus. So, XSetInputFocus below is not
9823 The call to XSetInputFocus below has also caused trouble. In
9824 cases where the XSetInputFocus done by the WM and the one
9825 below are temporally close (on a fast machine), the call
9826 below can generate additional FocusIn events which confuse
9829 /* Since we set WM_TAKE_FOCUS, we must call
9830 XSetInputFocus explicitly. But not if f is null,
9831 since that might be an event for a deleted frame. */
9834 Display
*d
= event
.xclient
.display
;
9835 /* Catch and ignore errors, in case window has been
9836 iconified by a window manager such as GWM. */
9837 int count
= x_catch_errors (d
);
9838 XSetInputFocus (d
, event
.xclient
.window
,
9839 /* The ICCCM says this is
9840 the only valid choice. */
9842 event
.xclient
.data
.l
[1]);
9843 /* This is needed to detect the error
9844 if there is an error. */
9846 x_uncatch_errors (d
, count
);
9848 /* Not certain about handling scroll bars here */
9851 else if (event
.xclient
.data
.l
[0]
9852 == dpyinfo
->Xatom_wm_save_yourself
)
9854 /* Save state modify the WM_COMMAND property to
9855 something which can reinstate us. This notifies
9856 the session manager, who's looking for such a
9857 PropertyNotify. Can restart processing when
9858 a keyboard or mouse event arrives. */
9861 f
= x_top_window_to_frame (dpyinfo
,
9862 event
.xclient
.window
);
9864 /* This is just so we only give real data once
9865 for a single Emacs process. */
9866 if (f
== SELECTED_FRAME ())
9867 XSetCommand (FRAME_X_DISPLAY (f
),
9868 event
.xclient
.window
,
9869 initial_argv
, initial_argc
);
9871 XSetCommand (FRAME_X_DISPLAY (f
),
9872 event
.xclient
.window
,
9876 else if (event
.xclient
.data
.l
[0]
9877 == dpyinfo
->Xatom_wm_delete_window
)
9880 = x_any_window_to_frame (dpyinfo
,
9881 event
.xclient
.window
);
9888 bufp
->kind
= delete_window_event
;
9889 XSETFRAME (bufp
->frame_or_window
, f
);
9898 else if (event
.xclient
.message_type
9899 == dpyinfo
->Xatom_wm_configure_denied
)
9902 else if (event
.xclient
.message_type
9903 == dpyinfo
->Xatom_wm_window_moved
)
9907 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9909 new_x
= event
.xclient
.data
.s
[0];
9910 new_y
= event
.xclient
.data
.s
[1];
9914 f
->output_data
.x
->left_pos
= new_x
;
9915 f
->output_data
.x
->top_pos
= new_y
;
9919 else if (event
.xclient
.message_type
9920 == dpyinfo
->Xatom_editres
)
9923 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9924 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9927 #endif /* HACK_EDITRES */
9928 else if ((event
.xclient
.message_type
9929 == dpyinfo
->Xatom_DONE
)
9930 || (event
.xclient
.message_type
9931 == dpyinfo
->Xatom_PAGE
))
9933 /* Ghostview job completed. Kill it. We could
9934 reply with "Next" if we received "Page", but we
9935 currently never do because we are interested in
9936 images, only, which should have 1 page. */
9937 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9939 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9940 x_kill_gs_process (pixmap
, f
);
9941 expose_frame (f
, 0, 0, 0, 0);
9943 #ifdef USE_TOOLKIT_SCROLL_BARS
9944 /* Scroll bar callbacks send a ClientMessage from which
9945 we construct an input_event. */
9946 else if (event
.xclient
.message_type
9947 == dpyinfo
->Xatom_Scrollbar
)
9949 x_scroll_bar_to_input_event (&event
, bufp
);
9950 ++bufp
, ++count
, --numchars
;
9953 #endif /* USE_TOOLKIT_SCROLL_BARS */
9959 case SelectionNotify
:
9960 #ifdef USE_X_TOOLKIT
9961 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9963 #endif /* not USE_X_TOOLKIT */
9964 x_handle_selection_notify (&event
.xselection
);
9967 case SelectionClear
: /* Someone has grabbed ownership. */
9968 #ifdef USE_X_TOOLKIT
9969 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9971 #endif /* USE_X_TOOLKIT */
9973 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9978 bufp
->kind
= selection_clear_event
;
9979 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9980 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9981 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9982 bufp
->frame_or_window
= Qnil
;
9991 case SelectionRequest
: /* Someone wants our selection. */
9992 #ifdef USE_X_TOOLKIT
9993 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9995 #endif /* USE_X_TOOLKIT */
9996 if (x_queue_selection_requests
)
9997 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
10001 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
10006 bufp
->kind
= selection_request_event
;
10007 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10008 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
10009 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10010 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
10011 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
10012 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10013 bufp
->frame_or_window
= Qnil
;
10022 case PropertyNotify
:
10023 #ifdef USE_X_TOOLKIT
10024 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10026 #endif /* not USE_X_TOOLKIT */
10027 x_handle_property_notify (&event
.xproperty
);
10030 case ReparentNotify
:
10031 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10035 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10036 x_real_positions (f
, &x
, &y
);
10037 f
->output_data
.x
->left_pos
= x
;
10038 f
->output_data
.x
->top_pos
= y
;
10043 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10046 if (f
->async_visible
== 0)
10048 f
->async_visible
= 1;
10049 f
->async_iconified
= 0;
10050 f
->output_data
.x
->has_been_visible
= 1;
10051 SET_FRAME_GARBAGED (f
);
10054 expose_frame (x_window_to_frame (dpyinfo
,
10055 event
.xexpose
.window
),
10056 event
.xexpose
.x
, event
.xexpose
.y
,
10057 event
.xexpose
.width
, event
.xexpose
.height
);
10061 #ifndef USE_TOOLKIT_SCROLL_BARS
10062 struct scroll_bar
*bar
;
10064 #if defined USE_X_TOOLKIT && defined USE_LUCID
10065 /* Submenus of the Lucid menu bar aren't widgets
10066 themselves, so there's no way to dispatch events
10067 to them. Recognize this case separately. */
10070 = x_window_to_menu_bar (event
.xexpose
.window
);
10072 xlwmenu_redisplay (widget
);
10074 #endif /* USE_X_TOOLKIT && USE_LUCID */
10076 #ifdef USE_TOOLKIT_SCROLL_BARS
10077 /* Dispatch event to the widget. */
10079 #else /* not USE_TOOLKIT_SCROLL_BARS */
10080 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10083 x_scroll_bar_expose (bar
, &event
);
10084 #ifdef USE_X_TOOLKIT
10087 #endif /* USE_X_TOOLKIT */
10088 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10092 case GraphicsExpose
: /* This occurs when an XCopyArea's
10093 source area was obscured or not
10095 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10099 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10100 event
.xgraphicsexpose
.width
,
10101 event
.xgraphicsexpose
.height
);
10103 #ifdef USE_X_TOOLKIT
10106 #endif /* USE_X_TOOLKIT */
10109 case NoExpose
: /* This occurs when an XCopyArea's
10110 source area was completely
10115 /* Redo the mouse-highlight after the tooltip has gone. */
10116 if (event
.xmap
.window
== tip_window
)
10119 redo_mouse_highlight ();
10122 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10123 if (f
) /* F may no longer exist if
10124 the frame was deleted. */
10126 /* While a frame is unmapped, display generation is
10127 disabled; you don't want to spend time updating a
10128 display that won't ever be seen. */
10129 f
->async_visible
= 0;
10130 /* We can't distinguish, from the event, whether the window
10131 has become iconified or invisible. So assume, if it
10132 was previously visible, than now it is iconified.
10133 But x_make_frame_invisible clears both
10134 the visible flag and the iconified flag;
10135 and that way, we know the window is not iconified now. */
10136 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10138 f
->async_iconified
= 1;
10140 bufp
->kind
= iconify_event
;
10141 XSETFRAME (bufp
->frame_or_window
, f
);
10151 if (event
.xmap
.window
== tip_window
)
10152 /* The tooltip has been drawn already. Avoid
10153 the SET_FRAME_GARBAGED below. */
10156 /* We use x_top_window_to_frame because map events can
10157 come for sub-windows and they don't mean that the
10158 frame is visible. */
10159 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10162 f
->async_visible
= 1;
10163 f
->async_iconified
= 0;
10164 f
->output_data
.x
->has_been_visible
= 1;
10166 /* wait_reading_process_input will notice this and update
10167 the frame's display structures. */
10168 SET_FRAME_GARBAGED (f
);
10172 bufp
->kind
= deiconify_event
;
10173 XSETFRAME (bufp
->frame_or_window
, f
);
10179 else if (! NILP (Vframe_list
)
10180 && ! NILP (XCDR (Vframe_list
)))
10181 /* Force a redisplay sooner or later
10182 to update the frame titles
10183 in case this is the second frame. */
10184 record_asynch_buffer_change ();
10189 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10191 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10194 /* Scroll bars consume key events, but we want
10195 the keys to go to the scroll bar's frame. */
10196 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10197 event
.xkey
.window
);
10198 if (widget
&& XmIsScrollBar (widget
))
10200 widget
= XtParent (widget
);
10201 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10204 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10208 KeySym keysym
, orig_keysym
;
10209 /* al%imercury@uunet.uu.net says that making this 81
10210 instead of 80 fixed a bug whereby meta chars made
10213 It seems that some version of XmbLookupString has
10214 a bug of not returning XBufferOverflow in
10215 status_return even if the input is too long to
10216 fit in 81 bytes. So, we must prepare sufficient
10217 bytes for copy_buffer. 513 bytes (256 chars for
10218 two-byte character set) seems to be a faily good
10219 approximation. -- 2000.8.10 handa@etl.go.jp */
10220 unsigned char copy_buffer
[513];
10221 unsigned char *copy_bufptr
= copy_buffer
;
10222 int copy_bufsiz
= sizeof (copy_buffer
);
10226 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10227 extra_keyboard_modifiers
);
10228 modifiers
= event
.xkey
.state
;
10230 /* This will have to go some day... */
10232 /* make_lispy_event turns chars into control chars.
10233 Don't do it here because XLookupString is too eager. */
10234 event
.xkey
.state
&= ~ControlMask
;
10235 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10236 | dpyinfo
->super_mod_mask
10237 | dpyinfo
->hyper_mod_mask
10238 | dpyinfo
->alt_mod_mask
);
10240 /* In case Meta is ComposeCharacter,
10241 clear its status. According to Markus Ehrnsperger
10242 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10243 this enables ComposeCharacter to work whether or
10244 not it is combined with Meta. */
10245 if (modifiers
& dpyinfo
->meta_mod_mask
)
10246 bzero (&compose_status
, sizeof (compose_status
));
10251 Status status_return
;
10253 nbytes
= XmbLookupString (FRAME_XIC (f
),
10254 &event
.xkey
, copy_bufptr
,
10255 copy_bufsiz
, &keysym
,
10257 if (status_return
== XBufferOverflow
)
10259 copy_bufsiz
= nbytes
+ 1;
10260 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10261 nbytes
= XmbLookupString (FRAME_XIC (f
),
10262 &event
.xkey
, copy_bufptr
,
10263 copy_bufsiz
, &keysym
,
10267 if (status_return
== XLookupNone
)
10269 else if (status_return
== XLookupChars
)
10274 else if (status_return
!= XLookupKeySym
10275 && status_return
!= XLookupBoth
)
10279 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10280 copy_bufsiz
, &keysym
,
10283 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10284 copy_bufsiz
, &keysym
,
10288 orig_keysym
= keysym
;
10292 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10293 || keysym
== XK_Delete
10294 #ifdef XK_ISO_Left_Tab
10295 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10297 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10298 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10299 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10301 /* This recognizes the "extended function keys".
10302 It seems there's no cleaner way.
10303 Test IsModifierKey to avoid handling mode_switch
10305 || ((unsigned) (keysym
) >= XK_Select
10306 && (unsigned)(keysym
) < XK_KP_Space
)
10308 #ifdef XK_dead_circumflex
10309 || orig_keysym
== XK_dead_circumflex
10311 #ifdef XK_dead_grave
10312 || orig_keysym
== XK_dead_grave
10314 #ifdef XK_dead_tilde
10315 || orig_keysym
== XK_dead_tilde
10317 #ifdef XK_dead_diaeresis
10318 || orig_keysym
== XK_dead_diaeresis
10320 #ifdef XK_dead_macron
10321 || orig_keysym
== XK_dead_macron
10323 #ifdef XK_dead_degree
10324 || orig_keysym
== XK_dead_degree
10326 #ifdef XK_dead_acute
10327 || orig_keysym
== XK_dead_acute
10329 #ifdef XK_dead_cedilla
10330 || orig_keysym
== XK_dead_cedilla
10332 #ifdef XK_dead_breve
10333 || orig_keysym
== XK_dead_breve
10335 #ifdef XK_dead_ogonek
10336 || orig_keysym
== XK_dead_ogonek
10338 #ifdef XK_dead_caron
10339 || orig_keysym
== XK_dead_caron
10341 #ifdef XK_dead_doubleacute
10342 || orig_keysym
== XK_dead_doubleacute
10344 #ifdef XK_dead_abovedot
10345 || orig_keysym
== XK_dead_abovedot
10347 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10348 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10349 /* Any "vendor-specific" key is ok. */
10350 || (orig_keysym
& (1 << 28)))
10351 && ! (IsModifierKey (orig_keysym
)
10353 #ifdef XK_Mode_switch
10354 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10357 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10359 #endif /* not HAVE_X11R5 */
10362 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10364 temp_buffer
[temp_index
++] = keysym
;
10365 bufp
->kind
= non_ascii_keystroke
;
10366 bufp
->code
= keysym
;
10367 XSETFRAME (bufp
->frame_or_window
, f
);
10370 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10372 bufp
->timestamp
= event
.xkey
.time
;
10377 else if (numchars
> nbytes
)
10383 for (i
= 0; i
< nbytes
; i
++)
10385 if (temp_index
== (sizeof temp_buffer
10388 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10391 if (/* If the event is not from XIM, */
10392 event
.xkey
.keycode
!= 0
10393 /* or the current locale doesn't request
10394 decoding of the intup data, ... */
10395 || coding
.type
== coding_type_raw_text
10396 || coding
.type
== coding_type_no_conversion
)
10398 /* ... we can use the input data as is. */
10403 /* We have to decode the input data. */
10407 require
= decoding_buffer_size (&coding
, nbytes
);
10408 p
= (unsigned char *) alloca (require
);
10409 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10410 decode_coding (&coding
, copy_bufptr
, p
,
10412 nbytes
= coding
.produced
;
10413 nchars
= coding
.produced_char
;
10417 /* Convert the input data to a sequence of
10418 character events. */
10419 for (i
= 0; i
< nbytes
; i
+= len
)
10421 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10423 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10425 : multibyte_char_keystroke
);
10427 XSETFRAME (bufp
->frame_or_window
, f
);
10430 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10432 bufp
->timestamp
= event
.xkey
.time
;
10437 numchars
-= nchars
;
10439 if (keysym
== NoSymbol
)
10449 /* Don't dispatch this event since XtDispatchEvent calls
10450 XFilterEvent, and two calls in a row may freeze the
10459 /* Don't dispatch this event since XtDispatchEvent calls
10460 XFilterEvent, and two calls in a row may freeze the
10467 /* Here's a possible interpretation of the whole
10468 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10469 you get a FocusIn event, you have to get a FocusOut
10470 event before you relinquish the focus. If you
10471 haven't received a FocusIn event, then a mere
10472 LeaveNotify is enough to free you. */
10476 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10478 if (event
.xcrossing
.focus
)
10480 /* Avoid nasty pop/raise loops. */
10481 if (f
&& (!(f
->auto_raise
)
10482 || !(f
->auto_lower
)
10483 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10485 x_new_focus_frame (dpyinfo
, f
);
10486 enter_timestamp
= event
.xcrossing
.time
;
10489 else if (f
== dpyinfo
->x_focus_frame
)
10490 x_new_focus_frame (dpyinfo
, 0);
10492 /* EnterNotify counts as mouse movement,
10493 so update things that depend on mouse position. */
10494 if (f
&& !f
->output_data
.x
->hourglass_p
)
10495 note_mouse_movement (f
, &event
.xmotion
);
10500 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10501 if (event
.xfocus
.detail
!= NotifyPointer
)
10502 dpyinfo
->x_focus_event_frame
= f
;
10505 x_new_focus_frame (dpyinfo
, f
);
10507 /* Don't stop displaying the initial startup message
10508 for a switch-frame event we don't need. */
10509 if (GC_NILP (Vterminal_frame
)
10510 && GC_CONSP (Vframe_list
)
10511 && !GC_NILP (XCDR (Vframe_list
)))
10513 bufp
->kind
= FOCUS_IN_EVENT
;
10514 XSETFRAME (bufp
->frame_or_window
, f
);
10516 ++bufp
, ++count
, --numchars
;
10521 if (f
&& FRAME_XIC (f
))
10522 XSetICFocus (FRAME_XIC (f
));
10528 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10531 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10533 /* If we move outside the frame, then we're
10534 certainly no longer on any text in the frame. */
10535 clear_mouse_face (dpyinfo
);
10536 dpyinfo
->mouse_face_mouse_frame
= 0;
10539 /* Generate a nil HELP_EVENT to cancel a help-echo.
10540 Do it only if there's something to cancel.
10541 Otherwise, the startup message is cleared when
10542 the mouse leaves the frame. */
10543 if (any_help_event_p
)
10548 XSETFRAME (frame
, f
);
10550 n
= gen_help_event (bufp
, numchars
,
10551 Qnil
, frame
, Qnil
, Qnil
, 0);
10552 bufp
+= n
, count
+= n
, numchars
-= n
;
10555 if (event
.xcrossing
.focus
)
10556 x_mouse_leave (dpyinfo
);
10559 if (f
== dpyinfo
->x_focus_event_frame
)
10560 dpyinfo
->x_focus_event_frame
= 0;
10561 if (f
== dpyinfo
->x_focus_frame
)
10562 x_new_focus_frame (dpyinfo
, 0);
10568 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10569 if (event
.xfocus
.detail
!= NotifyPointer
10570 && f
== dpyinfo
->x_focus_event_frame
)
10571 dpyinfo
->x_focus_event_frame
= 0;
10572 if (f
&& f
== dpyinfo
->x_focus_frame
)
10573 x_new_focus_frame (dpyinfo
, 0);
10576 if (f
&& FRAME_XIC (f
))
10577 XUnsetICFocus (FRAME_XIC (f
));
10584 previous_help_echo
= help_echo
;
10585 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10586 help_echo_pos
= -1;
10588 if (dpyinfo
->grabbed
&& last_mouse_frame
10589 && FRAME_LIVE_P (last_mouse_frame
))
10590 f
= last_mouse_frame
;
10592 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10595 note_mouse_movement (f
, &event
.xmotion
);
10598 #ifndef USE_TOOLKIT_SCROLL_BARS
10599 struct scroll_bar
*bar
10600 = x_window_to_scroll_bar (event
.xmotion
.window
);
10603 x_scroll_bar_note_movement (bar
, &event
);
10604 #endif /* USE_TOOLKIT_SCROLL_BARS */
10606 /* If we move outside the frame, then we're
10607 certainly no longer on any text in the frame. */
10608 clear_mouse_face (dpyinfo
);
10611 /* If the contents of the global variable help_echo
10612 has changed, generate a HELP_EVENT. */
10613 if (!NILP (help_echo
)
10614 || !NILP (previous_help_echo
))
10620 XSETFRAME (frame
, f
);
10624 any_help_event_p
= 1;
10625 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10626 help_echo_window
, help_echo_object
,
10628 bufp
+= n
, count
+= n
, numchars
-= n
;
10634 case ConfigureNotify
:
10635 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10638 #ifndef USE_X_TOOLKIT
10639 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10640 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10642 /* In the toolkit version, change_frame_size
10643 is called by the code that handles resizing
10644 of the EmacsFrame widget. */
10646 /* Even if the number of character rows and columns has
10647 not changed, the font size may have changed, so we need
10648 to check the pixel dimensions as well. */
10649 if (columns
!= f
->width
10650 || rows
!= f
->height
10651 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10652 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10654 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10655 SET_FRAME_GARBAGED (f
);
10656 cancel_mouse_face (f
);
10660 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10661 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10663 /* What we have now is the position of Emacs's own window.
10664 Convert that to the position of the window manager window. */
10665 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10666 &f
->output_data
.x
->top_pos
);
10669 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10670 xic_set_statusarea (f
);
10673 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10675 /* Since the WM decorations come below top_pos now,
10676 we must put them below top_pos in the future. */
10677 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10678 x_wm_set_size_hint (f
, (long) 0, 0);
10681 /* Some window managers pass (0,0) as the location of
10682 the window, and the Motif event handler stores it
10683 in the emacs widget, which messes up Motif menus. */
10684 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10686 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10687 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10689 #endif /* USE_MOTIF */
10694 case ButtonRelease
:
10696 /* If we decide we want to generate an event to be seen
10697 by the rest of Emacs, we put it here. */
10698 struct input_event emacs_event
;
10699 int tool_bar_p
= 0;
10701 emacs_event
.kind
= no_event
;
10702 bzero (&compose_status
, sizeof (compose_status
));
10704 if (dpyinfo
->grabbed
10705 && last_mouse_frame
10706 && FRAME_LIVE_P (last_mouse_frame
))
10707 f
= last_mouse_frame
;
10709 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10713 /* Is this in the tool-bar? */
10714 if (WINDOWP (f
->tool_bar_window
)
10715 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10717 Lisp_Object window
;
10720 x
= event
.xbutton
.x
;
10721 y
= event
.xbutton
.y
;
10724 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10725 if (EQ (window
, f
->tool_bar_window
))
10727 x_handle_tool_bar_click (f
, &event
.xbutton
);
10733 if (!dpyinfo
->x_focus_frame
10734 || f
== dpyinfo
->x_focus_frame
)
10735 construct_mouse_click (&emacs_event
, &event
, f
);
10739 #ifndef USE_TOOLKIT_SCROLL_BARS
10740 struct scroll_bar
*bar
10741 = x_window_to_scroll_bar (event
.xbutton
.window
);
10744 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10745 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10748 if (event
.type
== ButtonPress
)
10750 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10751 last_mouse_frame
= f
;
10752 /* Ignore any mouse motion that happened
10753 before this event; any subsequent mouse-movement
10754 Emacs events should reflect only motion after
10755 the ButtonPress. */
10757 f
->mouse_moved
= 0;
10760 last_tool_bar_item
= -1;
10764 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10767 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10769 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10775 #ifdef USE_X_TOOLKIT
10776 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10777 /* For a down-event in the menu bar,
10778 don't pass it to Xt right now.
10779 Instead, save it away
10780 and we will pass it to Xt from kbd_buffer_get_event.
10781 That way, we can run some Lisp code first. */
10782 if (f
&& event
.type
== ButtonPress
10783 /* Verify the event is really within the menu bar
10784 and not just sent to it due to grabbing. */
10785 && event
.xbutton
.x
>= 0
10786 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10787 && event
.xbutton
.y
>= 0
10788 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10789 && event
.xbutton
.same_screen
)
10791 SET_SAVED_BUTTON_EVENT
;
10792 XSETFRAME (last_mouse_press_frame
, f
);
10794 else if (event
.type
== ButtonPress
)
10796 last_mouse_press_frame
= Qnil
;
10800 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10801 but I am trying to be cautious. */
10802 else if (event
.type
== ButtonRelease
)
10804 if (!NILP (last_mouse_press_frame
))
10806 f
= XFRAME (last_mouse_press_frame
);
10807 if (f
->output_data
.x
)
10808 SET_SAVED_BUTTON_EVENT
;
10813 #endif /* USE_MOTIF */
10816 #endif /* USE_X_TOOLKIT */
10820 case CirculateNotify
:
10823 case CirculateRequest
:
10826 case VisibilityNotify
:
10829 case MappingNotify
:
10830 /* Someone has changed the keyboard mapping - update the
10832 switch (event
.xmapping
.request
)
10834 case MappingModifier
:
10835 x_find_modifier_meanings (dpyinfo
);
10836 /* This is meant to fall through. */
10837 case MappingKeyboard
:
10838 XRefreshKeyboardMapping (&event
.xmapping
);
10844 #ifdef USE_X_TOOLKIT
10846 XtDispatchEvent (&event
);
10848 #endif /* USE_X_TOOLKIT */
10856 /* On some systems, an X bug causes Emacs to get no more events
10857 when the window is destroyed. Detect that. (1994.) */
10860 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10861 One XNOOP in 100 loops will make Emacs terminate.
10862 B. Bretthauer, 1994 */
10864 if (x_noop_count
>= 100)
10868 if (next_noop_dpyinfo
== 0)
10869 next_noop_dpyinfo
= x_display_list
;
10871 XNoOp (next_noop_dpyinfo
->display
);
10873 /* Each time we get here, cycle through the displays now open. */
10874 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10878 /* If the focus was just given to an auto-raising frame,
10880 /* ??? This ought to be able to handle more than one such frame. */
10881 if (pending_autoraise_frame
)
10883 x_raise_frame (pending_autoraise_frame
);
10884 pending_autoraise_frame
= 0;
10895 /***********************************************************************
10897 ***********************************************************************/
10899 /* Note if the text cursor of window W has been overwritten by a
10900 drawing operation that outputs N glyphs starting at HPOS in the
10901 line given by output_cursor.vpos. N < 0 means all the rest of the
10902 line after HPOS has been written. */
10905 note_overwritten_text_cursor (w
, hpos
, n
)
10909 if (updated_area
== TEXT_AREA
10910 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10911 && hpos
<= w
->phys_cursor
.hpos
10913 || hpos
+ n
> w
->phys_cursor
.hpos
))
10914 w
->phys_cursor_on_p
= 0;
10918 /* Set clipping for output in glyph row ROW. W is the window in which
10919 we operate. GC is the graphics context to set clipping in.
10920 WHOLE_LINE_P non-zero means include the areas used for truncation
10921 mark display and alike in the clipping rectangle.
10923 ROW may be a text row or, e.g., a mode line. Text rows must be
10924 clipped to the interior of the window dedicated to text display,
10925 mode lines must be clipped to the whole window. */
10928 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10930 struct glyph_row
*row
;
10934 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10935 XRectangle clip_rect
;
10936 int window_x
, window_y
, window_width
, window_height
;
10938 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10940 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10941 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10942 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10943 clip_rect
.width
= window_width
;
10944 clip_rect
.height
= row
->visible_height
;
10946 /* If clipping to the whole line, including trunc marks, extend
10947 the rectangle to the left and increase its width. */
10950 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10951 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10954 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10958 /* Draw a hollow box cursor on window W in glyph row ROW. */
10961 x_draw_hollow_cursor (w
, row
)
10963 struct glyph_row
*row
;
10965 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10966 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10967 Display
*dpy
= FRAME_X_DISPLAY (f
);
10970 struct glyph
*cursor_glyph
;
10973 /* Compute frame-relative coordinates from window-relative
10975 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10976 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10977 + row
->ascent
- w
->phys_cursor_ascent
);
10978 h
= row
->height
- 1;
10980 /* Get the glyph the cursor is on. If we can't tell because
10981 the current matrix is invalid or such, give up. */
10982 cursor_glyph
= get_phys_cursor_glyph (w
);
10983 if (cursor_glyph
== NULL
)
10986 /* Compute the width of the rectangle to draw. If on a stretch
10987 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10988 rectangle as wide as the glyph, but use a canonical character
10990 wd
= cursor_glyph
->pixel_width
- 1;
10991 if (cursor_glyph
->type
== STRETCH_GLYPH
10992 && !x_stretch_cursor_p
)
10993 wd
= min (CANON_X_UNIT (f
), wd
);
10995 /* The foreground of cursor_gc is typically the same as the normal
10996 background color, which can cause the cursor box to be invisible. */
10997 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10998 if (dpyinfo
->scratch_cursor_gc
)
10999 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11001 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11002 GCForeground
, &xgcv
);
11003 gc
= dpyinfo
->scratch_cursor_gc
;
11005 /* Set clipping, draw the rectangle, and reset clipping again. */
11006 x_clip_to_row (w
, row
, gc
, 0);
11007 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11008 XSetClipMask (dpy
, gc
, None
);
11012 /* Draw a bar cursor on window W in glyph row ROW.
11014 Implementation note: One would like to draw a bar cursor with an
11015 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11016 Unfortunately, I didn't find a font yet that has this property set.
11020 x_draw_bar_cursor (w
, row
, width
)
11022 struct glyph_row
*row
;
11025 struct frame
*f
= XFRAME (w
->frame
);
11026 struct glyph
*cursor_glyph
;
11029 unsigned long mask
;
11034 /* If cursor is out of bounds, don't draw garbage. This can happen
11035 in mini-buffer windows when switching between echo area glyphs
11036 and mini-buffer. */
11037 cursor_glyph
= get_phys_cursor_glyph (w
);
11038 if (cursor_glyph
== NULL
)
11041 /* If on an image, draw like a normal cursor. That's usually better
11042 visible than drawing a bar, esp. if the image is large so that
11043 the bar might not be in the window. */
11044 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11046 struct glyph_row
*row
;
11047 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11048 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11052 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
11053 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11054 xgcv
.graphics_exposures
= 0;
11055 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11056 dpy
= FRAME_X_DISPLAY (f
);
11057 window
= FRAME_X_WINDOW (f
);
11058 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11061 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11064 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11065 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11069 width
= f
->output_data
.x
->cursor_width
;
11071 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11072 x_clip_to_row (w
, row
, gc
, 0);
11073 XFillRectangle (dpy
, window
, gc
,
11075 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11076 min (cursor_glyph
->pixel_width
, width
),
11078 XSetClipMask (dpy
, gc
, None
);
11083 /* Clear the cursor of window W to background color, and mark the
11084 cursor as not shown. This is used when the text where the cursor
11085 is is about to be rewritten. */
11091 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11092 x_update_window_cursor (w
, 0);
11096 /* Draw the cursor glyph of window W in glyph row ROW. See the
11097 comment of x_draw_glyphs for the meaning of HL. */
11100 x_draw_phys_cursor_glyph (w
, row
, hl
)
11102 struct glyph_row
*row
;
11103 enum draw_glyphs_face hl
;
11105 /* If cursor hpos is out of bounds, don't draw garbage. This can
11106 happen in mini-buffer windows when switching between echo area
11107 glyphs and mini-buffer. */
11108 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11110 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11111 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11114 /* When we erase the cursor, and ROW is overlapped by other
11115 rows, make sure that these overlapping parts of other rows
11117 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11119 if (row
> w
->current_matrix
->rows
11120 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11121 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11123 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11124 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11125 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11131 /* Erase the image of a cursor of window W from the screen. */
11134 x_erase_phys_cursor (w
)
11137 struct frame
*f
= XFRAME (w
->frame
);
11138 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11139 int hpos
= w
->phys_cursor
.hpos
;
11140 int vpos
= w
->phys_cursor
.vpos
;
11141 int mouse_face_here_p
= 0;
11142 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11143 struct glyph_row
*cursor_row
;
11144 struct glyph
*cursor_glyph
;
11145 enum draw_glyphs_face hl
;
11147 /* No cursor displayed or row invalidated => nothing to do on the
11149 if (w
->phys_cursor_type
== NO_CURSOR
)
11150 goto mark_cursor_off
;
11152 /* VPOS >= active_glyphs->nrows means that window has been resized.
11153 Don't bother to erase the cursor. */
11154 if (vpos
>= active_glyphs
->nrows
)
11155 goto mark_cursor_off
;
11157 /* If row containing cursor is marked invalid, there is nothing we
11159 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11160 if (!cursor_row
->enabled_p
)
11161 goto mark_cursor_off
;
11163 /* This can happen when the new row is shorter than the old one.
11164 In this case, either x_draw_glyphs or clear_end_of_line
11165 should have cleared the cursor. Note that we wouldn't be
11166 able to erase the cursor in this case because we don't have a
11167 cursor glyph at hand. */
11168 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11169 goto mark_cursor_off
;
11171 /* If the cursor is in the mouse face area, redisplay that when
11172 we clear the cursor. */
11173 if (! NILP (dpyinfo
->mouse_face_window
)
11174 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11175 && (vpos
> dpyinfo
->mouse_face_beg_row
11176 || (vpos
== dpyinfo
->mouse_face_beg_row
11177 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11178 && (vpos
< dpyinfo
->mouse_face_end_row
11179 || (vpos
== dpyinfo
->mouse_face_end_row
11180 && hpos
< dpyinfo
->mouse_face_end_col
))
11181 /* Don't redraw the cursor's spot in mouse face if it is at the
11182 end of a line (on a newline). The cursor appears there, but
11183 mouse highlighting does not. */
11184 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11185 mouse_face_here_p
= 1;
11187 /* Maybe clear the display under the cursor. */
11188 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11191 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11193 cursor_glyph
= get_phys_cursor_glyph (w
);
11194 if (cursor_glyph
== NULL
)
11195 goto mark_cursor_off
;
11197 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11199 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11201 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11203 cursor_glyph
->pixel_width
,
11204 cursor_row
->visible_height
,
11208 /* Erase the cursor by redrawing the character underneath it. */
11209 if (mouse_face_here_p
)
11210 hl
= DRAW_MOUSE_FACE
;
11211 else if (cursor_row
->inverse_p
)
11212 hl
= DRAW_INVERSE_VIDEO
;
11214 hl
= DRAW_NORMAL_TEXT
;
11215 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11218 w
->phys_cursor_on_p
= 0;
11219 w
->phys_cursor_type
= NO_CURSOR
;
11223 /* Non-zero if physical cursor of window W is within mouse face. */
11226 cursor_in_mouse_face_p (w
)
11229 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
11230 int in_mouse_face
= 0;
11232 if (WINDOWP (dpyinfo
->mouse_face_window
)
11233 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
11235 int hpos
= w
->phys_cursor
.hpos
;
11236 int vpos
= w
->phys_cursor
.vpos
;
11238 if (vpos
>= dpyinfo
->mouse_face_beg_row
11239 && vpos
<= dpyinfo
->mouse_face_end_row
11240 && (vpos
> dpyinfo
->mouse_face_beg_row
11241 || hpos
>= dpyinfo
->mouse_face_beg_col
)
11242 && (vpos
< dpyinfo
->mouse_face_end_row
11243 || hpos
< dpyinfo
->mouse_face_end_col
11244 || dpyinfo
->mouse_face_past_end
))
11248 return in_mouse_face
;
11252 /* Display or clear cursor of window W. If ON is zero, clear the
11253 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11254 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11257 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11259 int on
, hpos
, vpos
, x
, y
;
11261 struct frame
*f
= XFRAME (w
->frame
);
11262 int new_cursor_type
;
11263 int new_cursor_width
;
11264 struct glyph_matrix
*current_glyphs
;
11265 struct glyph_row
*glyph_row
;
11266 struct glyph
*glyph
;
11268 /* This is pointless on invisible frames, and dangerous on garbaged
11269 windows and frames; in the latter case, the frame or window may
11270 be in the midst of changing its size, and x and y may be off the
11272 if (! FRAME_VISIBLE_P (f
)
11273 || FRAME_GARBAGED_P (f
)
11274 || vpos
>= w
->current_matrix
->nrows
11275 || hpos
>= w
->current_matrix
->matrix_w
)
11278 /* If cursor is off and we want it off, return quickly. */
11279 if (!on
&& !w
->phys_cursor_on_p
)
11282 current_glyphs
= w
->current_matrix
;
11283 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11284 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11286 /* If cursor row is not enabled, we don't really know where to
11287 display the cursor. */
11288 if (!glyph_row
->enabled_p
)
11290 w
->phys_cursor_on_p
= 0;
11294 xassert (interrupt_input_blocked
);
11296 /* Set new_cursor_type to the cursor we want to be displayed. In a
11297 mini-buffer window, we want the cursor only to appear if we are
11298 reading input from this window. For the selected window, we want
11299 the cursor type given by the frame parameter. If explicitly
11300 marked off, draw no cursor. In all other cases, we want a hollow
11302 new_cursor_width
= -1;
11303 if (cursor_in_echo_area
11304 && FRAME_HAS_MINIBUF_P (f
)
11305 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11307 if (w
== XWINDOW (echo_area_window
))
11308 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11310 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11314 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11315 || w
!= XWINDOW (f
->selected_window
))
11317 extern int cursor_in_non_selected_windows
;
11319 if (MINI_WINDOW_P (w
)
11320 || !cursor_in_non_selected_windows
11321 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11322 new_cursor_type
= NO_CURSOR
;
11324 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11326 else if (w
->cursor_off_p
)
11327 new_cursor_type
= NO_CURSOR
;
11330 struct buffer
*b
= XBUFFER (w
->buffer
);
11332 if (EQ (b
->cursor_type
, Qt
))
11333 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11335 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11336 &new_cursor_width
);
11340 /* If cursor is currently being shown and we don't want it to be or
11341 it is in the wrong place, or the cursor type is not what we want,
11343 if (w
->phys_cursor_on_p
11345 || w
->phys_cursor
.x
!= x
11346 || w
->phys_cursor
.y
!= y
11347 || new_cursor_type
!= w
->phys_cursor_type
))
11348 x_erase_phys_cursor (w
);
11350 /* If the cursor is now invisible and we want it to be visible,
11352 if (on
&& !w
->phys_cursor_on_p
)
11354 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11355 w
->phys_cursor_height
= glyph_row
->height
;
11357 /* Set phys_cursor_.* before x_draw_.* is called because some
11358 of them may need the information. */
11359 w
->phys_cursor
.x
= x
;
11360 w
->phys_cursor
.y
= glyph_row
->y
;
11361 w
->phys_cursor
.hpos
= hpos
;
11362 w
->phys_cursor
.vpos
= vpos
;
11363 w
->phys_cursor_type
= new_cursor_type
;
11364 w
->phys_cursor_on_p
= 1;
11366 switch (new_cursor_type
)
11368 case HOLLOW_BOX_CURSOR
:
11369 x_draw_hollow_cursor (w
, glyph_row
);
11372 case FILLED_BOX_CURSOR
:
11373 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11377 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11388 if (w
== XWINDOW (f
->selected_window
))
11389 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11390 xic_set_preeditarea (w
, x
, y
);
11395 if (updating_frame
!= f
)
11396 XFlush (FRAME_X_DISPLAY (f
));
11401 /* Display the cursor on window W, or clear it. X and Y are window
11402 relative pixel coordinates. HPOS and VPOS are glyph matrix
11403 positions. If W is not the selected window, display a hollow
11404 cursor. ON non-zero means display the cursor at X, Y which
11405 correspond to HPOS, VPOS, otherwise it is cleared. */
11408 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11410 int on
, hpos
, vpos
, x
, y
;
11413 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11418 /* Display the cursor on window W, or clear it, according to ON_P.
11419 Don't change the cursor's position. */
11422 x_update_cursor (f
, on_p
)
11425 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11429 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11430 in the window tree rooted at W. */
11433 x_update_cursor_in_window_tree (w
, on_p
)
11439 if (!NILP (w
->hchild
))
11440 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11441 else if (!NILP (w
->vchild
))
11442 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11444 x_update_window_cursor (w
, on_p
);
11446 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11451 /* Switch the display of W's cursor on or off, according to the value
11455 x_update_window_cursor (w
, on
)
11459 /* Don't update cursor in windows whose frame is in the process
11460 of being deleted. */
11461 if (w
->current_matrix
)
11464 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11465 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11475 /* Refresh bitmap kitchen sink icon for frame F
11476 when we get an expose event for it. */
11482 /* Normally, the window manager handles this function. */
11485 /* Make the x-window of frame F use the gnu icon bitmap. */
11488 x_bitmap_icon (f
, file
)
11494 if (FRAME_X_WINDOW (f
) == 0)
11497 /* Free up our existing icon bitmap if any. */
11498 if (f
->output_data
.x
->icon_bitmap
> 0)
11499 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11500 f
->output_data
.x
->icon_bitmap
= 0;
11502 if (STRINGP (file
))
11503 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11506 /* Create the GNU bitmap if necessary. */
11507 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11508 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11509 = x_create_bitmap_from_data (f
, gnu_bits
,
11510 gnu_width
, gnu_height
);
11512 /* The first time we create the GNU bitmap,
11513 this increments the ref-count one extra time.
11514 As a result, the GNU bitmap is never freed.
11515 That way, we don't have to worry about allocating it again. */
11516 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11518 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11521 x_wm_set_icon_pixmap (f
, bitmap_id
);
11522 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11528 /* Make the x-window of frame F use a rectangle with text.
11529 Use ICON_NAME as the text. */
11532 x_text_icon (f
, icon_name
)
11536 if (FRAME_X_WINDOW (f
) == 0)
11541 XTextProperty text
;
11542 text
.value
= (unsigned char *) icon_name
;
11543 text
.encoding
= XA_STRING
;
11545 text
.nitems
= strlen (icon_name
);
11546 #ifdef USE_X_TOOLKIT
11547 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11549 #else /* not USE_X_TOOLKIT */
11550 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11551 #endif /* not USE_X_TOOLKIT */
11553 #else /* not HAVE_X11R4 */
11554 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11555 #endif /* not HAVE_X11R4 */
11557 if (f
->output_data
.x
->icon_bitmap
> 0)
11558 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11559 f
->output_data
.x
->icon_bitmap
= 0;
11560 x_wm_set_icon_pixmap (f
, 0);
11565 #define X_ERROR_MESSAGE_SIZE 200
11567 /* If non-nil, this should be a string.
11568 It means catch X errors and store the error message in this string. */
11570 static Lisp_Object x_error_message_string
;
11572 /* An X error handler which stores the error message in
11573 x_error_message_string. This is called from x_error_handler if
11574 x_catch_errors is in effect. */
11577 x_error_catcher (display
, error
)
11579 XErrorEvent
*error
;
11581 XGetErrorText (display
, error
->error_code
,
11582 XSTRING (x_error_message_string
)->data
,
11583 X_ERROR_MESSAGE_SIZE
);
11586 /* Begin trapping X errors for display DPY. Actually we trap X errors
11587 for all displays, but DPY should be the display you are actually
11590 After calling this function, X protocol errors no longer cause
11591 Emacs to exit; instead, they are recorded in the string
11592 stored in x_error_message_string.
11594 Calling x_check_errors signals an Emacs error if an X error has
11595 occurred since the last call to x_catch_errors or x_check_errors.
11597 Calling x_uncatch_errors resumes the normal error handling. */
11599 void x_check_errors ();
11600 static Lisp_Object
x_catch_errors_unwind ();
11603 x_catch_errors (dpy
)
11606 int count
= specpdl_ptr
- specpdl
;
11608 /* Make sure any errors from previous requests have been dealt with. */
11609 XSync (dpy
, False
);
11611 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11613 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11614 XSTRING (x_error_message_string
)->data
[0] = 0;
11619 /* Unbind the binding that we made to check for X errors. */
11622 x_catch_errors_unwind (old_val
)
11623 Lisp_Object old_val
;
11625 x_error_message_string
= old_val
;
11629 /* If any X protocol errors have arrived since the last call to
11630 x_catch_errors or x_check_errors, signal an Emacs error using
11631 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11634 x_check_errors (dpy
, format
)
11638 /* Make sure to catch any errors incurred so far. */
11639 XSync (dpy
, False
);
11641 if (XSTRING (x_error_message_string
)->data
[0])
11642 error (format
, XSTRING (x_error_message_string
)->data
);
11645 /* Nonzero if we had any X protocol errors
11646 since we did x_catch_errors on DPY. */
11649 x_had_errors_p (dpy
)
11652 /* Make sure to catch any errors incurred so far. */
11653 XSync (dpy
, False
);
11655 return XSTRING (x_error_message_string
)->data
[0] != 0;
11658 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11661 x_clear_errors (dpy
)
11664 XSTRING (x_error_message_string
)->data
[0] = 0;
11667 /* Stop catching X protocol errors and let them make Emacs die.
11668 DPY should be the display that was passed to x_catch_errors.
11669 COUNT should be the value that was returned by
11670 the corresponding call to x_catch_errors. */
11673 x_uncatch_errors (dpy
, count
)
11677 unbind_to (count
, Qnil
);
11681 static unsigned int x_wire_count
;
11684 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11689 /* Handle SIGPIPE, which can happen when the connection to a server
11690 simply goes away. SIGPIPE is handled by x_connection_signal.
11691 Don't need to do anything, because the write which caused the
11692 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11693 which will do the appropriate cleanup for us. */
11696 x_connection_signal (signalnum
) /* If we don't have an argument, */
11697 int signalnum
; /* some compilers complain in signal calls. */
11700 /* USG systems forget handlers when they are used;
11701 must reestablish each time */
11702 signal (signalnum
, x_connection_signal
);
11707 /************************************************************************
11709 ************************************************************************/
11711 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
11712 the text of an error message that lead to the connection loss. */
11715 x_connection_closed (dpy
, error_message
)
11717 char *error_message
;
11719 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
11720 Lisp_Object frame
, tail
;
11724 msg
= (char *) alloca (strlen (error_message
) + 1);
11725 strcpy (msg
, error_message
);
11726 handling_signal
= 0;
11728 /* Prevent being called recursively because of an error condition
11729 below. Otherwise, we might end up with printing ``can't find per
11730 display information'' in the recursive call instead of printing
11731 the original message here. */
11732 count
= x_catch_errors (dpy
);
11734 /* We have to close the display to inform Xt that it doesn't
11735 exist anymore. If we don't, Xt will continue to wait for
11736 events from the display. As a consequence, a sequence of
11738 M-x make-frame-on-display RET :1 RET
11739 ...kill the new frame, so that we get an IO error...
11740 M-x make-frame-on-display RET :1 RET
11742 will indefinitely wait in Xt for events for display `:1', opened
11743 in the first class to make-frame-on-display.
11745 Closing the display is reported to lead to a bus error on
11746 OpenWindows in certain situations. I suspect that is a bug
11747 in OpenWindows. I don't know how to cicumvent it here. */
11749 #ifdef USE_X_TOOLKIT
11750 /* If DPYINFO is null, this means we didn't open the display
11751 in the first place, so don't try to close it. */
11753 XtCloseDisplay (dpy
);
11756 /* Indicate that this display is dead. */
11758 dpyinfo
->display
= 0;
11760 /* First delete frames whose mini-buffers are on frames
11761 that are on the dead display. */
11762 FOR_EACH_FRAME (tail
, frame
)
11764 Lisp_Object minibuf_frame
;
11766 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11767 if (FRAME_X_P (XFRAME (frame
))
11768 && FRAME_X_P (XFRAME (minibuf_frame
))
11769 && ! EQ (frame
, minibuf_frame
)
11770 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11771 Fdelete_frame (frame
, Qt
);
11774 /* Now delete all remaining frames on the dead display.
11775 We are now sure none of these is used as the mini-buffer
11776 for another frame that we need to delete. */
11777 FOR_EACH_FRAME (tail
, frame
)
11778 if (FRAME_X_P (XFRAME (frame
))
11779 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11781 /* Set this to t so that Fdelete_frame won't get confused
11782 trying to find a replacement. */
11783 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11784 Fdelete_frame (frame
, Qt
);
11788 x_delete_display (dpyinfo
);
11790 x_uncatch_errors (dpy
, count
);
11792 if (x_display_list
== 0)
11794 fprintf (stderr
, "%s\n", msg
);
11795 shut_down_emacs (0, 0, Qnil
);
11799 /* Ordinary stack unwind doesn't deal with these. */
11801 sigunblock (sigmask (SIGIO
));
11803 sigunblock (sigmask (SIGALRM
));
11804 TOTALLY_UNBLOCK_INPUT
;
11806 clear_waiting_for_input ();
11811 /* This is the usual handler for X protocol errors.
11812 It kills all frames on the display that we got the error for.
11813 If that was the only one, it prints an error message and kills Emacs. */
11816 x_error_quitter (display
, error
)
11818 XErrorEvent
*error
;
11820 char buf
[256], buf1
[356];
11822 /* Note that there is no real way portable across R3/R4 to get the
11823 original error handler. */
11825 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11826 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11827 buf
, error
->request_code
);
11828 x_connection_closed (display
, buf1
);
11832 /* This is the first-level handler for X protocol errors.
11833 It calls x_error_quitter or x_error_catcher. */
11836 x_error_handler (display
, error
)
11838 XErrorEvent
*error
;
11840 if (! NILP (x_error_message_string
))
11841 x_error_catcher (display
, error
);
11843 x_error_quitter (display
, error
);
11847 /* This is the handler for X IO errors, always.
11848 It kills all frames on the display that we lost touch with.
11849 If that was the only one, it prints an error message and kills Emacs. */
11852 x_io_error_quitter (display
)
11857 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11858 x_connection_closed (display
, buf
);
11862 /* Changing the font of the frame. */
11864 /* Give frame F the font named FONTNAME as its default font, and
11865 return the full name of that font. FONTNAME may be a wildcard
11866 pattern; in that case, we choose some font that fits the pattern.
11867 The return value shows which font we chose. */
11870 x_new_font (f
, fontname
)
11872 register char *fontname
;
11874 struct font_info
*fontp
11875 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11880 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11881 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11882 f
->output_data
.x
->fontset
= -1;
11884 /* Compute the scroll bar width in character columns. */
11885 if (f
->scroll_bar_pixel_width
> 0)
11887 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11888 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11892 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11893 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11896 /* Now make the frame display the given font. */
11897 if (FRAME_X_WINDOW (f
) != 0)
11899 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11900 f
->output_data
.x
->font
->fid
);
11901 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11902 f
->output_data
.x
->font
->fid
);
11903 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11904 f
->output_data
.x
->font
->fid
);
11906 frame_update_line_height (f
);
11908 /* Don't change the size of a tip frame; there's no point in
11909 doing it because it's done in Fx_show_tip, and it leads to
11910 problems because the tip frame has no widget. */
11911 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
11912 x_set_window_size (f
, 0, f
->width
, f
->height
);
11915 /* If we are setting a new frame's font for the first time,
11916 there are no faces yet, so this font's height is the line height. */
11917 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11919 return build_string (fontp
->full_name
);
11922 /* Give frame F the fontset named FONTSETNAME as its default font, and
11923 return the full name of that fontset. FONTSETNAME may be a wildcard
11924 pattern; in that case, we choose some fontset that fits the pattern.
11925 The return value shows which fontset we chose. */
11928 x_new_fontset (f
, fontsetname
)
11932 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11933 Lisp_Object result
;
11938 if (f
->output_data
.x
->fontset
== fontset
)
11939 /* This fontset is already set in frame F. There's nothing more
11941 return fontset_name (fontset
);
11943 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11945 if (!STRINGP (result
))
11946 /* Can't load ASCII font. */
11949 /* Since x_new_font doesn't update any fontset information, do it now. */
11950 f
->output_data
.x
->fontset
= fontset
;
11954 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11955 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11958 return build_string (fontsetname
);
11962 /***********************************************************************
11964 ***********************************************************************/
11970 /* XIM destroy callback function, which is called whenever the
11971 connection to input method XIM dies. CLIENT_DATA contains a
11972 pointer to the x_display_info structure corresponding to XIM. */
11975 xim_destroy_callback (xim
, client_data
, call_data
)
11977 XPointer client_data
;
11978 XPointer call_data
;
11980 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11981 Lisp_Object frame
, tail
;
11985 /* No need to call XDestroyIC.. */
11986 FOR_EACH_FRAME (tail
, frame
)
11988 struct frame
*f
= XFRAME (frame
);
11989 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11991 FRAME_XIC (f
) = NULL
;
11992 if (FRAME_XIC_FONTSET (f
))
11994 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11995 FRAME_XIC_FONTSET (f
) = NULL
;
12000 /* No need to call XCloseIM. */
12001 dpyinfo
->xim
= NULL
;
12002 XFree (dpyinfo
->xim_styles
);
12006 #endif /* HAVE_X11R6 */
12008 /* Open the connection to the XIM server on display DPYINFO.
12009 RESOURCE_NAME is the resource name Emacs uses. */
12012 xim_open_dpy (dpyinfo
, resource_name
)
12013 struct x_display_info
*dpyinfo
;
12014 char *resource_name
;
12019 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
12020 dpyinfo
->xim
= xim
;
12025 XIMCallback destroy
;
12028 /* Get supported styles and XIM values. */
12029 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
12032 destroy
.callback
= xim_destroy_callback
;
12033 destroy
.client_data
= (XPointer
)dpyinfo
;
12034 /* This isn't prptotyped in OSF 5.0. */
12035 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
12039 #else /* not USE_XIM */
12040 dpyinfo
->xim
= NULL
;
12041 #endif /* not USE_XIM */
12045 #ifdef HAVE_X11R6_XIM
12049 struct x_display_info
*dpyinfo
;
12050 char *resource_name
;
12053 /* XIM instantiate callback function, which is called whenever an XIM
12054 server is available. DISPLAY is teh display of the XIM.
12055 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12056 when the callback was registered. */
12059 xim_instantiate_callback (display
, client_data
, call_data
)
12061 XPointer client_data
;
12062 XPointer call_data
;
12064 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12065 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12067 /* We don't support multiple XIM connections. */
12071 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12073 /* Create XIC for the existing frames on the same display, as long
12074 as they have no XIC. */
12075 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12077 Lisp_Object tail
, frame
;
12080 FOR_EACH_FRAME (tail
, frame
)
12082 struct frame
*f
= XFRAME (frame
);
12084 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12085 if (FRAME_XIC (f
) == NULL
)
12087 create_frame_xic (f
);
12088 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12089 xic_set_statusarea (f
);
12090 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12092 struct window
*w
= XWINDOW (f
->selected_window
);
12093 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12102 #endif /* HAVE_X11R6_XIM */
12105 /* Open a connection to the XIM server on display DPYINFO.
12106 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12107 connection only at the first time. On X11R6, open the connection
12108 in the XIM instantiate callback function. */
12111 xim_initialize (dpyinfo
, resource_name
)
12112 struct x_display_info
*dpyinfo
;
12113 char *resource_name
;
12116 #ifdef HAVE_X11R6_XIM
12117 struct xim_inst_t
*xim_inst
;
12120 dpyinfo
->xim
= NULL
;
12121 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12122 xim_inst
->dpyinfo
= dpyinfo
;
12123 len
= strlen (resource_name
);
12124 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12125 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12126 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12127 resource_name
, EMACS_CLASS
,
12128 xim_instantiate_callback
,
12129 /* Fixme: This is XPointer in
12130 XFree86 but (XPointer *) on
12131 Tru64, at least. */
12132 (XPointer
) xim_inst
);
12133 #else /* not HAVE_X11R6_XIM */
12134 dpyinfo
->xim
= NULL
;
12135 xim_open_dpy (dpyinfo
, resource_name
);
12136 #endif /* not HAVE_X11R6_XIM */
12138 #else /* not USE_XIM */
12139 dpyinfo
->xim
= NULL
;
12140 #endif /* not USE_XIM */
12144 /* Close the connection to the XIM server on display DPYINFO. */
12147 xim_close_dpy (dpyinfo
)
12148 struct x_display_info
*dpyinfo
;
12151 #ifdef HAVE_X11R6_XIM
12152 if (dpyinfo
->display
)
12153 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12155 xim_instantiate_callback
, NULL
);
12156 #endif /* not HAVE_X11R6_XIM */
12157 if (dpyinfo
->display
)
12158 XCloseIM (dpyinfo
->xim
);
12159 dpyinfo
->xim
= NULL
;
12160 XFree (dpyinfo
->xim_styles
);
12161 #endif /* USE_XIM */
12164 #endif /* not HAVE_X11R6_XIM */
12168 /* Calculate the absolute position in frame F
12169 from its current recorded position values and gravity. */
12172 x_calc_absolute_position (f
)
12176 int win_x
= 0, win_y
= 0;
12177 int flags
= f
->output_data
.x
->size_hint_flags
;
12180 /* We have nothing to do if the current position
12181 is already for the top-left corner. */
12182 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12185 #ifdef USE_X_TOOLKIT
12186 this_window
= XtWindow (f
->output_data
.x
->widget
);
12188 this_window
= FRAME_X_WINDOW (f
);
12191 /* Find the position of the outside upper-left corner of
12192 the inner window, with respect to the outer window.
12193 But do this only if we will need the results. */
12194 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12199 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12202 x_clear_errors (FRAME_X_DISPLAY (f
));
12203 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12205 /* From-window, to-window. */
12207 f
->output_data
.x
->parent_desc
,
12209 /* From-position, to-position. */
12210 0, 0, &win_x
, &win_y
,
12212 /* Child of win. */
12214 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12216 Window newroot
, newparent
= 0xdeadbeef;
12217 Window
*newchildren
;
12218 unsigned int nchildren
;
12220 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12221 &newparent
, &newchildren
, &nchildren
))
12224 XFree ((char *) newchildren
);
12226 f
->output_data
.x
->parent_desc
= newparent
;
12232 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12236 /* Treat negative positions as relative to the leftmost bottommost
12237 position that fits on the screen. */
12238 if (flags
& XNegative
)
12239 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12240 - 2 * f
->output_data
.x
->border_width
- win_x
12242 + f
->output_data
.x
->left_pos
);
12245 int height
= PIXEL_HEIGHT (f
);
12247 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12248 /* Something is fishy here. When using Motif, starting Emacs with
12249 `-g -0-0', the frame appears too low by a few pixels.
12251 This seems to be so because initially, while Emacs is starting,
12252 the column widget's height and the frame's pixel height are
12253 different. The column widget's height is the right one. In
12254 later invocations, when Emacs is up, the frame's pixel height
12257 It's not obvious where the initial small difference comes from.
12258 2000-12-01, gerd. */
12260 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12263 if (flags
& YNegative
)
12264 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12265 - 2 * f
->output_data
.x
->border_width
12268 + f
->output_data
.x
->top_pos
);
12271 /* The left_pos and top_pos
12272 are now relative to the top and left screen edges,
12273 so the flags should correspond. */
12274 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12277 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12278 to really change the position, and 0 when calling from
12279 x_make_frame_visible (in that case, XOFF and YOFF are the current
12280 position values). It is -1 when calling from x_set_frame_parameters,
12281 which means, do adjust for borders but don't change the gravity. */
12284 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12286 register int xoff
, yoff
;
12287 int change_gravity
;
12289 int modified_top
, modified_left
;
12291 if (change_gravity
> 0)
12293 f
->output_data
.x
->top_pos
= yoff
;
12294 f
->output_data
.x
->left_pos
= xoff
;
12295 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12297 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12299 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12300 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12302 x_calc_absolute_position (f
);
12305 x_wm_set_size_hint (f
, (long) 0, 0);
12307 modified_left
= f
->output_data
.x
->left_pos
;
12308 modified_top
= f
->output_data
.x
->top_pos
;
12309 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12310 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12311 /* It is a mystery why we need to add the border_width here
12312 when the frame is already visible, but experiment says we do. */
12313 if (change_gravity
!= 0)
12315 modified_left
+= f
->output_data
.x
->border_width
;
12316 modified_top
+= f
->output_data
.x
->border_width
;
12320 #ifdef USE_X_TOOLKIT
12321 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12322 modified_left
, modified_top
);
12323 #else /* not USE_X_TOOLKIT */
12324 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12325 modified_left
, modified_top
);
12326 #endif /* not USE_X_TOOLKIT */
12331 /* Change the size of frame F's X window to COLS/ROWS in the case F
12332 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12333 top-left-corner window gravity for this size change and subsequent
12334 size changes. Otherwise we leave the window gravity unchanged. */
12337 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12339 int change_gravity
;
12342 int pixelwidth
, pixelheight
;
12344 check_frame_size (f
, &rows
, &cols
);
12345 f
->output_data
.x
->vertical_scroll_bar_extra
12346 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12348 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12349 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12350 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12351 f
->output_data
.x
->flags_areas_extra
12352 = FRAME_FLAGS_AREA_WIDTH (f
);
12353 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12354 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12356 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12357 x_wm_set_size_hint (f
, (long) 0, 0);
12359 XSync (FRAME_X_DISPLAY (f
), False
);
12360 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12361 pixelwidth
, pixelheight
);
12363 /* Now, strictly speaking, we can't be sure that this is accurate,
12364 but the window manager will get around to dealing with the size
12365 change request eventually, and we'll hear how it went when the
12366 ConfigureNotify event gets here.
12368 We could just not bother storing any of this information here,
12369 and let the ConfigureNotify event set everything up, but that
12370 might be kind of confusing to the Lisp code, since size changes
12371 wouldn't be reported in the frame parameters until some random
12372 point in the future when the ConfigureNotify event arrives.
12374 We pass 1 for DELAY since we can't run Lisp code inside of
12376 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12377 PIXEL_WIDTH (f
) = pixelwidth
;
12378 PIXEL_HEIGHT (f
) = pixelheight
;
12380 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12381 receive in the ConfigureNotify event; if we get what we asked
12382 for, then the event won't cause the screen to become garbaged, so
12383 we have to make sure to do it here. */
12384 SET_FRAME_GARBAGED (f
);
12386 XFlush (FRAME_X_DISPLAY (f
));
12390 /* Call this to change the size of frame F's x-window.
12391 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12392 for this size change and subsequent size changes.
12393 Otherwise we leave the window gravity unchanged. */
12396 x_set_window_size (f
, change_gravity
, cols
, rows
)
12398 int change_gravity
;
12403 #ifdef USE_X_TOOLKIT
12405 if (f
->output_data
.x
->widget
!= NULL
)
12407 /* The x and y position of the widget is clobbered by the
12408 call to XtSetValues within EmacsFrameSetCharSize.
12409 This is a real kludge, but I don't understand Xt so I can't
12410 figure out a correct fix. Can anyone else tell me? -- rms. */
12411 int xpos
= f
->output_data
.x
->widget
->core
.x
;
12412 int ypos
= f
->output_data
.x
->widget
->core
.y
;
12413 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
12414 f
->output_data
.x
->widget
->core
.x
= xpos
;
12415 f
->output_data
.x
->widget
->core
.y
= ypos
;
12418 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12420 #else /* not USE_X_TOOLKIT */
12422 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12424 #endif /* not USE_X_TOOLKIT */
12426 /* If cursor was outside the new size, mark it as off. */
12427 mark_window_cursors_off (XWINDOW (f
->root_window
));
12429 /* Clear out any recollection of where the mouse highlighting was,
12430 since it might be in a place that's outside the new frame size.
12431 Actually checking whether it is outside is a pain in the neck,
12432 so don't try--just let the highlighting be done afresh with new size. */
12433 cancel_mouse_face (f
);
12438 /* Mouse warping. */
12441 x_set_mouse_position (f
, x
, y
)
12447 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
12448 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
12450 if (pix_x
< 0) pix_x
= 0;
12451 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
12453 if (pix_y
< 0) pix_y
= 0;
12454 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
12458 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12459 0, 0, 0, 0, pix_x
, pix_y
);
12463 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
12466 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
12472 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12473 0, 0, 0, 0, pix_x
, pix_y
);
12477 /* focus shifting, raising and lowering. */
12480 x_focus_on_frame (f
)
12483 #if 0 /* This proves to be unpleasant. */
12487 /* I don't think that the ICCCM allows programs to do things like this
12488 without the interaction of the window manager. Whatever you end up
12489 doing with this code, do it to x_unfocus_frame too. */
12490 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12491 RevertToPointerRoot
, CurrentTime
);
12496 x_unfocus_frame (f
)
12500 /* Look at the remarks in x_focus_on_frame. */
12501 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
12502 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
12503 RevertToPointerRoot
, CurrentTime
);
12507 /* Raise frame F. */
12513 if (f
->async_visible
)
12516 #ifdef USE_X_TOOLKIT
12517 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12518 #else /* not USE_X_TOOLKIT */
12519 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12520 #endif /* not USE_X_TOOLKIT */
12521 XFlush (FRAME_X_DISPLAY (f
));
12526 /* Lower frame F. */
12532 if (f
->async_visible
)
12535 #ifdef USE_X_TOOLKIT
12536 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12537 #else /* not USE_X_TOOLKIT */
12538 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12539 #endif /* not USE_X_TOOLKIT */
12540 XFlush (FRAME_X_DISPLAY (f
));
12546 XTframe_raise_lower (f
, raise_flag
)
12556 /* Change of visibility. */
12558 /* This tries to wait until the frame is really visible.
12559 However, if the window manager asks the user where to position
12560 the frame, this will return before the user finishes doing that.
12561 The frame will not actually be visible at that time,
12562 but it will become visible later when the window manager
12563 finishes with it. */
12566 x_make_frame_visible (f
)
12570 int original_top
, original_left
;
12571 int retry_count
= 2;
12577 type
= x_icon_type (f
);
12579 x_bitmap_icon (f
, type
);
12581 if (! FRAME_VISIBLE_P (f
))
12583 /* We test FRAME_GARBAGED_P here to make sure we don't
12584 call x_set_offset a second time
12585 if we get to x_make_frame_visible a second time
12586 before the window gets really visible. */
12587 if (! FRAME_ICONIFIED_P (f
)
12588 && ! f
->output_data
.x
->asked_for_visible
)
12589 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12591 f
->output_data
.x
->asked_for_visible
= 1;
12593 if (! EQ (Vx_no_window_manager
, Qt
))
12594 x_wm_set_window_state (f
, NormalState
);
12595 #ifdef USE_X_TOOLKIT
12596 /* This was XtPopup, but that did nothing for an iconified frame. */
12597 XtMapWidget (f
->output_data
.x
->widget
);
12598 #else /* not USE_X_TOOLKIT */
12599 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12600 #endif /* not USE_X_TOOLKIT */
12601 #if 0 /* This seems to bring back scroll bars in the wrong places
12602 if the window configuration has changed. They seem
12603 to come back ok without this. */
12604 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
12605 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12609 XFlush (FRAME_X_DISPLAY (f
));
12611 /* Synchronize to ensure Emacs knows the frame is visible
12612 before we do anything else. We do this loop with input not blocked
12613 so that incoming events are handled. */
12617 /* This must be before UNBLOCK_INPUT
12618 since events that arrive in response to the actions above
12619 will set it when they are handled. */
12620 int previously_visible
= f
->output_data
.x
->has_been_visible
;
12622 original_left
= f
->output_data
.x
->left_pos
;
12623 original_top
= f
->output_data
.x
->top_pos
;
12625 /* This must come after we set COUNT. */
12628 /* We unblock here so that arriving X events are processed. */
12630 /* Now move the window back to where it was "supposed to be".
12631 But don't do it if the gravity is negative.
12632 When the gravity is negative, this uses a position
12633 that is 3 pixels too low. Perhaps that's really the border width.
12635 Don't do this if the window has never been visible before,
12636 because the window manager may choose the position
12637 and we don't want to override it. */
12639 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
12640 && f
->output_data
.x
->win_gravity
== NorthWestGravity
12641 && previously_visible
)
12645 unsigned int width
, height
, border
, depth
;
12649 /* On some window managers (such as FVWM) moving an existing
12650 window, even to the same place, causes the window manager
12651 to introduce an offset. This can cause the window to move
12652 to an unexpected location. Check the geometry (a little
12653 slow here) and then verify that the window is in the right
12654 place. If the window is not in the right place, move it
12655 there, and take the potential window manager hit. */
12656 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12657 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
12659 if (original_left
!= x
|| original_top
!= y
)
12660 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12661 original_left
, original_top
);
12666 XSETFRAME (frame
, f
);
12668 /* Wait until the frame is visible. Process X events until a
12669 MapNotify event has been seen, or until we think we won't get a
12670 MapNotify at all.. */
12671 for (count
= input_signal_count
+ 10;
12672 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
12674 /* Force processing of queued events. */
12677 /* Machines that do polling rather than SIGIO have been
12678 observed to go into a busy-wait here. So we'll fake an
12679 alarm signal to let the handler know that there's something
12680 to be read. We used to raise a real alarm, but it seems
12681 that the handler isn't always enabled here. This is
12683 if (input_polling_used ())
12685 /* It could be confusing if a real alarm arrives while
12686 processing the fake one. Turn it off and let the
12687 handler reset it. */
12688 extern void poll_for_input_1
P_ ((void));
12689 int old_poll_suppress_count
= poll_suppress_count
;
12690 poll_suppress_count
= 1;
12691 poll_for_input_1 ();
12692 poll_suppress_count
= old_poll_suppress_count
;
12695 /* See if a MapNotify event has been processed. */
12696 FRAME_SAMPLE_VISIBILITY (f
);
12701 (let ((f (selected-frame)))
12705 the frame is not raised with various window managers on
12706 FreeBSD, Linux and Solaris. It turns out that, for some
12707 unknown reason, the call to XtMapWidget is completely ignored.
12708 Mapping the widget a second time works. */
12710 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
12715 /* Change from mapped state to withdrawn state. */
12717 /* Make the frame visible (mapped and not iconified). */
12720 x_make_frame_invisible (f
)
12725 #ifdef USE_X_TOOLKIT
12726 /* Use the frame's outermost window, not the one we normally draw on. */
12727 window
= XtWindow (f
->output_data
.x
->widget
);
12728 #else /* not USE_X_TOOLKIT */
12729 window
= FRAME_X_WINDOW (f
);
12730 #endif /* not USE_X_TOOLKIT */
12732 /* Don't keep the highlight on an invisible frame. */
12733 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12734 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12736 #if 0/* This might add unreliability; I don't trust it -- rms. */
12737 if (! f
->async_visible
&& ! f
->async_iconified
)
12743 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12744 that the current position of the window is user-specified, rather than
12745 program-specified, so that when the window is mapped again, it will be
12746 placed at the same location, without forcing the user to position it
12747 by hand again (they have already done that once for this window.) */
12748 x_wm_set_size_hint (f
, (long) 0, 1);
12752 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12753 DefaultScreen (FRAME_X_DISPLAY (f
))))
12755 UNBLOCK_INPUT_RESIGNAL
;
12756 error ("Can't notify window manager of window withdrawal");
12758 #else /* ! defined (HAVE_X11R4) */
12760 /* Tell the window manager what we're going to do. */
12761 if (! EQ (Vx_no_window_manager
, Qt
))
12765 unmap
.xunmap
.type
= UnmapNotify
;
12766 unmap
.xunmap
.window
= window
;
12767 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12768 unmap
.xunmap
.from_configure
= False
;
12769 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12770 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12772 SubstructureRedirectMaskSubstructureNotifyMask
,
12775 UNBLOCK_INPUT_RESIGNAL
;
12776 error ("Can't notify window manager of withdrawal");
12780 /* Unmap the window ourselves. Cheeky! */
12781 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12782 #endif /* ! defined (HAVE_X11R4) */
12784 /* We can't distinguish this from iconification
12785 just by the event that we get from the server.
12786 So we can't win using the usual strategy of letting
12787 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12788 and synchronize with the server to make sure we agree. */
12790 FRAME_ICONIFIED_P (f
) = 0;
12791 f
->async_visible
= 0;
12792 f
->async_iconified
= 0;
12799 /* Change window state from mapped to iconified. */
12802 x_iconify_frame (f
)
12808 /* Don't keep the highlight on an invisible frame. */
12809 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12810 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12812 if (f
->async_iconified
)
12817 FRAME_SAMPLE_VISIBILITY (f
);
12819 type
= x_icon_type (f
);
12821 x_bitmap_icon (f
, type
);
12823 #ifdef USE_X_TOOLKIT
12825 if (! FRAME_VISIBLE_P (f
))
12827 if (! EQ (Vx_no_window_manager
, Qt
))
12828 x_wm_set_window_state (f
, IconicState
);
12829 /* This was XtPopup, but that did nothing for an iconified frame. */
12830 XtMapWidget (f
->output_data
.x
->widget
);
12831 /* The server won't give us any event to indicate
12832 that an invisible frame was changed to an icon,
12833 so we have to record it here. */
12836 f
->async_iconified
= 1;
12837 f
->async_visible
= 0;
12842 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12843 XtWindow (f
->output_data
.x
->widget
),
12844 DefaultScreen (FRAME_X_DISPLAY (f
)));
12848 error ("Can't notify window manager of iconification");
12850 f
->async_iconified
= 1;
12851 f
->async_visible
= 0;
12855 XFlush (FRAME_X_DISPLAY (f
));
12857 #else /* not USE_X_TOOLKIT */
12859 /* Make sure the X server knows where the window should be positioned,
12860 in case the user deiconifies with the window manager. */
12861 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12862 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12864 /* Since we don't know which revision of X we're running, we'll use both
12865 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12867 /* X11R4: send a ClientMessage to the window manager using the
12868 WM_CHANGE_STATE type. */
12872 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12873 message
.xclient
.type
= ClientMessage
;
12874 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12875 message
.xclient
.format
= 32;
12876 message
.xclient
.data
.l
[0] = IconicState
;
12878 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12879 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12881 SubstructureRedirectMask
| SubstructureNotifyMask
,
12884 UNBLOCK_INPUT_RESIGNAL
;
12885 error ("Can't notify window manager of iconification");
12889 /* X11R3: set the initial_state field of the window manager hints to
12891 x_wm_set_window_state (f
, IconicState
);
12893 if (!FRAME_VISIBLE_P (f
))
12895 /* If the frame was withdrawn, before, we must map it. */
12896 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12899 f
->async_iconified
= 1;
12900 f
->async_visible
= 0;
12902 XFlush (FRAME_X_DISPLAY (f
));
12904 #endif /* not USE_X_TOOLKIT */
12908 /* Free X resources of frame F. */
12911 x_free_frame_resources (f
)
12914 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12918 /* If a display connection is dead, don't try sending more
12919 commands to the X server. */
12920 if (dpyinfo
->display
)
12922 if (f
->output_data
.x
->icon_desc
)
12923 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12927 free_frame_xic (f
);
12930 if (FRAME_X_WINDOW (f
))
12931 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12933 #ifdef USE_X_TOOLKIT
12934 if (f
->output_data
.x
->widget
)
12936 XtDestroyWidget (f
->output_data
.x
->widget
);
12937 f
->output_data
.x
->widget
= NULL
;
12939 free_frame_menubar (f
);
12940 #endif /* USE_X_TOOLKIT */
12942 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12943 unload_color (f
, f
->output_data
.x
->background_pixel
);
12944 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12945 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12946 unload_color (f
, f
->output_data
.x
->border_pixel
);
12947 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12949 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12950 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12951 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12952 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12953 if (f
->output_data
.x
->white_relief
.allocated_p
)
12954 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12955 if (f
->output_data
.x
->black_relief
.allocated_p
)
12956 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12958 if (FRAME_FACE_CACHE (f
))
12959 free_frame_faces (f
);
12962 XFlush (FRAME_X_DISPLAY (f
));
12965 if (f
->output_data
.x
->saved_menu_event
)
12966 xfree (f
->output_data
.x
->saved_menu_event
);
12968 xfree (f
->output_data
.x
);
12969 f
->output_data
.x
= NULL
;
12971 if (f
== dpyinfo
->x_focus_frame
)
12972 dpyinfo
->x_focus_frame
= 0;
12973 if (f
== dpyinfo
->x_focus_event_frame
)
12974 dpyinfo
->x_focus_event_frame
= 0;
12975 if (f
== dpyinfo
->x_highlight_frame
)
12976 dpyinfo
->x_highlight_frame
= 0;
12978 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12980 dpyinfo
->mouse_face_beg_row
12981 = dpyinfo
->mouse_face_beg_col
= -1;
12982 dpyinfo
->mouse_face_end_row
12983 = dpyinfo
->mouse_face_end_col
= -1;
12984 dpyinfo
->mouse_face_window
= Qnil
;
12985 dpyinfo
->mouse_face_deferred_gc
= 0;
12986 dpyinfo
->mouse_face_mouse_frame
= 0;
12993 /* Destroy the X window of frame F. */
12996 x_destroy_window (f
)
12999 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13001 /* If a display connection is dead, don't try sending more
13002 commands to the X server. */
13003 if (dpyinfo
->display
!= 0)
13004 x_free_frame_resources (f
);
13006 dpyinfo
->reference_count
--;
13010 /* Setting window manager hints. */
13012 /* Set the normal size hints for the window manager, for frame F.
13013 FLAGS is the flags word to use--or 0 meaning preserve the flags
13014 that the window now has.
13015 If USER_POSITION is nonzero, we set the USPosition
13016 flag (this is useful when FLAGS is 0). */
13019 x_wm_set_size_hint (f
, flags
, user_position
)
13024 XSizeHints size_hints
;
13026 #ifdef USE_X_TOOLKIT
13029 Dimension widget_width
, widget_height
;
13030 Window window
= XtWindow (f
->output_data
.x
->widget
);
13031 #else /* not USE_X_TOOLKIT */
13032 Window window
= FRAME_X_WINDOW (f
);
13033 #endif /* not USE_X_TOOLKIT */
13035 /* Setting PMaxSize caused various problems. */
13036 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
13038 size_hints
.x
= f
->output_data
.x
->left_pos
;
13039 size_hints
.y
= f
->output_data
.x
->top_pos
;
13041 #ifdef USE_X_TOOLKIT
13042 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
13043 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
13044 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
13045 size_hints
.height
= widget_height
;
13046 size_hints
.width
= widget_width
;
13047 #else /* not USE_X_TOOLKIT */
13048 size_hints
.height
= PIXEL_HEIGHT (f
);
13049 size_hints
.width
= PIXEL_WIDTH (f
);
13050 #endif /* not USE_X_TOOLKIT */
13052 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13053 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13054 size_hints
.max_width
13055 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13056 size_hints
.max_height
13057 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13059 /* Calculate the base and minimum sizes.
13061 (When we use the X toolkit, we don't do it here.
13062 Instead we copy the values that the widgets are using, below.) */
13063 #ifndef USE_X_TOOLKIT
13065 int base_width
, base_height
;
13066 int min_rows
= 0, min_cols
= 0;
13068 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13069 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13071 check_frame_size (f
, &min_rows
, &min_cols
);
13073 /* The window manager uses the base width hints to calculate the
13074 current number of rows and columns in the frame while
13075 resizing; min_width and min_height aren't useful for this
13076 purpose, since they might not give the dimensions for a
13077 zero-row, zero-column frame.
13079 We use the base_width and base_height members if we have
13080 them; otherwise, we set the min_width and min_height members
13081 to the size for a zero x zero frame. */
13084 size_hints
.flags
|= PBaseSize
;
13085 size_hints
.base_width
= base_width
;
13086 size_hints
.base_height
= base_height
;
13087 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13088 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13090 size_hints
.min_width
= base_width
;
13091 size_hints
.min_height
= base_height
;
13095 /* If we don't need the old flags, we don't need the old hint at all. */
13098 size_hints
.flags
|= flags
;
13101 #endif /* not USE_X_TOOLKIT */
13104 XSizeHints hints
; /* Sometimes I hate X Windows... */
13105 long supplied_return
;
13109 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13112 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13115 #ifdef USE_X_TOOLKIT
13116 size_hints
.base_height
= hints
.base_height
;
13117 size_hints
.base_width
= hints
.base_width
;
13118 size_hints
.min_height
= hints
.min_height
;
13119 size_hints
.min_width
= hints
.min_width
;
13123 size_hints
.flags
|= flags
;
13128 if (hints
.flags
& PSize
)
13129 size_hints
.flags
|= PSize
;
13130 if (hints
.flags
& PPosition
)
13131 size_hints
.flags
|= PPosition
;
13132 if (hints
.flags
& USPosition
)
13133 size_hints
.flags
|= USPosition
;
13134 if (hints
.flags
& USSize
)
13135 size_hints
.flags
|= USSize
;
13139 #ifndef USE_X_TOOLKIT
13144 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
13145 size_hints
.flags
|= PWinGravity
;
13149 size_hints
.flags
&= ~ PPosition
;
13150 size_hints
.flags
|= USPosition
;
13152 #endif /* PWinGravity */
13155 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13157 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13161 /* Used for IconicState or NormalState */
13164 x_wm_set_window_state (f
, state
)
13168 #ifdef USE_X_TOOLKIT
13171 XtSetArg (al
[0], XtNinitialState
, state
);
13172 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13173 #else /* not USE_X_TOOLKIT */
13174 Window window
= FRAME_X_WINDOW (f
);
13176 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
13177 f
->output_data
.x
->wm_hints
.initial_state
= state
;
13179 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13180 #endif /* not USE_X_TOOLKIT */
13184 x_wm_set_icon_pixmap (f
, pixmap_id
)
13188 Pixmap icon_pixmap
;
13190 #ifndef USE_X_TOOLKIT
13191 Window window
= FRAME_X_WINDOW (f
);
13196 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
13197 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
13201 /* It seems there is no way to turn off use of an icon pixmap.
13202 The following line does it, only if no icon has yet been created,
13203 for some window managers. But with mwm it crashes.
13204 Some people say it should clear the IconPixmapHint bit in this case,
13205 but that doesn't work, and the X consortium said it isn't the
13206 right thing at all. Since there is no way to win,
13207 best to explicitly give up. */
13209 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
13215 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
13219 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
13220 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13223 #else /* not USE_X_TOOLKIT */
13225 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
13226 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13228 #endif /* not USE_X_TOOLKIT */
13232 x_wm_set_icon_position (f
, icon_x
, icon_y
)
13234 int icon_x
, icon_y
;
13236 #ifdef USE_X_TOOLKIT
13237 Window window
= XtWindow (f
->output_data
.x
->widget
);
13239 Window window
= FRAME_X_WINDOW (f
);
13242 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
13243 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
13244 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
13246 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13250 /***********************************************************************
13252 ***********************************************************************/
13254 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
13257 x_get_font_info (f
, font_idx
)
13261 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
13265 /* Return a list of names of available fonts matching PATTERN on frame F.
13267 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13270 SIZE < 0 means include scalable fonts.
13272 Frame F null means we have not yet created any frame on X, and
13273 consult the first display in x_display_list. MAXNAMES sets a limit
13274 on how many fonts to match. */
13277 x_list_fonts (f
, pattern
, size
, maxnames
)
13279 Lisp_Object pattern
;
13283 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13284 Lisp_Object tem
, second_best
;
13285 struct x_display_info
*dpyinfo
13286 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13287 Display
*dpy
= dpyinfo
->display
;
13288 int try_XLoadQueryFont
= 0;
13290 int allow_scalable_fonts_p
= 0;
13294 allow_scalable_fonts_p
= 1;
13298 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13299 if (NILP (patterns
))
13300 patterns
= Fcons (pattern
, Qnil
);
13302 if (maxnames
== 1 && !size
)
13303 /* We can return any single font matching PATTERN. */
13304 try_XLoadQueryFont
= 1;
13306 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13309 char **names
= NULL
;
13311 pattern
= XCAR (patterns
);
13312 /* See if we cached the result for this particular query.
13313 The cache is an alist of the form:
13314 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13315 tem
= XCDR (dpyinfo
->name_list_element
);
13316 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13317 allow_scalable_fonts_p
? Qt
: Qnil
);
13318 list
= Fassoc (key
, tem
);
13321 list
= Fcdr_safe (list
);
13322 /* We have a cashed list. Don't have to get the list again. */
13326 /* At first, put PATTERN in the cache. */
13329 count
= x_catch_errors (dpy
);
13331 if (try_XLoadQueryFont
)
13334 unsigned long value
;
13336 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13337 if (x_had_errors_p (dpy
))
13339 /* This error is perhaps due to insufficient memory on X
13340 server. Let's just ignore it. */
13342 x_clear_errors (dpy
);
13346 && XGetFontProperty (font
, XA_FONT
, &value
))
13348 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13349 int len
= strlen (name
);
13352 /* If DXPC (a Differential X Protocol Compressor)
13353 Ver.3.7 is running, XGetAtomName will return null
13354 string. We must avoid such a name. */
13356 try_XLoadQueryFont
= 0;
13360 names
= (char **) alloca (sizeof (char *));
13361 /* Some systems only allow alloca assigned to a
13363 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13364 bcopy (name
, names
[0], len
+ 1);
13369 try_XLoadQueryFont
= 0;
13372 XFreeFont (dpy
, font
);
13375 if (!try_XLoadQueryFont
)
13377 /* We try at least 10 fonts because XListFonts will return
13378 auto-scaled fonts at the head. */
13379 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
13381 if (x_had_errors_p (dpy
))
13383 /* This error is perhaps due to insufficient memory on X
13384 server. Let's just ignore it. */
13386 x_clear_errors (dpy
);
13390 x_uncatch_errors (dpy
, count
);
13397 /* Make a list of all the fonts we got back.
13398 Store that in the font cache for the display. */
13399 for (i
= 0; i
< num_fonts
; i
++)
13402 char *p
= names
[i
];
13403 int average_width
= -1, dashes
= 0;
13405 /* Count the number of dashes in NAMES[I]. If there are
13406 14 dashes, and the field value following 12th dash
13407 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
13408 is usually too ugly to be used for editing. Let's
13414 if (dashes
== 7) /* PIXEL_SIZE field */
13416 else if (dashes
== 12) /* AVERAGE_WIDTH field */
13417 average_width
= atoi (p
);
13420 if (allow_scalable_fonts_p
13421 || dashes
< 14 || average_width
!= 0)
13423 tem
= build_string (names
[i
]);
13424 if (NILP (Fassoc (tem
, list
)))
13426 if (STRINGP (Vx_pixel_size_width_font_regexp
)
13427 && ((fast_c_string_match_ignore_case
13428 (Vx_pixel_size_width_font_regexp
, names
[i
]))
13430 /* We can set the value of PIXEL_SIZE to the
13431 width of this font. */
13432 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
13434 /* For the moment, width is not known. */
13435 list
= Fcons (Fcons (tem
, Qnil
), list
);
13439 if (!try_XLoadQueryFont
)
13440 XFreeFontNames (names
);
13443 /* Now store the result in the cache. */
13444 XCDR (dpyinfo
->name_list_element
)
13445 = Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
));
13448 if (NILP (list
)) continue; /* Try the remaining alternatives. */
13450 newlist
= second_best
= Qnil
;
13451 /* Make a list of the fonts that have the right width. */
13452 for (; CONSP (list
); list
= XCDR (list
))
13458 if (!CONSP (tem
) || NILP (XCAR (tem
)))
13462 newlist
= Fcons (XCAR (tem
), newlist
);
13466 if (!INTEGERP (XCDR (tem
)))
13468 /* Since we have not yet known the size of this font, we
13469 must try slow function call XLoadQueryFont. */
13470 XFontStruct
*thisinfo
;
13473 count
= x_catch_errors (dpy
);
13474 thisinfo
= XLoadQueryFont (dpy
,
13475 XSTRING (XCAR (tem
))->data
);
13476 if (x_had_errors_p (dpy
))
13478 /* This error is perhaps due to insufficient memory on X
13479 server. Let's just ignore it. */
13481 x_clear_errors (dpy
);
13483 x_uncatch_errors (dpy
, count
);
13489 = (thisinfo
->min_bounds
.width
== 0
13491 : make_number (thisinfo
->max_bounds
.width
));
13492 XFreeFont (dpy
, thisinfo
);
13495 /* For unknown reason, the previous call of XListFont had
13496 returned a font which can't be opened. Record the size
13497 as 0 not to try to open it again. */
13498 XCDR (tem
) = make_number (0);
13501 found_size
= XINT (XCDR (tem
));
13502 if (found_size
== size
)
13503 newlist
= Fcons (XCAR (tem
), newlist
);
13504 else if (found_size
> 0)
13506 if (NILP (second_best
))
13508 else if (found_size
< size
)
13510 if (XINT (XCDR (second_best
)) > size
13511 || XINT (XCDR (second_best
)) < found_size
)
13516 if (XINT (XCDR (second_best
)) > size
13517 && XINT (XCDR (second_best
)) > found_size
)
13522 if (!NILP (newlist
))
13524 else if (!NILP (second_best
))
13526 newlist
= Fcons (XCAR (second_best
), Qnil
);
13537 /* Check that FONT is valid on frame F. It is if it can be found in F's
13541 x_check_font (f
, font
)
13546 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13548 xassert (font
!= NULL
);
13550 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13551 if (dpyinfo
->font_table
[i
].name
13552 && font
== dpyinfo
->font_table
[i
].font
)
13555 xassert (i
< dpyinfo
->n_fonts
);
13558 #endif /* GLYPH_DEBUG != 0 */
13560 /* Set *W to the minimum width, *H to the minimum font height of FONT.
13561 Note: There are (broken) X fonts out there with invalid XFontStruct
13562 min_bounds contents. For example, handa@etl.go.jp reports that
13563 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
13564 have font->min_bounds.width == 0. */
13567 x_font_min_bounds (font
, w
, h
)
13571 *h
= FONT_HEIGHT (font
);
13572 *w
= font
->min_bounds
.width
;
13574 /* Try to handle the case where FONT->min_bounds has invalid
13575 contents. Since the only font known to have invalid min_bounds
13576 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
13578 *w
= font
->max_bounds
.width
;
13582 /* Compute the smallest character width and smallest font height over
13583 all fonts available on frame F. Set the members smallest_char_width
13584 and smallest_font_height in F's x_display_info structure to
13585 the values computed. Value is non-zero if smallest_font_height or
13586 smallest_char_width become smaller than they were before. */
13589 x_compute_min_glyph_bounds (f
)
13593 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13595 int old_width
= dpyinfo
->smallest_char_width
;
13596 int old_height
= dpyinfo
->smallest_font_height
;
13598 dpyinfo
->smallest_font_height
= 100000;
13599 dpyinfo
->smallest_char_width
= 100000;
13601 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13602 if (dpyinfo
->font_table
[i
].name
)
13604 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
13607 font
= (XFontStruct
*) fontp
->font
;
13608 xassert (font
!= (XFontStruct
*) ~0);
13609 x_font_min_bounds (font
, &w
, &h
);
13611 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
13612 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
13615 xassert (dpyinfo
->smallest_char_width
> 0
13616 && dpyinfo
->smallest_font_height
> 0);
13618 return (dpyinfo
->n_fonts
== 1
13619 || dpyinfo
->smallest_char_width
< old_width
13620 || dpyinfo
->smallest_font_height
< old_height
);
13624 /* Load font named FONTNAME of the size SIZE for frame F, and return a
13625 pointer to the structure font_info while allocating it dynamically.
13626 If SIZE is 0, load any size of font.
13627 If loading is failed, return NULL. */
13630 x_load_font (f
, fontname
, size
)
13632 register char *fontname
;
13635 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13636 Lisp_Object font_names
;
13639 /* Get a list of all the fonts that match this name. Once we
13640 have a list of matching fonts, we compare them against the fonts
13641 we already have by comparing names. */
13642 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
13644 if (!NILP (font_names
))
13649 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13650 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
13651 if (dpyinfo
->font_table
[i
].name
13652 && (!strcmp (dpyinfo
->font_table
[i
].name
,
13653 XSTRING (XCAR (tail
))->data
)
13654 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
13655 XSTRING (XCAR (tail
))->data
)))
13656 return (dpyinfo
->font_table
+ i
);
13659 /* Load the font and add it to the table. */
13663 struct font_info
*fontp
;
13664 unsigned long value
;
13667 /* If we have found fonts by x_list_font, load one of them. If
13668 not, we still try to load a font by the name given as FONTNAME
13669 because XListFonts (called in x_list_font) of some X server has
13670 a bug of not finding a font even if the font surely exists and
13671 is loadable by XLoadQueryFont. */
13672 if (size
> 0 && !NILP (font_names
))
13673 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
13676 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
13677 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
13678 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
13680 /* This error is perhaps due to insufficient memory on X
13681 server. Let's just ignore it. */
13683 x_clear_errors (FRAME_X_DISPLAY (f
));
13685 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
13690 /* Find a free slot in the font table. */
13691 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13692 if (dpyinfo
->font_table
[i
].name
== NULL
)
13695 /* If no free slot found, maybe enlarge the font table. */
13696 if (i
== dpyinfo
->n_fonts
13697 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
13700 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
13701 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
13702 dpyinfo
->font_table
13703 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
13706 fontp
= dpyinfo
->font_table
+ i
;
13707 if (i
== dpyinfo
->n_fonts
)
13708 ++dpyinfo
->n_fonts
;
13710 /* Now fill in the slots of *FONTP. */
13712 fontp
->font
= font
;
13713 fontp
->font_idx
= i
;
13714 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
13715 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
13717 /* Try to get the full name of FONT. Put it in FULL_NAME. */
13719 if (XGetFontProperty (font
, XA_FONT
, &value
))
13721 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
13725 /* Count the number of dashes in the "full name".
13726 If it is too few, this isn't really the font's full name,
13728 In X11R4, the fonts did not come with their canonical names
13739 full_name
= (char *) xmalloc (p
- name
+ 1);
13740 bcopy (name
, full_name
, p
- name
+ 1);
13746 if (full_name
!= 0)
13747 fontp
->full_name
= full_name
;
13749 fontp
->full_name
= fontp
->name
;
13751 fontp
->size
= font
->max_bounds
.width
;
13752 fontp
->height
= FONT_HEIGHT (font
);
13754 if (NILP (font_names
))
13756 /* We come here because of a bug of XListFonts mentioned at
13757 the head of this block. Let's store this information in
13758 the cache for x_list_fonts. */
13759 Lisp_Object lispy_name
= build_string (fontname
);
13760 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13761 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
13764 XCDR (dpyinfo
->name_list_element
)
13765 = Fcons (Fcons (key
,
13766 Fcons (Fcons (lispy_full_name
,
13767 make_number (fontp
->size
)),
13769 XCDR (dpyinfo
->name_list_element
));
13772 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
13774 XCDR (dpyinfo
->name_list_element
)
13775 = Fcons (Fcons (key
,
13776 Fcons (Fcons (lispy_full_name
,
13777 make_number (fontp
->size
)),
13779 XCDR (dpyinfo
->name_list_element
));
13783 /* The slot `encoding' specifies how to map a character
13784 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13785 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13786 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13787 2:0xA020..0xFF7F). For the moment, we don't know which charset
13788 uses this font. So, we set information in fontp->encoding[1]
13789 which is never used by any charset. If mapping can't be
13790 decided, set FONT_ENCODING_NOT_DECIDED. */
13792 = (font
->max_byte1
== 0
13794 ? (font
->min_char_or_byte2
< 0x80
13795 ? (font
->max_char_or_byte2
< 0x80
13796 ? 0 /* 0x20..0x7F */
13797 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13798 : 1) /* 0xA0..0xFF */
13800 : (font
->min_byte1
< 0x80
13801 ? (font
->max_byte1
< 0x80
13802 ? (font
->min_char_or_byte2
< 0x80
13803 ? (font
->max_char_or_byte2
< 0x80
13804 ? 0 /* 0x2020..0x7F7F */
13805 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13806 : 3) /* 0x20A0..0x7FFF */
13807 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13808 : (font
->min_char_or_byte2
< 0x80
13809 ? (font
->max_char_or_byte2
< 0x80
13810 ? 2 /* 0xA020..0xFF7F */
13811 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13812 : 1))); /* 0xA0A0..0xFFFF */
13814 fontp
->baseline_offset
13815 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13816 ? (long) value
: 0);
13817 fontp
->relative_compose
13818 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13819 ? (long) value
: 0);
13820 fontp
->default_ascent
13821 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13822 ? (long) value
: 0);
13824 /* Set global flag fonts_changed_p to non-zero if the font loaded
13825 has a character with a smaller width than any other character
13826 before, or if the font loaded has a smalle>r height than any
13827 other font loaded before. If this happens, it will make a
13828 glyph matrix reallocation necessary. */
13829 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13836 /* Return a pointer to struct font_info of a font named FONTNAME for
13837 frame F. If no such font is loaded, return NULL. */
13840 x_query_font (f
, fontname
)
13842 register char *fontname
;
13844 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13847 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13848 if (dpyinfo
->font_table
[i
].name
13849 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13850 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13851 return (dpyinfo
->font_table
+ i
);
13856 /* Find a CCL program for a font specified by FONTP, and set the member
13857 `encoder' of the structure. */
13860 x_find_ccl_program (fontp
)
13861 struct font_info
*fontp
;
13863 Lisp_Object list
, elt
;
13866 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13870 && STRINGP (XCAR (elt
))
13871 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13873 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
13880 struct ccl_program
*ccl
13881 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13883 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13886 fontp
->font_encoder
= ccl
;
13892 /***********************************************************************
13894 ***********************************************************************/
13896 #ifdef USE_X_TOOLKIT
13897 static XrmOptionDescRec emacs_options
[] = {
13898 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13899 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13901 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13902 XrmoptionSepArg
, NULL
},
13903 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13905 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13906 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13907 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13908 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13909 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13910 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13911 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13913 #endif /* USE_X_TOOLKIT */
13915 static int x_initialized
;
13917 #ifdef MULTI_KBOARD
13918 /* Test whether two display-name strings agree up to the dot that separates
13919 the screen number from the server number. */
13921 same_x_server (name1
, name2
)
13922 char *name1
, *name2
;
13924 int seen_colon
= 0;
13925 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13926 int system_name_length
= strlen (system_name
);
13927 int length_until_period
= 0;
13929 while (system_name
[length_until_period
] != 0
13930 && system_name
[length_until_period
] != '.')
13931 length_until_period
++;
13933 /* Treat `unix' like an empty host name. */
13934 if (! strncmp (name1
, "unix:", 5))
13936 if (! strncmp (name2
, "unix:", 5))
13938 /* Treat this host's name like an empty host name. */
13939 if (! strncmp (name1
, system_name
, system_name_length
)
13940 && name1
[system_name_length
] == ':')
13941 name1
+= system_name_length
;
13942 if (! strncmp (name2
, system_name
, system_name_length
)
13943 && name2
[system_name_length
] == ':')
13944 name2
+= system_name_length
;
13945 /* Treat this host's domainless name like an empty host name. */
13946 if (! strncmp (name1
, system_name
, length_until_period
)
13947 && name1
[length_until_period
] == ':')
13948 name1
+= length_until_period
;
13949 if (! strncmp (name2
, system_name
, length_until_period
)
13950 && name2
[length_until_period
] == ':')
13951 name2
+= length_until_period
;
13953 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13957 if (seen_colon
&& *name1
== '.')
13961 && (*name1
== '.' || *name1
== '\0')
13962 && (*name2
== '.' || *name2
== '\0'));
13966 struct x_display_info
*
13967 x_term_init (display_name
, xrm_option
, resource_name
)
13968 Lisp_Object display_name
;
13970 char *resource_name
;
13974 struct x_display_info
*dpyinfo
;
13979 if (!x_initialized
)
13985 #ifdef USE_X_TOOLKIT
13986 /* weiner@footloose.sps.mot.com reports that this causes
13988 X protocol error: BadAtom (invalid Atom parameter)
13989 on protocol request 18skiloaf.
13990 So let's not use it until R6. */
13991 #ifdef HAVE_X11XTR6
13992 XtSetLanguageProc (NULL
, NULL
, NULL
);
14003 argv
[argc
++] = "-xrm";
14004 argv
[argc
++] = xrm_option
;
14006 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
14007 resource_name
, EMACS_CLASS
,
14008 emacs_options
, XtNumber (emacs_options
),
14011 #ifdef HAVE_X11XTR6
14012 /* I think this is to compensate for XtSetLanguageProc. */
14017 #else /* not USE_X_TOOLKIT */
14019 XSetLocaleModifiers ("");
14021 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
14022 #endif /* not USE_X_TOOLKIT */
14024 /* Detect failure. */
14031 /* We have definitely succeeded. Record the new connection. */
14033 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
14034 bzero (dpyinfo
, sizeof *dpyinfo
);
14036 #ifdef MULTI_KBOARD
14038 struct x_display_info
*share
;
14041 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
14042 share
= share
->next
, tail
= XCDR (tail
))
14043 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
14044 XSTRING (display_name
)->data
))
14047 dpyinfo
->kboard
= share
->kboard
;
14050 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
14051 init_kboard (dpyinfo
->kboard
);
14052 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
14054 char *vendor
= ServerVendor (dpy
);
14056 dpyinfo
->kboard
->Vsystem_key_alist
14057 = call1 (Qvendor_specific_keysyms
,
14058 build_string (vendor
? vendor
: ""));
14062 dpyinfo
->kboard
->next_kboard
= all_kboards
;
14063 all_kboards
= dpyinfo
->kboard
;
14064 /* Don't let the initial kboard remain current longer than necessary.
14065 That would cause problems if a file loaded on startup tries to
14066 prompt in the mini-buffer. */
14067 if (current_kboard
== initial_kboard
)
14068 current_kboard
= dpyinfo
->kboard
;
14070 dpyinfo
->kboard
->reference_count
++;
14074 /* Put this display on the chain. */
14075 dpyinfo
->next
= x_display_list
;
14076 x_display_list
= dpyinfo
;
14078 /* Put it on x_display_name_list as well, to keep them parallel. */
14079 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
14080 x_display_name_list
);
14081 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
14083 dpyinfo
->display
= dpy
;
14086 XSetAfterFunction (x_current_display
, x_trace_wire
);
14090 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
14091 + STRING_BYTES (XSTRING (Vsystem_name
))
14093 sprintf (dpyinfo
->x_id_name
, "%s@%s",
14094 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
14096 /* Figure out which modifier bits mean what. */
14097 x_find_modifier_meanings (dpyinfo
);
14099 /* Get the scroll bar cursor. */
14100 dpyinfo
->vertical_scroll_bar_cursor
14101 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
14103 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
14104 resource_name
, EMACS_CLASS
);
14105 #ifdef HAVE_XRMSETDATABASE
14106 XrmSetDatabase (dpyinfo
->display
, xrdb
);
14108 dpyinfo
->display
->db
= xrdb
;
14110 /* Put the rdb where we can find it in a way that works on
14112 dpyinfo
->xrdb
= xrdb
;
14114 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
14115 DefaultScreen (dpyinfo
->display
));
14116 select_visual (dpyinfo
);
14117 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
14118 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
14119 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
14120 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
14121 dpyinfo
->grabbed
= 0;
14122 dpyinfo
->reference_count
= 0;
14123 dpyinfo
->icon_bitmap_id
= -1;
14124 dpyinfo
->font_table
= NULL
;
14125 dpyinfo
->n_fonts
= 0;
14126 dpyinfo
->font_table_size
= 0;
14127 dpyinfo
->bitmaps
= 0;
14128 dpyinfo
->bitmaps_size
= 0;
14129 dpyinfo
->bitmaps_last
= 0;
14130 dpyinfo
->scratch_cursor_gc
= 0;
14131 dpyinfo
->mouse_face_mouse_frame
= 0;
14132 dpyinfo
->mouse_face_deferred_gc
= 0;
14133 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
14134 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
14135 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
14136 dpyinfo
->mouse_face_window
= Qnil
;
14137 dpyinfo
->mouse_face_overlay
= Qnil
;
14138 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
14139 dpyinfo
->mouse_face_defer
= 0;
14140 dpyinfo
->x_focus_frame
= 0;
14141 dpyinfo
->x_focus_event_frame
= 0;
14142 dpyinfo
->x_highlight_frame
= 0;
14143 dpyinfo
->image_cache
= make_image_cache ();
14145 /* See if a private colormap is requested. */
14146 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
14148 if (dpyinfo
->visual
->class == PseudoColor
)
14151 value
= display_x_get_resource (dpyinfo
,
14152 build_string ("privateColormap"),
14153 build_string ("PrivateColormap"),
14155 if (STRINGP (value
)
14156 && (!strcmp (XSTRING (value
)->data
, "true")
14157 || !strcmp (XSTRING (value
)->data
, "on")))
14158 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
14162 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
14163 dpyinfo
->visual
, AllocNone
);
14166 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
14167 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
14168 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
14169 dpyinfo
->resy
= pixels
* 25.4 / mm
;
14170 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
14171 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
14172 dpyinfo
->resx
= pixels
* 25.4 / mm
;
14175 dpyinfo
->Xatom_wm_protocols
14176 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
14177 dpyinfo
->Xatom_wm_take_focus
14178 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
14179 dpyinfo
->Xatom_wm_save_yourself
14180 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
14181 dpyinfo
->Xatom_wm_delete_window
14182 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
14183 dpyinfo
->Xatom_wm_change_state
14184 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
14185 dpyinfo
->Xatom_wm_configure_denied
14186 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
14187 dpyinfo
->Xatom_wm_window_moved
14188 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
14189 dpyinfo
->Xatom_editres
14190 = XInternAtom (dpyinfo
->display
, "Editres", False
);
14191 dpyinfo
->Xatom_CLIPBOARD
14192 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
14193 dpyinfo
->Xatom_TIMESTAMP
14194 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
14195 dpyinfo
->Xatom_TEXT
14196 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
14197 dpyinfo
->Xatom_COMPOUND_TEXT
14198 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
14199 dpyinfo
->Xatom_DELETE
14200 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
14201 dpyinfo
->Xatom_MULTIPLE
14202 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
14203 dpyinfo
->Xatom_INCR
14204 = XInternAtom (dpyinfo
->display
, "INCR", False
);
14205 dpyinfo
->Xatom_EMACS_TMP
14206 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
14207 dpyinfo
->Xatom_TARGETS
14208 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
14209 dpyinfo
->Xatom_NULL
14210 = XInternAtom (dpyinfo
->display
, "NULL", False
);
14211 dpyinfo
->Xatom_ATOM_PAIR
14212 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
14213 /* For properties of font. */
14214 dpyinfo
->Xatom_PIXEL_SIZE
14215 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
14216 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
14217 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
14218 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
14219 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
14220 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
14221 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
14223 /* Ghostscript support. */
14224 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
14225 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
14227 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
14230 dpyinfo
->cut_buffers_initialized
= 0;
14232 connection
= ConnectionNumber (dpyinfo
->display
);
14233 dpyinfo
->connection
= connection
;
14238 null_bits
[0] = 0x00;
14240 dpyinfo
->null_pixel
14241 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14242 null_bits
, 1, 1, (long) 0, (long) 0,
14247 extern int gray_bitmap_width
, gray_bitmap_height
;
14248 extern char *gray_bitmap_bits
;
14250 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14252 gray_bitmap_width
, gray_bitmap_height
,
14253 (unsigned long) 1, (unsigned long) 0, 1);
14257 xim_initialize (dpyinfo
, resource_name
);
14260 #ifdef subprocesses
14261 /* This is only needed for distinguishing keyboard and process input. */
14262 if (connection
!= 0)
14263 add_keyboard_wait_descriptor (connection
);
14266 #ifndef F_SETOWN_BUG
14268 #ifdef F_SETOWN_SOCK_NEG
14269 /* stdin is a socket here */
14270 fcntl (connection
, F_SETOWN
, -getpid ());
14271 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14272 fcntl (connection
, F_SETOWN
, getpid ());
14273 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14274 #endif /* ! defined (F_SETOWN) */
14275 #endif /* F_SETOWN_BUG */
14278 if (interrupt_input
)
14279 init_sigio (connection
);
14280 #endif /* ! defined (SIGIO) */
14283 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
14284 /* Make sure that we have a valid font for dialog boxes
14285 so that Xt does not crash. */
14287 Display
*dpy
= dpyinfo
->display
;
14288 XrmValue d
, fr
, to
;
14292 d
.addr
= (XPointer
)&dpy
;
14293 d
.size
= sizeof (Display
*);
14294 fr
.addr
= XtDefaultFont
;
14295 fr
.size
= sizeof (XtDefaultFont
);
14296 to
.size
= sizeof (Font
*);
14297 to
.addr
= (XPointer
)&font
;
14298 count
= x_catch_errors (dpy
);
14299 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
14301 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
14302 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
14303 x_uncatch_errors (dpy
, count
);
14308 /* See if we should run in synchronous mode. This is useful
14309 for debugging X code. */
14312 value
= display_x_get_resource (dpyinfo
,
14313 build_string ("synchronous"),
14314 build_string ("Synchronous"),
14316 if (STRINGP (value
)
14317 && (!strcmp (XSTRING (value
)->data
, "true")
14318 || !strcmp (XSTRING (value
)->data
, "on")))
14319 XSynchronize (dpyinfo
->display
, True
);
14327 /* Get rid of display DPYINFO, assuming all frames are already gone,
14328 and without sending any more commands to the X server. */
14331 x_delete_display (dpyinfo
)
14332 struct x_display_info
*dpyinfo
;
14334 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
14336 /* Discard this display from x_display_name_list and x_display_list.
14337 We can't use Fdelq because that can quit. */
14338 if (! NILP (x_display_name_list
)
14339 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
14340 x_display_name_list
= XCDR (x_display_name_list
);
14345 tail
= x_display_name_list
;
14346 while (CONSP (tail
) && CONSP (XCDR (tail
)))
14348 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
14350 XCDR (tail
) = XCDR (XCDR (tail
));
14353 tail
= XCDR (tail
);
14357 if (next_noop_dpyinfo
== dpyinfo
)
14358 next_noop_dpyinfo
= dpyinfo
->next
;
14360 if (x_display_list
== dpyinfo
)
14361 x_display_list
= dpyinfo
->next
;
14364 struct x_display_info
*tail
;
14366 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
14367 if (tail
->next
== dpyinfo
)
14368 tail
->next
= tail
->next
->next
;
14371 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
14372 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
14373 XrmDestroyDatabase (dpyinfo
->xrdb
);
14376 #ifdef MULTI_KBOARD
14377 if (--dpyinfo
->kboard
->reference_count
== 0)
14378 delete_kboard (dpyinfo
->kboard
);
14382 xim_close_dpy (dpyinfo
);
14385 xfree (dpyinfo
->font_table
);
14386 xfree (dpyinfo
->x_id_name
);
14387 xfree (dpyinfo
->color_cells
);
14392 /* Set up use of X before we make the first connection. */
14394 static struct redisplay_interface x_redisplay_interface
=
14399 x_clear_end_of_line
,
14401 x_after_update_window_line
,
14402 x_update_window_begin
,
14403 x_update_window_end
,
14406 x_clear_mouse_face
,
14407 x_get_glyph_overhangs
,
14408 x_fix_overlapping_area
14414 rif
= &x_redisplay_interface
;
14416 clear_frame_hook
= x_clear_frame
;
14417 ins_del_lines_hook
= x_ins_del_lines
;
14418 change_line_highlight_hook
= x_change_line_highlight
;
14419 delete_glyphs_hook
= x_delete_glyphs
;
14420 ring_bell_hook
= XTring_bell
;
14421 reset_terminal_modes_hook
= XTreset_terminal_modes
;
14422 set_terminal_modes_hook
= XTset_terminal_modes
;
14423 update_begin_hook
= x_update_begin
;
14424 update_end_hook
= x_update_end
;
14425 set_terminal_window_hook
= XTset_terminal_window
;
14426 read_socket_hook
= XTread_socket
;
14427 frame_up_to_date_hook
= XTframe_up_to_date
;
14428 reassert_line_highlight_hook
= XTreassert_line_highlight
;
14429 mouse_position_hook
= XTmouse_position
;
14430 frame_rehighlight_hook
= XTframe_rehighlight
;
14431 frame_raise_lower_hook
= XTframe_raise_lower
;
14432 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
14433 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
14434 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
14435 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
14436 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
14438 scroll_region_ok
= 1; /* we'll scroll partial frames */
14439 char_ins_del_ok
= 1;
14440 line_ins_del_ok
= 1; /* we'll just blt 'em */
14441 fast_clear_end_of_line
= 1; /* X does this well */
14442 memory_below_frame
= 0; /* we don't remember what scrolls
14447 last_tool_bar_item
= -1;
14448 any_help_event_p
= 0;
14450 /* Try to use interrupt input; if we can't, then start polling. */
14451 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
14453 #ifdef USE_X_TOOLKIT
14454 XtToolkitInitialize ();
14456 Xt_app_con
= XtCreateApplicationContext ();
14458 /* Register a converter from strings to pixels, which uses
14459 Emacs' color allocation infrastructure. */
14460 XtAppSetTypeConverter (Xt_app_con
,
14461 XtRString
, XtRPixel
, cvt_string_to_pixel
,
14462 cvt_string_to_pixel_args
,
14463 XtNumber (cvt_string_to_pixel_args
),
14464 XtCacheByDisplay
, cvt_pixel_dtor
);
14466 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
14468 /* Install an asynchronous timer that processes Xt timeout events
14469 every 0.1s. This is necessary because some widget sets use
14470 timeouts internally, for example the LessTif menu bar, or the
14471 Xaw3d scroll bar. When Xt timouts aren't processed, these
14472 widgets don't behave normally. */
14474 EMACS_TIME interval
;
14475 EMACS_SET_SECS_USECS (interval
, 0, 100000);
14476 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
14480 #ifdef USE_TOOLKIT_SCROLL_BARS
14481 xaw3d_arrow_scroll
= False
;
14482 xaw3d_pick_top
= True
;
14485 /* Note that there is no real way portable across R3/R4 to get the
14486 original error handler. */
14487 XSetErrorHandler (x_error_handler
);
14488 XSetIOErrorHandler (x_io_error_quitter
);
14490 /* Disable Window Change signals; they are handled by X events. */
14492 signal (SIGWINCH
, SIG_DFL
);
14493 #endif /* ! defined (SIGWINCH) */
14495 signal (SIGPIPE
, x_connection_signal
);
14502 staticpro (&x_error_message_string
);
14503 x_error_message_string
= Qnil
;
14505 staticpro (&x_display_name_list
);
14506 x_display_name_list
= Qnil
;
14508 staticpro (&last_mouse_scroll_bar
);
14509 last_mouse_scroll_bar
= Qnil
;
14511 staticpro (&Qvendor_specific_keysyms
);
14512 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
14514 staticpro (&last_mouse_press_frame
);
14515 last_mouse_press_frame
= Qnil
;
14518 staticpro (&help_echo
);
14519 help_echo_object
= Qnil
;
14520 staticpro (&help_echo_object
);
14521 help_echo_window
= Qnil
;
14522 staticpro (&help_echo_window
);
14523 previous_help_echo
= Qnil
;
14524 staticpro (&previous_help_echo
);
14525 help_echo_pos
= -1;
14527 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
14528 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
14529 For example, if a block cursor is over a tab, it will be drawn as\n\
14530 wide as that tab on the display.");
14531 x_stretch_cursor_p
= 0;
14533 DEFVAR_BOOL ("x-use-underline-position-properties",
14534 &x_use_underline_position_properties
,
14535 "*Non-nil means make use of UNDERLINE_POSITION font properties.\n\
14536 Nil means ignore them. If you encounter fonts with bogus\n\
14537 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior\n\
14538 to 4.1, set this to nil.");
14539 x_use_underline_position_properties
= 1;
14541 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
14542 "What X toolkit scroll bars Emacs uses.\n\
14543 A value of nil means Emacs doesn't use X toolkit scroll bars.\n\
14544 Otherwise, value is a symbol describing the X toolkit.");
14545 #ifdef USE_TOOLKIT_SCROLL_BARS
14547 Vx_toolkit_scroll_bars
= intern ("motif");
14548 #elif defined HAVE_XAW3D
14549 Vx_toolkit_scroll_bars
= intern ("xaw3d");
14551 Vx_toolkit_scroll_bars
= intern ("xaw");
14554 Vx_toolkit_scroll_bars
= Qnil
;
14557 staticpro (&last_mouse_motion_frame
);
14558 last_mouse_motion_frame
= Qnil
;
14561 #endif /* not HAVE_X_WINDOWS */