1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001, 2002
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"
84 #include "intervals.h"
90 #include <X11/Shell.h>
93 #ifdef HAVE_SYS_TIME_H
101 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
102 extern void xlwmenu_redisplay
P_ ((Widget
));
107 extern void free_frame_menubar
P_ ((struct frame
*));
108 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
111 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
113 extern void _XEditResCheckMessages ();
114 #endif /* not NO_EDITRES */
116 /* Include toolkit specific headers for the scroll bar widget. */
118 #ifdef USE_TOOLKIT_SCROLL_BARS
119 #if defined USE_MOTIF
120 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
121 #include <Xm/ScrollBar.h>
122 #else /* !USE_MOTIF i.e. use Xaw */
125 #include <X11/Xaw3d/Simple.h>
126 #include <X11/Xaw3d/Scrollbar.h>
127 #define ARROW_SCROLLBAR
128 #include <X11/Xaw3d/ScrollbarP.h>
129 #else /* !HAVE_XAW3D */
130 #include <X11/Xaw/Simple.h>
131 #include <X11/Xaw/Scrollbar.h>
132 #endif /* !HAVE_XAW3D */
134 #define XtNpickTop "pickTop"
135 #endif /* !XtNpickTop */
136 #endif /* !USE_MOTIF */
137 #endif /* USE_TOOLKIT_SCROLL_BARS */
139 #endif /* USE_X_TOOLKIT */
141 #ifndef USE_X_TOOLKIT
142 #define x_any_window_to_frame x_window_to_frame
143 #define x_top_window_to_frame x_window_to_frame
148 #ifndef XtNinitialState
149 #define XtNinitialState "initialState"
153 #define abs(x) ((x) < 0 ? -(x) : (x))
155 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
158 /* Fringe bitmaps. */
160 enum fringe_bitmap_type
163 LEFT_TRUNCATION_BITMAP
,
164 RIGHT_TRUNCATION_BITMAP
,
165 OVERLAY_ARROW_BITMAP
,
166 CONTINUED_LINE_BITMAP
,
167 CONTINUATION_LINE_BITMAP
,
171 /* Bitmap drawn to indicate lines not displaying text if
172 `indicate-empty-lines' is non-nil. */
177 static unsigned char zv_bits
[] = {
178 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
179 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
180 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
181 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
182 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
183 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
184 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
185 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
187 /* An arrow like this: `<-'. */
190 #define left_height 8
191 static unsigned char left_bits
[] = {
192 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
194 /* Right truncation arrow bitmap `->'. */
196 #define right_width 8
197 #define right_height 8
198 static unsigned char right_bits
[] = {
199 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
201 /* Marker for continued lines. */
203 #define continued_width 8
204 #define continued_height 8
205 static unsigned char continued_bits
[] = {
206 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
208 /* Marker for continuation lines. */
210 #define continuation_width 8
211 #define continuation_height 8
212 static unsigned char continuation_bits
[] = {
213 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
215 /* Overlay arrow bitmap. */
221 static unsigned char ov_bits
[] = {
222 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
224 /* A triangular arrow. */
227 static unsigned char ov_bits
[] = {
228 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
232 extern Lisp_Object Qhelp_echo
;
235 /* Non-nil means Emacs uses toolkit scroll bars. */
237 Lisp_Object Vx_toolkit_scroll_bars
;
239 /* If a string, XTread_socket generates an event to display that string.
240 (The display is done in read_char.) */
242 static Lisp_Object help_echo
;
243 static Lisp_Object help_echo_window
;
244 static Lisp_Object help_echo_object
;
245 static int help_echo_pos
;
247 /* Temporary variable for XTread_socket. */
249 static Lisp_Object previous_help_echo
;
251 /* Non-zero means that a HELP_EVENT has been generated since Emacs
254 static int any_help_event_p
;
256 /* Non-zero means autoselect window with the mouse cursor. */
258 int mouse_autoselect_window
;
260 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
261 static Lisp_Object last_window
;
263 /* Non-zero means draw block and hollow cursor as wide as the glyph
264 under it. For example, if a block cursor is over a tab, it will be
265 drawn as wide as that tab on the display. */
267 int x_stretch_cursor_p
;
269 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
271 int x_use_underline_position_properties
;
273 /* This is a chain of structures for all the X displays currently in
276 struct x_display_info
*x_display_list
;
278 /* This is a list of cons cells, each of the form (NAME
279 . FONT-LIST-CACHE), one for each element of x_display_list and in
280 the same order. NAME is the name of the frame. FONT-LIST-CACHE
281 records previous values returned by x-list-fonts. */
283 Lisp_Object x_display_name_list
;
285 /* Frame being updated by update_frame. This is declared in term.c.
286 This is set by update_begin and looked at by all the XT functions.
287 It is zero while not inside an update. In that case, the XT
288 functions assume that `selected_frame' is the frame to apply to. */
290 extern struct frame
*updating_frame
;
292 /* This is a frame waiting to be auto-raised, within XTread_socket. */
294 struct frame
*pending_autoraise_frame
;
297 /* The application context for Xt use. */
298 XtAppContext Xt_app_con
;
299 static String Xt_default_resources
[] = {0};
300 #endif /* USE_X_TOOLKIT */
302 /* Nominal cursor position -- where to draw output.
303 HPOS and VPOS are window relative glyph matrix coordinates.
304 X and Y are window relative pixel coordinates. */
306 struct cursor_pos output_cursor
;
308 /* Non-zero means user is interacting with a toolkit scroll bar. */
310 static int toolkit_scroll_bar_interaction
;
314 Formerly, we used PointerMotionHintMask (in standard_event_mask)
315 so that we would have to call XQueryPointer after each MotionNotify
316 event to ask for another such event. However, this made mouse tracking
317 slow, and there was a bug that made it eventually stop.
319 Simply asking for MotionNotify all the time seems to work better.
321 In order to avoid asking for motion events and then throwing most
322 of them away or busy-polling the server for mouse positions, we ask
323 the server for pointer motion hints. This means that we get only
324 one event per group of mouse movements. "Groups" are delimited by
325 other kinds of events (focus changes and button clicks, for
326 example), or by XQueryPointer calls; when one of these happens, we
327 get another MotionNotify event the next time the mouse moves. This
328 is at least as efficient as getting motion events when mouse
329 tracking is on, and I suspect only negligibly worse when tracking
332 /* Where the mouse was last time we reported a mouse event. */
334 FRAME_PTR last_mouse_frame
;
335 static XRectangle last_mouse_glyph
;
336 static Lisp_Object last_mouse_press_frame
;
338 /* The scroll bar in which the last X motion event occurred.
340 If the last X motion event occurred in a scroll bar, we set this so
341 XTmouse_position can know whether to report a scroll bar motion or
344 If the last X motion event didn't occur in a scroll bar, we set
345 this to Qnil, to tell XTmouse_position to return an ordinary motion
348 static Lisp_Object last_mouse_scroll_bar
;
350 /* This is a hack. We would really prefer that XTmouse_position would
351 return the time associated with the position it returns, but there
352 doesn't seem to be any way to wrest the time-stamp from the server
353 along with the position query. So, we just keep track of the time
354 of the last movement we received, and return that in hopes that
355 it's somewhat accurate. */
357 static Time last_mouse_movement_time
;
359 /* Incremented by XTread_socket whenever it really tries to read
363 static int volatile input_signal_count
;
365 static int input_signal_count
;
368 /* Used locally within XTread_socket. */
370 static int x_noop_count
;
372 /* Initial values of argv and argc. */
374 extern char **initial_argv
;
375 extern int initial_argc
;
377 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
379 /* Tells if a window manager is present or not. */
381 extern Lisp_Object Vx_no_window_manager
;
383 extern Lisp_Object Qface
, Qmouse_face
;
387 /* A mask of extra modifier bits to put into every keyboard char. */
389 extern EMACS_INT extra_keyboard_modifiers
;
391 /* The keysyms to use for the various modifiers. */
393 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
394 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
396 static Lisp_Object Qvendor_specific_keysyms
;
397 static Lisp_Object Qlatin_1
, Qutf_8
;
399 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
400 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
403 /* Enumeration for overriding/changing the face to use for drawing
404 glyphs in x_draw_glyphs. */
406 enum draw_glyphs_face
416 static int cursor_in_mouse_face_p
P_ ((struct window
*));
417 static int clear_mouse_face
P_ ((struct x_display_info
*));
418 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
419 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
420 static const XColor
*x_color_cells
P_ ((Display
*, int *));
421 static void x_update_window_end
P_ ((struct window
*, int, int));
422 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
423 void x_delete_display
P_ ((struct x_display_info
*));
424 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
426 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
427 int *, int *, Lisp_Object
));
428 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
429 int *, int *, int *, int *, int));
430 static void set_output_cursor
P_ ((struct cursor_pos
*));
431 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
432 int *, int *, int *, int));
433 static void note_mode_line_or_margin_highlight
P_ ((struct window
*, int,
435 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
436 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
437 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
438 static void show_mouse_face
P_ ((struct x_display_info
*,
439 enum draw_glyphs_face
));
440 static int x_io_error_quitter
P_ ((Display
*));
441 int x_catch_errors
P_ ((Display
*));
442 void x_uncatch_errors
P_ ((Display
*, int));
443 void x_lower_frame
P_ ((struct frame
*));
444 void x_scroll_bar_clear
P_ ((struct frame
*));
445 int x_had_errors_p
P_ ((Display
*));
446 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
447 void x_raise_frame
P_ ((struct frame
*));
448 void x_set_window_size
P_ ((struct frame
*, int, int, int));
449 void x_wm_set_window_state
P_ ((struct frame
*, int));
450 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
451 void x_initialize
P_ ((void));
452 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
453 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
454 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
456 enum draw_glyphs_face
));
457 static void x_update_end
P_ ((struct frame
*));
458 static void XTframe_up_to_date
P_ ((struct frame
*));
459 static void XTset_terminal_modes
P_ ((void));
460 static void XTreset_terminal_modes
P_ ((void));
461 static void XTcursor_to
P_ ((int, int, int, int));
462 static void x_write_glyphs
P_ ((struct glyph
*, int));
463 static void x_clear_end_of_line
P_ ((int));
464 static void x_clear_frame
P_ ((void));
465 static void x_clear_cursor
P_ ((struct window
*));
466 static void frame_highlight
P_ ((struct frame
*));
467 static void frame_unhighlight
P_ ((struct frame
*));
468 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
469 static int x_focus_changed
P_ ((int,
471 struct x_display_info
*,
473 struct input_event
*,
475 static int x_detect_focus_change
P_ ((struct x_display_info
*,
477 struct input_event
*,
479 static void XTframe_rehighlight
P_ ((struct frame
*));
480 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
481 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
482 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
483 enum text_cursor_kinds
));
484 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
486 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
487 static int expose_window_tree
P_ ((struct window
*, XRectangle
*));
488 static void expose_overlaps
P_ ((struct window
*, struct glyph_row
*,
489 struct glyph_row
*));
490 static int expose_window
P_ ((struct window
*, XRectangle
*));
491 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
492 XRectangle
*, enum glyph_row_area
));
493 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
495 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
496 static void x_update_window_cursor
P_ ((struct window
*, int));
497 static void x_erase_phys_cursor
P_ ((struct window
*));
498 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
499 static void x_draw_fringe_bitmap
P_ ((struct window
*, struct glyph_row
*,
500 enum fringe_bitmap_type
, int left_p
));
502 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
504 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
505 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*, struct glyph_row
*));
506 static void notice_overwritten_cursor
P_ ((struct window
*, enum glyph_row_area
,
507 int, int, int, int));
508 static void x_flush
P_ ((struct frame
*f
));
509 static void x_update_begin
P_ ((struct frame
*));
510 static void x_update_window_begin
P_ ((struct window
*));
511 static void x_draw_vertical_border
P_ ((struct window
*));
512 static void x_after_update_window_line
P_ ((struct glyph_row
*));
513 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
514 static void x_produce_stretch_glyph
P_ ((struct it
*));
515 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
516 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
517 enum scroll_bar_part
*,
518 Lisp_Object
*, Lisp_Object
*,
520 static void x_check_fullscreen
P_ ((struct frame
*));
521 static void x_check_fullscreen_move
P_ ((struct frame
*));
523 /* Flush display of frame F, or of all frames if F is null. */
532 Lisp_Object rest
, frame
;
533 FOR_EACH_FRAME (rest
, frame
)
534 x_flush (XFRAME (frame
));
536 else if (FRAME_X_P (f
))
537 XFlush (FRAME_X_DISPLAY (f
));
542 /* Remove calls to XFlush by defining XFlush to an empty replacement.
543 Calls to XFlush should be unnecessary because the X output buffer
544 is flushed automatically as needed by calls to XPending,
545 XNextEvent, or XWindowEvent according to the XFlush man page.
546 XTread_socket calls XPending. Removing XFlush improves
549 #define XFlush(DISPLAY) (void) 0
552 /***********************************************************************
554 ***********************************************************************/
558 /* This is a function useful for recording debugging information about
559 the sequence of occurrences in this file. */
567 struct record event_record
[100];
569 int event_record_index
;
571 record_event (locus
, type
)
575 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
576 event_record_index
= 0;
578 event_record
[event_record_index
].locus
= locus
;
579 event_record
[event_record_index
].type
= type
;
580 event_record_index
++;
587 /* Return the struct x_display_info corresponding to DPY. */
589 struct x_display_info
*
590 x_display_info_for_display (dpy
)
593 struct x_display_info
*dpyinfo
;
595 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
596 if (dpyinfo
->display
== dpy
)
604 /***********************************************************************
605 Starting and ending an update
606 ***********************************************************************/
608 /* Start an update of frame F. This function is installed as a hook
609 for update_begin, i.e. it is called when update_begin is called.
610 This function is called prior to calls to x_update_window_begin for
611 each window being updated. Currently, there is nothing to do here
612 because all interesting stuff is done on a window basis. */
622 /* Start update of window W. Set the global variable updated_window
623 to the window being updated and set output_cursor to the cursor
627 x_update_window_begin (w
)
630 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
631 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
634 set_output_cursor (&w
->cursor
);
638 if (f
== display_info
->mouse_face_mouse_frame
)
640 /* Don't do highlighting for mouse motion during the update. */
641 display_info
->mouse_face_defer
= 1;
643 /* If F needs to be redrawn, simply forget about any prior mouse
645 if (FRAME_GARBAGED_P (f
))
646 display_info
->mouse_face_window
= Qnil
;
648 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
649 their mouse_face_p flag set, which means that they are always
650 unequal to rows in a desired matrix which never have that
651 flag set. So, rows containing mouse-face glyphs are never
652 scrolled, and we don't have to switch the mouse highlight off
653 here to prevent it from being scrolled. */
655 /* Can we tell that this update does not affect the window
656 where the mouse highlight is? If so, no need to turn off.
657 Likewise, don't do anything if the frame is garbaged;
658 in that case, the frame's current matrix that we would use
659 is all wrong, and we will redisplay that line anyway. */
660 if (!NILP (display_info
->mouse_face_window
)
661 && w
== XWINDOW (display_info
->mouse_face_window
))
665 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
666 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
669 if (i
< w
->desired_matrix
->nrows
)
670 clear_mouse_face (display_info
);
679 /* Draw a vertical window border to the right of window W if W doesn't
680 have vertical scroll bars. */
683 x_draw_vertical_border (w
)
686 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
688 /* Redraw borders between horizontally adjacent windows. Don't
689 do it for frames with vertical scroll bars because either the
690 right scroll bar of a window, or the left scroll bar of its
691 neighbor will suffice as a border. */
692 if (!WINDOW_RIGHTMOST_P (w
)
693 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
697 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
698 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
701 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
702 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
707 /* End update of window W (which is equal to updated_window).
709 Draw vertical borders between horizontally adjacent windows, and
710 display W's cursor if CURSOR_ON_P is non-zero.
712 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
713 glyphs in mouse-face were overwritten. In that case we have to
714 make sure that the mouse-highlight is properly redrawn.
716 W may be a menu bar pseudo-window in case we don't have X toolkit
717 support. Such windows don't have a cursor, so don't display it
721 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
723 int cursor_on_p
, mouse_face_overwritten_p
;
725 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
727 if (!w
->pseudo_window_p
)
732 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
734 output_cursor
.x
, output_cursor
.y
);
736 x_draw_vertical_border (w
);
740 /* If a row with mouse-face was overwritten, arrange for
741 XTframe_up_to_date to redisplay the mouse highlight. */
742 if (mouse_face_overwritten_p
)
744 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
745 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
746 dpyinfo
->mouse_face_window
= Qnil
;
749 updated_window
= NULL
;
753 /* End update of frame F. This function is installed as a hook in
760 /* Mouse highlight may be displayed again. */
761 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
764 XFlush (FRAME_X_DISPLAY (f
));
769 /* This function is called from various places in xdisp.c whenever a
770 complete update has been performed. The global variable
771 updated_window is not available here. */
774 XTframe_up_to_date (f
)
779 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
781 if (dpyinfo
->mouse_face_deferred_gc
782 || f
== dpyinfo
->mouse_face_mouse_frame
)
785 if (dpyinfo
->mouse_face_mouse_frame
)
786 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
787 dpyinfo
->mouse_face_mouse_x
,
788 dpyinfo
->mouse_face_mouse_y
);
789 dpyinfo
->mouse_face_deferred_gc
= 0;
796 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
797 arrow bitmaps, or clear the fringes if no bitmaps are required
798 before DESIRED_ROW is made current. The window being updated is
799 found in updated_window. This function It is called from
800 update_window_line only if it is known that there are differences
801 between bitmaps to be drawn between current row and DESIRED_ROW. */
804 x_after_update_window_line (desired_row
)
805 struct glyph_row
*desired_row
;
807 struct window
*w
= updated_window
;
813 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
816 x_draw_row_fringe_bitmaps (w
, desired_row
);
820 /* When a window has disappeared, make sure that no rest of
821 full-width rows stays visible in the internal border. Could
822 check here if updated_window is the leftmost/rightmost window,
823 but I guess it's not worth doing since vertically split windows
824 are almost never used, internal border is rarely set, and the
825 overhead is very small. */
826 if (windows_or_buffers_changed
827 && desired_row
->full_width_p
828 && (f
= XFRAME (w
->frame
),
829 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
831 && (height
= desired_row
->visible_height
,
834 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
836 /* Internal border is drawn below the tool bar. */
837 if (WINDOWP (f
->tool_bar_window
)
838 && w
== XWINDOW (f
->tool_bar_window
))
842 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
843 0, y
, width
, height
, False
);
844 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
845 f
->output_data
.x
->pixel_width
- width
,
846 y
, width
, height
, False
);
852 /* Draw the bitmap WHICH in one of the left or right fringes of
853 window W. ROW is the glyph row for which to display the bitmap; it
854 determines the vertical position at which the bitmap has to be
858 x_draw_fringe_bitmap (w
, row
, which
, left_p
)
860 struct glyph_row
*row
;
861 enum fringe_bitmap_type which
;
864 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
865 Display
*display
= FRAME_X_DISPLAY (f
);
866 Window window
= FRAME_X_WINDOW (f
);
869 unsigned char *bits
= NULL
;
871 GC gc
= f
->output_data
.x
->normal_gc
;
873 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
875 /* Must clip because of partially visible lines. */
876 x_clip_to_row (w
, row
, gc
, 1);
878 /* Convert row to frame coordinates. */
879 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
883 case NO_FRINGE_BITMAP
:
888 case LEFT_TRUNCATION_BITMAP
:
894 case OVERLAY_ARROW_BITMAP
:
900 case RIGHT_TRUNCATION_BITMAP
:
906 case CONTINUED_LINE_BITMAP
:
907 wd
= continued_width
;
908 h
= continued_height
;
909 bits
= continued_bits
;
912 case CONTINUATION_LINE_BITMAP
:
913 wd
= continuation_width
;
914 h
= continuation_height
;
915 bits
= continuation_bits
;
920 h
= zv_height
- (y
% zv_period
);
921 bits
= zv_bits
+ (y
% zv_period
);
928 /* Clip bitmap if too high. */
932 /* Set dy to the offset in the row to start drawing the bitmap. */
933 dy
= (row
->height
- h
) / 2;
935 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
936 PREPARE_FACE_FOR_DISPLAY (f
, face
);
938 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
943 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
944 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
945 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
947 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
948 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
950 /* If W has a vertical border to its left, don't draw over it. */
951 int border
= ((XFASTINT (w
->left
) > 0
952 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
954 b1
= (window_box_left (w
, -1)
955 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
957 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
962 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
963 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
964 x
= (window_box_right (w
, -1)
965 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
966 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
968 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
970 b1
= window_box_right (w
, -1);
971 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
977 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
979 /* In case the same realized face is used for fringes and
980 for something displayed in the text (e.g. face `region' on
981 mono-displays, the fill style may have been changed to
982 FillSolid in x_draw_glyph_string_background. */
984 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
986 XSetForeground (display
, face
->gc
, face
->background
);
988 XFillRectangle (display
, window
, face
->gc
,
990 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
993 row
->visible_height
);
995 XSetForeground (display
, face
->gc
, face
->foreground
);
998 if (which
!= NO_FRINGE_BITMAP
)
1000 /* Draw the bitmap. I believe these small pixmaps can be cached
1002 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
1004 face
->background
, depth
);
1005 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
1006 XFreePixmap (display
, pixmap
);
1009 XSetClipMask (display
, gc
, None
);
1013 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
1014 function with input blocked. */
1017 x_draw_row_fringe_bitmaps (w
, row
)
1019 struct glyph_row
*row
;
1021 struct frame
*f
= XFRAME (w
->frame
);
1022 enum fringe_bitmap_type bitmap
;
1024 xassert (interrupt_input_blocked
);
1026 /* If row is completely invisible, because of vscrolling, we
1027 don't have to draw anything. */
1028 if (row
->visible_height
<= 0)
1031 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
1033 /* Decide which bitmap to draw in the left fringe. */
1034 if (row
->overlay_arrow_p
)
1035 bitmap
= OVERLAY_ARROW_BITMAP
;
1036 else if (row
->truncated_on_left_p
)
1037 bitmap
= LEFT_TRUNCATION_BITMAP
;
1038 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1039 bitmap
= CONTINUATION_LINE_BITMAP
;
1040 else if (row
->indicate_empty_line_p
)
1041 bitmap
= ZV_LINE_BITMAP
;
1043 bitmap
= NO_FRINGE_BITMAP
;
1045 x_draw_fringe_bitmap (w
, row
, bitmap
, 1);
1048 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1050 /* Decide which bitmap to draw in the right fringe. */
1051 if (row
->truncated_on_right_p
)
1052 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1053 else if (row
->continued_p
)
1054 bitmap
= CONTINUED_LINE_BITMAP
;
1055 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1056 bitmap
= ZV_LINE_BITMAP
;
1058 bitmap
= NO_FRINGE_BITMAP
;
1060 x_draw_fringe_bitmap (w
, row
, bitmap
, 0);
1066 /* This is called when starting Emacs and when restarting after
1067 suspend. When starting Emacs, no X window is mapped. And nothing
1068 must be done to Emacs's own window if it is suspended (though that
1072 XTset_terminal_modes ()
1076 /* This is called when exiting or suspending Emacs. Exiting will make
1077 the X-windows go away, and suspending requires no action. */
1080 XTreset_terminal_modes ()
1086 /***********************************************************************
1088 ***********************************************************************/
1090 /* Set the global variable output_cursor to CURSOR. All cursor
1091 positions are relative to updated_window. */
1094 set_output_cursor (cursor
)
1095 struct cursor_pos
*cursor
;
1097 output_cursor
.hpos
= cursor
->hpos
;
1098 output_cursor
.vpos
= cursor
->vpos
;
1099 output_cursor
.x
= cursor
->x
;
1100 output_cursor
.y
= cursor
->y
;
1104 /* Set a nominal cursor position.
1106 HPOS and VPOS are column/row positions in a window glyph matrix. X
1107 and Y are window text area relative pixel positions.
1109 If this is done during an update, updated_window will contain the
1110 window that is being updated and the position is the future output
1111 cursor position for that window. If updated_window is null, use
1112 selected_window and display the cursor at the given position. */
1115 XTcursor_to (vpos
, hpos
, y
, x
)
1116 int vpos
, hpos
, y
, x
;
1120 /* If updated_window is not set, work on selected_window. */
1124 w
= XWINDOW (selected_window
);
1126 /* Set the output cursor. */
1127 output_cursor
.hpos
= hpos
;
1128 output_cursor
.vpos
= vpos
;
1129 output_cursor
.x
= x
;
1130 output_cursor
.y
= y
;
1132 /* If not called as part of an update, really display the cursor.
1133 This will also set the cursor position of W. */
1134 if (updated_window
== NULL
)
1137 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1138 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1145 /***********************************************************************
1147 ***********************************************************************/
1149 /* Function prototypes of this page. */
1151 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1155 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1156 int, XChar2b
*, int,
1158 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1159 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1160 static void x_append_glyph
P_ ((struct it
*));
1161 static void x_append_composite_glyph
P_ ((struct it
*));
1162 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1164 static void x_produce_glyphs
P_ ((struct it
*));
1165 static void x_produce_image_glyph
P_ ((struct it
*it
));
1168 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1169 is not contained in the font. */
1171 static INLINE XCharStruct
*
1172 x_per_char_metric (font
, char2b
)
1176 /* The result metric information. */
1177 XCharStruct
*pcm
= NULL
;
1179 xassert (font
&& char2b
);
1181 if (font
->per_char
!= NULL
)
1183 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1185 /* min_char_or_byte2 specifies the linear character index
1186 corresponding to the first element of the per_char array,
1187 max_char_or_byte2 is the index of the last character. A
1188 character with non-zero CHAR2B->byte1 is not in the font.
1189 A character with byte2 less than min_char_or_byte2 or
1190 greater max_char_or_byte2 is not in the font. */
1191 if (char2b
->byte1
== 0
1192 && char2b
->byte2
>= font
->min_char_or_byte2
1193 && char2b
->byte2
<= font
->max_char_or_byte2
)
1194 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1198 /* If either min_byte1 or max_byte1 are nonzero, both
1199 min_char_or_byte2 and max_char_or_byte2 are less than
1200 256, and the 2-byte character index values corresponding
1201 to the per_char array element N (counting from 0) are:
1203 byte1 = N/D + min_byte1
1204 byte2 = N\D + min_char_or_byte2
1208 D = max_char_or_byte2 - min_char_or_byte2 + 1
1209 / = integer division
1210 \ = integer modulus */
1211 if (char2b
->byte1
>= font
->min_byte1
1212 && char2b
->byte1
<= font
->max_byte1
1213 && char2b
->byte2
>= font
->min_char_or_byte2
1214 && char2b
->byte2
<= font
->max_char_or_byte2
)
1216 pcm
= (font
->per_char
1217 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1218 * (char2b
->byte1
- font
->min_byte1
))
1219 + (char2b
->byte2
- font
->min_char_or_byte2
));
1225 /* If the per_char pointer is null, all glyphs between the first
1226 and last character indexes inclusive have the same
1227 information, as given by both min_bounds and max_bounds. */
1228 if (char2b
->byte2
>= font
->min_char_or_byte2
1229 && char2b
->byte2
<= font
->max_char_or_byte2
)
1230 pcm
= &font
->max_bounds
;
1233 return ((pcm
== NULL
1234 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1239 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1240 the two-byte form of C. Encoding is returned in *CHAR2B. */
1243 x_encode_char (c
, char2b
, font_info
)
1246 struct font_info
*font_info
;
1248 int charset
= CHAR_CHARSET (c
);
1249 XFontStruct
*font
= font_info
->font
;
1251 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1252 This may be either a program in a special encoder language or a
1254 if (font_info
->font_encoder
)
1256 /* It's a program. */
1257 struct ccl_program
*ccl
= font_info
->font_encoder
;
1259 if (CHARSET_DIMENSION (charset
) == 1)
1261 ccl
->reg
[0] = charset
;
1262 ccl
->reg
[1] = char2b
->byte2
;
1266 ccl
->reg
[0] = charset
;
1267 ccl
->reg
[1] = char2b
->byte1
;
1268 ccl
->reg
[2] = char2b
->byte2
;
1271 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1273 /* We assume that MSBs are appropriately set/reset by CCL
1275 if (font
->max_byte1
== 0) /* 1-byte font */
1276 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1278 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1280 else if (font_info
->encoding
[charset
])
1282 /* Fixed encoding scheme. See fontset.h for the meaning of the
1283 encoding numbers. */
1284 int enc
= font_info
->encoding
[charset
];
1286 if ((enc
== 1 || enc
== 2)
1287 && CHARSET_DIMENSION (charset
) == 2)
1288 char2b
->byte1
|= 0x80;
1290 if (enc
== 1 || enc
== 3)
1291 char2b
->byte2
|= 0x80;
1296 /* Get face and two-byte form of character C in face FACE_ID on frame
1297 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1298 means we want to display multibyte text. DISPLAY_P non-zero means
1299 make sure that X resources for the face returned are allocated.
1300 Value is a pointer to a realized face that is ready for display if
1301 DISPLAY_P is non-zero. */
1303 static INLINE
struct face
*
1304 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
1308 int multibyte_p
, display_p
;
1310 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1314 /* Unibyte case. We don't have to encode, but we have to make
1315 sure to use a face suitable for unibyte. */
1318 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1319 face
= FACE_FROM_ID (f
, face_id
);
1321 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1323 /* Case of ASCII in a face known to fit ASCII. */
1329 int c1
, c2
, charset
;
1331 /* Split characters into bytes. If c2 is -1 afterwards, C is
1332 really a one-byte character so that byte1 is zero. */
1333 SPLIT_CHAR (c
, charset
, c1
, c2
);
1335 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1337 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1339 /* Maybe encode the character in *CHAR2B. */
1340 if (face
->font
!= NULL
)
1342 struct font_info
*font_info
1343 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1345 x_encode_char (c
, char2b
, font_info
);
1349 /* Make sure X resources of the face are allocated. */
1352 xassert (face
!= NULL
);
1353 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1360 /* Get face and two-byte form of character glyph GLYPH on frame F.
1361 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1362 a pointer to a realized face that is ready for display. */
1364 static INLINE
struct face
*
1365 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1367 struct glyph
*glyph
;
1373 xassert (glyph
->type
== CHAR_GLYPH
);
1374 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1379 if (!glyph
->multibyte_p
)
1381 /* Unibyte case. We don't have to encode, but we have to make
1382 sure to use a face suitable for unibyte. */
1384 char2b
->byte2
= glyph
->u
.ch
;
1386 else if (glyph
->u
.ch
< 128
1387 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1389 /* Case of ASCII in a face known to fit ASCII. */
1391 char2b
->byte2
= glyph
->u
.ch
;
1395 int c1
, c2
, charset
;
1397 /* Split characters into bytes. If c2 is -1 afterwards, C is
1398 really a one-byte character so that byte1 is zero. */
1399 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1401 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1403 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1405 /* Maybe encode the character in *CHAR2B. */
1406 if (charset
!= CHARSET_ASCII
)
1408 struct font_info
*font_info
1409 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1412 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1415 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1420 /* Make sure X resources of the face are allocated. */
1421 xassert (face
!= NULL
);
1422 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1427 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1428 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1434 struct glyph
*glyph
;
1435 enum glyph_row_area area
= it
->area
;
1437 xassert (it
->glyph_row
);
1438 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1440 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1441 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1443 glyph
->charpos
= CHARPOS (it
->position
);
1444 glyph
->object
= it
->object
;
1445 glyph
->pixel_width
= it
->pixel_width
;
1446 glyph
->voffset
= it
->voffset
;
1447 glyph
->type
= CHAR_GLYPH
;
1448 glyph
->multibyte_p
= it
->multibyte_p
;
1449 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1450 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1451 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1452 || it
->phys_descent
> it
->descent
);
1453 glyph
->padding_p
= 0;
1454 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1455 glyph
->face_id
= it
->face_id
;
1456 glyph
->u
.ch
= it
->char_to_display
;
1457 ++it
->glyph_row
->used
[area
];
1461 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1462 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1465 x_append_composite_glyph (it
)
1468 struct glyph
*glyph
;
1469 enum glyph_row_area area
= it
->area
;
1471 xassert (it
->glyph_row
);
1473 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1474 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1476 glyph
->charpos
= CHARPOS (it
->position
);
1477 glyph
->object
= it
->object
;
1478 glyph
->pixel_width
= it
->pixel_width
;
1479 glyph
->voffset
= it
->voffset
;
1480 glyph
->type
= COMPOSITE_GLYPH
;
1481 glyph
->multibyte_p
= it
->multibyte_p
;
1482 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1483 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1484 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1485 || it
->phys_descent
> it
->descent
);
1486 glyph
->padding_p
= 0;
1487 glyph
->glyph_not_available_p
= 0;
1488 glyph
->face_id
= it
->face_id
;
1489 glyph
->u
.cmp_id
= it
->cmp_id
;
1490 ++it
->glyph_row
->used
[area
];
1495 /* Change IT->ascent and IT->height according to the setting of
1499 take_vertical_position_into_account (it
)
1504 if (it
->voffset
< 0)
1505 /* Increase the ascent so that we can display the text higher
1507 it
->ascent
+= abs (it
->voffset
);
1509 /* Increase the descent so that we can display the text lower
1511 it
->descent
+= it
->voffset
;
1516 /* Produce glyphs/get display metrics for the image IT is loaded with.
1517 See the description of struct display_iterator in dispextern.h for
1518 an overview of struct display_iterator. */
1521 x_produce_image_glyph (it
)
1527 xassert (it
->what
== IT_IMAGE
);
1529 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1530 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1533 /* Make sure X resources of the face and image are loaded. */
1534 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1535 prepare_image_for_display (it
->f
, img
);
1537 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1538 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1539 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1543 if (face
->box
!= FACE_NO_BOX
)
1545 if (face
->box_line_width
> 0)
1547 it
->ascent
+= face
->box_line_width
;
1548 it
->descent
+= face
->box_line_width
;
1551 if (it
->start_of_box_run_p
)
1552 it
->pixel_width
+= abs (face
->box_line_width
);
1553 if (it
->end_of_box_run_p
)
1554 it
->pixel_width
+= abs (face
->box_line_width
);
1557 take_vertical_position_into_account (it
);
1561 struct glyph
*glyph
;
1562 enum glyph_row_area area
= it
->area
;
1564 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1565 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1567 glyph
->charpos
= CHARPOS (it
->position
);
1568 glyph
->object
= it
->object
;
1569 glyph
->pixel_width
= it
->pixel_width
;
1570 glyph
->voffset
= it
->voffset
;
1571 glyph
->type
= IMAGE_GLYPH
;
1572 glyph
->multibyte_p
= it
->multibyte_p
;
1573 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1574 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1575 glyph
->overlaps_vertically_p
= 0;
1576 glyph
->padding_p
= 0;
1577 glyph
->glyph_not_available_p
= 0;
1578 glyph
->face_id
= it
->face_id
;
1579 glyph
->u
.img_id
= img
->id
;
1580 ++it
->glyph_row
->used
[area
];
1586 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1587 of the glyph, WIDTH and HEIGHT are the width and height of the
1588 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1589 ascent of the glyph (0 <= ASCENT <= 1). */
1592 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1598 struct glyph
*glyph
;
1599 enum glyph_row_area area
= it
->area
;
1601 xassert (ascent
>= 0 && ascent
<= 1);
1603 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1604 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1606 glyph
->charpos
= CHARPOS (it
->position
);
1607 glyph
->object
= object
;
1608 glyph
->pixel_width
= width
;
1609 glyph
->voffset
= it
->voffset
;
1610 glyph
->type
= STRETCH_GLYPH
;
1611 glyph
->multibyte_p
= it
->multibyte_p
;
1612 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1613 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1614 glyph
->overlaps_vertically_p
= 0;
1615 glyph
->padding_p
= 0;
1616 glyph
->glyph_not_available_p
= 0;
1617 glyph
->face_id
= it
->face_id
;
1618 glyph
->u
.stretch
.ascent
= height
* ascent
;
1619 glyph
->u
.stretch
.height
= height
;
1620 ++it
->glyph_row
->used
[area
];
1625 /* Produce a stretch glyph for iterator IT. IT->object is the value
1626 of the glyph property displayed. The value must be a list
1627 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1630 1. `:width WIDTH' specifies that the space should be WIDTH *
1631 canonical char width wide. WIDTH may be an integer or floating
1634 2. `:relative-width FACTOR' specifies that the width of the stretch
1635 should be computed from the width of the first character having the
1636 `glyph' property, and should be FACTOR times that width.
1638 3. `:align-to HPOS' specifies that the space should be wide enough
1639 to reach HPOS, a value in canonical character units.
1641 Exactly one of the above pairs must be present.
1643 4. `:height HEIGHT' specifies that the height of the stretch produced
1644 should be HEIGHT, measured in canonical character units.
1646 5. `:relative-height FACTOR' specifies that the height of the
1647 stretch should be FACTOR times the height of the characters having
1650 Either none or exactly one of 4 or 5 must be present.
1652 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1653 of the stretch should be used for the ascent of the stretch.
1654 ASCENT must be in the range 0 <= ASCENT <= 100. */
1657 ((INTEGERP (X) || FLOATP (X)) \
1663 x_produce_stretch_glyph (it
)
1666 /* (space :width WIDTH :height HEIGHT. */
1668 extern Lisp_Object Qspace
;
1670 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1671 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1672 extern Lisp_Object QCalign_to
;
1673 Lisp_Object prop
, plist
;
1674 double width
= 0, height
= 0, ascent
= 0;
1675 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1676 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1678 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1680 /* List should start with `space'. */
1681 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1682 plist
= XCDR (it
->object
);
1684 /* Compute the width of the stretch. */
1685 if (prop
= Fplist_get (plist
, QCwidth
),
1687 /* Absolute width `:width WIDTH' specified and valid. */
1688 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1689 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1692 /* Relative width `:relative-width FACTOR' specified and valid.
1693 Compute the width of the characters having the `glyph'
1696 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1699 if (it
->multibyte_p
)
1701 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1702 - IT_BYTEPOS (*it
));
1703 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1706 it2
.c
= *p
, it2
.len
= 1;
1708 it2
.glyph_row
= NULL
;
1709 it2
.what
= IT_CHARACTER
;
1710 x_produce_glyphs (&it2
);
1711 width
= NUMVAL (prop
) * it2
.pixel_width
;
1713 else if (prop
= Fplist_get (plist
, QCalign_to
),
1715 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1717 /* Nothing specified -> width defaults to canonical char width. */
1718 width
= CANON_X_UNIT (it
->f
);
1720 /* Compute height. */
1721 if (prop
= Fplist_get (plist
, QCheight
),
1723 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1724 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1726 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1728 height
= FONT_HEIGHT (font
);
1730 /* Compute percentage of height used for ascent. If
1731 `:ascent ASCENT' is present and valid, use that. Otherwise,
1732 derive the ascent from the font in use. */
1733 if (prop
= Fplist_get (plist
, QCascent
),
1734 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1735 ascent
= NUMVAL (prop
) / 100.0;
1737 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1746 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1747 if (!STRINGP (object
))
1748 object
= it
->w
->buffer
;
1749 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1752 it
->pixel_width
= width
;
1753 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1754 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1757 if (face
->box
!= FACE_NO_BOX
)
1759 if (face
->box_line_width
> 0)
1761 it
->ascent
+= face
->box_line_width
;
1762 it
->descent
+= face
->box_line_width
;
1765 if (it
->start_of_box_run_p
)
1766 it
->pixel_width
+= abs (face
->box_line_width
);
1767 if (it
->end_of_box_run_p
)
1768 it
->pixel_width
+= abs (face
->box_line_width
);
1771 take_vertical_position_into_account (it
);
1774 /* Return proper value to be used as baseline offset of font that has
1775 ASCENT and DESCENT to draw characters by the font at the vertical
1776 center of the line of frame F.
1778 Here, out task is to find the value of BOFF in the following figure;
1780 -------------------------+-----------+-
1781 -+-+---------+-+ | |
1783 | | | | F_ASCENT F_HEIGHT
1786 | | |-|-+------+-----------|------- baseline
1788 | |---------|-+-+ | |
1790 -+-+---------+-+ F_DESCENT |
1791 -------------------------+-----------+-
1793 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1794 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1795 DESCENT = FONT->descent
1796 HEIGHT = FONT_HEIGHT (FONT)
1797 F_DESCENT = (F->output_data.x->font->descent
1798 - F->output_data.x->baseline_offset)
1799 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1802 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1804 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1805 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1806 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1808 /* Produce glyphs/get display metrics for the display element IT is
1809 loaded with. See the description of struct display_iterator in
1810 dispextern.h for an overview of struct display_iterator. */
1813 x_produce_glyphs (it
)
1816 it
->glyph_not_available_p
= 0;
1818 if (it
->what
== IT_CHARACTER
)
1822 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1824 int font_not_found_p
;
1825 struct font_info
*font_info
;
1826 int boff
; /* baseline offset */
1827 /* We may change it->multibyte_p upon unibyte<->multibyte
1828 conversion. So, save the current value now and restore it
1831 Note: It seems that we don't have to record multibyte_p in
1832 struct glyph because the character code itself tells if or
1833 not the character is multibyte. Thus, in the future, we must
1834 consider eliminating the field `multibyte_p' in the struct
1836 int saved_multibyte_p
= it
->multibyte_p
;
1838 /* Maybe translate single-byte characters to multibyte, or the
1840 it
->char_to_display
= it
->c
;
1841 if (!ASCII_BYTE_P (it
->c
))
1843 if (unibyte_display_via_language_environment
1844 && SINGLE_BYTE_CHAR_P (it
->c
)
1846 || !NILP (Vnonascii_translation_table
)))
1848 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1849 it
->multibyte_p
= 1;
1850 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1851 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1853 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1854 && !it
->multibyte_p
)
1856 it
->multibyte_p
= 1;
1857 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1858 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1862 /* Get font to use. Encode IT->char_to_display. */
1863 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1864 it
->face_id
, &char2b
,
1865 it
->multibyte_p
, 0);
1868 /* When no suitable font found, use the default font. */
1869 font_not_found_p
= font
== NULL
;
1870 if (font_not_found_p
)
1872 font
= FRAME_FONT (it
->f
);
1873 boff
= it
->f
->output_data
.x
->baseline_offset
;
1878 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1879 boff
= font_info
->baseline_offset
;
1880 if (font_info
->vertical_centering
)
1881 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1884 if (it
->char_to_display
>= ' '
1885 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1887 /* Either unibyte or ASCII. */
1892 pcm
= x_per_char_metric (font
, &char2b
);
1893 it
->ascent
= font
->ascent
+ boff
;
1894 it
->descent
= font
->descent
- boff
;
1898 it
->phys_ascent
= pcm
->ascent
+ boff
;
1899 it
->phys_descent
= pcm
->descent
- boff
;
1900 it
->pixel_width
= pcm
->width
;
1904 it
->glyph_not_available_p
= 1;
1905 it
->phys_ascent
= font
->ascent
+ boff
;
1906 it
->phys_descent
= font
->descent
- boff
;
1907 it
->pixel_width
= FONT_WIDTH (font
);
1910 /* If this is a space inside a region of text with
1911 `space-width' property, change its width. */
1912 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1914 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1916 /* If face has a box, add the box thickness to the character
1917 height. If character has a box line to the left and/or
1918 right, add the box line width to the character's width. */
1919 if (face
->box
!= FACE_NO_BOX
)
1921 int thick
= face
->box_line_width
;
1925 it
->ascent
+= thick
;
1926 it
->descent
+= thick
;
1931 if (it
->start_of_box_run_p
)
1932 it
->pixel_width
+= thick
;
1933 if (it
->end_of_box_run_p
)
1934 it
->pixel_width
+= thick
;
1937 /* If face has an overline, add the height of the overline
1938 (1 pixel) and a 1 pixel margin to the character height. */
1939 if (face
->overline_p
)
1942 take_vertical_position_into_account (it
);
1944 /* If we have to actually produce glyphs, do it. */
1949 /* Translate a space with a `space-width' property
1950 into a stretch glyph. */
1951 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1952 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1953 it
->ascent
+ it
->descent
, ascent
);
1956 x_append_glyph (it
);
1958 /* If characters with lbearing or rbearing are displayed
1959 in this line, record that fact in a flag of the
1960 glyph row. This is used to optimize X output code. */
1961 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1962 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1965 else if (it
->char_to_display
== '\n')
1967 /* A newline has no width but we need the height of the line. */
1968 it
->pixel_width
= 0;
1970 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1971 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1973 if (face
->box
!= FACE_NO_BOX
1974 && face
->box_line_width
> 0)
1976 it
->ascent
+= face
->box_line_width
;
1977 it
->descent
+= face
->box_line_width
;
1980 else if (it
->char_to_display
== '\t')
1982 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1983 int x
= it
->current_x
+ it
->continuation_lines_width
;
1984 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1986 /* If the distance from the current position to the next tab
1987 stop is less than a canonical character width, use the
1988 tab stop after that. */
1989 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1990 next_tab_x
+= tab_width
;
1992 it
->pixel_width
= next_tab_x
- x
;
1994 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1995 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1999 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
2000 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2001 it
->ascent
+ it
->descent
, ascent
);
2006 /* A multi-byte character. Assume that the display width of the
2007 character is the width of the character multiplied by the
2008 width of the font. */
2010 /* If we found a font, this font should give us the right
2011 metrics. If we didn't find a font, use the frame's
2012 default font and calculate the width of the character
2013 from the charset width; this is what old redisplay code
2015 pcm
= x_per_char_metric (font
, &char2b
);
2016 if (font_not_found_p
|| !pcm
)
2018 int charset
= CHAR_CHARSET (it
->char_to_display
);
2020 it
->glyph_not_available_p
= 1;
2021 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2022 * CHARSET_WIDTH (charset
));
2023 it
->phys_ascent
= font
->ascent
+ boff
;
2024 it
->phys_descent
= font
->descent
- boff
;
2028 it
->pixel_width
= pcm
->width
;
2029 it
->phys_ascent
= pcm
->ascent
+ boff
;
2030 it
->phys_descent
= pcm
->descent
- boff
;
2032 && (pcm
->lbearing
< 0
2033 || pcm
->rbearing
> pcm
->width
))
2034 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2037 it
->ascent
= font
->ascent
+ boff
;
2038 it
->descent
= font
->descent
- boff
;
2039 if (face
->box
!= FACE_NO_BOX
)
2041 int thick
= face
->box_line_width
;
2045 it
->ascent
+= thick
;
2046 it
->descent
+= thick
;
2051 if (it
->start_of_box_run_p
)
2052 it
->pixel_width
+= thick
;
2053 if (it
->end_of_box_run_p
)
2054 it
->pixel_width
+= thick
;
2057 /* If face has an overline, add the height of the overline
2058 (1 pixel) and a 1 pixel margin to the character height. */
2059 if (face
->overline_p
)
2062 take_vertical_position_into_account (it
);
2065 x_append_glyph (it
);
2067 it
->multibyte_p
= saved_multibyte_p
;
2069 else if (it
->what
== IT_COMPOSITION
)
2071 /* Note: A composition is represented as one glyph in the
2072 glyph matrix. There are no padding glyphs. */
2075 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2077 int font_not_found_p
;
2078 struct font_info
*font_info
;
2079 int boff
; /* baseline offset */
2080 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2082 /* Maybe translate single-byte characters to multibyte. */
2083 it
->char_to_display
= it
->c
;
2084 if (unibyte_display_via_language_environment
2085 && SINGLE_BYTE_CHAR_P (it
->c
)
2088 && !NILP (Vnonascii_translation_table
))))
2090 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2093 /* Get face and font to use. Encode IT->char_to_display. */
2094 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2095 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2096 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2097 it
->face_id
, &char2b
, it
->multibyte_p
, 0);
2100 /* When no suitable font found, use the default font. */
2101 font_not_found_p
= font
== NULL
;
2102 if (font_not_found_p
)
2104 font
= FRAME_FONT (it
->f
);
2105 boff
= it
->f
->output_data
.x
->baseline_offset
;
2110 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2111 boff
= font_info
->baseline_offset
;
2112 if (font_info
->vertical_centering
)
2113 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2116 /* There are no padding glyphs, so there is only one glyph to
2117 produce for the composition. Important is that pixel_width,
2118 ascent and descent are the values of what is drawn by
2119 draw_glyphs (i.e. the values of the overall glyphs composed). */
2122 /* If we have not yet calculated pixel size data of glyphs of
2123 the composition for the current face font, calculate them
2124 now. Theoretically, we have to check all fonts for the
2125 glyphs, but that requires much time and memory space. So,
2126 here we check only the font of the first glyph. This leads
2127 to incorrect display very rarely, and C-l (recenter) can
2128 correct the display anyway. */
2129 if (cmp
->font
!= (void *) font
)
2131 /* Ascent and descent of the font of the first character of
2132 this composition (adjusted by baseline offset). Ascent
2133 and descent of overall glyphs should not be less than
2134 them respectively. */
2135 int font_ascent
= font
->ascent
+ boff
;
2136 int font_descent
= font
->descent
- boff
;
2137 /* Bounding box of the overall glyphs. */
2138 int leftmost
, rightmost
, lowest
, highest
;
2139 int i
, width
, ascent
, descent
;
2141 cmp
->font
= (void *) font
;
2143 /* Initialize the bounding box. */
2145 && (pcm
= x_per_char_metric (font
, &char2b
)))
2148 ascent
= pcm
->ascent
;
2149 descent
= pcm
->descent
;
2153 width
= FONT_WIDTH (font
);
2154 ascent
= font
->ascent
;
2155 descent
= font
->descent
;
2159 lowest
= - descent
+ boff
;
2160 highest
= ascent
+ boff
;
2164 && font_info
->default_ascent
2165 && CHAR_TABLE_P (Vuse_default_ascent
)
2166 && !NILP (Faref (Vuse_default_ascent
,
2167 make_number (it
->char_to_display
))))
2168 highest
= font_info
->default_ascent
+ boff
;
2170 /* Draw the first glyph at the normal position. It may be
2171 shifted to right later if some other glyphs are drawn at
2173 cmp
->offsets
[0] = 0;
2174 cmp
->offsets
[1] = boff
;
2176 /* Set cmp->offsets for the remaining glyphs. */
2177 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2179 int left
, right
, btm
, top
;
2180 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2181 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2183 face
= FACE_FROM_ID (it
->f
, face_id
);
2184 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2185 it
->multibyte_p
, 0);
2189 font
= FRAME_FONT (it
->f
);
2190 boff
= it
->f
->output_data
.x
->baseline_offset
;
2196 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2197 boff
= font_info
->baseline_offset
;
2198 if (font_info
->vertical_centering
)
2199 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2203 && (pcm
= x_per_char_metric (font
, &char2b
)))
2206 ascent
= pcm
->ascent
;
2207 descent
= pcm
->descent
;
2211 width
= FONT_WIDTH (font
);
2216 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2218 /* Relative composition with or without
2220 left
= (leftmost
+ rightmost
- width
) / 2;
2221 btm
= - descent
+ boff
;
2222 if (font_info
&& font_info
->relative_compose
2223 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2224 || NILP (Faref (Vignore_relative_composition
,
2225 make_number (ch
)))))
2228 if (- descent
>= font_info
->relative_compose
)
2229 /* One extra pixel between two glyphs. */
2231 else if (ascent
<= 0)
2232 /* One extra pixel between two glyphs. */
2233 btm
= lowest
- 1 - ascent
- descent
;
2238 /* A composition rule is specified by an integer
2239 value that encodes global and new reference
2240 points (GREF and NREF). GREF and NREF are
2241 specified by numbers as below:
2249 ---3---4---5--- baseline
2251 6---7---8 -- descent
2253 int rule
= COMPOSITION_RULE (cmp
, i
);
2254 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2256 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2257 grefx
= gref
% 3, nrefx
= nref
% 3;
2258 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2261 + grefx
* (rightmost
- leftmost
) / 2
2262 - nrefx
* width
/ 2);
2263 btm
= ((grefy
== 0 ? highest
2265 : grefy
== 2 ? lowest
2266 : (highest
+ lowest
) / 2)
2267 - (nrefy
== 0 ? ascent
+ descent
2268 : nrefy
== 1 ? descent
- boff
2270 : (ascent
+ descent
) / 2));
2273 cmp
->offsets
[i
* 2] = left
;
2274 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2276 /* Update the bounding box of the overall glyphs. */
2277 right
= left
+ width
;
2278 top
= btm
+ descent
+ ascent
;
2279 if (left
< leftmost
)
2281 if (right
> rightmost
)
2289 /* If there are glyphs whose x-offsets are negative,
2290 shift all glyphs to the right and make all x-offsets
2294 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2295 cmp
->offsets
[i
* 2] -= leftmost
;
2296 rightmost
-= leftmost
;
2299 cmp
->pixel_width
= rightmost
;
2300 cmp
->ascent
= highest
;
2301 cmp
->descent
= - lowest
;
2302 if (cmp
->ascent
< font_ascent
)
2303 cmp
->ascent
= font_ascent
;
2304 if (cmp
->descent
< font_descent
)
2305 cmp
->descent
= font_descent
;
2308 it
->pixel_width
= cmp
->pixel_width
;
2309 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2310 it
->descent
= it
->phys_descent
= cmp
->descent
;
2312 if (face
->box
!= FACE_NO_BOX
)
2314 int thick
= face
->box_line_width
;
2318 it
->ascent
+= thick
;
2319 it
->descent
+= thick
;
2324 if (it
->start_of_box_run_p
)
2325 it
->pixel_width
+= thick
;
2326 if (it
->end_of_box_run_p
)
2327 it
->pixel_width
+= thick
;
2330 /* If face has an overline, add the height of the overline
2331 (1 pixel) and a 1 pixel margin to the character height. */
2332 if (face
->overline_p
)
2335 take_vertical_position_into_account (it
);
2338 x_append_composite_glyph (it
);
2340 else if (it
->what
== IT_IMAGE
)
2341 x_produce_image_glyph (it
);
2342 else if (it
->what
== IT_STRETCH
)
2343 x_produce_stretch_glyph (it
);
2345 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2346 because this isn't true for images with `:ascent 100'. */
2347 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2348 if (it
->area
== TEXT_AREA
)
2349 it
->current_x
+= it
->pixel_width
;
2351 it
->descent
+= it
->extra_line_spacing
;
2353 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2354 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2355 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2356 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2360 /* Estimate the pixel height of the mode or top line on frame F.
2361 FACE_ID specifies what line's height to estimate. */
2364 x_estimate_mode_line_height (f
, face_id
)
2366 enum face_id face_id
;
2368 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2370 /* This function is called so early when Emacs starts that the face
2371 cache and mode line face are not yet initialized. */
2372 if (FRAME_FACE_CACHE (f
))
2374 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2378 height
= FONT_HEIGHT (face
->font
);
2379 if (face
->box_line_width
> 0)
2380 height
+= 2 * face
->box_line_width
;
2388 /***********************************************************************
2390 ***********************************************************************/
2392 /* A sequence of glyphs to be drawn in the same face.
2394 This data structure is not really completely X specific, so it
2395 could possibly, at least partially, be useful for other systems. It
2396 is currently not part of the external redisplay interface because
2397 it's not clear what other systems will need. */
2401 /* X-origin of the string. */
2404 /* Y-origin and y-position of the base line of this string. */
2407 /* The width of the string, not including a face extension. */
2410 /* The width of the string, including a face extension. */
2411 int background_width
;
2413 /* The height of this string. This is the height of the line this
2414 string is drawn in, and can be different from the height of the
2415 font the string is drawn in. */
2418 /* Number of pixels this string overwrites in front of its x-origin.
2419 This number is zero if the string has an lbearing >= 0; it is
2420 -lbearing, if the string has an lbearing < 0. */
2423 /* Number of pixels this string overwrites past its right-most
2424 nominal x-position, i.e. x + width. Zero if the string's
2425 rbearing is <= its nominal width, rbearing - width otherwise. */
2428 /* The frame on which the glyph string is drawn. */
2431 /* The window on which the glyph string is drawn. */
2434 /* X display and window for convenience. */
2438 /* The glyph row for which this string was built. It determines the
2439 y-origin and height of the string. */
2440 struct glyph_row
*row
;
2442 /* The area within row. */
2443 enum glyph_row_area area
;
2445 /* Characters to be drawn, and number of characters. */
2449 /* A face-override for drawing cursors, mouse face and similar. */
2450 enum draw_glyphs_face hl
;
2452 /* Face in which this string is to be drawn. */
2455 /* Font in which this string is to be drawn. */
2458 /* Font info for this string. */
2459 struct font_info
*font_info
;
2461 /* Non-null means this string describes (part of) a composition.
2462 All characters from char2b are drawn composed. */
2463 struct composition
*cmp
;
2465 /* Index of this glyph string's first character in the glyph
2466 definition of CMP. If this is zero, this glyph string describes
2467 the first character of a composition. */
2470 /* 1 means this glyph strings face has to be drawn to the right end
2471 of the window's drawing area. */
2472 unsigned extends_to_end_of_line_p
: 1;
2474 /* 1 means the background of this string has been drawn. */
2475 unsigned background_filled_p
: 1;
2477 /* 1 means glyph string must be drawn with 16-bit functions. */
2478 unsigned two_byte_p
: 1;
2480 /* 1 means that the original font determined for drawing this glyph
2481 string could not be loaded. The member `font' has been set to
2482 the frame's default font in this case. */
2483 unsigned font_not_found_p
: 1;
2485 /* 1 means that the face in which this glyph string is drawn has a
2487 unsigned stippled_p
: 1;
2489 /* 1 means only the foreground of this glyph string must be drawn,
2490 and we should use the physical height of the line this glyph
2491 string appears in as clip rect. */
2492 unsigned for_overlaps_p
: 1;
2494 /* The GC to use for drawing this glyph string. */
2497 /* A pointer to the first glyph in the string. This glyph
2498 corresponds to char2b[0]. Needed to draw rectangles if
2499 font_not_found_p is 1. */
2500 struct glyph
*first_glyph
;
2502 /* Image, if any. */
2505 struct glyph_string
*next
, *prev
;
2512 x_dump_glyph_string (s
)
2513 struct glyph_string
*s
;
2515 fprintf (stderr
, "glyph string\n");
2516 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2517 s
->x
, s
->y
, s
->width
, s
->height
);
2518 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2519 fprintf (stderr
, " hl = %d\n", s
->hl
);
2520 fprintf (stderr
, " left overhang = %d, right = %d\n",
2521 s
->left_overhang
, s
->right_overhang
);
2522 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2523 fprintf (stderr
, " extends to end of line = %d\n",
2524 s
->extends_to_end_of_line_p
);
2525 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2526 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2529 #endif /* GLYPH_DEBUG */
2533 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2534 struct glyph_string
**,
2535 struct glyph_string
*,
2536 struct glyph_string
*));
2537 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2538 struct glyph_string
**,
2539 struct glyph_string
*,
2540 struct glyph_string
*));
2541 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2542 struct glyph_string
**,
2543 struct glyph_string
*));
2544 static int x_left_overwritten
P_ ((struct glyph_string
*));
2545 static int x_left_overwriting
P_ ((struct glyph_string
*));
2546 static int x_right_overwritten
P_ ((struct glyph_string
*));
2547 static int x_right_overwriting
P_ ((struct glyph_string
*));
2548 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2550 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2551 XChar2b
*, struct window
*,
2553 enum glyph_row_area
, int,
2554 enum draw_glyphs_face
));
2555 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2556 enum glyph_row_area
, int, int,
2557 enum draw_glyphs_face
, int));
2558 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2559 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2560 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2562 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2563 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2564 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2565 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2566 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2567 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2568 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2569 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2570 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2572 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2573 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2574 unsigned long *, double, int));
2575 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2576 double, int, unsigned long));
2577 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2578 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2579 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2580 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2581 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2582 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2583 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2585 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2586 int, int, int, int, XRectangle
*));
2587 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2588 int, int, int, XRectangle
*));
2589 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2590 enum glyph_row_area
));
2591 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2593 enum glyph_row_area
, int, int));
2596 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2600 /* Append the list of glyph strings with head H and tail T to the list
2601 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2604 x_append_glyph_string_lists (head
, tail
, h
, t
)
2605 struct glyph_string
**head
, **tail
;
2606 struct glyph_string
*h
, *t
;
2620 /* Prepend the list of glyph strings with head H and tail T to the
2621 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2625 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2626 struct glyph_string
**head
, **tail
;
2627 struct glyph_string
*h
, *t
;
2641 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2642 Set *HEAD and *TAIL to the resulting list. */
2645 x_append_glyph_string (head
, tail
, s
)
2646 struct glyph_string
**head
, **tail
;
2647 struct glyph_string
*s
;
2649 s
->next
= s
->prev
= NULL
;
2650 x_append_glyph_string_lists (head
, tail
, s
, s
);
2654 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2659 struct glyph_string
*s
;
2661 if (s
->font
== FRAME_FONT (s
->f
)
2662 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2663 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2665 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2668 /* Cursor on non-default face: must merge. */
2672 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2673 xgcv
.foreground
= s
->face
->background
;
2675 /* If the glyph would be invisible, try a different foreground. */
2676 if (xgcv
.foreground
== xgcv
.background
)
2677 xgcv
.foreground
= s
->face
->foreground
;
2678 if (xgcv
.foreground
== xgcv
.background
)
2679 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2680 if (xgcv
.foreground
== xgcv
.background
)
2681 xgcv
.foreground
= s
->face
->foreground
;
2683 /* Make sure the cursor is distinct from text in this face. */
2684 if (xgcv
.background
== s
->face
->background
2685 && xgcv
.foreground
== s
->face
->foreground
)
2687 xgcv
.background
= s
->face
->foreground
;
2688 xgcv
.foreground
= s
->face
->background
;
2691 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2692 xgcv
.font
= s
->font
->fid
;
2693 xgcv
.graphics_exposures
= False
;
2694 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2696 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2697 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2700 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2701 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2703 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2708 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2711 x_set_mouse_face_gc (s
)
2712 struct glyph_string
*s
;
2717 /* What face has to be used last for the mouse face? */
2718 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2719 face
= FACE_FROM_ID (s
->f
, face_id
);
2721 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2723 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2724 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2726 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2727 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2728 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2730 /* If font in this face is same as S->font, use it. */
2731 if (s
->font
== s
->face
->font
)
2732 s
->gc
= s
->face
->gc
;
2735 /* Otherwise construct scratch_cursor_gc with values from FACE
2740 xgcv
.background
= s
->face
->background
;
2741 xgcv
.foreground
= s
->face
->foreground
;
2742 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2743 xgcv
.font
= s
->font
->fid
;
2744 xgcv
.graphics_exposures
= False
;
2745 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2747 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2748 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2751 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2752 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2754 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2757 xassert (s
->gc
!= 0);
2761 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2762 Faces to use in the mode line have already been computed when the
2763 matrix was built, so there isn't much to do, here. */
2766 x_set_mode_line_face_gc (s
)
2767 struct glyph_string
*s
;
2769 s
->gc
= s
->face
->gc
;
2773 /* Set S->gc of glyph string S for drawing that glyph string. Set
2774 S->stippled_p to a non-zero value if the face of S has a stipple
2778 x_set_glyph_string_gc (s
)
2779 struct glyph_string
*s
;
2781 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2783 if (s
->hl
== DRAW_NORMAL_TEXT
)
2785 s
->gc
= s
->face
->gc
;
2786 s
->stippled_p
= s
->face
->stipple
!= 0;
2788 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2790 x_set_mode_line_face_gc (s
);
2791 s
->stippled_p
= s
->face
->stipple
!= 0;
2793 else if (s
->hl
== DRAW_CURSOR
)
2795 x_set_cursor_gc (s
);
2798 else if (s
->hl
== DRAW_MOUSE_FACE
)
2800 x_set_mouse_face_gc (s
);
2801 s
->stippled_p
= s
->face
->stipple
!= 0;
2803 else if (s
->hl
== DRAW_IMAGE_RAISED
2804 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2806 s
->gc
= s
->face
->gc
;
2807 s
->stippled_p
= s
->face
->stipple
!= 0;
2811 s
->gc
= s
->face
->gc
;
2812 s
->stippled_p
= s
->face
->stipple
!= 0;
2815 /* GC must have been set. */
2816 xassert (s
->gc
!= 0);
2820 /* Return in *R the clipping rectangle for glyph string S. */
2823 x_get_glyph_string_clip_rect (s
, r
)
2824 struct glyph_string
*s
;
2827 if (s
->row
->full_width_p
)
2829 /* Draw full-width. X coordinates are relative to S->w->left. */
2830 int canon_x
= CANON_X_UNIT (s
->f
);
2832 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2833 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2835 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2837 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2838 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2842 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2844 /* Unless displaying a mode or menu bar line, which are always
2845 fully visible, clip to the visible part of the row. */
2846 if (s
->w
->pseudo_window_p
)
2847 r
->height
= s
->row
->visible_height
;
2849 r
->height
= s
->height
;
2853 /* This is a text line that may be partially visible. */
2854 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2855 r
->width
= window_box_width (s
->w
, s
->area
);
2856 r
->height
= s
->row
->visible_height
;
2859 /* If S draws overlapping rows, it's sufficient to use the top and
2860 bottom of the window for clipping because this glyph string
2861 intentionally draws over other lines. */
2862 if (s
->for_overlaps_p
)
2864 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2865 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2869 /* Don't use S->y for clipping because it doesn't take partially
2870 visible lines into account. For example, it can be negative for
2871 partially visible lines at the top of a window. */
2872 if (!s
->row
->full_width_p
2873 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2874 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2876 r
->y
= max (0, s
->row
->y
);
2878 /* If drawing a tool-bar window, draw it over the internal border
2879 at the top of the window. */
2880 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2881 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2884 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2888 /* Set clipping for output of glyph string S. S may be part of a mode
2889 line or menu if we don't have X toolkit support. */
2892 x_set_glyph_string_clipping (s
)
2893 struct glyph_string
*s
;
2896 x_get_glyph_string_clip_rect (s
, &r
);
2897 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2901 /* Compute left and right overhang of glyph string S. If S is a glyph
2902 string for a composition, assume overhangs don't exist. */
2905 x_compute_glyph_string_overhangs (s
)
2906 struct glyph_string
*s
;
2909 && s
->first_glyph
->type
== CHAR_GLYPH
)
2912 int direction
, font_ascent
, font_descent
;
2913 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2914 &font_ascent
, &font_descent
, &cs
);
2915 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2916 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2921 /* Compute overhangs and x-positions for glyph string S and its
2922 predecessors, or successors. X is the starting x-position for S.
2923 BACKWARD_P non-zero means process predecessors. */
2926 x_compute_overhangs_and_x (s
, x
, backward_p
)
2927 struct glyph_string
*s
;
2935 x_compute_glyph_string_overhangs (s
);
2945 x_compute_glyph_string_overhangs (s
);
2954 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2955 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2956 assumed to be zero. */
2959 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2960 struct glyph
*glyph
;
2966 if (glyph
->type
== CHAR_GLYPH
)
2970 struct font_info
*font_info
;
2974 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2976 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2978 && (pcm
= x_per_char_metric (font
, &char2b
)))
2980 if (pcm
->rbearing
> pcm
->width
)
2981 *right
= pcm
->rbearing
- pcm
->width
;
2982 if (pcm
->lbearing
< 0)
2983 *left
= -pcm
->lbearing
;
2989 /* Return the index of the first glyph preceding glyph string S that
2990 is overwritten by S because of S's left overhang. Value is -1
2991 if no glyphs are overwritten. */
2994 x_left_overwritten (s
)
2995 struct glyph_string
*s
;
2999 if (s
->left_overhang
)
3002 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3003 int first
= s
->first_glyph
- glyphs
;
3005 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
3006 x
-= glyphs
[i
].pixel_width
;
3017 /* Return the index of the first glyph preceding glyph string S that
3018 is overwriting S because of its right overhang. Value is -1 if no
3019 glyph in front of S overwrites S. */
3022 x_left_overwriting (s
)
3023 struct glyph_string
*s
;
3026 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3027 int first
= s
->first_glyph
- glyphs
;
3031 for (i
= first
- 1; i
>= 0; --i
)
3034 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3037 x
-= glyphs
[i
].pixel_width
;
3044 /* Return the index of the last glyph following glyph string S that is
3045 not overwritten by S because of S's right overhang. Value is -1 if
3046 no such glyph is found. */
3049 x_right_overwritten (s
)
3050 struct glyph_string
*s
;
3054 if (s
->right_overhang
)
3057 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3058 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3059 int end
= s
->row
->used
[s
->area
];
3061 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3062 x
+= glyphs
[i
].pixel_width
;
3071 /* Return the index of the last glyph following glyph string S that
3072 overwrites S because of its left overhang. Value is negative
3073 if no such glyph is found. */
3076 x_right_overwriting (s
)
3077 struct glyph_string
*s
;
3080 int end
= s
->row
->used
[s
->area
];
3081 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3082 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3086 for (i
= first
; i
< end
; ++i
)
3089 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3092 x
+= glyphs
[i
].pixel_width
;
3099 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3102 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3103 struct glyph_string
*s
;
3107 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3108 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3109 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3110 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3114 /* Draw the background of glyph_string S. If S->background_filled_p
3115 is non-zero don't draw it. FORCE_P non-zero means draw the
3116 background even if it wouldn't be drawn normally. This is used
3117 when a string preceding S draws into the background of S, or S
3118 contains the first component of a composition. */
3121 x_draw_glyph_string_background (s
, force_p
)
3122 struct glyph_string
*s
;
3125 /* Nothing to do if background has already been drawn or if it
3126 shouldn't be drawn in the first place. */
3127 if (!s
->background_filled_p
)
3129 int box_line_width
= max (s
->face
->box_line_width
, 0);
3133 /* Fill background with a stipple pattern. */
3134 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3135 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3136 s
->y
+ box_line_width
,
3137 s
->background_width
,
3138 s
->height
- 2 * box_line_width
);
3139 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3140 s
->background_filled_p
= 1;
3142 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3143 || s
->font_not_found_p
3144 || s
->extends_to_end_of_line_p
3147 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3148 s
->background_width
,
3149 s
->height
- 2 * box_line_width
);
3150 s
->background_filled_p
= 1;
3156 /* Draw the foreground of glyph string S. */
3159 x_draw_glyph_string_foreground (s
)
3160 struct glyph_string
*s
;
3164 /* If first glyph of S has a left box line, start drawing the text
3165 of S to the right of that box line. */
3166 if (s
->face
->box
!= FACE_NO_BOX
3167 && s
->first_glyph
->left_box_line_p
)
3168 x
= s
->x
+ abs (s
->face
->box_line_width
);
3172 /* Draw characters of S as rectangles if S's font could not be
3174 if (s
->font_not_found_p
)
3176 for (i
= 0; i
< s
->nchars
; ++i
)
3178 struct glyph
*g
= s
->first_glyph
+ i
;
3179 XDrawRectangle (s
->display
, s
->window
,
3180 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3182 x
+= g
->pixel_width
;
3187 char *char1b
= (char *) s
->char2b
;
3188 int boff
= s
->font_info
->baseline_offset
;
3190 if (s
->font_info
->vertical_centering
)
3191 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3193 /* If we can use 8-bit functions, condense S->char2b. */
3195 for (i
= 0; i
< s
->nchars
; ++i
)
3196 char1b
[i
] = s
->char2b
[i
].byte2
;
3198 /* Draw text with XDrawString if background has already been
3199 filled. Otherwise, use XDrawImageString. (Note that
3200 XDrawImageString is usually faster than XDrawString.) Always
3201 use XDrawImageString when drawing the cursor so that there is
3202 no chance that characters under a box cursor are invisible. */
3203 if (s
->for_overlaps_p
3204 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3206 /* Draw characters with 16-bit or 8-bit functions. */
3208 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3209 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3211 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3212 s
->ybase
- boff
, char1b
, s
->nchars
);
3217 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3218 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3220 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3221 s
->ybase
- boff
, char1b
, s
->nchars
);
3226 /* Draw the foreground of composite glyph string S. */
3229 x_draw_composite_glyph_string_foreground (s
)
3230 struct glyph_string
*s
;
3234 /* If first glyph of S has a left box line, start drawing the text
3235 of S to the right of that box line. */
3236 if (s
->face
->box
!= FACE_NO_BOX
3237 && s
->first_glyph
->left_box_line_p
)
3238 x
= s
->x
+ abs (s
->face
->box_line_width
);
3242 /* S is a glyph string for a composition. S->gidx is the index of
3243 the first character drawn for glyphs of this composition.
3244 S->gidx == 0 means we are drawing the very first character of
3245 this composition. */
3247 /* Draw a rectangle for the composition if the font for the very
3248 first character of the composition could not be loaded. */
3249 if (s
->font_not_found_p
)
3252 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3253 s
->width
- 1, s
->height
- 1);
3257 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3258 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3259 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3260 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3266 #ifdef USE_X_TOOLKIT
3268 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3269 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3270 XrmValue
*, XrmValue
*, XtPointer
*));
3271 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3272 XrmValue
*, Cardinal
*));
3275 /* Return the frame on which widget WIDGET is used.. Abort if frame
3276 cannot be determined. */
3278 static struct frame
*
3279 x_frame_of_widget (widget
)
3282 struct x_display_info
*dpyinfo
;
3286 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3288 /* Find the top-level shell of the widget. Note that this function
3289 can be called when the widget is not yet realized, so XtWindow
3290 (widget) == 0. That's the reason we can't simply use
3291 x_any_window_to_frame. */
3292 while (!XtIsTopLevelShell (widget
))
3293 widget
= XtParent (widget
);
3295 /* Look for a frame with that top-level widget. Allocate the color
3296 on that frame to get the right gamma correction value. */
3297 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3298 if (GC_FRAMEP (XCAR (tail
))
3299 && (f
= XFRAME (XCAR (tail
)),
3300 (f
->output_data
.nothing
!= 1
3301 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3302 && f
->output_data
.x
->widget
== widget
)
3309 /* Allocate the color COLOR->pixel on the screen and display of
3310 widget WIDGET in colormap CMAP. If an exact match cannot be
3311 allocated, try the nearest color available. Value is non-zero
3312 if successful. This is called from lwlib. */
3315 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3320 struct frame
*f
= x_frame_of_widget (widget
);
3321 return x_alloc_nearest_color (f
, cmap
, color
);
3325 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3326 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3327 If this produces the same color as PIXEL, try a color where all RGB
3328 values have DELTA added. Return the allocated color in *PIXEL.
3329 DISPLAY is the X display, CMAP is the colormap to operate on.
3330 Value is non-zero if successful. */
3333 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3337 unsigned long *pixel
;
3341 struct frame
*f
= x_frame_of_widget (widget
);
3342 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3346 /* Structure specifying which arguments should be passed by Xt to
3347 cvt_string_to_pixel. We want the widget's screen and colormap. */
3349 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3351 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3353 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3358 /* The address of this variable is returned by
3359 cvt_string_to_pixel. */
3361 static Pixel cvt_string_to_pixel_value
;
3364 /* Convert a color name to a pixel color.
3366 DPY is the display we are working on.
3368 ARGS is an array of *NARGS XrmValue structures holding additional
3369 information about the widget for which the conversion takes place.
3370 The contents of this array are determined by the specification
3371 in cvt_string_to_pixel_args.
3373 FROM is a pointer to an XrmValue which points to the color name to
3374 convert. TO is an XrmValue in which to return the pixel color.
3376 CLOSURE_RET is a pointer to user-data, in which we record if
3377 we allocated the color or not.
3379 Value is True if successful, False otherwise. */
3382 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3386 XrmValue
*from
, *to
;
3387 XtPointer
*closure_ret
;
3397 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3398 "wrongParameters", "cvt_string_to_pixel",
3400 "Screen and colormap args required", NULL
, NULL
);
3404 screen
= *(Screen
**) args
[0].addr
;
3405 cmap
= *(Colormap
*) args
[1].addr
;
3406 color_name
= (String
) from
->addr
;
3408 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3410 *closure_ret
= (XtPointer
) False
;
3411 pixel
= WhitePixelOfScreen (screen
);
3413 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3415 *closure_ret
= (XtPointer
) False
;
3416 pixel
= BlackPixelOfScreen (screen
);
3418 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3419 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3421 pixel
= color
.pixel
;
3422 *closure_ret
= (XtPointer
) True
;
3427 Cardinal nparams
= 1;
3429 params
[0] = color_name
;
3430 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3431 "badValue", "cvt_string_to_pixel",
3432 "XtToolkitError", "Invalid color `%s'",
3437 if (to
->addr
!= NULL
)
3439 if (to
->size
< sizeof (Pixel
))
3441 to
->size
= sizeof (Pixel
);
3445 *(Pixel
*) to
->addr
= pixel
;
3449 cvt_string_to_pixel_value
= pixel
;
3450 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3453 to
->size
= sizeof (Pixel
);
3458 /* Free a pixel color which was previously allocated via
3459 cvt_string_to_pixel. This is registered as the destructor
3460 for this type of resource via XtSetTypeConverter.
3462 APP is the application context in which we work.
3464 TO is a pointer to an XrmValue holding the color to free.
3465 CLOSURE is the value we stored in CLOSURE_RET for this color
3466 in cvt_string_to_pixel.
3468 ARGS and NARGS are like for cvt_string_to_pixel. */
3471 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3480 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3482 "Screen and colormap arguments required",
3485 else if (closure
!= NULL
)
3487 /* We did allocate the pixel, so free it. */
3488 Screen
*screen
= *(Screen
**) args
[0].addr
;
3489 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3490 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3491 (Pixel
*) to
->addr
, 1);
3496 #endif /* USE_X_TOOLKIT */
3499 /* Value is an array of XColor structures for the contents of the
3500 color map of display DPY. Set *NCELLS to the size of the array.
3501 Note that this probably shouldn't be called for large color maps,
3502 say a 24-bit TrueColor map. */
3504 static const XColor
*
3505 x_color_cells (dpy
, ncells
)
3509 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3511 if (dpyinfo
->color_cells
== NULL
)
3513 Screen
*screen
= dpyinfo
->screen
;
3516 dpyinfo
->ncolor_cells
3517 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3518 dpyinfo
->color_cells
3519 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3520 * sizeof *dpyinfo
->color_cells
);
3522 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3523 dpyinfo
->color_cells
[i
].pixel
= i
;
3525 XQueryColors (dpy
, dpyinfo
->cmap
,
3526 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3529 *ncells
= dpyinfo
->ncolor_cells
;
3530 return dpyinfo
->color_cells
;
3534 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3535 colors in COLORS. Use cached information, if available. */
3538 x_query_colors (f
, colors
, ncolors
)
3543 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3545 if (dpyinfo
->color_cells
)
3548 for (i
= 0; i
< ncolors
; ++i
)
3550 unsigned long pixel
= colors
[i
].pixel
;
3551 xassert (pixel
< dpyinfo
->ncolor_cells
);
3552 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3553 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3557 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3561 /* On frame F, translate pixel color to RGB values for the color in
3562 COLOR. Use cached information, if available. */
3565 x_query_color (f
, color
)
3569 x_query_colors (f
, color
, 1);
3573 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3574 exact match can't be allocated, try the nearest color available.
3575 Value is non-zero if successful. Set *COLOR to the color
3579 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3586 rc
= XAllocColor (dpy
, cmap
, color
);
3589 /* If we got to this point, the colormap is full, so we're going
3590 to try to get the next closest color. The algorithm used is
3591 a least-squares matching, which is what X uses for closest
3592 color matching with StaticColor visuals. */
3594 unsigned long nearest_delta
= ~0;
3596 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3598 for (nearest
= i
= 0; i
< ncells
; ++i
)
3600 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3601 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3602 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3603 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3605 if (delta
< nearest_delta
)
3608 nearest_delta
= delta
;
3612 color
->red
= cells
[nearest
].red
;
3613 color
->green
= cells
[nearest
].green
;
3614 color
->blue
= cells
[nearest
].blue
;
3615 rc
= XAllocColor (dpy
, cmap
, color
);
3619 /* If allocation succeeded, and the allocated pixel color is not
3620 equal to a cached pixel color recorded earlier, there was a
3621 change in the colormap, so clear the color cache. */
3622 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3623 XColor
*cached_color
;
3625 if (dpyinfo
->color_cells
3626 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3627 (cached_color
->red
!= color
->red
3628 || cached_color
->blue
!= color
->blue
3629 || cached_color
->green
!= color
->green
)))
3631 xfree (dpyinfo
->color_cells
);
3632 dpyinfo
->color_cells
= NULL
;
3633 dpyinfo
->ncolor_cells
= 0;
3637 #ifdef DEBUG_X_COLORS
3639 register_color (color
->pixel
);
3640 #endif /* DEBUG_X_COLORS */
3646 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3647 exact match can't be allocated, try the nearest color available.
3648 Value is non-zero if successful. Set *COLOR to the color
3652 x_alloc_nearest_color (f
, cmap
, color
)
3657 gamma_correct (f
, color
);
3658 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3662 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3663 It's necessary to do this instead of just using PIXEL directly to
3664 get color reference counts right. */
3667 x_copy_color (f
, pixel
)
3669 unsigned long pixel
;
3673 color
.pixel
= pixel
;
3675 x_query_color (f
, &color
);
3676 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3678 #ifdef DEBUG_X_COLORS
3679 register_color (pixel
);
3685 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3686 It's necessary to do this instead of just using PIXEL directly to
3687 get color reference counts right. */
3690 x_copy_dpy_color (dpy
, cmap
, pixel
)
3693 unsigned long pixel
;
3697 color
.pixel
= pixel
;
3699 XQueryColor (dpy
, cmap
, &color
);
3700 XAllocColor (dpy
, cmap
, &color
);
3702 #ifdef DEBUG_X_COLORS
3703 register_color (pixel
);
3709 /* Brightness beyond which a color won't have its highlight brightness
3712 Nominally, highlight colors for `3d' faces are calculated by
3713 brightening an object's color by a constant scale factor, but this
3714 doesn't yield good results for dark colors, so for colors who's
3715 brightness is less than this value (on a scale of 0-65535) have an
3716 use an additional additive factor.
3718 The value here is set so that the default menu-bar/mode-line color
3719 (grey75) will not have its highlights changed at all. */
3720 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3723 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3724 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3725 If this produces the same color as PIXEL, try a color where all RGB
3726 values have DELTA added. Return the allocated color in *PIXEL.
3727 DISPLAY is the X display, CMAP is the colormap to operate on.
3728 Value is non-zero if successful. */
3731 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3735 unsigned long *pixel
;
3743 /* Get RGB color values. */
3744 color
.pixel
= *pixel
;
3745 x_query_color (f
, &color
);
3747 /* Change RGB values by specified FACTOR. Avoid overflow! */
3748 xassert (factor
>= 0);
3749 new.red
= min (0xffff, factor
* color
.red
);
3750 new.green
= min (0xffff, factor
* color
.green
);
3751 new.blue
= min (0xffff, factor
* color
.blue
);
3753 /* Calculate brightness of COLOR. */
3754 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3756 /* We only boost colors that are darker than
3757 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3758 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3759 /* Make an additive adjustment to NEW, because it's dark enough so
3760 that scaling by FACTOR alone isn't enough. */
3762 /* How far below the limit this color is (0 - 1, 1 being darker). */
3763 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3764 /* The additive adjustment. */
3765 int min_delta
= delta
* dimness
* factor
/ 2;
3769 new.red
= max (0, new.red
- min_delta
);
3770 new.green
= max (0, new.green
- min_delta
);
3771 new.blue
= max (0, new.blue
- min_delta
);
3775 new.red
= min (0xffff, min_delta
+ new.red
);
3776 new.green
= min (0xffff, min_delta
+ new.green
);
3777 new.blue
= min (0xffff, min_delta
+ new.blue
);
3781 /* Try to allocate the color. */
3782 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3785 if (new.pixel
== *pixel
)
3787 /* If we end up with the same color as before, try adding
3788 delta to the RGB values. */
3789 x_free_colors (f
, &new.pixel
, 1);
3791 new.red
= min (0xffff, delta
+ color
.red
);
3792 new.green
= min (0xffff, delta
+ color
.green
);
3793 new.blue
= min (0xffff, delta
+ color
.blue
);
3794 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3805 /* Set up the foreground color for drawing relief lines of glyph
3806 string S. RELIEF is a pointer to a struct relief containing the GC
3807 with which lines will be drawn. Use a color that is FACTOR or
3808 DELTA lighter or darker than the relief's background which is found
3809 in S->f->output_data.x->relief_background. If such a color cannot
3810 be allocated, use DEFAULT_PIXEL, instead. */
3813 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3815 struct relief
*relief
;
3818 unsigned long default_pixel
;
3821 struct x_output
*di
= f
->output_data
.x
;
3822 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3823 unsigned long pixel
;
3824 unsigned long background
= di
->relief_background
;
3825 Colormap cmap
= FRAME_X_COLORMAP (f
);
3826 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3827 Display
*dpy
= FRAME_X_DISPLAY (f
);
3829 xgcv
.graphics_exposures
= False
;
3830 xgcv
.line_width
= 1;
3832 /* Free previously allocated color. The color cell will be reused
3833 when it has been freed as many times as it was allocated, so this
3834 doesn't affect faces using the same colors. */
3836 && relief
->allocated_p
)
3838 x_free_colors (f
, &relief
->pixel
, 1);
3839 relief
->allocated_p
= 0;
3842 /* Allocate new color. */
3843 xgcv
.foreground
= default_pixel
;
3845 if (dpyinfo
->n_planes
!= 1
3846 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3848 relief
->allocated_p
= 1;
3849 xgcv
.foreground
= relief
->pixel
= pixel
;
3852 if (relief
->gc
== 0)
3854 xgcv
.stipple
= dpyinfo
->gray
;
3856 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3859 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3863 /* Set up colors for the relief lines around glyph string S. */
3866 x_setup_relief_colors (s
)
3867 struct glyph_string
*s
;
3869 struct x_output
*di
= s
->f
->output_data
.x
;
3870 unsigned long color
;
3872 if (s
->face
->use_box_color_for_shadows_p
)
3873 color
= s
->face
->box_color
;
3874 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3876 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3877 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3882 /* Get the background color of the face. */
3883 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3884 color
= xgcv
.background
;
3887 if (di
->white_relief
.gc
== 0
3888 || color
!= di
->relief_background
)
3890 di
->relief_background
= color
;
3891 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3892 WHITE_PIX_DEFAULT (s
->f
));
3893 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3894 BLACK_PIX_DEFAULT (s
->f
));
3899 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3900 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3901 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3902 relief. LEFT_P non-zero means draw a relief on the left side of
3903 the rectangle. RIGHT_P non-zero means draw a relief on the right
3904 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3908 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3909 raised_p
, left_p
, right_p
, clip_rect
)
3911 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3912 XRectangle
*clip_rect
;
3914 Display
*dpy
= FRAME_X_DISPLAY (f
);
3915 Window window
= FRAME_X_WINDOW (f
);
3920 gc
= f
->output_data
.x
->white_relief
.gc
;
3922 gc
= f
->output_data
.x
->black_relief
.gc
;
3923 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3926 for (i
= 0; i
< width
; ++i
)
3927 XDrawLine (dpy
, window
, gc
,
3928 left_x
+ i
* left_p
, top_y
+ i
,
3929 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3933 for (i
= 0; i
< width
; ++i
)
3934 XDrawLine (dpy
, window
, gc
,
3935 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3937 XSetClipMask (dpy
, gc
, None
);
3939 gc
= f
->output_data
.x
->black_relief
.gc
;
3941 gc
= f
->output_data
.x
->white_relief
.gc
;
3942 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3945 for (i
= 0; i
< width
; ++i
)
3946 XDrawLine (dpy
, window
, gc
,
3947 left_x
+ i
* left_p
, bottom_y
- i
,
3948 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3952 for (i
= 0; i
< width
; ++i
)
3953 XDrawLine (dpy
, window
, gc
,
3954 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3956 XSetClipMask (dpy
, gc
, None
);
3960 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3961 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3962 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3963 left side of the rectangle. RIGHT_P non-zero means draw a line
3964 on the right side of the rectangle. CLIP_RECT is the clipping
3965 rectangle to use when drawing. */
3968 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3969 left_p
, right_p
, clip_rect
)
3970 struct glyph_string
*s
;
3971 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3972 XRectangle
*clip_rect
;
3976 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3977 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3978 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3981 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3982 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3986 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3987 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3990 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3991 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3995 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3996 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3998 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3999 XSetClipMask (s
->display
, s
->gc
, None
);
4003 /* Draw a box around glyph string S. */
4006 x_draw_glyph_string_box (s
)
4007 struct glyph_string
*s
;
4009 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
4010 int left_p
, right_p
;
4011 struct glyph
*last_glyph
;
4012 XRectangle clip_rect
;
4014 last_x
= window_box_right (s
->w
, s
->area
);
4015 if (s
->row
->full_width_p
4016 && !s
->w
->pseudo_window_p
)
4018 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
4019 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
4020 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
4023 /* The glyph that may have a right box line. */
4024 last_glyph
= (s
->cmp
|| s
->img
4026 : s
->first_glyph
+ s
->nchars
- 1);
4028 width
= abs (s
->face
->box_line_width
);
4029 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
4031 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
4033 : min (last_x
, s
->x
+ s
->background_width
) - 1);
4035 bottom_y
= top_y
+ s
->height
- 1;
4037 left_p
= (s
->first_glyph
->left_box_line_p
4038 || (s
->hl
== DRAW_MOUSE_FACE
4040 || s
->prev
->hl
!= s
->hl
)));
4041 right_p
= (last_glyph
->right_box_line_p
4042 || (s
->hl
== DRAW_MOUSE_FACE
4044 || s
->next
->hl
!= s
->hl
)));
4046 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4048 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4049 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4050 left_p
, right_p
, &clip_rect
);
4053 x_setup_relief_colors (s
);
4054 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4055 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4060 /* Draw foreground of image glyph string S. */
4063 x_draw_image_foreground (s
)
4064 struct glyph_string
*s
;
4067 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4069 /* If first glyph of S has a left box line, start drawing it to the
4070 right of that line. */
4071 if (s
->face
->box
!= FACE_NO_BOX
4072 && s
->first_glyph
->left_box_line_p
)
4073 x
= s
->x
+ abs (s
->face
->box_line_width
);
4077 /* If there is a margin around the image, adjust x- and y-position
4079 x
+= s
->img
->hmargin
;
4080 y
+= s
->img
->vmargin
;
4086 /* We can't set both a clip mask and use XSetClipRectangles
4087 because the latter also sets a clip mask. We also can't
4088 trust on the shape extension to be available
4089 (XShapeCombineRegion). So, compute the rectangle to draw
4091 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4094 XRectangle clip_rect
, image_rect
, r
;
4096 xgcv
.clip_mask
= s
->img
->mask
;
4097 xgcv
.clip_x_origin
= x
;
4098 xgcv
.clip_y_origin
= y
;
4099 xgcv
.function
= GXcopy
;
4100 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4102 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4105 image_rect
.width
= s
->img
->width
;
4106 image_rect
.height
= s
->img
->height
;
4107 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4108 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4109 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4113 XRectangle clip_rect
, image_rect
, r
;
4115 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4118 image_rect
.width
= s
->img
->width
;
4119 image_rect
.height
= s
->img
->height
;
4120 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4121 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4122 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4124 /* When the image has a mask, we can expect that at
4125 least part of a mouse highlight or a block cursor will
4126 be visible. If the image doesn't have a mask, make
4127 a block cursor visible by drawing a rectangle around
4128 the image. I believe it's looking better if we do
4129 nothing here for mouse-face. */
4130 if (s
->hl
== DRAW_CURSOR
)
4132 int r
= s
->img
->relief
;
4134 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
4135 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4140 /* Draw a rectangle if image could not be loaded. */
4141 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4142 s
->img
->width
- 1, s
->img
->height
- 1);
4146 /* Draw a relief around the image glyph string S. */
4149 x_draw_image_relief (s
)
4150 struct glyph_string
*s
;
4152 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4155 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4157 /* If first glyph of S has a left box line, start drawing it to the
4158 right of that line. */
4159 if (s
->face
->box
!= FACE_NO_BOX
4160 && s
->first_glyph
->left_box_line_p
)
4161 x
= s
->x
+ abs (s
->face
->box_line_width
);
4165 /* If there is a margin around the image, adjust x- and y-position
4167 x
+= s
->img
->hmargin
;
4168 y
+= s
->img
->vmargin
;
4170 if (s
->hl
== DRAW_IMAGE_SUNKEN
4171 || s
->hl
== DRAW_IMAGE_RAISED
)
4173 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
4174 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4178 thick
= abs (s
->img
->relief
);
4179 raised_p
= s
->img
->relief
> 0;
4184 x1
= x
+ s
->img
->width
+ thick
- 1;
4185 y1
= y
+ s
->img
->height
+ thick
- 1;
4187 x_setup_relief_colors (s
);
4188 x_get_glyph_string_clip_rect (s
, &r
);
4189 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4193 /* Draw the foreground of image glyph string S to PIXMAP. */
4196 x_draw_image_foreground_1 (s
, pixmap
)
4197 struct glyph_string
*s
;
4201 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4203 /* If first glyph of S has a left box line, start drawing it to the
4204 right of that line. */
4205 if (s
->face
->box
!= FACE_NO_BOX
4206 && s
->first_glyph
->left_box_line_p
)
4207 x
= abs (s
->face
->box_line_width
);
4211 /* If there is a margin around the image, adjust x- and y-position
4213 x
+= s
->img
->hmargin
;
4214 y
+= s
->img
->vmargin
;
4220 /* We can't set both a clip mask and use XSetClipRectangles
4221 because the latter also sets a clip mask. We also can't
4222 trust on the shape extension to be available
4223 (XShapeCombineRegion). So, compute the rectangle to draw
4225 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4229 xgcv
.clip_mask
= s
->img
->mask
;
4230 xgcv
.clip_x_origin
= x
;
4231 xgcv
.clip_y_origin
= y
;
4232 xgcv
.function
= GXcopy
;
4233 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4235 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4236 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4237 XSetClipMask (s
->display
, s
->gc
, None
);
4241 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4242 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4244 /* When the image has a mask, we can expect that at
4245 least part of a mouse highlight or a block cursor will
4246 be visible. If the image doesn't have a mask, make
4247 a block cursor visible by drawing a rectangle around
4248 the image. I believe it's looking better if we do
4249 nothing here for mouse-face. */
4250 if (s
->hl
== DRAW_CURSOR
)
4252 int r
= s
->img
->relief
;
4254 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
4255 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4260 /* Draw a rectangle if image could not be loaded. */
4261 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4262 s
->img
->width
- 1, s
->img
->height
- 1);
4266 /* Draw part of the background of glyph string S. X, Y, W, and H
4267 give the rectangle to draw. */
4270 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4271 struct glyph_string
*s
;
4276 /* Fill background with a stipple pattern. */
4277 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4278 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4279 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4282 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4286 /* Draw image glyph string S.
4289 s->x +-------------------------
4292 | +-------------------------
4295 | | +-------------------
4301 x_draw_image_glyph_string (s
)
4302 struct glyph_string
*s
;
4305 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4306 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4308 Pixmap pixmap
= None
;
4310 height
= s
->height
- 2 * box_line_vwidth
;
4312 /* Fill background with face under the image. Do it only if row is
4313 taller than image or if image has a clip mask to reduce
4315 s
->stippled_p
= s
->face
->stipple
!= 0;
4316 if (height
> s
->img
->height
4320 || s
->img
->pixmap
== 0
4321 || s
->width
!= s
->background_width
)
4323 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4324 x
= s
->x
+ box_line_hwidth
;
4328 y
= s
->y
+ box_line_vwidth
;
4332 /* Create a pixmap as large as the glyph string. Fill it
4333 with the background color. Copy the image to it, using
4334 its mask. Copy the temporary pixmap to the display. */
4335 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4336 int depth
= DefaultDepthOfScreen (screen
);
4338 /* Create a pixmap as large as the glyph string. */
4339 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4340 s
->background_width
,
4343 /* Don't clip in the following because we're working on the
4345 XSetClipMask (s
->display
, s
->gc
, None
);
4347 /* Fill the pixmap with the background color/stipple. */
4350 /* Fill background with a stipple pattern. */
4351 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4352 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4353 0, 0, s
->background_width
, s
->height
);
4354 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4359 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4361 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4362 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4363 0, 0, s
->background_width
, s
->height
);
4364 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4368 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4370 s
->background_filled_p
= 1;
4373 /* Draw the foreground. */
4376 x_draw_image_foreground_1 (s
, pixmap
);
4377 x_set_glyph_string_clipping (s
);
4378 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4379 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4380 XFreePixmap (s
->display
, pixmap
);
4383 x_draw_image_foreground (s
);
4385 /* If we must draw a relief around the image, do it. */
4387 || s
->hl
== DRAW_IMAGE_RAISED
4388 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4389 x_draw_image_relief (s
);
4393 /* Draw stretch glyph string S. */
4396 x_draw_stretch_glyph_string (s
)
4397 struct glyph_string
*s
;
4399 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4400 s
->stippled_p
= s
->face
->stipple
!= 0;
4402 if (s
->hl
== DRAW_CURSOR
4403 && !x_stretch_cursor_p
)
4405 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4406 as wide as the stretch glyph. */
4407 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4410 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4412 /* Clear rest using the GC of the original non-cursor face. */
4413 if (width
< s
->background_width
)
4415 int x
= s
->x
+ width
, y
= s
->y
;
4416 int w
= s
->background_width
- width
, h
= s
->height
;
4420 if (s
->row
->mouse_face_p
4421 && cursor_in_mouse_face_p (s
->w
))
4423 x_set_mouse_face_gc (s
);
4429 x_get_glyph_string_clip_rect (s
, &r
);
4430 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4432 if (s
->face
->stipple
)
4434 /* Fill background with a stipple pattern. */
4435 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4436 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4437 XSetFillStyle (s
->display
, gc
, FillSolid
);
4442 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4443 XSetForeground (s
->display
, gc
, xgcv
.background
);
4444 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4445 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4449 else if (!s
->background_filled_p
)
4450 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4453 s
->background_filled_p
= 1;
4457 /* Draw glyph string S. */
4460 x_draw_glyph_string (s
)
4461 struct glyph_string
*s
;
4463 int relief_drawn_p
= 0;
4465 /* If S draws into the background of its successor, draw the
4466 background of the successor first so that S can draw into it.
4467 This makes S->next use XDrawString instead of XDrawImageString. */
4468 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4470 xassert (s
->next
->img
== NULL
);
4471 x_set_glyph_string_gc (s
->next
);
4472 x_set_glyph_string_clipping (s
->next
);
4473 x_draw_glyph_string_background (s
->next
, 1);
4476 /* Set up S->gc, set clipping and draw S. */
4477 x_set_glyph_string_gc (s
);
4479 /* Draw relief (if any) in advance for char/composition so that the
4480 glyph string can be drawn over it. */
4481 if (!s
->for_overlaps_p
4482 && s
->face
->box
!= FACE_NO_BOX
4483 && (s
->first_glyph
->type
== CHAR_GLYPH
4484 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4487 x_set_glyph_string_clipping (s
);
4488 x_draw_glyph_string_background (s
, 1);
4489 x_draw_glyph_string_box (s
);
4490 x_set_glyph_string_clipping (s
);
4494 x_set_glyph_string_clipping (s
);
4496 switch (s
->first_glyph
->type
)
4499 x_draw_image_glyph_string (s
);
4503 x_draw_stretch_glyph_string (s
);
4507 if (s
->for_overlaps_p
)
4508 s
->background_filled_p
= 1;
4510 x_draw_glyph_string_background (s
, 0);
4511 x_draw_glyph_string_foreground (s
);
4514 case COMPOSITE_GLYPH
:
4515 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4516 s
->background_filled_p
= 1;
4518 x_draw_glyph_string_background (s
, 1);
4519 x_draw_composite_glyph_string_foreground (s
);
4526 if (!s
->for_overlaps_p
)
4528 /* Draw underline. */
4529 if (s
->face
->underline_p
)
4531 unsigned long tem
, h
;
4534 /* Get the underline thickness. Default is 1 pixel. */
4535 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4538 /* Get the underline position. This is the recommended
4539 vertical offset in pixels from the baseline to the top of
4540 the underline. This is a signed value according to the
4541 specs, and its default is
4543 ROUND ((maximum descent) / 2), with
4544 ROUND(x) = floor (x + 0.5) */
4546 if (x_use_underline_position_properties
4547 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4548 y
= s
->ybase
+ (long) tem
;
4549 else if (s
->face
->font
)
4550 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4552 y
= s
->y
+ s
->height
- h
;
4554 if (s
->face
->underline_defaulted_p
)
4555 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4556 s
->x
, y
, s
->width
, h
);
4560 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4561 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4562 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4563 s
->x
, y
, s
->width
, h
);
4564 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4568 /* Draw overline. */
4569 if (s
->face
->overline_p
)
4571 unsigned long dy
= 0, h
= 1;
4573 if (s
->face
->overline_color_defaulted_p
)
4574 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4579 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4580 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4581 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4583 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4587 /* Draw strike-through. */
4588 if (s
->face
->strike_through_p
)
4590 unsigned long h
= 1;
4591 unsigned long dy
= (s
->height
- h
) / 2;
4593 if (s
->face
->strike_through_color_defaulted_p
)
4594 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4599 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4600 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4601 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4603 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4607 /* Draw relief if not yet drawn. */
4608 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4609 x_draw_glyph_string_box (s
);
4612 /* Reset clipping. */
4613 XSetClipMask (s
->display
, s
->gc
, None
);
4617 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4618 struct face
**, int));
4621 /* Fill glyph string S with composition components specified by S->cmp.
4623 FACES is an array of faces for all components of this composition.
4624 S->gidx is the index of the first component for S.
4625 OVERLAPS_P non-zero means S should draw the foreground only, and
4626 use its physical height for clipping.
4628 Value is the index of a component not in S. */
4631 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4632 struct glyph_string
*s
;
4633 struct face
**faces
;
4640 s
->for_overlaps_p
= overlaps_p
;
4642 s
->face
= faces
[s
->gidx
];
4643 s
->font
= s
->face
->font
;
4644 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4646 /* For all glyphs of this composition, starting at the offset
4647 S->gidx, until we reach the end of the definition or encounter a
4648 glyph that requires the different face, add it to S. */
4650 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4653 /* All glyph strings for the same composition has the same width,
4654 i.e. the width set for the first component of the composition. */
4656 s
->width
= s
->first_glyph
->pixel_width
;
4658 /* If the specified font could not be loaded, use the frame's
4659 default font, but record the fact that we couldn't load it in
4660 the glyph string so that we can draw rectangles for the
4661 characters of the glyph string. */
4662 if (s
->font
== NULL
)
4664 s
->font_not_found_p
= 1;
4665 s
->font
= FRAME_FONT (s
->f
);
4668 /* Adjust base line for subscript/superscript text. */
4669 s
->ybase
+= s
->first_glyph
->voffset
;
4671 xassert (s
->face
&& s
->face
->gc
);
4673 /* This glyph string must always be drawn with 16-bit functions. */
4676 return s
->gidx
+ s
->nchars
;
4680 /* Fill glyph string S from a sequence of character glyphs.
4682 FACE_ID is the face id of the string. START is the index of the
4683 first glyph to consider, END is the index of the last + 1.
4684 OVERLAPS_P non-zero means S should draw the foreground only, and
4685 use its physical height for clipping.
4687 Value is the index of the first glyph not in S. */
4690 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4691 struct glyph_string
*s
;
4693 int start
, end
, overlaps_p
;
4695 struct glyph
*glyph
, *last
;
4697 int glyph_not_available_p
;
4699 xassert (s
->f
== XFRAME (s
->w
->frame
));
4700 xassert (s
->nchars
== 0);
4701 xassert (start
>= 0 && end
> start
);
4703 s
->for_overlaps_p
= overlaps_p
,
4704 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4705 last
= s
->row
->glyphs
[s
->area
] + end
;
4706 voffset
= glyph
->voffset
;
4708 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4711 && glyph
->type
== CHAR_GLYPH
4712 && glyph
->voffset
== voffset
4713 /* Same face id implies same font, nowadays. */
4714 && glyph
->face_id
== face_id
4715 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4719 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4720 s
->char2b
+ s
->nchars
,
4722 s
->two_byte_p
= two_byte_p
;
4724 xassert (s
->nchars
<= end
- start
);
4725 s
->width
+= glyph
->pixel_width
;
4729 s
->font
= s
->face
->font
;
4730 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4732 /* If the specified font could not be loaded, use the frame's font,
4733 but record the fact that we couldn't load it in
4734 S->font_not_found_p so that we can draw rectangles for the
4735 characters of the glyph string. */
4736 if (s
->font
== NULL
|| glyph_not_available_p
)
4738 s
->font_not_found_p
= 1;
4739 s
->font
= FRAME_FONT (s
->f
);
4742 /* Adjust base line for subscript/superscript text. */
4743 s
->ybase
+= voffset
;
4745 xassert (s
->face
&& s
->face
->gc
);
4746 return glyph
- s
->row
->glyphs
[s
->area
];
4750 /* Fill glyph string S from image glyph S->first_glyph. */
4753 x_fill_image_glyph_string (s
)
4754 struct glyph_string
*s
;
4756 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4757 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4759 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4760 s
->font
= s
->face
->font
;
4761 s
->width
= s
->first_glyph
->pixel_width
;
4763 /* Adjust base line for subscript/superscript text. */
4764 s
->ybase
+= s
->first_glyph
->voffset
;
4768 /* Fill glyph string S from a sequence of stretch glyphs.
4770 ROW is the glyph row in which the glyphs are found, AREA is the
4771 area within the row. START is the index of the first glyph to
4772 consider, END is the index of the last + 1.
4774 Value is the index of the first glyph not in S. */
4777 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4778 struct glyph_string
*s
;
4779 struct glyph_row
*row
;
4780 enum glyph_row_area area
;
4783 struct glyph
*glyph
, *last
;
4784 int voffset
, face_id
;
4786 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4788 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4789 last
= s
->row
->glyphs
[s
->area
] + end
;
4790 face_id
= glyph
->face_id
;
4791 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4792 s
->font
= s
->face
->font
;
4793 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4794 s
->width
= glyph
->pixel_width
;
4795 voffset
= glyph
->voffset
;
4799 && glyph
->type
== STRETCH_GLYPH
4800 && glyph
->voffset
== voffset
4801 && glyph
->face_id
== face_id
);
4803 s
->width
+= glyph
->pixel_width
;
4805 /* Adjust base line for subscript/superscript text. */
4806 s
->ybase
+= voffset
;
4808 /* The case that face->gc == 0 is handled when drawing the glyph
4809 string by calling PREPARE_FACE_FOR_DISPLAY. */
4811 return glyph
- s
->row
->glyphs
[s
->area
];
4815 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4816 of XChar2b structures for S; it can't be allocated in
4817 x_init_glyph_string because it must be allocated via `alloca'. W
4818 is the window on which S is drawn. ROW and AREA are the glyph row
4819 and area within the row from which S is constructed. START is the
4820 index of the first glyph structure covered by S. HL is a
4821 face-override for drawing S. */
4824 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4825 struct glyph_string
*s
;
4828 struct glyph_row
*row
;
4829 enum glyph_row_area area
;
4831 enum draw_glyphs_face hl
;
4833 bzero (s
, sizeof *s
);
4835 s
->f
= XFRAME (w
->frame
);
4836 s
->display
= FRAME_X_DISPLAY (s
->f
);
4837 s
->window
= FRAME_X_WINDOW (s
->f
);
4842 s
->first_glyph
= row
->glyphs
[area
] + start
;
4843 s
->height
= row
->height
;
4844 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4846 /* Display the internal border below the tool-bar window. */
4847 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4848 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4850 s
->ybase
= s
->y
+ row
->ascent
;
4854 /* Set background width of glyph string S. START is the index of the
4855 first glyph following S. LAST_X is the right-most x-position + 1
4856 in the drawing area. */
4859 x_set_glyph_string_background_width (s
, start
, last_x
)
4860 struct glyph_string
*s
;
4864 /* If the face of this glyph string has to be drawn to the end of
4865 the drawing area, set S->extends_to_end_of_line_p. */
4866 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4868 if (start
== s
->row
->used
[s
->area
]
4869 && s
->area
== TEXT_AREA
4870 && ((s
->hl
== DRAW_NORMAL_TEXT
4871 && (s
->row
->fill_line_p
4872 || s
->face
->background
!= default_face
->background
4873 || s
->face
->stipple
!= default_face
->stipple
4874 || s
->row
->mouse_face_p
))
4875 || s
->hl
== DRAW_MOUSE_FACE
4876 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4877 && s
->row
->fill_line_p
)))
4878 s
->extends_to_end_of_line_p
= 1;
4880 /* If S extends its face to the end of the line, set its
4881 background_width to the distance to the right edge of the drawing
4883 if (s
->extends_to_end_of_line_p
)
4884 s
->background_width
= last_x
- s
->x
+ 1;
4886 s
->background_width
= s
->width
;
4890 /* Add a glyph string for a stretch glyph to the list of strings
4891 between HEAD and TAIL. START is the index of the stretch glyph in
4892 row area AREA of glyph row ROW. END is the index of the last glyph
4893 in that glyph row area. X is the current output position assigned
4894 to the new glyph string constructed. HL overrides that face of the
4895 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4896 is the right-most x-position of the drawing area. */
4898 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4899 and below -- keep them on one line. */
4900 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4903 s = (struct glyph_string *) alloca (sizeof *s); \
4904 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4905 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4906 x_append_glyph_string (&HEAD, &TAIL, s); \
4912 /* Add a glyph string for an image glyph to the list of strings
4913 between HEAD and TAIL. START is the index of the image glyph in
4914 row area AREA of glyph row ROW. END is the index of the last glyph
4915 in that glyph row area. X is the current output position assigned
4916 to the new glyph string constructed. HL overrides that face of the
4917 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4918 is the right-most x-position of the drawing area. */
4920 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4923 s = (struct glyph_string *) alloca (sizeof *s); \
4924 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4925 x_fill_image_glyph_string (s); \
4926 x_append_glyph_string (&HEAD, &TAIL, s); \
4933 /* Add a glyph string for a sequence of character glyphs to the list
4934 of strings between HEAD and TAIL. START is the index of the first
4935 glyph in row area AREA of glyph row ROW that is part of the new
4936 glyph string. END is the index of the last glyph in that glyph row
4937 area. X is the current output position assigned to the new glyph
4938 string constructed. HL overrides that face of the glyph; e.g. it
4939 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4940 right-most x-position of the drawing area. */
4942 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4948 c = (ROW)->glyphs[AREA][START].u.ch; \
4949 face_id = (ROW)->glyphs[AREA][START].face_id; \
4951 s = (struct glyph_string *) alloca (sizeof *s); \
4952 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4953 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4954 x_append_glyph_string (&HEAD, &TAIL, s); \
4956 START = x_fill_glyph_string (s, face_id, START, END, \
4962 /* Add a glyph string for a composite sequence to the list of strings
4963 between HEAD and TAIL. START is the index of the first glyph in
4964 row area AREA of glyph row ROW that is part of the new glyph
4965 string. END is the index of the last glyph in that glyph row area.
4966 X is the current output position assigned to the new glyph string
4967 constructed. HL overrides that face of the glyph; e.g. it is
4968 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4969 x-position of the drawing area. */
4971 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4973 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4974 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4975 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4976 struct composition *cmp = composition_table[cmp_id]; \
4977 int glyph_len = cmp->glyph_len; \
4979 struct face **faces; \
4980 struct glyph_string *first_s = NULL; \
4983 base_face = base_face->ascii_face; \
4984 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4985 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4986 /* At first, fill in `char2b' and `faces'. */ \
4987 for (n = 0; n < glyph_len; n++) \
4989 int c = COMPOSITION_GLYPH (cmp, n); \
4990 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4991 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4992 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4993 this_face_id, char2b + n, 1, 1); \
4996 /* Make glyph_strings for each glyph sequence that is drawable by \
4997 the same face, and append them to HEAD/TAIL. */ \
4998 for (n = 0; n < cmp->glyph_len;) \
5000 s = (struct glyph_string *) alloca (sizeof *s); \
5001 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
5002 x_append_glyph_string (&(HEAD), &(TAIL), s); \
5010 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
5018 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
5019 of AREA of glyph row ROW on window W between indices START and END.
5020 HL overrides the face for drawing glyph strings, e.g. it is
5021 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
5022 x-positions of the drawing area.
5024 This is an ugly monster macro construct because we must use alloca
5025 to allocate glyph strings (because x_draw_glyphs can be called
5028 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5031 HEAD = TAIL = NULL; \
5032 while (START < END) \
5034 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
5035 switch (first_glyph->type) \
5038 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
5039 TAIL, HL, X, LAST_X, \
5043 case COMPOSITE_GLYPH: \
5044 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
5045 HEAD, TAIL, HL, X, LAST_X,\
5049 case STRETCH_GLYPH: \
5050 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5051 HEAD, TAIL, HL, X, LAST_X); \
5055 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5056 TAIL, HL, X, LAST_X); \
5063 x_set_glyph_string_background_width (s, START, LAST_X); \
5070 /* Draw glyphs between START and END in AREA of ROW on window W,
5071 starting at x-position X. X is relative to AREA in W. HL is a
5072 face-override with the following meaning:
5074 DRAW_NORMAL_TEXT draw normally
5075 DRAW_CURSOR draw in cursor face
5076 DRAW_MOUSE_FACE draw in mouse face.
5077 DRAW_INVERSE_VIDEO draw in mode line face
5078 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5079 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5081 If OVERLAPS_P is non-zero, draw only the foreground of characters
5082 and clip to the physical height of ROW.
5084 Value is the x-position reached, relative to AREA of W. */
5087 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
5090 struct glyph_row
*row
;
5091 enum glyph_row_area area
;
5093 enum draw_glyphs_face hl
;
5096 struct glyph_string
*head
, *tail
;
5097 struct glyph_string
*s
;
5098 int last_x
, area_width
;
5102 /* Let's rather be paranoid than getting a SEGV. */
5103 end
= min (end
, row
->used
[area
]);
5104 start
= max (0, start
);
5105 start
= min (end
, start
);
5107 /* Translate X to frame coordinates. Set last_x to the right
5108 end of the drawing area. */
5109 if (row
->full_width_p
)
5111 /* X is relative to the left edge of W, without scroll bars
5113 struct frame
*f
= XFRAME (w
->frame
);
5114 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5117 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5118 last_x
= window_left_x
+ area_width
;
5120 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5122 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5123 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5129 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5130 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5134 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5135 area_width
= window_box_width (w
, area
);
5136 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5139 /* Build a doubly-linked list of glyph_string structures between
5140 head and tail from what we have to draw. Note that the macro
5141 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5142 the reason we use a separate variable `i'. */
5144 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5147 x_reached
= tail
->x
+ tail
->background_width
;
5151 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5152 the row, redraw some glyphs in front or following the glyph
5153 strings built above. */
5154 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5157 struct glyph_string
*h
, *t
;
5159 /* Compute overhangs for all glyph strings. */
5160 for (s
= head
; s
; s
= s
->next
)
5161 x_compute_glyph_string_overhangs (s
);
5163 /* Prepend glyph strings for glyphs in front of the first glyph
5164 string that are overwritten because of the first glyph
5165 string's left overhang. The background of all strings
5166 prepended must be drawn because the first glyph string
5168 i
= x_left_overwritten (head
);
5172 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5173 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5176 x_compute_overhangs_and_x (t
, head
->x
, 1);
5177 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5180 /* Prepend glyph strings for glyphs in front of the first glyph
5181 string that overwrite that glyph string because of their
5182 right overhang. For these strings, only the foreground must
5183 be drawn, because it draws over the glyph string at `head'.
5184 The background must not be drawn because this would overwrite
5185 right overhangs of preceding glyphs for which no glyph
5187 i
= x_left_overwriting (head
);
5190 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5191 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5193 for (s
= h
; s
; s
= s
->next
)
5194 s
->background_filled_p
= 1;
5195 x_compute_overhangs_and_x (t
, head
->x
, 1);
5196 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5199 /* Append glyphs strings for glyphs following the last glyph
5200 string tail that are overwritten by tail. The background of
5201 these strings has to be drawn because tail's foreground draws
5203 i
= x_right_overwritten (tail
);
5206 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5207 DRAW_NORMAL_TEXT
, x
, last_x
,
5209 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5210 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5213 /* Append glyph strings for glyphs following the last glyph
5214 string tail that overwrite tail. The foreground of such
5215 glyphs has to be drawn because it writes into the background
5216 of tail. The background must not be drawn because it could
5217 paint over the foreground of following glyphs. */
5218 i
= x_right_overwriting (tail
);
5221 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5222 DRAW_NORMAL_TEXT
, x
, last_x
,
5224 for (s
= h
; s
; s
= s
->next
)
5225 s
->background_filled_p
= 1;
5226 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5227 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5231 /* Draw all strings. */
5232 for (s
= head
; s
; s
= s
->next
)
5233 x_draw_glyph_string (s
);
5235 if (area
== TEXT_AREA
5236 && !row
->full_width_p
5237 /* When drawing overlapping rows, only the glyph strings'
5238 foreground is drawn, which doesn't erase a cursor
5242 int x0
= head
? head
->x
: x
;
5243 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5245 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5246 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5248 if (XFASTINT (w
->left_margin_width
) != 0)
5250 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5251 x0
-= left_area_width
;
5252 x1
-= left_area_width
;
5255 notice_overwritten_cursor (w
, area
, x0
, x1
,
5256 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5259 /* Value is the x-position up to which drawn, relative to AREA of W.
5260 This doesn't include parts drawn because of overhangs. */
5261 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5262 if (!row
->full_width_p
)
5264 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
5265 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5266 if (area
> TEXT_AREA
)
5267 x_reached
-= window_box_width (w
, TEXT_AREA
);
5274 /* Fix the display of area AREA of overlapping row ROW in window W. */
5277 x_fix_overlapping_area (w
, row
, area
)
5279 struct glyph_row
*row
;
5280 enum glyph_row_area area
;
5286 if (area
== LEFT_MARGIN_AREA
)
5288 else if (area
== TEXT_AREA
)
5289 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5291 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5292 + window_box_width (w
, TEXT_AREA
));
5294 for (i
= 0; i
< row
->used
[area
];)
5296 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5298 int start
= i
, start_x
= x
;
5302 x
+= row
->glyphs
[area
][i
].pixel_width
;
5305 while (i
< row
->used
[area
]
5306 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5308 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5309 DRAW_NORMAL_TEXT
, 1);
5313 x
+= row
->glyphs
[area
][i
].pixel_width
;
5322 /* Output LEN glyphs starting at START at the nominal cursor position.
5323 Advance the nominal cursor over the text. The global variable
5324 updated_window contains the window being updated, updated_row is
5325 the glyph row being updated, and updated_area is the area of that
5326 row being updated. */
5329 x_write_glyphs (start
, len
)
5330 struct glyph
*start
;
5335 xassert (updated_window
&& updated_row
);
5340 hpos
= start
- updated_row
->glyphs
[updated_area
];
5341 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5342 updated_row
, updated_area
,
5344 DRAW_NORMAL_TEXT
, 0);
5346 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
5347 if (updated_area
== TEXT_AREA
5348 && updated_window
->phys_cursor_on_p
5349 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
5350 && updated_window
->phys_cursor
.hpos
>= hpos
5351 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
5352 updated_window
->phys_cursor_on_p
= 0;
5356 /* Advance the output cursor. */
5357 output_cursor
.hpos
+= len
;
5358 output_cursor
.x
= x
;
5362 /* Insert LEN glyphs from START at the nominal cursor position. */
5365 x_insert_glyphs (start
, len
)
5366 struct glyph
*start
;
5371 int line_height
, shift_by_width
, shifted_region_width
;
5372 struct glyph_row
*row
;
5373 struct glyph
*glyph
;
5374 int frame_x
, frame_y
, hpos
;
5376 xassert (updated_window
&& updated_row
);
5379 f
= XFRAME (WINDOW_FRAME (w
));
5381 /* Get the height of the line we are in. */
5383 line_height
= row
->height
;
5385 /* Get the width of the glyphs to insert. */
5387 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5388 shift_by_width
+= glyph
->pixel_width
;
5390 /* Get the width of the region to shift right. */
5391 shifted_region_width
= (window_box_width (w
, updated_area
)
5396 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5397 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5398 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5399 f
->output_data
.x
->normal_gc
,
5401 shifted_region_width
, line_height
,
5402 frame_x
+ shift_by_width
, frame_y
);
5404 /* Write the glyphs. */
5405 hpos
= start
- row
->glyphs
[updated_area
];
5406 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5407 DRAW_NORMAL_TEXT
, 0);
5409 /* Advance the output cursor. */
5410 output_cursor
.hpos
+= len
;
5411 output_cursor
.x
+= shift_by_width
;
5416 /* Delete N glyphs at the nominal cursor position. Not implemented
5427 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5428 If they are <= 0, this is probably an error. */
5431 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5438 xassert (width
> 0 && height
> 0);
5439 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5443 /* Erase the current text line from the nominal cursor position
5444 (inclusive) to pixel column TO_X (exclusive). The idea is that
5445 everything from TO_X onward is already erased.
5447 TO_X is a pixel position relative to updated_area of
5448 updated_window. TO_X == -1 means clear to the end of this area. */
5451 x_clear_end_of_line (to_x
)
5455 struct window
*w
= updated_window
;
5456 int max_x
, min_y
, max_y
;
5457 int from_x
, from_y
, to_y
;
5459 xassert (updated_window
&& updated_row
);
5460 f
= XFRAME (w
->frame
);
5462 if (updated_row
->full_width_p
)
5464 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5465 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5466 && !w
->pseudo_window_p
)
5467 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5470 max_x
= window_box_width (w
, updated_area
);
5471 max_y
= window_text_bottom_y (w
);
5473 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5474 of window. For TO_X > 0, truncate to end of drawing area. */
5480 to_x
= min (to_x
, max_x
);
5482 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5484 /* Notice if the cursor will be cleared by this operation. */
5485 if (!updated_row
->full_width_p
)
5486 notice_overwritten_cursor (w
, updated_area
,
5487 output_cursor
.x
, -1,
5489 MATRIX_ROW_BOTTOM_Y (updated_row
));
5491 from_x
= output_cursor
.x
;
5493 /* Translate to frame coordinates. */
5494 if (updated_row
->full_width_p
)
5496 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5497 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5501 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5502 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5505 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5506 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5507 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5509 /* Prevent inadvertently clearing to end of the X window. */
5510 if (to_x
> from_x
&& to_y
> from_y
)
5513 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5514 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5521 /* Clear entire frame. If updating_frame is non-null, clear that
5522 frame. Otherwise clear the selected frame. */
5532 f
= SELECTED_FRAME ();
5534 /* Clearing the frame will erase any cursor, so mark them all as no
5536 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5537 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5538 output_cursor
.x
= -1;
5540 /* We don't set the output cursor here because there will always
5541 follow an explicit cursor_to. */
5543 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5545 /* We have to clear the scroll bars, too. If we have changed
5546 colors or something like that, then they should be notified. */
5547 x_scroll_bar_clear (f
);
5549 XFlush (FRAME_X_DISPLAY (f
));
5555 /* Invert the middle quarter of the frame for .15 sec. */
5557 /* We use the select system call to do the waiting, so we have to make
5558 sure it's available. If it isn't, we just won't do visual bells. */
5560 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5563 /* Subtract the `struct timeval' values X and Y, storing the result in
5564 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5567 timeval_subtract (result
, x
, y
)
5568 struct timeval
*result
, x
, y
;
5570 /* Perform the carry for the later subtraction by updating y. This
5571 is safer because on some systems the tv_sec member is unsigned. */
5572 if (x
.tv_usec
< y
.tv_usec
)
5574 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5575 y
.tv_usec
-= 1000000 * nsec
;
5579 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5581 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5582 y
.tv_usec
+= 1000000 * nsec
;
5586 /* Compute the time remaining to wait. tv_usec is certainly
5588 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5589 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5591 /* Return indication of whether the result should be considered
5593 return x
.tv_sec
< y
.tv_sec
;
5605 /* Create a GC that will use the GXxor function to flip foreground
5606 pixels into background pixels. */
5610 values
.function
= GXxor
;
5611 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5612 ^ f
->output_data
.x
->background_pixel
);
5614 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5615 GCFunction
| GCForeground
, &values
);
5619 /* Get the height not including a menu bar widget. */
5620 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5621 /* Height of each line to flash. */
5622 int flash_height
= FRAME_LINE_HEIGHT (f
);
5623 /* These will be the left and right margins of the rectangles. */
5624 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5625 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5629 /* Don't flash the area between a scroll bar and the frame
5630 edge it is next to. */
5631 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5633 case vertical_scroll_bar_left
:
5634 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5637 case vertical_scroll_bar_right
:
5638 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5645 width
= flash_right
- flash_left
;
5647 /* If window is tall, flash top and bottom line. */
5648 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5650 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5652 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5653 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5654 width
, flash_height
);
5655 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5657 (height
- flash_height
5658 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5659 width
, flash_height
);
5662 /* If it is short, flash it all. */
5663 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5664 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5665 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5670 struct timeval wakeup
;
5672 EMACS_GET_TIME (wakeup
);
5674 /* Compute time to wait until, propagating carry from usecs. */
5675 wakeup
.tv_usec
+= 150000;
5676 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5677 wakeup
.tv_usec
%= 1000000;
5679 /* Keep waiting until past the time wakeup or any input gets
5681 while (! detect_input_pending ())
5683 struct timeval current
;
5684 struct timeval timeout
;
5686 EMACS_GET_TIME (current
);
5688 /* Break if result would be negative. */
5689 if (timeval_subtract (¤t
, wakeup
, current
))
5692 /* How long `select' should wait. */
5694 timeout
.tv_usec
= 10000;
5696 /* Try to wait that long--but we might wake up sooner. */
5697 select (0, NULL
, NULL
, NULL
, &timeout
);
5701 /* If window is tall, flash top and bottom line. */
5702 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5704 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5706 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5707 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5708 width
, flash_height
);
5709 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5711 (height
- flash_height
5712 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5713 width
, flash_height
);
5716 /* If it is short, flash it all. */
5717 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5718 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5719 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5721 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5729 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5732 /* Make audible bell. */
5737 struct frame
*f
= SELECTED_FRAME ();
5739 if (FRAME_X_DISPLAY (f
))
5741 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5748 XBell (FRAME_X_DISPLAY (f
), 0);
5749 XFlush (FRAME_X_DISPLAY (f
));
5756 /* Specify how many text lines, from the top of the window,
5757 should be affected by insert-lines and delete-lines operations.
5758 This, and those operations, are used only within an update
5759 that is bounded by calls to x_update_begin and x_update_end. */
5762 XTset_terminal_window (n
)
5765 /* This function intentionally left blank. */
5770 /***********************************************************************
5772 ***********************************************************************/
5774 /* Perform an insert-lines or delete-lines operation, inserting N
5775 lines or deleting -N lines at vertical position VPOS. */
5778 x_ins_del_lines (vpos
, n
)
5785 /* Scroll part of the display as described by RUN. */
5788 x_scroll_run (w
, run
)
5792 struct frame
*f
= XFRAME (w
->frame
);
5793 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5795 /* Get frame-relative bounding box of the text display area of W,
5796 without mode lines. Include in this box the left and right
5798 window_box (w
, -1, &x
, &y
, &width
, &height
);
5799 width
+= FRAME_X_FRINGE_WIDTH (f
);
5800 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5802 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5803 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5804 bottom_y
= y
+ height
;
5808 /* Scrolling up. Make sure we don't copy part of the mode
5809 line at the bottom. */
5810 if (from_y
+ run
->height
> bottom_y
)
5811 height
= bottom_y
- from_y
;
5813 height
= run
->height
;
5817 /* Scolling down. Make sure we don't copy over the mode line.
5819 if (to_y
+ run
->height
> bottom_y
)
5820 height
= bottom_y
- to_y
;
5822 height
= run
->height
;
5827 /* Cursor off. Will be switched on again in x_update_window_end. */
5831 XCopyArea (FRAME_X_DISPLAY (f
),
5832 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5833 f
->output_data
.x
->normal_gc
,
5843 /***********************************************************************
5845 ***********************************************************************/
5847 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5848 corner of the exposed rectangle. W and H are width and height of
5849 the exposed area. All are pixel values. W or H zero means redraw
5850 the entire frame. */
5853 expose_frame (f
, x
, y
, w
, h
)
5858 int mouse_face_overwritten_p
= 0;
5860 TRACE ((stderr
, "expose_frame "));
5862 /* No need to redraw if frame will be redrawn soon. */
5863 if (FRAME_GARBAGED_P (f
))
5865 TRACE ((stderr
, " garbaged\n"));
5869 /* If basic faces haven't been realized yet, there is no point in
5870 trying to redraw anything. This can happen when we get an expose
5871 event while Emacs is starting, e.g. by moving another window. */
5872 if (FRAME_FACE_CACHE (f
) == NULL
5873 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5875 TRACE ((stderr
, " no faces\n"));
5879 if (w
== 0 || h
== 0)
5882 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5883 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5893 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5894 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5896 if (WINDOWP (f
->tool_bar_window
))
5897 mouse_face_overwritten_p
5898 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5900 #ifndef USE_X_TOOLKIT
5901 if (WINDOWP (f
->menu_bar_window
))
5902 mouse_face_overwritten_p
5903 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5904 #endif /* not USE_X_TOOLKIT */
5906 /* Some window managers support a focus-follows-mouse style with
5907 delayed raising of frames. Imagine a partially obscured frame,
5908 and moving the mouse into partially obscured mouse-face on that
5909 frame. The visible part of the mouse-face will be highlighted,
5910 then the WM raises the obscured frame. With at least one WM, KDE
5911 2.1, Emacs is not getting any event for the raising of the frame
5912 (even tried with SubstructureRedirectMask), only Expose events.
5913 These expose events will draw text normally, i.e. not
5914 highlighted. Which means we must redo the highlight here.
5915 Subsume it under ``we love X''. --gerd 2001-08-15 */
5916 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5918 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5919 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5921 int x
= dpyinfo
->mouse_face_mouse_x
;
5922 int y
= dpyinfo
->mouse_face_mouse_y
;
5923 clear_mouse_face (dpyinfo
);
5924 note_mouse_highlight (f
, x
, y
);
5930 /* Redraw (parts) of all windows in the window tree rooted at W that
5931 intersect R. R contains frame pixel coordinates. Value is
5932 non-zero if the exposure overwrites mouse-face. */
5935 expose_window_tree (w
, r
)
5939 struct frame
*f
= XFRAME (w
->frame
);
5940 int mouse_face_overwritten_p
= 0;
5942 while (w
&& !FRAME_GARBAGED_P (f
))
5944 if (!NILP (w
->hchild
))
5945 mouse_face_overwritten_p
5946 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5947 else if (!NILP (w
->vchild
))
5948 mouse_face_overwritten_p
5949 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5951 mouse_face_overwritten_p
|= expose_window (w
, r
);
5953 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5956 return mouse_face_overwritten_p
;
5960 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5961 which intersects rectangle R. R is in window-relative coordinates. */
5964 expose_area (w
, row
, r
, area
)
5966 struct glyph_row
*row
;
5968 enum glyph_row_area area
;
5970 struct glyph
*first
= row
->glyphs
[area
];
5971 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5973 int first_x
, start_x
, x
;
5975 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5976 /* If row extends face to end of line write the whole line. */
5977 x_draw_glyphs (w
, 0, row
, area
, 0, row
->used
[area
],
5978 DRAW_NORMAL_TEXT
, 0);
5981 /* Set START_X to the window-relative start position for drawing glyphs of
5982 AREA. The first glyph of the text area can be partially visible.
5983 The first glyphs of other areas cannot. */
5984 if (area
== LEFT_MARGIN_AREA
)
5986 else if (area
== TEXT_AREA
)
5987 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5989 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5990 + window_box_width (w
, TEXT_AREA
));
5993 /* Find the first glyph that must be redrawn. */
5995 && x
+ first
->pixel_width
< r
->x
)
5997 x
+= first
->pixel_width
;
6001 /* Find the last one. */
6005 && x
< r
->x
+ r
->width
)
6007 x
+= last
->pixel_width
;
6013 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
6014 first
- row
->glyphs
[area
],
6015 last
- row
->glyphs
[area
],
6016 DRAW_NORMAL_TEXT
, 0);
6021 /* Redraw the parts of the glyph row ROW on window W intersecting
6022 rectangle R. R is in window-relative coordinates. Value is
6023 non-zero if mouse-face was overwritten. */
6026 expose_line (w
, row
, r
)
6028 struct glyph_row
*row
;
6031 xassert (row
->enabled_p
);
6033 if (row
->mode_line_p
|| w
->pseudo_window_p
)
6034 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
6035 DRAW_NORMAL_TEXT
, 0);
6038 if (row
->used
[LEFT_MARGIN_AREA
])
6039 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
6040 if (row
->used
[TEXT_AREA
])
6041 expose_area (w
, row
, r
, TEXT_AREA
);
6042 if (row
->used
[RIGHT_MARGIN_AREA
])
6043 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
6044 x_draw_row_fringe_bitmaps (w
, row
);
6047 return row
->mouse_face_p
;
6051 /* Return non-zero if W's cursor intersects rectangle R. */
6054 x_phys_cursor_in_rect_p (w
, r
)
6058 XRectangle cr
, result
;
6059 struct glyph
*cursor_glyph
;
6061 cursor_glyph
= get_phys_cursor_glyph (w
);
6064 cr
.x
= w
->phys_cursor
.x
;
6065 cr
.y
= w
->phys_cursor
.y
;
6066 cr
.width
= cursor_glyph
->pixel_width
;
6067 cr
.height
= w
->phys_cursor_height
;
6068 return x_intersect_rectangles (&cr
, r
, &result
);
6075 /* Redraw those parts of glyphs rows during expose event handling that
6076 overlap other rows. Redrawing of an exposed line writes over parts
6077 of lines overlapping that exposed line; this function fixes that.
6079 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
6080 row in W's current matrix that is exposed and overlaps other rows.
6081 LAST_OVERLAPPING_ROW is the last such row. */
6084 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
6086 struct glyph_row
*first_overlapping_row
;
6087 struct glyph_row
*last_overlapping_row
;
6089 struct glyph_row
*row
;
6091 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
6092 if (row
->overlapping_p
)
6094 xassert (row
->enabled_p
&& !row
->mode_line_p
);
6096 if (row
->used
[LEFT_MARGIN_AREA
])
6097 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
6099 if (row
->used
[TEXT_AREA
])
6100 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
6102 if (row
->used
[RIGHT_MARGIN_AREA
])
6103 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
6108 /* Redraw the part of window W intersection rectangle FR. Pixel
6109 coordinates in FR are frame-relative. Call this function with
6110 input blocked. Value is non-zero if the exposure overwrites
6114 expose_window (w
, fr
)
6118 struct frame
*f
= XFRAME (w
->frame
);
6120 int mouse_face_overwritten_p
= 0;
6122 /* If window is not yet fully initialized, do nothing. This can
6123 happen when toolkit scroll bars are used and a window is split.
6124 Reconfiguring the scroll bar will generate an expose for a newly
6126 if (w
->current_matrix
== NULL
)
6129 /* When we're currently updating the window, display and current
6130 matrix usually don't agree. Arrange for a thorough display
6132 if (w
== updated_window
)
6134 SET_FRAME_GARBAGED (f
);
6138 /* Frame-relative pixel rectangle of W. */
6139 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6140 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6141 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6142 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6144 if (x_intersect_rectangles (fr
, &wr
, &r
))
6146 int yb
= window_text_bottom_y (w
);
6147 struct glyph_row
*row
;
6148 int cursor_cleared_p
;
6149 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
6151 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6152 r
.x
, r
.y
, r
.width
, r
.height
));
6154 /* Convert to window coordinates. */
6155 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
6156 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
6158 /* Turn off the cursor. */
6159 if (!w
->pseudo_window_p
6160 && x_phys_cursor_in_rect_p (w
, &r
))
6163 cursor_cleared_p
= 1;
6166 cursor_cleared_p
= 0;
6168 /* Update lines intersecting rectangle R. */
6169 first_overlapping_row
= last_overlapping_row
= NULL
;
6170 for (row
= w
->current_matrix
->rows
;
6175 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6177 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
6178 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
6179 || (r
.y
>= y0
&& r
.y
< y1
)
6180 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
6182 if (row
->overlapping_p
)
6184 if (first_overlapping_row
== NULL
)
6185 first_overlapping_row
= row
;
6186 last_overlapping_row
= row
;
6189 if (expose_line (w
, row
, &r
))
6190 mouse_face_overwritten_p
= 1;
6197 /* Display the mode line if there is one. */
6198 if (WINDOW_WANTS_MODELINE_P (w
)
6199 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6201 && row
->y
< r
.y
+ r
.height
)
6203 if (expose_line (w
, row
, &r
))
6204 mouse_face_overwritten_p
= 1;
6207 if (!w
->pseudo_window_p
)
6209 /* Fix the display of overlapping rows. */
6210 if (first_overlapping_row
)
6211 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
6213 /* Draw border between windows. */
6214 x_draw_vertical_border (w
);
6216 /* Turn the cursor on again. */
6217 if (cursor_cleared_p
)
6218 x_update_window_cursor (w
, 1);
6222 return mouse_face_overwritten_p
;
6226 /* Determine the intersection of two rectangles R1 and R2. Return
6227 the intersection in *RESULT. Value is non-zero if RESULT is not
6231 x_intersect_rectangles (r1
, r2
, result
)
6232 XRectangle
*r1
, *r2
, *result
;
6234 XRectangle
*left
, *right
;
6235 XRectangle
*upper
, *lower
;
6236 int intersection_p
= 0;
6238 /* Rearrange so that R1 is the left-most rectangle. */
6240 left
= r1
, right
= r2
;
6242 left
= r2
, right
= r1
;
6244 /* X0 of the intersection is right.x0, if this is inside R1,
6245 otherwise there is no intersection. */
6246 if (right
->x
<= left
->x
+ left
->width
)
6248 result
->x
= right
->x
;
6250 /* The right end of the intersection is the minimum of the
6251 the right ends of left and right. */
6252 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6255 /* Same game for Y. */
6257 upper
= r1
, lower
= r2
;
6259 upper
= r2
, lower
= r1
;
6261 /* The upper end of the intersection is lower.y0, if this is inside
6262 of upper. Otherwise, there is no intersection. */
6263 if (lower
->y
<= upper
->y
+ upper
->height
)
6265 result
->y
= lower
->y
;
6267 /* The lower end of the intersection is the minimum of the lower
6268 ends of upper and lower. */
6269 result
->height
= (min (lower
->y
+ lower
->height
,
6270 upper
->y
+ upper
->height
)
6276 return intersection_p
;
6287 /* We used to only do this if Vx_no_window_manager was non-nil, but
6288 the ICCCM (section 4.1.6) says that the window's border pixmap
6289 and border pixel are window attributes which are "private to the
6290 client", so we can always change it to whatever we want. */
6292 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6293 f
->output_data
.x
->border_pixel
);
6295 x_update_cursor (f
, 1);
6299 frame_unhighlight (f
)
6302 /* We used to only do this if Vx_no_window_manager was non-nil, but
6303 the ICCCM (section 4.1.6) says that the window's border pixmap
6304 and border pixel are window attributes which are "private to the
6305 client", so we can always change it to whatever we want. */
6307 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6308 f
->output_data
.x
->border_tile
);
6310 x_update_cursor (f
, 1);
6313 /* The focus has changed. Update the frames as necessary to reflect
6314 the new situation. Note that we can't change the selected frame
6315 here, because the Lisp code we are interrupting might become confused.
6316 Each event gets marked with the frame in which it occurred, so the
6317 Lisp code can tell when the switch took place by examining the events. */
6320 x_new_focus_frame (dpyinfo
, frame
)
6321 struct x_display_info
*dpyinfo
;
6322 struct frame
*frame
;
6324 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6326 if (frame
!= dpyinfo
->x_focus_frame
)
6328 /* Set this before calling other routines, so that they see
6329 the correct value of x_focus_frame. */
6330 dpyinfo
->x_focus_frame
= frame
;
6332 if (old_focus
&& old_focus
->auto_lower
)
6333 x_lower_frame (old_focus
);
6336 selected_frame
= frame
;
6337 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6339 Fselect_window (selected_frame
->selected_window
);
6340 choose_minibuf_frame ();
6343 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6344 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6346 pending_autoraise_frame
= 0;
6349 x_frame_rehighlight (dpyinfo
);
6352 /* Handle FocusIn and FocusOut state changes for FRAME.
6353 If FRAME has focus and there exists more than one frame, puts
6354 an FOCUS_IN_EVENT into BUFP.
6355 Returns number of events inserted into BUFP. */
6358 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
, numchars
)
6361 struct x_display_info
*dpyinfo
;
6362 struct frame
*frame
;
6363 struct input_event
*bufp
;
6368 if (type
== FocusIn
)
6370 if (dpyinfo
->x_focus_event_frame
!= frame
)
6372 x_new_focus_frame (dpyinfo
, frame
);
6373 dpyinfo
->x_focus_event_frame
= frame
;
6375 /* Don't stop displaying the initial startup message
6376 for a switch-frame event we don't need. */
6378 && GC_NILP (Vterminal_frame
)
6379 && GC_CONSP (Vframe_list
)
6380 && !GC_NILP (XCDR (Vframe_list
)))
6382 bufp
->kind
= FOCUS_IN_EVENT
;
6383 XSETFRAME (bufp
->frame_or_window
, frame
);
6391 frame
->output_data
.x
->focus_state
|= state
;
6394 if (FRAME_XIC (frame
))
6395 XSetICFocus (FRAME_XIC (frame
));
6398 else if (type
== FocusOut
)
6400 frame
->output_data
.x
->focus_state
&= ~state
;
6402 if (dpyinfo
->x_focus_event_frame
== frame
)
6404 dpyinfo
->x_focus_event_frame
= 0;
6405 x_new_focus_frame (dpyinfo
, 0);
6409 if (FRAME_XIC (frame
))
6410 XUnsetICFocus (FRAME_XIC (frame
));
6417 /* The focus may have changed. Figure out if it is a real focus change,
6418 by checking both FocusIn/Out and Enter/LeaveNotify events.
6420 Returns number of events inserted into BUFP. */
6423 x_detect_focus_change (dpyinfo
, event
, bufp
, numchars
)
6424 struct x_display_info
*dpyinfo
;
6426 struct input_event
*bufp
;
6429 struct frame
*frame
;
6432 frame
= x_top_window_to_frame (dpyinfo
, event
->xany
.window
);
6433 if (! frame
) return nr_events
;
6435 switch (event
->type
)
6439 if (event
->xcrossing
.detail
!= NotifyInferior
6440 && event
->xcrossing
.focus
6441 && ! (frame
->output_data
.x
->focus_state
& FOCUS_EXPLICIT
))
6442 nr_events
= x_focus_changed ((event
->type
== EnterNotify
6443 ? FocusIn
: FocusOut
),
6453 nr_events
= x_focus_changed (event
->type
,
6454 (event
->xfocus
.detail
== NotifyPointer
6455 ? FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
6467 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6470 x_mouse_leave (dpyinfo
)
6471 struct x_display_info
*dpyinfo
;
6473 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6476 /* The focus has changed, or we have redirected a frame's focus to
6477 another frame (this happens when a frame uses a surrogate
6478 mini-buffer frame). Shift the highlight as appropriate.
6480 The FRAME argument doesn't necessarily have anything to do with which
6481 frame is being highlighted or un-highlighted; we only use it to find
6482 the appropriate X display info. */
6485 XTframe_rehighlight (frame
)
6486 struct frame
*frame
;
6488 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6492 x_frame_rehighlight (dpyinfo
)
6493 struct x_display_info
*dpyinfo
;
6495 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6497 if (dpyinfo
->x_focus_frame
)
6499 dpyinfo
->x_highlight_frame
6500 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6501 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6502 : dpyinfo
->x_focus_frame
);
6503 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6505 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6506 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6510 dpyinfo
->x_highlight_frame
= 0;
6512 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6515 frame_unhighlight (old_highlight
);
6516 if (dpyinfo
->x_highlight_frame
)
6517 frame_highlight (dpyinfo
->x_highlight_frame
);
6523 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6525 /* Initialize mode_switch_bit and modifier_meaning. */
6527 x_find_modifier_meanings (dpyinfo
)
6528 struct x_display_info
*dpyinfo
;
6530 int min_code
, max_code
;
6533 XModifierKeymap
*mods
;
6535 dpyinfo
->meta_mod_mask
= 0;
6536 dpyinfo
->shift_lock_mask
= 0;
6537 dpyinfo
->alt_mod_mask
= 0;
6538 dpyinfo
->super_mod_mask
= 0;
6539 dpyinfo
->hyper_mod_mask
= 0;
6542 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6544 min_code
= dpyinfo
->display
->min_keycode
;
6545 max_code
= dpyinfo
->display
->max_keycode
;
6548 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6549 min_code
, max_code
- min_code
+ 1,
6551 mods
= XGetModifierMapping (dpyinfo
->display
);
6553 /* Scan the modifier table to see which modifier bits the Meta and
6554 Alt keysyms are on. */
6556 int row
, col
; /* The row and column in the modifier table. */
6558 for (row
= 3; row
< 8; row
++)
6559 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6562 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6564 /* Zeroes are used for filler. Skip them. */
6568 /* Are any of this keycode's keysyms a meta key? */
6572 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6574 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6580 dpyinfo
->meta_mod_mask
|= (1 << row
);
6585 dpyinfo
->alt_mod_mask
|= (1 << row
);
6590 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6595 dpyinfo
->super_mod_mask
|= (1 << row
);
6599 /* Ignore this if it's not on the lock modifier. */
6600 if ((1 << row
) == LockMask
)
6601 dpyinfo
->shift_lock_mask
= LockMask
;
6609 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6610 if (! dpyinfo
->meta_mod_mask
)
6612 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6613 dpyinfo
->alt_mod_mask
= 0;
6616 /* If some keys are both alt and meta,
6617 make them just meta, not alt. */
6618 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6620 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6623 XFree ((char *) syms
);
6624 XFreeModifiermap (mods
);
6627 /* Convert between the modifier bits X uses and the modifier bits
6631 x_x_to_emacs_modifiers (dpyinfo
, state
)
6632 struct x_display_info
*dpyinfo
;
6635 EMACS_UINT mod_meta
= meta_modifier
;
6636 EMACS_UINT mod_alt
= alt_modifier
;
6637 EMACS_UINT mod_hyper
= hyper_modifier
;
6638 EMACS_UINT mod_super
= super_modifier
;
6641 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6642 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6643 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6644 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6645 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6646 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6647 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6648 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6651 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6652 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6653 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
6654 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
6655 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
6656 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
6660 x_emacs_to_x_modifiers (dpyinfo
, state
)
6661 struct x_display_info
*dpyinfo
;
6664 EMACS_UINT mod_meta
= meta_modifier
;
6665 EMACS_UINT mod_alt
= alt_modifier
;
6666 EMACS_UINT mod_hyper
= hyper_modifier
;
6667 EMACS_UINT mod_super
= super_modifier
;
6671 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6672 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6673 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6674 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6675 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6676 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6677 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6678 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6681 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
6682 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
6683 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
6684 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6685 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6686 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
6689 /* Convert a keysym to its name. */
6692 x_get_keysym_name (keysym
)
6698 value
= XKeysymToString (keysym
);
6706 /* Mouse clicks and mouse movement. Rah. */
6708 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6709 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6710 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6711 not force the value into range. */
6714 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6716 register int pix_x
, pix_y
;
6717 register int *x
, *y
;
6721 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6722 even for negative values. */
6724 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6726 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6728 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6729 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6733 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6734 bounds
->height
= f
->output_data
.x
->line_height
;
6735 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6736 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6743 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6744 pix_x
= FRAME_WINDOW_WIDTH (f
);
6748 else if (pix_y
> f
->height
)
6757 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6758 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6759 can't tell the positions because W's display is not up to date,
6763 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6766 int *frame_x
, *frame_y
;
6770 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6771 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6773 if (display_completed
)
6775 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6776 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6777 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6783 *frame_x
+= glyph
->pixel_width
;
6791 *frame_y
= *frame_x
= 0;
6795 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6796 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6801 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6803 If the event is a button press, then note that we have grabbed
6807 construct_mouse_click (result
, event
, f
)
6808 struct input_event
*result
;
6809 XButtonEvent
*event
;
6812 /* Make the event type NO_EVENT; we'll change that when we decide
6814 result
->kind
= MOUSE_CLICK_EVENT
;
6815 result
->code
= event
->button
- Button1
;
6816 result
->timestamp
= event
->time
;
6817 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6819 | (event
->type
== ButtonRelease
6823 XSETINT (result
->x
, event
->x
);
6824 XSETINT (result
->y
, event
->y
);
6825 XSETFRAME (result
->frame_or_window
, f
);
6831 /* Function to report a mouse movement to the mainstream Emacs code.
6832 The input handler calls this.
6834 We have received a mouse movement event, which is given in *event.
6835 If the mouse is over a different glyph than it was last time, tell
6836 the mainstream emacs code by setting mouse_moved. If not, ask for
6837 another motion event, so we can check again the next time it moves. */
6839 static XMotionEvent last_mouse_motion_event
;
6840 static Lisp_Object last_mouse_motion_frame
;
6843 note_mouse_movement (frame
, event
)
6845 XMotionEvent
*event
;
6847 last_mouse_movement_time
= event
->time
;
6848 last_mouse_motion_event
= *event
;
6849 XSETFRAME (last_mouse_motion_frame
, frame
);
6851 if (event
->window
!= FRAME_X_WINDOW (frame
))
6853 frame
->mouse_moved
= 1;
6854 last_mouse_scroll_bar
= Qnil
;
6855 note_mouse_highlight (frame
, -1, -1);
6858 /* Has the mouse moved off the glyph it was on at the last sighting? */
6859 else if (event
->x
< last_mouse_glyph
.x
6860 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6861 || event
->y
< last_mouse_glyph
.y
6862 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6864 frame
->mouse_moved
= 1;
6865 last_mouse_scroll_bar
= Qnil
;
6866 note_mouse_highlight (frame
, event
->x
, event
->y
);
6871 /************************************************************************
6873 ************************************************************************/
6875 /* Find the glyph under window-relative coordinates X/Y in window W.
6876 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6877 strings. Return in *HPOS and *VPOS the row and column number of
6878 the glyph found. Return in *AREA the glyph area containing X.
6879 Value is a pointer to the glyph found or null if X/Y is not on
6880 text, or we can't tell because W's current matrix is not up to
6883 static struct glyph
*
6884 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6887 int *hpos
, *vpos
, *area
;
6890 struct glyph
*glyph
, *end
;
6891 struct glyph_row
*row
= NULL
;
6892 int x0
, i
, left_area_width
;
6894 /* Find row containing Y. Give up if some row is not enabled. */
6895 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6897 row
= MATRIX_ROW (w
->current_matrix
, i
);
6898 if (!row
->enabled_p
)
6900 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6907 /* Give up if Y is not in the window. */
6908 if (i
== w
->current_matrix
->nrows
)
6911 /* Get the glyph area containing X. */
6912 if (w
->pseudo_window_p
)
6919 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6920 if (x
< left_area_width
)
6922 *area
= LEFT_MARGIN_AREA
;
6925 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6928 x0
= row
->x
+ left_area_width
;
6932 *area
= RIGHT_MARGIN_AREA
;
6933 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6937 /* Find glyph containing X. */
6938 glyph
= row
->glyphs
[*area
];
6939 end
= glyph
+ row
->used
[*area
];
6942 if (x
< x0
+ glyph
->pixel_width
)
6944 if (w
->pseudo_window_p
)
6946 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6950 x0
+= glyph
->pixel_width
;
6957 *hpos
= glyph
- row
->glyphs
[*area
];
6962 /* Convert frame-relative x/y to coordinates relative to window W.
6963 Takes pseudo-windows into account. */
6966 frame_to_window_pixel_xy (w
, x
, y
)
6970 if (w
->pseudo_window_p
)
6972 /* A pseudo-window is always full-width, and starts at the
6973 left edge of the frame, plus a frame border. */
6974 struct frame
*f
= XFRAME (w
->frame
);
6975 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6976 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6980 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6981 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6986 /* Take proper action when mouse has moved to the mode or header line
6987 or marginal area of window W, x-position X and y-position Y. Area
6988 is 1, 3, 6 or 7 for the mode line, header line, left and right
6989 marginal area respectively. X is relative to the start of the text
6990 display area of W, so the width of bitmap areas and scroll bars
6991 must be subtracted to get a position relative to the start of the
6995 note_mode_line_or_margin_highlight (w
, x
, y
, portion
)
6999 struct frame
*f
= XFRAME (w
->frame
);
7000 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7001 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
7003 Lisp_Object string
, help
, map
, pos
;
7005 if (portion
== 1 || portion
== 3)
7006 string
= mode_line_string (w
, x
, y
, portion
== 1, &charpos
);
7008 string
= marginal_area_string (w
, x
, y
, portion
, &charpos
);
7010 if (STRINGP (string
))
7012 pos
= make_number (charpos
);
7014 /* If we're on a string with `help-echo' text property, arrange
7015 for the help to be displayed. This is done by setting the
7016 global variable help_echo to the help string. */
7017 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
7021 XSETWINDOW (help_echo_window
, w
);
7022 help_echo_object
= string
;
7023 help_echo_pos
= charpos
;
7026 /* Change the mouse pointer according to what is under X/Y. */
7027 map
= Fget_text_property (pos
, Qlocal_map
, string
);
7029 map
= Fget_text_property (pos
, Qkeymap
, string
);
7031 cursor
= f
->output_data
.x
->nontext_cursor
;
7034 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7038 /* Take proper action when the mouse has moved to position X, Y on
7039 frame F as regards highlighting characters that have mouse-face
7040 properties. Also de-highlighting chars where the mouse was before.
7041 X and Y can be negative or out of range. */
7044 note_mouse_highlight (f
, x
, y
)
7048 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7052 Cursor cursor
= None
;
7055 /* When a menu is active, don't highlight because this looks odd. */
7056 #ifdef USE_X_TOOLKIT
7057 if (popup_activated ())
7061 if (NILP (Vmouse_highlight
)
7062 || !f
->glyphs_initialized_p
)
7065 dpyinfo
->mouse_face_mouse_x
= x
;
7066 dpyinfo
->mouse_face_mouse_y
= y
;
7067 dpyinfo
->mouse_face_mouse_frame
= f
;
7069 if (dpyinfo
->mouse_face_defer
)
7074 dpyinfo
->mouse_face_deferred_gc
= 1;
7078 /* Which window is that in? */
7079 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
7081 /* If we were displaying active text in another window, clear that. */
7082 if (! EQ (window
, dpyinfo
->mouse_face_window
))
7083 clear_mouse_face (dpyinfo
);
7085 /* Not on a window -> return. */
7086 if (!WINDOWP (window
))
7089 /* Convert to window-relative pixel coordinates. */
7090 w
= XWINDOW (window
);
7091 frame_to_window_pixel_xy (w
, &x
, &y
);
7093 /* Handle tool-bar window differently since it doesn't display a
7095 if (EQ (window
, f
->tool_bar_window
))
7097 note_tool_bar_highlight (f
, x
, y
);
7101 /* Mouse is on the mode, header line or margin? */
7102 if (portion
== 1 || portion
== 3 || portion
== 6 || portion
== 7)
7104 note_mode_line_or_margin_highlight (w
, x
, y
, portion
);
7109 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
7111 cursor
= f
->output_data
.x
->text_cursor
;
7113 /* Are we in a window whose display is up to date?
7114 And verify the buffer's text has not changed. */
7115 b
= XBUFFER (w
->buffer
);
7116 if (/* Within text portion of the window. */
7118 && EQ (w
->window_end_valid
, w
->buffer
)
7119 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
7120 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
7122 int hpos
, vpos
, pos
, i
, area
;
7123 struct glyph
*glyph
;
7125 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
7126 Lisp_Object
*overlay_vec
= NULL
;
7128 struct buffer
*obuf
;
7129 int obegv
, ozv
, same_region
;
7131 /* Find the glyph under X/Y. */
7132 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
7134 /* Clear mouse face if X/Y not over text. */
7136 || area
!= TEXT_AREA
7137 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
7139 if (clear_mouse_face (dpyinfo
))
7144 pos
= glyph
->charpos
;
7145 object
= glyph
->object
;
7146 if (!STRINGP (object
) && !BUFFERP (object
))
7149 /* If we get an out-of-range value, return now; avoid an error. */
7150 if (BUFFERP (object
) && pos
> BUF_Z (b
))
7153 /* Make the window's buffer temporarily current for
7154 overlays_at and compute_char_face. */
7155 obuf
= current_buffer
;
7162 /* Is this char mouse-active or does it have help-echo? */
7163 position
= make_number (pos
);
7165 if (BUFFERP (object
))
7167 /* Put all the overlays we want in a vector in overlay_vec.
7168 Store the length in len. If there are more than 10, make
7169 enough space for all, and try again. */
7171 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7172 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
7173 if (noverlays
> len
)
7176 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7177 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
7180 /* Sort overlays into increasing priority order. */
7181 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7186 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
7187 && vpos
>= dpyinfo
->mouse_face_beg_row
7188 && vpos
<= dpyinfo
->mouse_face_end_row
7189 && (vpos
> dpyinfo
->mouse_face_beg_row
7190 || hpos
>= dpyinfo
->mouse_face_beg_col
)
7191 && (vpos
< dpyinfo
->mouse_face_end_row
7192 || hpos
< dpyinfo
->mouse_face_end_col
7193 || dpyinfo
->mouse_face_past_end
));
7198 /* Check mouse-face highlighting. */
7200 /* If there exists an overlay with mouse-face overlapping
7201 the one we are currently highlighting, we have to
7202 check if we enter the overlapping overlay, and then
7203 highlight only that. */
7204 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
7205 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
7207 /* Find the highest priority overlay that has a mouse-face
7210 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
7212 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
7213 if (!NILP (mouse_face
))
7214 overlay
= overlay_vec
[i
];
7217 /* If we're actually highlighting the same overlay as
7218 before, there's no need to do that again. */
7220 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
7221 goto check_help_echo
;
7223 dpyinfo
->mouse_face_overlay
= overlay
;
7225 /* Clear the display of the old active region, if any. */
7226 if (clear_mouse_face (dpyinfo
))
7229 /* If no overlay applies, get a text property. */
7231 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7233 /* Handle the overlay case. */
7234 if (!NILP (overlay
))
7236 /* Find the range of text around this char that
7237 should be active. */
7238 Lisp_Object before
, after
;
7241 before
= Foverlay_start (overlay
);
7242 after
= Foverlay_end (overlay
);
7243 /* Record this as the current active region. */
7244 fast_find_position (w
, XFASTINT (before
),
7245 &dpyinfo
->mouse_face_beg_col
,
7246 &dpyinfo
->mouse_face_beg_row
,
7247 &dpyinfo
->mouse_face_beg_x
,
7248 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7250 dpyinfo
->mouse_face_past_end
7251 = !fast_find_position (w
, XFASTINT (after
),
7252 &dpyinfo
->mouse_face_end_col
,
7253 &dpyinfo
->mouse_face_end_row
,
7254 &dpyinfo
->mouse_face_end_x
,
7255 &dpyinfo
->mouse_face_end_y
, Qnil
);
7256 dpyinfo
->mouse_face_window
= window
;
7257 dpyinfo
->mouse_face_face_id
7258 = face_at_buffer_position (w
, pos
, 0, 0,
7259 &ignore
, pos
+ 1, 1);
7261 /* Display it as active. */
7262 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7265 /* Handle the text property case. */
7266 else if (!NILP (mouse_face
) && BUFFERP (object
))
7268 /* Find the range of text around this char that
7269 should be active. */
7270 Lisp_Object before
, after
, beginning
, end
;
7273 beginning
= Fmarker_position (w
->start
);
7274 end
= make_number (BUF_Z (XBUFFER (object
))
7275 - XFASTINT (w
->window_end_pos
));
7277 = Fprevious_single_property_change (make_number (pos
+ 1),
7281 = Fnext_single_property_change (position
, Qmouse_face
,
7284 /* Record this as the current active region. */
7285 fast_find_position (w
, XFASTINT (before
),
7286 &dpyinfo
->mouse_face_beg_col
,
7287 &dpyinfo
->mouse_face_beg_row
,
7288 &dpyinfo
->mouse_face_beg_x
,
7289 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7290 dpyinfo
->mouse_face_past_end
7291 = !fast_find_position (w
, XFASTINT (after
),
7292 &dpyinfo
->mouse_face_end_col
,
7293 &dpyinfo
->mouse_face_end_row
,
7294 &dpyinfo
->mouse_face_end_x
,
7295 &dpyinfo
->mouse_face_end_y
, Qnil
);
7296 dpyinfo
->mouse_face_window
= window
;
7298 if (BUFFERP (object
))
7299 dpyinfo
->mouse_face_face_id
7300 = face_at_buffer_position (w
, pos
, 0, 0,
7301 &ignore
, pos
+ 1, 1);
7303 /* Display it as active. */
7304 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7307 else if (!NILP (mouse_face
) && STRINGP (object
))
7312 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7315 e
= Fnext_single_property_change (position
, Qmouse_face
,
7318 b
= make_number (0);
7320 e
= make_number (SCHARS (object
) - 1);
7321 fast_find_string_pos (w
, XINT (b
), object
,
7322 &dpyinfo
->mouse_face_beg_col
,
7323 &dpyinfo
->mouse_face_beg_row
,
7324 &dpyinfo
->mouse_face_beg_x
,
7325 &dpyinfo
->mouse_face_beg_y
, 0);
7326 fast_find_string_pos (w
, XINT (e
), object
,
7327 &dpyinfo
->mouse_face_end_col
,
7328 &dpyinfo
->mouse_face_end_row
,
7329 &dpyinfo
->mouse_face_end_x
,
7330 &dpyinfo
->mouse_face_end_y
, 1);
7331 dpyinfo
->mouse_face_past_end
= 0;
7332 dpyinfo
->mouse_face_window
= window
;
7333 dpyinfo
->mouse_face_face_id
7334 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7336 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7339 else if (STRINGP (object
) && NILP (mouse_face
))
7341 /* A string which doesn't have mouse-face, but
7342 the text ``under'' it might have. */
7343 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7344 int start
= MATRIX_ROW_START_CHARPOS (r
);
7346 pos
= string_buffer_position (w
, object
, start
);
7348 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7352 if (!NILP (mouse_face
) && !NILP (overlay
))
7354 Lisp_Object before
= Foverlay_start (overlay
);
7355 Lisp_Object after
= Foverlay_end (overlay
);
7358 /* Note that we might not be able to find position
7359 BEFORE in the glyph matrix if the overlay is
7360 entirely covered by a `display' property. In
7361 this case, we overshoot. So let's stop in
7362 the glyph matrix before glyphs for OBJECT. */
7363 fast_find_position (w
, XFASTINT (before
),
7364 &dpyinfo
->mouse_face_beg_col
,
7365 &dpyinfo
->mouse_face_beg_row
,
7366 &dpyinfo
->mouse_face_beg_x
,
7367 &dpyinfo
->mouse_face_beg_y
,
7370 dpyinfo
->mouse_face_past_end
7371 = !fast_find_position (w
, XFASTINT (after
),
7372 &dpyinfo
->mouse_face_end_col
,
7373 &dpyinfo
->mouse_face_end_row
,
7374 &dpyinfo
->mouse_face_end_x
,
7375 &dpyinfo
->mouse_face_end_y
,
7377 dpyinfo
->mouse_face_window
= window
;
7378 dpyinfo
->mouse_face_face_id
7379 = face_at_buffer_position (w
, pos
, 0, 0,
7380 &ignore
, pos
+ 1, 1);
7382 /* Display it as active. */
7383 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7391 /* Look for a `help-echo' property. */
7393 Lisp_Object help
, overlay
;
7395 /* Check overlays first. */
7396 help
= overlay
= Qnil
;
7397 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7399 overlay
= overlay_vec
[i
];
7400 help
= Foverlay_get (overlay
, Qhelp_echo
);
7406 help_echo_window
= window
;
7407 help_echo_object
= overlay
;
7408 help_echo_pos
= pos
;
7412 Lisp_Object object
= glyph
->object
;
7413 int charpos
= glyph
->charpos
;
7415 /* Try text properties. */
7416 if (STRINGP (object
)
7418 && charpos
< SCHARS (object
))
7420 help
= Fget_text_property (make_number (charpos
),
7421 Qhelp_echo
, object
);
7424 /* If the string itself doesn't specify a help-echo,
7425 see if the buffer text ``under'' it does. */
7427 = MATRIX_ROW (w
->current_matrix
, vpos
);
7428 int start
= MATRIX_ROW_START_CHARPOS (r
);
7429 int pos
= string_buffer_position (w
, object
, start
);
7432 help
= Fget_char_property (make_number (pos
),
7433 Qhelp_echo
, w
->buffer
);
7442 else if (BUFFERP (object
)
7445 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7451 help_echo_window
= window
;
7452 help_echo_object
= object
;
7453 help_echo_pos
= charpos
;
7460 current_buffer
= obuf
;
7466 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7470 redo_mouse_highlight ()
7472 if (!NILP (last_mouse_motion_frame
)
7473 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7474 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7475 last_mouse_motion_event
.x
,
7476 last_mouse_motion_event
.y
);
7481 /***********************************************************************
7483 ***********************************************************************/
7485 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7486 struct glyph
**, int *, int *, int *));
7488 /* Tool-bar item index of the item on which a mouse button was pressed
7491 static int last_tool_bar_item
;
7494 /* Get information about the tool-bar item at position X/Y on frame F.
7495 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7496 the current matrix of the tool-bar window of F, or NULL if not
7497 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7498 item in F->tool_bar_items. Value is
7500 -1 if X/Y is not on a tool-bar item
7501 0 if X/Y is on the same item that was highlighted before.
7505 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7508 struct glyph
**glyph
;
7509 int *hpos
, *vpos
, *prop_idx
;
7511 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7512 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7515 /* Find the glyph under X/Y. */
7516 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7520 /* Get the start of this tool-bar item's properties in
7521 f->tool_bar_items. */
7522 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7525 /* Is mouse on the highlighted item? */
7526 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7527 && *vpos
>= dpyinfo
->mouse_face_beg_row
7528 && *vpos
<= dpyinfo
->mouse_face_end_row
7529 && (*vpos
> dpyinfo
->mouse_face_beg_row
7530 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7531 && (*vpos
< dpyinfo
->mouse_face_end_row
7532 || *hpos
< dpyinfo
->mouse_face_end_col
7533 || dpyinfo
->mouse_face_past_end
))
7540 /* Handle mouse button event on the tool-bar of frame F, at
7541 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
7545 x_handle_tool_bar_click (f
, button_event
)
7547 XButtonEvent
*button_event
;
7549 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7550 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7551 int hpos
, vpos
, prop_idx
;
7552 struct glyph
*glyph
;
7553 Lisp_Object enabled_p
;
7554 int x
= button_event
->x
;
7555 int y
= button_event
->y
;
7557 /* If not on the highlighted tool-bar item, return. */
7558 frame_to_window_pixel_xy (w
, &x
, &y
);
7559 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7562 /* If item is disabled, do nothing. */
7563 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7564 if (NILP (enabled_p
))
7567 if (button_event
->type
== ButtonPress
)
7569 /* Show item in pressed state. */
7570 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7571 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7572 last_tool_bar_item
= prop_idx
;
7576 Lisp_Object key
, frame
;
7577 struct input_event event
;
7579 /* Show item in released state. */
7580 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7581 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7583 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7585 XSETFRAME (frame
, f
);
7586 event
.kind
= TOOL_BAR_EVENT
;
7587 event
.frame_or_window
= frame
;
7589 kbd_buffer_store_event (&event
);
7591 event
.kind
= TOOL_BAR_EVENT
;
7592 event
.frame_or_window
= frame
;
7594 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7595 button_event
->state
);
7596 kbd_buffer_store_event (&event
);
7597 last_tool_bar_item
= -1;
7602 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7603 tool-bar window-relative coordinates X/Y. Called from
7604 note_mouse_highlight. */
7607 note_tool_bar_highlight (f
, x
, y
)
7611 Lisp_Object window
= f
->tool_bar_window
;
7612 struct window
*w
= XWINDOW (window
);
7613 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7615 struct glyph
*glyph
;
7616 struct glyph_row
*row
;
7618 Lisp_Object enabled_p
;
7620 enum draw_glyphs_face draw
;
7621 int mouse_down_p
, rc
;
7623 /* Function note_mouse_highlight is called with negative x(y
7624 values when mouse moves outside of the frame. */
7625 if (x
<= 0 || y
<= 0)
7627 clear_mouse_face (dpyinfo
);
7631 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7634 /* Not on tool-bar item. */
7635 clear_mouse_face (dpyinfo
);
7641 clear_mouse_face (dpyinfo
);
7643 /* Mouse is down, but on different tool-bar item? */
7644 mouse_down_p
= (dpyinfo
->grabbed
7645 && f
== last_mouse_frame
7646 && FRAME_LIVE_P (f
));
7648 && last_tool_bar_item
!= prop_idx
)
7651 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7652 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7654 /* If tool-bar item is not enabled, don't highlight it. */
7655 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7656 if (!NILP (enabled_p
))
7658 /* Compute the x-position of the glyph. In front and past the
7659 image is a space. We include this is the highlighted area. */
7660 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7661 for (i
= x
= 0; i
< hpos
; ++i
)
7662 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7664 /* Record this as the current active region. */
7665 dpyinfo
->mouse_face_beg_col
= hpos
;
7666 dpyinfo
->mouse_face_beg_row
= vpos
;
7667 dpyinfo
->mouse_face_beg_x
= x
;
7668 dpyinfo
->mouse_face_beg_y
= row
->y
;
7669 dpyinfo
->mouse_face_past_end
= 0;
7671 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7672 dpyinfo
->mouse_face_end_row
= vpos
;
7673 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7674 dpyinfo
->mouse_face_end_y
= row
->y
;
7675 dpyinfo
->mouse_face_window
= window
;
7676 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7678 /* Display it as active. */
7679 show_mouse_face (dpyinfo
, draw
);
7680 dpyinfo
->mouse_face_image_state
= draw
;
7685 /* Set help_echo to a help string to display for this tool-bar item.
7686 XTread_socket does the rest. */
7687 help_echo_object
= help_echo_window
= Qnil
;
7689 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7690 if (NILP (help_echo
))
7691 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7696 /* Find the glyph matrix position of buffer position CHARPOS in window
7697 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7698 current glyphs must be up to date. If CHARPOS is above window
7699 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7700 of last line in W. In the row containing CHARPOS, stop before glyphs
7701 having STOP as object. */
7703 #if 0 /* This is a version of fast_find_position that's more correct
7704 in the presence of hscrolling, for example. I didn't install
7705 it right away because the problem fixed is minor, it failed
7706 in 20.x as well, and I think it's too risky to install
7707 so near the release of 21.1. 2001-09-25 gerd. */
7710 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7713 int *hpos
, *vpos
, *x
, *y
;
7716 struct glyph_row
*row
, *first
;
7717 struct glyph
*glyph
, *end
;
7718 int i
, past_end
= 0;
7720 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7721 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7724 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7726 *x
= *y
= *hpos
= *vpos
= 0;
7731 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7738 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7740 glyph
= row
->glyphs
[TEXT_AREA
];
7741 end
= glyph
+ row
->used
[TEXT_AREA
];
7743 /* Skip over glyphs not having an object at the start of the row.
7744 These are special glyphs like truncation marks on terminal
7746 if (row
->displays_text_p
)
7748 && INTEGERP (glyph
->object
)
7749 && !EQ (stop
, glyph
->object
)
7750 && glyph
->charpos
< 0)
7752 *x
+= glyph
->pixel_width
;
7757 && !INTEGERP (glyph
->object
)
7758 && !EQ (stop
, glyph
->object
)
7759 && (!BUFFERP (glyph
->object
)
7760 || glyph
->charpos
< charpos
))
7762 *x
+= glyph
->pixel_width
;
7766 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7773 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7776 int *hpos
, *vpos
, *x
, *y
;
7781 int maybe_next_line_p
= 0;
7782 int line_start_position
;
7783 int yb
= window_text_bottom_y (w
);
7784 struct glyph_row
*row
, *best_row
;
7785 int row_vpos
, best_row_vpos
;
7788 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7789 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7793 if (row
->used
[TEXT_AREA
])
7794 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7796 line_start_position
= 0;
7798 if (line_start_position
> pos
)
7800 /* If the position sought is the end of the buffer,
7801 don't include the blank lines at the bottom of the window. */
7802 else if (line_start_position
== pos
7803 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7805 maybe_next_line_p
= 1;
7808 else if (line_start_position
> 0)
7811 best_row_vpos
= row_vpos
;
7814 if (row
->y
+ row
->height
>= yb
)
7821 /* Find the right column within BEST_ROW. */
7823 current_x
= best_row
->x
;
7824 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7826 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7827 int charpos
= glyph
->charpos
;
7829 if (BUFFERP (glyph
->object
))
7834 *vpos
= best_row_vpos
;
7839 else if (charpos
> pos
)
7842 else if (EQ (glyph
->object
, stop
))
7847 current_x
+= glyph
->pixel_width
;
7850 /* If we're looking for the end of the buffer,
7851 and we didn't find it in the line we scanned,
7852 use the start of the following line. */
7853 if (maybe_next_line_p
)
7858 current_x
= best_row
->x
;
7861 *vpos
= best_row_vpos
;
7862 *hpos
= lastcol
+ 1;
7871 /* Find the position of the glyph for position POS in OBJECT in
7872 window W's current matrix, and return in *X, *Y the pixel
7873 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
7875 RIGHT_P non-zero means return the position of the right edge of the
7876 glyph, RIGHT_P zero means return the left edge position.
7878 If no glyph for POS exists in the matrix, return the position of
7879 the glyph with the next smaller position that is in the matrix, if
7880 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7881 exists in the matrix, return the position of the glyph with the
7882 next larger position in OBJECT.
7884 Value is non-zero if a glyph was found. */
7887 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7891 int *hpos
, *vpos
, *x
, *y
;
7894 int yb
= window_text_bottom_y (w
);
7895 struct glyph_row
*r
;
7896 struct glyph
*best_glyph
= NULL
;
7897 struct glyph_row
*best_row
= NULL
;
7900 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7901 r
->enabled_p
&& r
->y
< yb
;
7904 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7905 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7908 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7909 if (EQ (g
->object
, object
))
7911 if (g
->charpos
== pos
)
7918 else if (best_glyph
== NULL
7919 || ((abs (g
->charpos
- pos
)
7920 < abs (best_glyph
->charpos
- pos
))
7923 : g
->charpos
> pos
)))
7937 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7941 *x
+= best_glyph
->pixel_width
;
7946 *vpos
= best_row
- w
->current_matrix
->rows
;
7949 return best_glyph
!= NULL
;
7953 /* Display the active region described by mouse_face_*
7954 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7957 show_mouse_face (dpyinfo
, draw
)
7958 struct x_display_info
*dpyinfo
;
7959 enum draw_glyphs_face draw
;
7961 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7962 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7964 if (/* If window is in the process of being destroyed, don't bother
7966 w
->current_matrix
!= NULL
7967 /* Don't update mouse highlight if hidden */
7968 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
7969 /* Recognize when we are called to operate on rows that don't exist
7970 anymore. This can happen when a window is split. */
7971 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7973 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7974 struct glyph_row
*row
, *first
, *last
;
7976 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7977 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7979 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7981 int start_hpos
, end_hpos
, start_x
;
7983 /* For all but the first row, the highlight starts at column 0. */
7986 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7987 start_x
= dpyinfo
->mouse_face_beg_x
;
7996 end_hpos
= dpyinfo
->mouse_face_end_col
;
7998 end_hpos
= row
->used
[TEXT_AREA
];
8000 if (end_hpos
> start_hpos
)
8002 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
8003 start_hpos
, end_hpos
, draw
, 0);
8006 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
8010 /* When we've written over the cursor, arrange for it to
8011 be displayed again. */
8012 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
8013 x_display_cursor (w
, 1,
8014 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
8015 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
8018 /* Change the mouse cursor. */
8019 if (draw
== DRAW_NORMAL_TEXT
)
8020 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8021 f
->output_data
.x
->text_cursor
);
8022 else if (draw
== DRAW_MOUSE_FACE
)
8023 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8024 f
->output_data
.x
->cross_cursor
);
8026 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8027 f
->output_data
.x
->nontext_cursor
);
8030 /* Clear out the mouse-highlighted active region.
8031 Redraw it un-highlighted first. Value is non-zero if mouse
8032 face was actually drawn unhighlighted. */
8035 clear_mouse_face (dpyinfo
)
8036 struct x_display_info
*dpyinfo
;
8040 if (!NILP (dpyinfo
->mouse_face_window
))
8042 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
8046 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
8047 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
8048 dpyinfo
->mouse_face_window
= Qnil
;
8049 dpyinfo
->mouse_face_overlay
= Qnil
;
8054 /* Clear any mouse-face on window W. This function is part of the
8055 redisplay interface, and is called from try_window_id and similar
8056 functions to ensure the mouse-highlight is off. */
8059 x_clear_mouse_face (w
)
8062 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
8066 XSETWINDOW (window
, w
);
8067 if (EQ (window
, dpyinfo
->mouse_face_window
))
8068 clear_mouse_face (dpyinfo
);
8073 /* Just discard the mouse face information for frame F, if any.
8074 This is used when the size of F is changed. */
8077 cancel_mouse_face (f
)
8081 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8083 window
= dpyinfo
->mouse_face_window
;
8084 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
8086 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
8087 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
8088 dpyinfo
->mouse_face_window
= Qnil
;
8093 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
8096 /* Try to determine frame pixel position and size of the glyph under
8097 frame pixel coordinates X/Y on frame F . Return the position and
8098 size in *RECT. Value is non-zero if we could compute these
8102 glyph_rect (f
, x
, y
, rect
)
8108 int part
, found
= 0;
8110 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
8113 struct window
*w
= XWINDOW (window
);
8114 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8115 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
8117 frame_to_window_pixel_xy (w
, &x
, &y
);
8119 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
8122 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
8123 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
8126 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
8129 rect
->width
= g
->pixel_width
;
8130 rect
->height
= r
->height
;
8131 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
8132 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
8142 /* Return the current position of the mouse.
8143 *FP should be a frame which indicates which display to ask about.
8145 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
8146 and *PART to the frame, window, and scroll bar part that the mouse
8147 is over. Set *X and *Y to the portion and whole of the mouse's
8148 position on the scroll bar.
8150 If the mouse movement started elsewhere, set *FP to the frame the
8151 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
8154 Set *TIME to the server time-stamp for the time at which the mouse
8155 was at this position.
8157 Don't store anything if we don't have a valid set of values to report.
8159 This clears the mouse_moved flag, so we can wait for the next mouse
8163 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
8166 Lisp_Object
*bar_window
;
8167 enum scroll_bar_part
*part
;
8169 unsigned long *time
;
8175 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
8176 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
8182 Window dummy_window
;
8185 Lisp_Object frame
, tail
;
8187 /* Clear the mouse-moved flag for every frame on this display. */
8188 FOR_EACH_FRAME (tail
, frame
)
8189 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
8190 XFRAME (frame
)->mouse_moved
= 0;
8192 last_mouse_scroll_bar
= Qnil
;
8194 /* Figure out which root window we're on. */
8195 XQueryPointer (FRAME_X_DISPLAY (*fp
),
8196 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
8198 /* The root window which contains the pointer. */
8201 /* Trash which we can't trust if the pointer is on
8202 a different screen. */
8205 /* The position on that root window. */
8208 /* More trash we can't trust. */
8211 /* Modifier keys and pointer buttons, about which
8213 (unsigned int *) &dummy
);
8215 /* Now we have a position on the root; find the innermost window
8216 containing the pointer. */
8220 int parent_x
= 0, parent_y
= 0;
8225 /* XTranslateCoordinates can get errors if the window
8226 structure is changing at the same time this function
8227 is running. So at least we must not crash from them. */
8229 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
8231 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
8232 && FRAME_LIVE_P (last_mouse_frame
))
8234 /* If mouse was grabbed on a frame, give coords for that frame
8235 even if the mouse is now outside it. */
8236 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8238 /* From-window, to-window. */
8239 root
, FRAME_X_WINDOW (last_mouse_frame
),
8241 /* From-position, to-position. */
8242 root_x
, root_y
, &win_x
, &win_y
,
8246 f1
= last_mouse_frame
;
8252 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8254 /* From-window, to-window. */
8257 /* From-position, to-position. */
8258 root_x
, root_y
, &win_x
, &win_y
,
8263 if (child
== None
|| child
== win
)
8271 /* Now we know that:
8272 win is the innermost window containing the pointer
8273 (XTC says it has no child containing the pointer),
8274 win_x and win_y are the pointer's position in it
8275 (XTC did this the last time through), and
8276 parent_x and parent_y are the pointer's position in win's parent.
8277 (They are what win_x and win_y were when win was child.
8278 If win is the root window, it has no parent, and
8279 parent_{x,y} are invalid, but that's okay, because we'll
8280 never use them in that case.) */
8282 /* Is win one of our frames? */
8283 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
8285 #ifdef USE_X_TOOLKIT
8286 /* If we end up with the menu bar window, say it's not
8289 && f1
->output_data
.x
->menubar_widget
8290 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
8292 #endif /* USE_X_TOOLKIT */
8295 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
8298 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
8300 /* If not, is it one of our scroll bars? */
8303 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
8307 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8313 if (f1
== 0 && insist
> 0)
8314 f1
= SELECTED_FRAME ();
8318 /* Ok, we found a frame. Store all the values.
8319 last_mouse_glyph is a rectangle used to reduce the
8320 generation of mouse events. To not miss any motion
8321 events, we must divide the frame into rectangles of the
8322 size of the smallest character that could be displayed
8323 on it, i.e. into the same rectangles that matrices on
8324 the frame are divided into. */
8326 int width
, height
, gx
, gy
;
8329 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
8330 last_mouse_glyph
= rect
;
8333 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8334 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8338 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8339 round down even for negative values. */
8344 gx
= (gx
+ width
- 1) / width
* width
;
8345 gy
= (gy
+ height
- 1) / height
* height
;
8347 last_mouse_glyph
.width
= width
;
8348 last_mouse_glyph
.height
= height
;
8349 last_mouse_glyph
.x
= gx
;
8350 last_mouse_glyph
.y
= gy
;
8356 XSETINT (*x
, win_x
);
8357 XSETINT (*y
, win_y
);
8358 *time
= last_mouse_movement_time
;
8367 #ifdef USE_X_TOOLKIT
8369 /* Atimer callback function for TIMER. Called every 0.1s to process
8370 Xt timeouts, if needed. We must avoid calling XtAppPending as
8371 much as possible because that function does an implicit XFlush
8372 that slows us down. */
8375 x_process_timeouts (timer
)
8376 struct atimer
*timer
;
8378 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
8381 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8382 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8387 #endif /* USE_X_TOOLKIT */
8390 /* Scroll bar support. */
8392 /* Given an X window ID, find the struct scroll_bar which manages it.
8393 This can be called in GC, so we have to make sure to strip off mark
8396 static struct scroll_bar
*
8397 x_window_to_scroll_bar (window_id
)
8402 for (tail
= Vframe_list
;
8403 XGCTYPE (tail
) == Lisp_Cons
;
8406 Lisp_Object frame
, bar
, condemned
;
8408 frame
= XCAR (tail
);
8409 /* All elements of Vframe_list should be frames. */
8410 if (! GC_FRAMEP (frame
))
8413 /* Scan this frame's scroll bar list for a scroll bar with the
8415 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8416 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8417 /* This trick allows us to search both the ordinary and
8418 condemned scroll bar lists with one loop. */
8419 ! GC_NILP (bar
) || (bar
= condemned
,
8422 bar
= XSCROLL_BAR (bar
)->next
)
8423 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8424 return XSCROLL_BAR (bar
);
8431 #if defined USE_LUCID
8433 /* Return the Lucid menu bar WINDOW is part of. Return null
8434 if WINDOW is not part of a menu bar. */
8437 x_window_to_menu_bar (window
)
8442 for (tail
= Vframe_list
;
8443 XGCTYPE (tail
) == Lisp_Cons
;
8446 Lisp_Object frame
= XCAR (tail
);
8447 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8449 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8456 #endif /* USE_LUCID */
8459 /************************************************************************
8461 ************************************************************************/
8463 #ifdef USE_TOOLKIT_SCROLL_BARS
8465 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8466 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8467 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8468 struct scroll_bar
*));
8469 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8473 /* Id of action hook installed for scroll bars. */
8475 static XtActionHookId action_hook_id
;
8477 /* Lisp window being scrolled. Set when starting to interact with
8478 a toolkit scroll bar, reset to nil when ending the interaction. */
8480 static Lisp_Object window_being_scrolled
;
8482 /* Last scroll bar part sent in xm_scroll_callback. */
8484 static int last_scroll_bar_part
;
8486 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8487 that movements of 1/20 of the screen size are mapped to up/down. */
8489 static Boolean xaw3d_arrow_scroll
;
8491 /* Whether the drag scrolling maintains the mouse at the top of the
8492 thumb. If not, resizing the thumb needs to be done more carefully
8493 to avoid jerkyness. */
8495 static Boolean xaw3d_pick_top
;
8498 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8499 bars are used.. The hook is responsible for detecting when
8500 the user ends an interaction with the scroll bar, and generates
8501 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
8504 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8507 XtPointer client_data
;
8511 Cardinal
*num_params
;
8517 scroll_bar_p
= XmIsScrollBar (widget
);
8518 end_action
= "Release";
8519 #else /* !USE_MOTIF i.e. use Xaw */
8520 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8521 end_action
= "EndScroll";
8522 #endif /* USE_MOTIF */
8525 && strcmp (action_name
, end_action
) == 0
8526 && WINDOWP (window_being_scrolled
))
8530 x_send_scroll_bar_event (window_being_scrolled
,
8531 scroll_bar_end_scroll
, 0, 0);
8532 w
= XWINDOW (window_being_scrolled
);
8533 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8534 window_being_scrolled
= Qnil
;
8535 last_scroll_bar_part
= -1;
8537 /* Xt timeouts no longer needed. */
8538 toolkit_scroll_bar_interaction
= 0;
8542 /* A vector of windows used for communication between
8543 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8545 static struct window
**scroll_bar_windows
;
8546 static int scroll_bar_windows_size
;
8549 /* Send a client message with message type Xatom_Scrollbar for a
8550 scroll action to the frame of WINDOW. PART is a value identifying
8551 the part of the scroll bar that was clicked on. PORTION is the
8552 amount to scroll of a whole of WHOLE. */
8555 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8557 int part
, portion
, whole
;
8560 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8561 struct window
*w
= XWINDOW (window
);
8562 struct frame
*f
= XFRAME (w
->frame
);
8567 /* Construct a ClientMessage event to send to the frame. */
8568 ev
->type
= ClientMessage
;
8569 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8570 ev
->display
= FRAME_X_DISPLAY (f
);
8571 ev
->window
= FRAME_X_WINDOW (f
);
8574 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8575 not enough to store a pointer or Lisp_Object on a 64 bit system.
8576 So, store the window in scroll_bar_windows and pass the index
8577 into that array in the event. */
8578 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8579 if (scroll_bar_windows
[i
] == NULL
)
8582 if (i
== scroll_bar_windows_size
)
8584 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8585 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8586 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8588 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8590 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8591 scroll_bar_windows_size
= new_size
;
8594 scroll_bar_windows
[i
] = w
;
8595 ev
->data
.l
[0] = (long) i
;
8596 ev
->data
.l
[1] = (long) part
;
8597 ev
->data
.l
[2] = (long) 0;
8598 ev
->data
.l
[3] = (long) portion
;
8599 ev
->data
.l
[4] = (long) whole
;
8601 /* Make Xt timeouts work while the scroll bar is active. */
8602 toolkit_scroll_bar_interaction
= 1;
8604 /* Setting the event mask to zero means that the message will
8605 be sent to the client that created the window, and if that
8606 window no longer exists, no event will be sent. */
8607 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8612 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8616 x_scroll_bar_to_input_event (event
, ievent
)
8618 struct input_event
*ievent
;
8620 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8625 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8626 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8628 XSETWINDOW (window
, w
);
8629 f
= XFRAME (w
->frame
);
8631 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
8632 ievent
->frame_or_window
= window
;
8634 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8635 ievent
->part
= ev
->data
.l
[1];
8636 ievent
->code
= ev
->data
.l
[2];
8637 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8638 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8639 ievent
->modifiers
= 0;
8645 /* Minimum and maximum values used for Motif scroll bars. */
8648 #define XM_SB_MAX 10000000
8649 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8652 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8653 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8654 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
8657 xm_scroll_callback (widget
, client_data
, call_data
)
8659 XtPointer client_data
, call_data
;
8661 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8662 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8663 int part
= -1, whole
= 0, portion
= 0;
8667 case XmCR_DECREMENT
:
8668 bar
->dragging
= Qnil
;
8669 part
= scroll_bar_up_arrow
;
8672 case XmCR_INCREMENT
:
8673 bar
->dragging
= Qnil
;
8674 part
= scroll_bar_down_arrow
;
8677 case XmCR_PAGE_DECREMENT
:
8678 bar
->dragging
= Qnil
;
8679 part
= scroll_bar_above_handle
;
8682 case XmCR_PAGE_INCREMENT
:
8683 bar
->dragging
= Qnil
;
8684 part
= scroll_bar_below_handle
;
8688 bar
->dragging
= Qnil
;
8689 part
= scroll_bar_to_top
;
8692 case XmCR_TO_BOTTOM
:
8693 bar
->dragging
= Qnil
;
8694 part
= scroll_bar_to_bottom
;
8700 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8701 && XINT (bar
->dragging
) <= cs
->value
);
8703 /* Get the slider size. */
8705 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8708 whole
= XM_SB_RANGE
- slider_size
;
8709 portion
= min (cs
->value
- XM_SB_MIN
, whole
);
8710 part
= scroll_bar_handle
;
8711 bar
->dragging
= make_number (cs
->value
);
8715 case XmCR_VALUE_CHANGED
:
8721 window_being_scrolled
= bar
->window
;
8722 last_scroll_bar_part
= part
;
8723 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8728 #else /* !USE_MOTIF, i.e. Xaw. */
8731 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8732 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8733 scroll bar struct. CALL_DATA is a pointer to a float saying where
8737 xaw_jump_callback (widget
, client_data
, call_data
)
8739 XtPointer client_data
, call_data
;
8741 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8742 float top
= *(float *) call_data
;
8744 int whole
, portion
, height
;
8747 /* Get the size of the thumb, a value between 0 and 1. */
8749 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8753 portion
= shown
< 1 ? top
* whole
: 0;
8755 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8756 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8757 the bottom, so we force the scrolling whenever we see that we're
8758 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8759 we try to ensure that we always stay two pixels away from the
8761 part
= scroll_bar_down_arrow
;
8763 part
= scroll_bar_handle
;
8765 window_being_scrolled
= bar
->window
;
8766 bar
->dragging
= make_number (portion
);
8767 last_scroll_bar_part
= part
;
8768 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8772 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8773 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8774 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8775 the scroll bar. CALL_DATA is an integer specifying the action that
8776 has taken place. It's magnitude is in the range 0..height of the
8777 scroll bar. Negative values mean scroll towards buffer start.
8778 Values < height of scroll bar mean line-wise movement. */
8781 xaw_scroll_callback (widget
, client_data
, call_data
)
8783 XtPointer client_data
, call_data
;
8785 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8786 int position
= (int) call_data
;
8790 /* Get the height of the scroll bar. */
8792 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8795 if (abs (position
) >= height
)
8796 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8798 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8799 it maps line-movement to call_data = max(5, height/20). */
8800 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8801 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8803 part
= scroll_bar_move_ratio
;
8805 window_being_scrolled
= bar
->window
;
8806 bar
->dragging
= Qnil
;
8807 last_scroll_bar_part
= part
;
8808 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8812 #endif /* not USE_MOTIF */
8815 /* Create the widget for scroll bar BAR on frame F. Record the widget
8816 and X window of the scroll bar in BAR. */
8819 x_create_toolkit_scroll_bar (f
, bar
)
8821 struct scroll_bar
*bar
;
8827 char *scroll_bar_name
= "verticalScrollBar";
8828 unsigned long pixel
;
8833 /* Set resources. Create the widget. */
8834 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8835 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8836 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8837 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8838 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8839 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8840 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8842 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8845 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8849 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8852 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8856 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8857 scroll_bar_name
, av
, ac
);
8859 /* Add one callback for everything that can happen. */
8860 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8862 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8864 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8866 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8868 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8870 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8872 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8875 /* Realize the widget. Only after that is the X window created. */
8876 XtRealizeWidget (widget
);
8878 /* Set the cursor to an arrow. I didn't find a resource to do that.
8879 And I'm wondering why it hasn't an arrow cursor by default. */
8880 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8881 f
->output_data
.x
->nontext_cursor
);
8883 #else /* !USE_MOTIF i.e. use Xaw */
8885 /* Set resources. Create the widget. The background of the
8886 Xaw3d scroll bar widget is a little bit light for my taste.
8887 We don't alter it here to let users change it according
8888 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8889 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8890 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8891 /* For smoother scrolling with Xaw3d -sm */
8892 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8894 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8897 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8901 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8904 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8908 /* Top/bottom shadow colors. */
8910 /* Allocate them, if necessary. */
8911 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
8913 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8914 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8915 &pixel
, 1.2, 0x8000))
8917 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
8919 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8921 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8922 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8923 &pixel
, 0.6, 0x4000))
8925 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
8928 /* Tell the toolkit about them. */
8929 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
8930 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8931 /* We tried to allocate a color for the top/bottom shadow, and
8932 failed, so tell Xaw3d to use dithering instead. */
8934 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
8938 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
8939 be more consistent with other emacs 3d colors, and since Xaw3d is
8940 not good at dealing with allocation failure. */
8942 /* This tells Xaw3d to use real colors instead of dithering for
8944 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
8947 /* Specify the colors. */
8948 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
8951 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
8954 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
8957 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
8962 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8963 f
->output_data
.x
->edit_widget
, av
, ac
);
8967 char *val
= initial
;
8968 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8969 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8971 { /* ARROW_SCROLL */
8972 xaw3d_arrow_scroll
= True
;
8973 /* Isn't that just a personal preference ? -sm */
8974 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8978 /* Define callbacks. */
8979 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8980 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8983 /* Realize the widget. Only after that is the X window created. */
8984 XtRealizeWidget (widget
);
8986 #endif /* !USE_MOTIF */
8988 /* Install an action hook that lets us detect when the user
8989 finishes interacting with a scroll bar. */
8990 if (action_hook_id
== 0)
8991 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8993 /* Remember X window and widget in the scroll bar vector. */
8994 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8995 xwindow
= XtWindow (widget
);
8996 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
9002 /* Set the thumb size and position of scroll bar BAR. We are currently
9003 displaying PORTION out of a whole WHOLE, and our position POSITION. */
9006 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
9007 struct scroll_bar
*bar
;
9008 int portion
, position
, whole
;
9010 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9011 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
9018 /* We use an estimate of 30 chars per line rather than the real
9019 `portion' value. This has the disadvantage that the thumb size
9020 is not very representative, but it makes our life a lot easier.
9021 Otherwise, we have to constantly adjust the thumb size, which
9022 we can't always do quickly enough: while dragging, the size of
9023 the thumb might prevent the user from dragging the thumb all the
9024 way to the end. but Motif and some versions of Xaw3d don't allow
9025 updating the thumb size while dragging. Also, even if we can update
9026 its size, the update will often happen too late.
9027 If you don't believe it, check out revision 1.650 of xterm.c to see
9028 what hoops we were going through and the still poor behavior we got. */
9029 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
9030 /* When the thumb is at the bottom, position == whole.
9031 So we need to increase `whole' to make space for the thumb. */
9038 top
= (float) position
/ whole
;
9039 shown
= (float) portion
/ whole
;
9042 if (NILP (bar
->dragging
))
9046 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
9047 is the scroll bar's maximum and MIN is the scroll bar's minimum
9049 size
= shown
* XM_SB_RANGE
;
9050 size
= min (size
, XM_SB_RANGE
);
9051 size
= max (size
, 1);
9053 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
9054 value
= top
* XM_SB_RANGE
;
9055 value
= min (value
, XM_SB_MAX
- size
);
9056 value
= max (value
, XM_SB_MIN
);
9058 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
9060 #else /* !USE_MOTIF i.e. use Xaw */
9066 top
= (float) position
/ whole
;
9067 shown
= (float) portion
/ whole
;
9071 float old_top
, old_shown
;
9073 XtVaGetValues (widget
,
9074 XtNtopOfThumb
, &old_top
,
9075 XtNshown
, &old_shown
,
9079 /* Massage the top+shown values. */
9080 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
9081 top
= max (0, min (1, top
));
9084 /* Keep two pixels available for moving the thumb down. */
9085 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
9087 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
9088 check that your system's configuration file contains a define
9089 for `NARROWPROTO'. See s/freebsd.h for an example. */
9090 if (top
!= old_top
|| shown
!= old_shown
)
9092 if (NILP (bar
->dragging
))
9093 XawScrollbarSetThumb (widget
, top
, shown
);
9097 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
9098 int scroll_mode
= 0;
9100 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
9101 if (xaw3d_arrow_scroll
)
9103 /* Xaw3d stupidly ignores resize requests while dragging
9104 so we have to make it believe it's not in dragging mode. */
9105 scroll_mode
= sb
->scrollbar
.scroll_mode
;
9106 if (scroll_mode
== 2)
9107 sb
->scrollbar
.scroll_mode
= 0;
9110 /* Try to make the scrolling a tad smoother. */
9111 if (!xaw3d_pick_top
)
9112 shown
= min (shown
, old_shown
);
9114 XawScrollbarSetThumb (widget
, top
, shown
);
9117 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
9118 sb
->scrollbar
.scroll_mode
= scroll_mode
;
9123 #endif /* !USE_MOTIF */
9128 #endif /* USE_TOOLKIT_SCROLL_BARS */
9132 /************************************************************************
9133 Scroll bars, general
9134 ************************************************************************/
9136 /* Create a scroll bar and return the scroll bar vector for it. W is
9137 the Emacs window on which to create the scroll bar. TOP, LEFT,
9138 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
9141 static struct scroll_bar
*
9142 x_scroll_bar_create (w
, top
, left
, width
, height
)
9144 int top
, left
, width
, height
;
9146 struct frame
*f
= XFRAME (w
->frame
);
9147 struct scroll_bar
*bar
9148 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
9152 #ifdef USE_TOOLKIT_SCROLL_BARS
9153 x_create_toolkit_scroll_bar (f
, bar
);
9154 #else /* not USE_TOOLKIT_SCROLL_BARS */
9156 XSetWindowAttributes a
;
9160 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
9161 if (a
.background_pixel
== -1)
9162 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
9164 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
9165 | ButtonMotionMask
| PointerMotionHintMask
9167 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
9169 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
9171 /* Clear the area of W that will serve as a scroll bar. This is
9172 for the case that a window has been split horizontally. In
9173 this case, no clear_frame is generated to reduce flickering. */
9174 if (width
> 0 && height
> 0)
9175 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9177 window_box_height (w
), False
);
9179 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9180 /* Position and size of scroll bar. */
9181 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9183 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9185 /* Border width, depth, class, and visual. */
9192 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
9194 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9196 XSETWINDOW (bar
->window
, w
);
9197 XSETINT (bar
->top
, top
);
9198 XSETINT (bar
->left
, left
);
9199 XSETINT (bar
->width
, width
);
9200 XSETINT (bar
->height
, height
);
9201 XSETINT (bar
->start
, 0);
9202 XSETINT (bar
->end
, 0);
9203 bar
->dragging
= Qnil
;
9205 /* Add bar to its frame's list of scroll bars. */
9206 bar
->next
= FRAME_SCROLL_BARS (f
);
9208 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9209 if (!NILP (bar
->next
))
9210 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9212 /* Map the window/widget. */
9213 #ifdef USE_TOOLKIT_SCROLL_BARS
9215 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
9216 XtConfigureWidget (scroll_bar
,
9217 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9219 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9220 max (height
, 1), 0);
9221 XtMapWidget (scroll_bar
);
9223 #else /* not USE_TOOLKIT_SCROLL_BARS */
9224 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9225 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9232 /* Draw BAR's handle in the proper position.
9234 If the handle is already drawn from START to END, don't bother
9235 redrawing it, unless REBUILD is non-zero; in that case, always
9236 redraw it. (REBUILD is handy for drawing the handle after expose
9239 Normally, we want to constrain the start and end of the handle to
9240 fit inside its rectangle, but if the user is dragging the scroll
9241 bar handle, we want to let them drag it down all the way, so that
9242 the bar's top is as far down as it goes; otherwise, there's no way
9243 to move to the very end of the buffer. */
9245 #ifndef USE_TOOLKIT_SCROLL_BARS
9248 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
9249 struct scroll_bar
*bar
;
9253 int dragging
= ! NILP (bar
->dragging
);
9254 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9255 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9256 GC gc
= f
->output_data
.x
->normal_gc
;
9258 /* If the display is already accurate, do nothing. */
9260 && start
== XINT (bar
->start
)
9261 && end
== XINT (bar
->end
))
9267 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
9268 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9269 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9271 /* Make sure the values are reasonable, and try to preserve
9272 the distance between start and end. */
9274 int length
= end
- start
;
9278 else if (start
> top_range
)
9280 end
= start
+ length
;
9284 else if (end
> top_range
&& ! dragging
)
9288 /* Store the adjusted setting in the scroll bar. */
9289 XSETINT (bar
->start
, start
);
9290 XSETINT (bar
->end
, end
);
9292 /* Clip the end position, just for display. */
9293 if (end
> top_range
)
9296 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
9297 below top positions, to make sure the handle is always at least
9298 that many pixels tall. */
9299 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
9301 /* Draw the empty space above the handle. Note that we can't clear
9302 zero-height areas; that means "clear to end of window." */
9304 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9305 /* x, y, width, height, and exposures. */
9306 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9307 VERTICAL_SCROLL_BAR_TOP_BORDER
,
9308 inside_width
, start
,
9311 /* Change to proper foreground color if one is specified. */
9312 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9313 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9314 f
->output_data
.x
->scroll_bar_foreground_pixel
);
9316 /* Draw the handle itself. */
9317 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9318 /* x, y, width, height */
9319 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9320 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
9321 inside_width
, end
- start
);
9323 /* Restore the foreground color of the GC if we changed it above. */
9324 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9325 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9326 f
->output_data
.x
->foreground_pixel
);
9328 /* Draw the empty space below the handle. Note that we can't
9329 clear zero-height areas; that means "clear to end of window." */
9330 if (end
< inside_height
)
9331 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9332 /* x, y, width, height, and exposures. */
9333 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9334 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
9335 inside_width
, inside_height
- end
,
9343 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9345 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
9349 x_scroll_bar_remove (bar
)
9350 struct scroll_bar
*bar
;
9352 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9355 #ifdef USE_TOOLKIT_SCROLL_BARS
9356 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
9358 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9361 /* Disassociate this scroll bar from its window. */
9362 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
9368 /* Set the handle of the vertical scroll bar for WINDOW to indicate
9369 that we are displaying PORTION characters out of a total of WHOLE
9370 characters, starting at POSITION. If WINDOW has no scroll bar,
9374 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
9376 int portion
, whole
, position
;
9378 struct frame
*f
= XFRAME (w
->frame
);
9379 struct scroll_bar
*bar
;
9380 int top
, height
, left
, sb_left
, width
, sb_width
;
9381 int window_x
, window_y
, window_width
, window_height
;
9383 /* Get window dimensions. */
9384 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9386 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9387 height
= window_height
;
9389 /* Compute the left edge of the scroll bar area. */
9390 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9391 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
9393 left
= XFASTINT (w
->left
);
9394 left
*= CANON_X_UNIT (f
);
9395 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
9397 /* Compute the width of the scroll bar which might be less than
9398 the width of the area reserved for the scroll bar. */
9399 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
9400 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
9404 /* Compute the left edge of the scroll bar. */
9405 #ifdef USE_TOOLKIT_SCROLL_BARS
9406 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9407 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
9409 sb_left
= left
+ (width
- sb_width
) / 2;
9411 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9412 sb_left
= left
+ width
- sb_width
;
9417 /* Does the scroll bar exist yet? */
9418 if (NILP (w
->vertical_scroll_bar
))
9420 if (width
> 0 && height
> 0)
9423 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9424 left
, top
, width
, height
, False
);
9428 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9432 /* It may just need to be moved and resized. */
9433 unsigned int mask
= 0;
9435 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9439 if (sb_left
!= XINT (bar
->left
))
9441 if (top
!= XINT (bar
->top
))
9443 if (sb_width
!= XINT (bar
->width
))
9445 if (height
!= XINT (bar
->height
))
9448 #ifdef USE_TOOLKIT_SCROLL_BARS
9450 /* Since toolkit scroll bars are smaller than the space reserved
9451 for them on the frame, we have to clear "under" them. */
9452 if (width
> 0 && height
> 0)
9453 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9454 left
, top
, width
, height
, False
);
9456 /* Move/size the scroll bar widget. */
9458 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9459 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9461 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9462 max (height
, 1), 0);
9464 #else /* not USE_TOOLKIT_SCROLL_BARS */
9466 /* Clear areas not covered by the scroll bar because of
9467 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9468 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9470 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9471 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9473 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9474 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9475 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9479 /* Clear areas not covered by the scroll bar because it's not as
9480 wide as the area reserved for it. This makes sure a
9481 previous mode line display is cleared after C-x 2 C-x 1, for
9484 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9485 int rest
= area_width
- sb_width
;
9486 if (rest
> 0 && height
> 0)
9488 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
9489 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9490 left
+ area_width
- rest
, top
,
9491 rest
, height
, False
);
9493 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9494 left
, top
, rest
, height
, False
);
9498 /* Move/size the scroll bar window. */
9503 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9505 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9507 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9511 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9513 /* Remember new settings. */
9514 XSETINT (bar
->left
, sb_left
);
9515 XSETINT (bar
->top
, top
);
9516 XSETINT (bar
->width
, sb_width
);
9517 XSETINT (bar
->height
, height
);
9522 #ifdef USE_TOOLKIT_SCROLL_BARS
9523 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9524 #else /* not USE_TOOLKIT_SCROLL_BARS */
9525 /* Set the scroll bar's current state, unless we're currently being
9527 if (NILP (bar
->dragging
))
9529 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9532 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9535 int start
= ((double) position
* top_range
) / whole
;
9536 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9537 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9540 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9542 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9546 /* The following three hooks are used when we're doing a thorough
9547 redisplay of the frame. We don't explicitly know which scroll bars
9548 are going to be deleted, because keeping track of when windows go
9549 away is a real pain - "Can you say set-window-configuration, boys
9550 and girls?" Instead, we just assert at the beginning of redisplay
9551 that *all* scroll bars are to be removed, and then save a scroll bar
9552 from the fiery pit when we actually redisplay its window. */
9554 /* Arrange for all scroll bars on FRAME to be removed at the next call
9555 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9556 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9559 XTcondemn_scroll_bars (frame
)
9562 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9563 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9566 bar
= FRAME_SCROLL_BARS (frame
);
9567 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9568 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9569 XSCROLL_BAR (bar
)->prev
= Qnil
;
9570 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9571 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9572 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9577 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9578 Note that WINDOW isn't necessarily condemned at all. */
9581 XTredeem_scroll_bar (window
)
9582 struct window
*window
;
9584 struct scroll_bar
*bar
;
9587 /* We can't redeem this window's scroll bar if it doesn't have one. */
9588 if (NILP (window
->vertical_scroll_bar
))
9591 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9593 /* Unlink it from the condemned list. */
9594 f
= XFRAME (WINDOW_FRAME (window
));
9595 if (NILP (bar
->prev
))
9597 /* If the prev pointer is nil, it must be the first in one of
9599 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9600 /* It's not condemned. Everything's fine. */
9602 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9603 window
->vertical_scroll_bar
))
9604 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9606 /* If its prev pointer is nil, it must be at the front of
9607 one or the other! */
9611 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9613 if (! NILP (bar
->next
))
9614 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9616 bar
->next
= FRAME_SCROLL_BARS (f
);
9618 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9619 if (! NILP (bar
->next
))
9620 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9623 /* Remove all scroll bars on FRAME that haven't been saved since the
9624 last call to `*condemn_scroll_bars_hook'. */
9627 XTjudge_scroll_bars (f
)
9630 Lisp_Object bar
, next
;
9632 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9634 /* Clear out the condemned list now so we won't try to process any
9635 more events on the hapless scroll bars. */
9636 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9638 for (; ! NILP (bar
); bar
= next
)
9640 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9642 x_scroll_bar_remove (b
);
9645 b
->next
= b
->prev
= Qnil
;
9648 /* Now there should be no references to the condemned scroll bars,
9649 and they should get garbage-collected. */
9653 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9654 is a no-op when using toolkit scroll bars.
9656 This may be called from a signal handler, so we have to ignore GC
9660 x_scroll_bar_expose (bar
, event
)
9661 struct scroll_bar
*bar
;
9664 #ifndef USE_TOOLKIT_SCROLL_BARS
9666 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9667 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9668 GC gc
= f
->output_data
.x
->normal_gc
;
9669 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9673 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9675 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9676 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9678 /* x, y, width, height */
9680 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9681 XINT (bar
->height
) - 1);
9685 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9688 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9689 is set to something other than NO_EVENT, it is enqueued.
9691 This may be called from a signal handler, so we have to ignore GC
9694 #ifndef USE_TOOLKIT_SCROLL_BARS
9697 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9698 struct scroll_bar
*bar
;
9700 struct input_event
*emacs_event
;
9702 if (! GC_WINDOWP (bar
->window
))
9705 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
9706 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9707 emacs_event
->modifiers
9708 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9709 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9710 event
->xbutton
.state
)
9711 | (event
->type
== ButtonRelease
9714 emacs_event
->frame_or_window
= bar
->window
;
9715 emacs_event
->arg
= Qnil
;
9716 emacs_event
->timestamp
= event
->xbutton
.time
;
9719 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9721 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9724 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9725 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9728 if (y
> top_range
) y
= top_range
;
9730 if (y
< XINT (bar
->start
))
9731 emacs_event
->part
= scroll_bar_above_handle
;
9732 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9733 emacs_event
->part
= scroll_bar_handle
;
9735 emacs_event
->part
= scroll_bar_below_handle
;
9737 /* Just because the user has clicked on the handle doesn't mean
9738 they want to drag it. Lisp code needs to be able to decide
9739 whether or not we're dragging. */
9741 /* If the user has just clicked on the handle, record where they're
9743 if (event
->type
== ButtonPress
9744 && emacs_event
->part
== scroll_bar_handle
)
9745 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9748 /* If the user has released the handle, set it to its final position. */
9749 if (event
->type
== ButtonRelease
9750 && ! NILP (bar
->dragging
))
9752 int new_start
= y
- XINT (bar
->dragging
);
9753 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9755 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9756 bar
->dragging
= Qnil
;
9759 /* Same deal here as the other #if 0. */
9761 /* Clicks on the handle are always reported as occurring at the top of
9763 if (emacs_event
->part
== scroll_bar_handle
)
9764 emacs_event
->x
= bar
->start
;
9766 XSETINT (emacs_event
->x
, y
);
9768 XSETINT (emacs_event
->x
, y
);
9771 XSETINT (emacs_event
->y
, top_range
);
9775 /* Handle some mouse motion while someone is dragging the scroll bar.
9777 This may be called from a signal handler, so we have to ignore GC
9781 x_scroll_bar_note_movement (bar
, event
)
9782 struct scroll_bar
*bar
;
9785 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9787 last_mouse_movement_time
= event
->xmotion
.time
;
9790 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9792 /* If we're dragging the bar, display it. */
9793 if (! GC_NILP (bar
->dragging
))
9795 /* Where should the handle be now? */
9796 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9798 if (new_start
!= XINT (bar
->start
))
9800 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9802 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9807 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9809 /* Return information to the user about the current position of the mouse
9810 on the scroll bar. */
9813 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9815 Lisp_Object
*bar_window
;
9816 enum scroll_bar_part
*part
;
9818 unsigned long *time
;
9820 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9821 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9822 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9824 Window dummy_window
;
9826 unsigned int dummy_mask
;
9830 /* Get the mouse's position relative to the scroll bar window, and
9832 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9834 /* Root, child, root x and root y. */
9835 &dummy_window
, &dummy_window
,
9836 &dummy_coord
, &dummy_coord
,
9838 /* Position relative to scroll bar. */
9841 /* Mouse buttons and modifier keys. */
9848 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9851 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9853 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9855 if (! NILP (bar
->dragging
))
9856 win_y
-= XINT (bar
->dragging
);
9860 if (win_y
> top_range
)
9864 *bar_window
= bar
->window
;
9866 if (! NILP (bar
->dragging
))
9867 *part
= scroll_bar_handle
;
9868 else if (win_y
< XINT (bar
->start
))
9869 *part
= scroll_bar_above_handle
;
9870 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9871 *part
= scroll_bar_handle
;
9873 *part
= scroll_bar_below_handle
;
9875 XSETINT (*x
, win_y
);
9876 XSETINT (*y
, top_range
);
9879 last_mouse_scroll_bar
= Qnil
;
9882 *time
= last_mouse_movement_time
;
9888 /* The screen has been cleared so we may have changed foreground or
9889 background colors, and the scroll bars may need to be redrawn.
9890 Clear out the scroll bars, and ask for expose events, so we can
9894 x_scroll_bar_clear (f
)
9897 #ifndef USE_TOOLKIT_SCROLL_BARS
9900 /* We can have scroll bars even if this is 0,
9901 if we just turned off scroll bar mode.
9902 But in that case we should not clear them. */
9903 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9904 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9905 bar
= XSCROLL_BAR (bar
)->next
)
9906 XClearArea (FRAME_X_DISPLAY (f
),
9907 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9909 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9912 /* This processes Expose events from the menu-bar specific X event
9913 loop in xmenu.c. This allows to redisplay the frame if necessary
9914 when handling menu-bar or pop-up items. */
9917 process_expose_from_menu (event
)
9921 struct x_display_info
*dpyinfo
;
9922 int frame_exposed_p
= 0;
9926 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9927 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9930 if (f
->async_visible
== 0)
9932 f
->async_visible
= 1;
9933 f
->async_iconified
= 0;
9934 f
->output_data
.x
->has_been_visible
= 1;
9935 SET_FRAME_GARBAGED (f
);
9939 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9940 event
.xexpose
.x
, event
.xexpose
.y
,
9941 event
.xexpose
.width
, event
.xexpose
.height
);
9942 frame_exposed_p
= 1;
9947 struct scroll_bar
*bar
9948 = x_window_to_scroll_bar (event
.xexpose
.window
);
9951 x_scroll_bar_expose (bar
, &event
);
9955 return frame_exposed_p
;
9958 /* Define a queue to save up SelectionRequest events for later handling. */
9960 struct selection_event_queue
9963 struct selection_event_queue
*next
;
9966 static struct selection_event_queue
*queue
;
9968 /* Nonzero means queue up certain events--don't process them yet. */
9970 static int x_queue_selection_requests
;
9972 /* Queue up an X event *EVENT, to be processed later. */
9975 x_queue_event (f
, event
)
9979 struct selection_event_queue
*queue_tmp
9980 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9982 if (queue_tmp
!= NULL
)
9984 queue_tmp
->event
= *event
;
9985 queue_tmp
->next
= queue
;
9990 /* Take all the queued events and put them back
9991 so that they get processed afresh. */
9994 x_unqueue_events (display
)
9997 while (queue
!= NULL
)
9999 struct selection_event_queue
*queue_tmp
= queue
;
10000 XPutBackEvent (display
, &queue_tmp
->event
);
10001 queue
= queue_tmp
->next
;
10002 xfree ((char *)queue_tmp
);
10006 /* Start queuing SelectionRequest events. */
10009 x_start_queuing_selection_requests (display
)
10012 x_queue_selection_requests
++;
10015 /* Stop queuing SelectionRequest events. */
10018 x_stop_queuing_selection_requests (display
)
10021 x_queue_selection_requests
--;
10022 x_unqueue_events (display
);
10025 /* The main X event-reading loop - XTread_socket. */
10028 /* Time stamp of enter window event. This is only used by XTread_socket,
10029 but we have to put it out here, since static variables within functions
10030 sometimes don't work. */
10032 static Time enter_timestamp
;
10035 /* This holds the state XLookupString needs to implement dead keys
10036 and other tricks known as "compose processing". _X Window System_
10037 says that a portable program can't use this, but Stephen Gildea assures
10038 me that letting the compiler initialize it to zeros will work okay.
10040 This must be defined outside of XTread_socket, for the same reasons
10041 given for enter_timestamp, above. */
10043 static XComposeStatus compose_status
;
10045 /* Record the last 100 characters stored
10046 to help debug the loss-of-chars-during-GC problem. */
10048 static int temp_index
;
10049 static short temp_buffer
[100];
10051 /* Set this to nonzero to fake an "X I/O error"
10052 on a particular display. */
10054 struct x_display_info
*XTread_socket_fake_io_error
;
10056 /* When we find no input here, we occasionally do a no-op command
10057 to verify that the X server is still running and we can still talk with it.
10058 We try all the open displays, one by one.
10059 This variable is used for cycling thru the displays. */
10061 static struct x_display_info
*next_noop_dpyinfo
;
10063 #define SET_SAVED_MENU_EVENT(size) \
10066 if (f->output_data.x->saved_menu_event == 0) \
10067 f->output_data.x->saved_menu_event \
10068 = (XEvent *) xmalloc (sizeof (XEvent)); \
10069 bcopy (&event, f->output_data.x->saved_menu_event, size); \
10070 if (numchars >= 1) \
10072 bufp->kind = MENU_BAR_ACTIVATE_EVENT; \
10073 XSETFRAME (bufp->frame_or_window, f); \
10074 bufp->arg = Qnil; \
10082 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
10083 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
10085 /* Read events coming from the X server.
10086 This routine is called by the SIGIO handler.
10087 We return as soon as there are no more events to be read.
10089 Events representing keys are stored in buffer BUFP,
10090 which can hold up to NUMCHARS characters.
10091 We return the number of characters stored into the buffer,
10092 thus pretending to be `read'.
10094 EXPECTED is nonzero if the caller knows input is available. */
10097 XTread_socket (sd
, bufp
, numchars
, expected
)
10099 /* register */ struct input_event
*bufp
;
10100 /* register */ int numchars
;
10107 int event_found
= 0;
10108 struct x_display_info
*dpyinfo
;
10109 struct coding_system coding
;
10111 if (interrupt_input_blocked
)
10113 interrupt_input_pending
= 1;
10117 interrupt_input_pending
= 0;
10120 /* So people can tell when we have read the available input. */
10121 input_signal_count
++;
10124 abort (); /* Don't think this happens. */
10128 /* Find the display we are supposed to read input for.
10129 It's the one communicating on descriptor SD. */
10130 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
10132 #if 0 /* This ought to be unnecessary; let's verify it. */
10134 /* If available, Xlib uses FIOSNBIO to make the socket
10135 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
10136 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
10137 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
10138 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
10139 #endif /* ! defined (FIOSNBIO) */
10142 #if 0 /* This code can't be made to work, with multiple displays,
10143 and appears not to be used on any system any more.
10144 Also keyboard.c doesn't turn O_NDELAY on and off
10145 for X connections. */
10147 #ifndef HAVE_SELECT
10148 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
10150 extern int read_alarm_should_throw
;
10151 read_alarm_should_throw
= 1;
10152 XPeekEvent (dpyinfo
->display
, &event
);
10153 read_alarm_should_throw
= 0;
10155 #endif /* HAVE_SELECT */
10159 /* For debugging, this gives a way to fake an I/O error. */
10160 if (dpyinfo
== XTread_socket_fake_io_error
)
10162 XTread_socket_fake_io_error
= 0;
10163 x_io_error_quitter (dpyinfo
->display
);
10168 count
+= x_session_check_input (bufp
, &numchars
);
10172 while (XPending (dpyinfo
->display
))
10174 XNextEvent (dpyinfo
->display
, &event
);
10178 /* Filter events for the current X input method.
10179 XFilterEvent returns non-zero if the input method has
10180 consumed the event. We pass the frame's X window to
10181 XFilterEvent because that's the one for which the IC
10183 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
10184 event
.xclient
.window
);
10185 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
10191 switch (event
.type
)
10193 case ClientMessage
:
10195 if (event
.xclient
.message_type
10196 == dpyinfo
->Xatom_wm_protocols
10197 && event
.xclient
.format
== 32)
10199 if (event
.xclient
.data
.l
[0]
10200 == dpyinfo
->Xatom_wm_take_focus
)
10202 /* Use x_any_window_to_frame because this
10203 could be the shell widget window
10204 if the frame has no title bar. */
10205 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10207 /* Not quite sure this is needed -pd */
10208 if (f
&& FRAME_XIC (f
))
10209 XSetICFocus (FRAME_XIC (f
));
10211 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
10212 instructs the WM to set the input focus automatically for
10213 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
10214 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
10215 it has set the focus. So, XSetInputFocus below is not
10218 The call to XSetInputFocus below has also caused trouble. In
10219 cases where the XSetInputFocus done by the WM and the one
10220 below are temporally close (on a fast machine), the call
10221 below can generate additional FocusIn events which confuse
10224 /* Since we set WM_TAKE_FOCUS, we must call
10225 XSetInputFocus explicitly. But not if f is null,
10226 since that might be an event for a deleted frame. */
10229 Display
*d
= event
.xclient
.display
;
10230 /* Catch and ignore errors, in case window has been
10231 iconified by a window manager such as GWM. */
10232 int count
= x_catch_errors (d
);
10233 XSetInputFocus (d
, event
.xclient
.window
,
10234 /* The ICCCM says this is
10235 the only valid choice. */
10237 event
.xclient
.data
.l
[1]);
10238 /* This is needed to detect the error
10239 if there is an error. */
10241 x_uncatch_errors (d
, count
);
10243 /* Not certain about handling scroll bars here */
10246 else if (event
.xclient
.data
.l
[0]
10247 == dpyinfo
->Xatom_wm_save_yourself
)
10249 /* Save state modify the WM_COMMAND property to
10250 something which can reinstate us. This notifies
10251 the session manager, who's looking for such a
10252 PropertyNotify. Can restart processing when
10253 a keyboard or mouse event arrives. */
10254 /* If we have a session manager, don't set this.
10255 KDE will then start two Emacsen, one for the
10256 session manager and one for this. */
10259 && ! x_session_have_connection ()
10263 f
= x_top_window_to_frame (dpyinfo
,
10264 event
.xclient
.window
);
10265 /* This is just so we only give real data once
10266 for a single Emacs process. */
10267 if (f
== SELECTED_FRAME ())
10268 XSetCommand (FRAME_X_DISPLAY (f
),
10269 event
.xclient
.window
,
10270 initial_argv
, initial_argc
);
10272 XSetCommand (FRAME_X_DISPLAY (f
),
10273 event
.xclient
.window
,
10277 else if (event
.xclient
.data
.l
[0]
10278 == dpyinfo
->Xatom_wm_delete_window
)
10281 = x_any_window_to_frame (dpyinfo
,
10282 event
.xclient
.window
);
10289 bufp
->kind
= DELETE_WINDOW_EVENT
;
10290 XSETFRAME (bufp
->frame_or_window
, f
);
10299 else if (event
.xclient
.message_type
10300 == dpyinfo
->Xatom_wm_configure_denied
)
10303 else if (event
.xclient
.message_type
10304 == dpyinfo
->Xatom_wm_window_moved
)
10308 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10310 new_x
= event
.xclient
.data
.s
[0];
10311 new_y
= event
.xclient
.data
.s
[1];
10315 f
->output_data
.x
->left_pos
= new_x
;
10316 f
->output_data
.x
->top_pos
= new_y
;
10319 #ifdef HACK_EDITRES
10320 else if (event
.xclient
.message_type
10321 == dpyinfo
->Xatom_editres
)
10324 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10325 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
10328 #endif /* HACK_EDITRES */
10329 else if ((event
.xclient
.message_type
10330 == dpyinfo
->Xatom_DONE
)
10331 || (event
.xclient
.message_type
10332 == dpyinfo
->Xatom_PAGE
))
10334 /* Ghostview job completed. Kill it. We could
10335 reply with "Next" if we received "Page", but we
10336 currently never do because we are interested in
10337 images, only, which should have 1 page. */
10338 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
10340 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10341 x_kill_gs_process (pixmap
, f
);
10342 expose_frame (f
, 0, 0, 0, 0);
10344 #ifdef USE_TOOLKIT_SCROLL_BARS
10345 /* Scroll bar callbacks send a ClientMessage from which
10346 we construct an input_event. */
10347 else if (event
.xclient
.message_type
10348 == dpyinfo
->Xatom_Scrollbar
)
10350 x_scroll_bar_to_input_event (&event
, bufp
);
10351 ++bufp
, ++count
, --numchars
;
10354 #endif /* USE_TOOLKIT_SCROLL_BARS */
10360 case SelectionNotify
:
10361 #ifdef USE_X_TOOLKIT
10362 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
10364 #endif /* not USE_X_TOOLKIT */
10365 x_handle_selection_notify (&event
.xselection
);
10368 case SelectionClear
: /* Someone has grabbed ownership. */
10369 #ifdef USE_X_TOOLKIT
10370 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
10372 #endif /* USE_X_TOOLKIT */
10374 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
10379 bufp
->kind
= SELECTION_CLEAR_EVENT
;
10380 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10381 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10382 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10383 bufp
->frame_or_window
= Qnil
;
10392 case SelectionRequest
: /* Someone wants our selection. */
10393 #ifdef USE_X_TOOLKIT
10394 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
10396 #endif /* USE_X_TOOLKIT */
10397 if (x_queue_selection_requests
)
10398 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
10402 XSelectionRequestEvent
*eventp
10403 = (XSelectionRequestEvent
*) &event
;
10408 bufp
->kind
= SELECTION_REQUEST_EVENT
;
10409 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10410 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
10411 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10412 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
10413 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
10414 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10415 bufp
->frame_or_window
= Qnil
;
10424 case PropertyNotify
:
10425 #if 0 /* This is plain wrong. In the case that we are waiting for a
10426 PropertyNotify used as an ACK in incremental selection
10427 transfer, the property will be on the receiver's window. */
10428 #if defined USE_X_TOOLKIT
10429 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10433 x_handle_property_notify (&event
.xproperty
);
10436 case ReparentNotify
:
10437 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10441 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10442 x_real_positions (f
, &x
, &y
);
10443 f
->output_data
.x
->left_pos
= x
;
10444 f
->output_data
.x
->top_pos
= y
;
10449 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10452 x_check_fullscreen (f
);
10454 if (f
->async_visible
== 0)
10456 f
->async_visible
= 1;
10457 f
->async_iconified
= 0;
10458 f
->output_data
.x
->has_been_visible
= 1;
10459 SET_FRAME_GARBAGED (f
);
10462 expose_frame (x_window_to_frame (dpyinfo
,
10463 event
.xexpose
.window
),
10464 event
.xexpose
.x
, event
.xexpose
.y
,
10465 event
.xexpose
.width
, event
.xexpose
.height
);
10469 #ifndef USE_TOOLKIT_SCROLL_BARS
10470 struct scroll_bar
*bar
;
10472 #if defined USE_LUCID
10473 /* Submenus of the Lucid menu bar aren't widgets
10474 themselves, so there's no way to dispatch events
10475 to them. Recognize this case separately. */
10478 = x_window_to_menu_bar (event
.xexpose
.window
);
10480 xlwmenu_redisplay (widget
);
10482 #endif /* USE_LUCID */
10484 #ifdef USE_TOOLKIT_SCROLL_BARS
10485 /* Dispatch event to the widget. */
10487 #else /* not USE_TOOLKIT_SCROLL_BARS */
10488 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10491 x_scroll_bar_expose (bar
, &event
);
10492 #ifdef USE_X_TOOLKIT
10495 #endif /* USE_X_TOOLKIT */
10496 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10500 case GraphicsExpose
: /* This occurs when an XCopyArea's
10501 source area was obscured or not
10503 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10507 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10508 event
.xgraphicsexpose
.width
,
10509 event
.xgraphicsexpose
.height
);
10511 #ifdef USE_X_TOOLKIT
10514 #endif /* USE_X_TOOLKIT */
10517 case NoExpose
: /* This occurs when an XCopyArea's
10518 source area was completely
10523 /* Redo the mouse-highlight after the tooltip has gone. */
10524 if (event
.xmap
.window
== tip_window
)
10527 redo_mouse_highlight ();
10530 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10531 if (f
) /* F may no longer exist if
10532 the frame was deleted. */
10534 /* While a frame is unmapped, display generation is
10535 disabled; you don't want to spend time updating a
10536 display that won't ever be seen. */
10537 f
->async_visible
= 0;
10538 /* We can't distinguish, from the event, whether the window
10539 has become iconified or invisible. So assume, if it
10540 was previously visible, than now it is iconified.
10541 But x_make_frame_invisible clears both
10542 the visible flag and the iconified flag;
10543 and that way, we know the window is not iconified now. */
10544 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10546 f
->async_iconified
= 1;
10548 bufp
->kind
= ICONIFY_EVENT
;
10549 XSETFRAME (bufp
->frame_or_window
, f
);
10559 if (event
.xmap
.window
== tip_window
)
10560 /* The tooltip has been drawn already. Avoid
10561 the SET_FRAME_GARBAGED below. */
10564 /* We use x_top_window_to_frame because map events can
10565 come for sub-windows and they don't mean that the
10566 frame is visible. */
10567 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10570 f
->async_visible
= 1;
10571 f
->async_iconified
= 0;
10572 f
->output_data
.x
->has_been_visible
= 1;
10574 /* wait_reading_process_input will notice this and update
10575 the frame's display structures. */
10576 SET_FRAME_GARBAGED (f
);
10580 bufp
->kind
= DEICONIFY_EVENT
;
10581 XSETFRAME (bufp
->frame_or_window
, f
);
10587 else if (! NILP (Vframe_list
)
10588 && ! NILP (XCDR (Vframe_list
)))
10589 /* Force a redisplay sooner or later
10590 to update the frame titles
10591 in case this is the second frame. */
10592 record_asynch_buffer_change ();
10598 /* Dispatch KeyPress events when in menu. */
10599 if (popup_activated_flag
)
10602 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10604 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
10606 dpyinfo
->mouse_face_hidden
= 1;
10607 clear_mouse_face (dpyinfo
);
10610 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10613 /* Scroll bars consume key events, but we want
10614 the keys to go to the scroll bar's frame. */
10615 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10616 event
.xkey
.window
);
10617 if (widget
&& XmIsScrollBar (widget
))
10619 widget
= XtParent (widget
);
10620 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10623 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10627 KeySym keysym
, orig_keysym
;
10628 /* al%imercury@uunet.uu.net says that making this 81
10629 instead of 80 fixed a bug whereby meta chars made
10632 It seems that some version of XmbLookupString has
10633 a bug of not returning XBufferOverflow in
10634 status_return even if the input is too long to
10635 fit in 81 bytes. So, we must prepare sufficient
10636 bytes for copy_buffer. 513 bytes (256 chars for
10637 two-byte character set) seems to be a fairly good
10638 approximation. -- 2000.8.10 handa@etl.go.jp */
10639 unsigned char copy_buffer
[513];
10640 unsigned char *copy_bufptr
= copy_buffer
;
10641 int copy_bufsiz
= sizeof (copy_buffer
);
10643 Lisp_Object coding_system
= Qlatin_1
;
10646 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10647 extra_keyboard_modifiers
);
10648 modifiers
= event
.xkey
.state
;
10650 /* This will have to go some day... */
10652 /* make_lispy_event turns chars into control chars.
10653 Don't do it here because XLookupString is too eager. */
10654 event
.xkey
.state
&= ~ControlMask
;
10655 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10656 | dpyinfo
->super_mod_mask
10657 | dpyinfo
->hyper_mod_mask
10658 | dpyinfo
->alt_mod_mask
);
10660 /* In case Meta is ComposeCharacter,
10661 clear its status. According to Markus Ehrnsperger
10662 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10663 this enables ComposeCharacter to work whether or
10664 not it is combined with Meta. */
10665 if (modifiers
& dpyinfo
->meta_mod_mask
)
10666 bzero (&compose_status
, sizeof (compose_status
));
10671 Status status_return
;
10673 coding_system
= Vlocale_coding_system
;
10674 nbytes
= XmbLookupString (FRAME_XIC (f
),
10675 &event
.xkey
, copy_bufptr
,
10676 copy_bufsiz
, &keysym
,
10678 if (status_return
== XBufferOverflow
)
10680 copy_bufsiz
= nbytes
+ 1;
10681 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10682 nbytes
= XmbLookupString (FRAME_XIC (f
),
10683 &event
.xkey
, copy_bufptr
,
10684 copy_bufsiz
, &keysym
,
10687 /* Xutf8LookupString is a new but already deprecated interface. -stef */
10688 #if 0 && defined X_HAVE_UTF8_STRING
10689 else if (status_return
== XLookupKeySym
)
10690 { /* Try again but with utf-8. */
10691 coding_system
= Qutf_8
;
10692 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
10693 &event
.xkey
, copy_bufptr
,
10694 copy_bufsiz
, &keysym
,
10696 if (status_return
== XBufferOverflow
)
10698 copy_bufsiz
= nbytes
+ 1;
10699 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10700 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
10703 copy_bufsiz
, &keysym
,
10709 if (status_return
== XLookupNone
)
10711 else if (status_return
== XLookupChars
)
10716 else if (status_return
!= XLookupKeySym
10717 && status_return
!= XLookupBoth
)
10721 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10722 copy_bufsiz
, &keysym
,
10725 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10726 copy_bufsiz
, &keysym
,
10730 orig_keysym
= keysym
;
10734 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10735 || keysym
== XK_Delete
10736 #ifdef XK_ISO_Left_Tab
10737 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10739 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10740 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10741 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10743 /* This recognizes the "extended function keys".
10744 It seems there's no cleaner way.
10745 Test IsModifierKey to avoid handling mode_switch
10747 || ((unsigned) (keysym
) >= XK_Select
10748 && (unsigned)(keysym
) < XK_KP_Space
)
10750 #ifdef XK_dead_circumflex
10751 || orig_keysym
== XK_dead_circumflex
10753 #ifdef XK_dead_grave
10754 || orig_keysym
== XK_dead_grave
10756 #ifdef XK_dead_tilde
10757 || orig_keysym
== XK_dead_tilde
10759 #ifdef XK_dead_diaeresis
10760 || orig_keysym
== XK_dead_diaeresis
10762 #ifdef XK_dead_macron
10763 || orig_keysym
== XK_dead_macron
10765 #ifdef XK_dead_degree
10766 || orig_keysym
== XK_dead_degree
10768 #ifdef XK_dead_acute
10769 || orig_keysym
== XK_dead_acute
10771 #ifdef XK_dead_cedilla
10772 || orig_keysym
== XK_dead_cedilla
10774 #ifdef XK_dead_breve
10775 || orig_keysym
== XK_dead_breve
10777 #ifdef XK_dead_ogonek
10778 || orig_keysym
== XK_dead_ogonek
10780 #ifdef XK_dead_caron
10781 || orig_keysym
== XK_dead_caron
10783 #ifdef XK_dead_doubleacute
10784 || orig_keysym
== XK_dead_doubleacute
10786 #ifdef XK_dead_abovedot
10787 || orig_keysym
== XK_dead_abovedot
10789 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10790 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10791 /* Any "vendor-specific" key is ok. */
10792 || (orig_keysym
& (1 << 28))
10793 || (keysym
!= NoSymbol
&& nbytes
== 0))
10794 && ! (IsModifierKey (orig_keysym
)
10796 #ifdef XK_Mode_switch
10797 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10800 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10802 #endif /* not HAVE_X11R5 */
10803 /* The symbols from XK_ISO_Lock to
10804 XK_ISO_Last_Group_Lock doesn't have real
10805 modifiers but should be treated similarly
10806 to Mode_switch by Emacs. */
10807 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
10808 || ((unsigned)(orig_keysym
) >= XK_ISO_Lock
10809 && (unsigned)(orig_keysym
) <= XK_ISO_Last_Group_Lock
)
10813 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10815 temp_buffer
[temp_index
++] = keysym
;
10816 bufp
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
10817 bufp
->code
= keysym
;
10818 XSETFRAME (bufp
->frame_or_window
, f
);
10821 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10823 bufp
->timestamp
= event
.xkey
.time
;
10828 else if (numchars
> nbytes
)
10834 /* The input should be decoded with `coding_system'
10835 which depends on which X*LookupString function
10836 we used just above and the locale. */
10837 setup_coding_system (coding_system
, &coding
);
10838 coding
.src_multibyte
= 0;
10839 coding
.dst_multibyte
= 1;
10840 /* The input is converted to events, thus we can't
10841 handle composition. Anyway, there's no XIM that
10842 gives us composition information. */
10843 coding
.composing
= COMPOSITION_DISABLED
;
10845 for (i
= 0; i
< nbytes
; i
++)
10847 if (temp_index
== (sizeof temp_buffer
10850 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10854 /* Decode the input data. */
10858 require
= decoding_buffer_size (&coding
, nbytes
);
10859 p
= (unsigned char *) alloca (require
);
10860 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10861 /* We explicitely disable composition
10862 handling because key data should
10863 not contain any composition
10865 coding
.composing
= COMPOSITION_DISABLED
;
10866 decode_coding (&coding
, copy_bufptr
, p
,
10868 nbytes
= coding
.produced
;
10869 nchars
= coding
.produced_char
;
10873 /* Convert the input data to a sequence of
10874 character events. */
10875 for (i
= 0; i
< nbytes
; i
+= len
)
10877 if (nchars
== nbytes
)
10878 c
= copy_bufptr
[i
], len
= 1;
10880 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10883 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10884 ? ASCII_KEYSTROKE_EVENT
10885 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
10887 XSETFRAME (bufp
->frame_or_window
, f
);
10890 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10892 bufp
->timestamp
= event
.xkey
.time
;
10897 numchars
-= nchars
;
10899 if (keysym
== NoSymbol
)
10909 /* Don't dispatch this event since XtDispatchEvent calls
10910 XFilterEvent, and two calls in a row may freeze the
10919 /* Don't dispatch this event since XtDispatchEvent calls
10920 XFilterEvent, and two calls in a row may freeze the
10931 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
10934 bufp
+= n
, count
+= n
, numchars
-= n
;
10937 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10940 if (event
.xcrossing
.focus
)
10942 /* Avoid nasty pop/raise loops. */
10943 if (f
&& (!(f
->auto_raise
)
10944 || !(f
->auto_lower
)
10945 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10947 x_new_focus_frame (dpyinfo
, f
);
10948 enter_timestamp
= event
.xcrossing
.time
;
10951 else if (f
== dpyinfo
->x_focus_frame
)
10952 x_new_focus_frame (dpyinfo
, 0);
10955 /* EnterNotify counts as mouse movement,
10956 so update things that depend on mouse position. */
10957 if (f
&& !f
->output_data
.x
->hourglass_p
)
10958 note_mouse_movement (f
, &event
.xmotion
);
10966 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
10969 bufp
+= n
, count
+= n
, numchars
-= n
;
10979 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
10982 bufp
+= n
, count
+= n
, numchars
-= n
;
10986 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10989 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10991 /* If we move outside the frame, then we're
10992 certainly no longer on any text in the frame. */
10993 clear_mouse_face (dpyinfo
);
10994 dpyinfo
->mouse_face_mouse_frame
= 0;
10997 /* Generate a nil HELP_EVENT to cancel a help-echo.
10998 Do it only if there's something to cancel.
10999 Otherwise, the startup message is cleared when
11000 the mouse leaves the frame. */
11001 if (any_help_event_p
)
11006 XSETFRAME (frame
, f
);
11008 n
= gen_help_event (bufp
, numchars
,
11009 Qnil
, frame
, Qnil
, Qnil
, 0);
11010 bufp
+= n
, count
+= n
, numchars
-= n
;
11020 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
11023 bufp
+= n
, count
+= n
, numchars
-= n
;
11031 previous_help_echo
= help_echo
;
11032 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
11033 help_echo_pos
= -1;
11035 if (dpyinfo
->grabbed
&& last_mouse_frame
11036 && FRAME_LIVE_P (last_mouse_frame
))
11037 f
= last_mouse_frame
;
11039 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
11041 if (dpyinfo
->mouse_face_hidden
)
11043 dpyinfo
->mouse_face_hidden
= 0;
11044 clear_mouse_face (dpyinfo
);
11050 /* Generate SELECT_WINDOW_EVENTs when needed. */
11051 if (mouse_autoselect_window
)
11053 Lisp_Object window
;
11056 window
= window_from_coordinates (f
,
11057 event
.xmotion
.x
, event
.xmotion
.y
,
11060 /* Window will be selected only when it is not selected now and
11061 last mouse movement event was not in it. Minibuffer window
11062 will be selected iff it is active. */
11063 if (WINDOWP(window
)
11064 && !EQ (window
, last_window
)
11065 && !EQ (window
, selected_window
)
11068 bufp
->kind
= SELECT_WINDOW_EVENT
;
11069 bufp
->frame_or_window
= window
;
11071 ++bufp
, ++count
, --numchars
;
11074 last_window
=window
;
11076 note_mouse_movement (f
, &event
.xmotion
);
11080 #ifndef USE_TOOLKIT_SCROLL_BARS
11081 struct scroll_bar
*bar
11082 = x_window_to_scroll_bar (event
.xmotion
.window
);
11085 x_scroll_bar_note_movement (bar
, &event
);
11086 #endif /* USE_TOOLKIT_SCROLL_BARS */
11088 /* If we move outside the frame, then we're
11089 certainly no longer on any text in the frame. */
11090 clear_mouse_face (dpyinfo
);
11093 /* If the contents of the global variable help_echo
11094 has changed, generate a HELP_EVENT. */
11095 if (!NILP (help_echo
)
11096 || !NILP (previous_help_echo
))
11102 XSETFRAME (frame
, f
);
11106 any_help_event_p
= 1;
11107 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
11108 help_echo_window
, help_echo_object
,
11110 bufp
+= n
, count
+= n
, numchars
-= n
;
11116 case ConfigureNotify
:
11117 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
11120 #ifndef USE_X_TOOLKIT
11121 /* If there is a pending resize for fullscreen, don't
11122 do this one, the right one will come later.
11123 The toolkit version doesn't seem to need this, but we
11124 need to reset it below. */
11126 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
11127 && FRAME_NEW_WIDTH (f
) != 0);
11128 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
11129 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
11133 /* In the toolkit version, change_frame_size
11134 is called by the code that handles resizing
11135 of the EmacsFrame widget. */
11137 /* Even if the number of character rows and columns has
11138 not changed, the font size may have changed, so we need
11139 to check the pixel dimensions as well. */
11140 if (columns
!= f
->width
11141 || rows
!= f
->height
11142 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
11143 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
11145 change_frame_size (f
, rows
, columns
, 0, 1, 0);
11146 SET_FRAME_GARBAGED (f
);
11147 cancel_mouse_face (f
);
11151 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
11152 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
11154 /* What we have now is the position of Emacs's own window.
11155 Convert that to the position of the window manager window. */
11156 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
11157 &f
->output_data
.x
->top_pos
);
11159 x_check_fullscreen_move(f
);
11160 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
11161 f
->output_data
.x
->want_fullscreen
&=
11162 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
11164 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
11165 xic_set_statusarea (f
);
11168 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11170 /* Since the WM decorations come below top_pos now,
11171 we must put them below top_pos in the future. */
11172 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11173 x_wm_set_size_hint (f
, (long) 0, 0);
11176 /* Some window managers pass (0,0) as the location of
11177 the window, and the Motif event handler stores it
11178 in the emacs widget, which messes up Motif menus. */
11179 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
11181 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
11182 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
11184 #endif /* USE_MOTIF */
11189 case ButtonRelease
:
11191 /* If we decide we want to generate an event to be seen
11192 by the rest of Emacs, we put it here. */
11193 struct input_event emacs_event
;
11194 int tool_bar_p
= 0;
11196 emacs_event
.kind
= NO_EVENT
;
11197 bzero (&compose_status
, sizeof (compose_status
));
11199 if (dpyinfo
->grabbed
11200 && last_mouse_frame
11201 && FRAME_LIVE_P (last_mouse_frame
))
11202 f
= last_mouse_frame
;
11204 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11208 /* Is this in the tool-bar? */
11209 if (WINDOWP (f
->tool_bar_window
)
11210 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
11212 Lisp_Object window
;
11215 x
= event
.xbutton
.x
;
11216 y
= event
.xbutton
.y
;
11219 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
11220 if (EQ (window
, f
->tool_bar_window
))
11222 x_handle_tool_bar_click (f
, &event
.xbutton
);
11228 if (!dpyinfo
->x_focus_frame
11229 || f
== dpyinfo
->x_focus_frame
)
11230 construct_mouse_click (&emacs_event
, &event
, f
);
11234 #ifndef USE_TOOLKIT_SCROLL_BARS
11235 struct scroll_bar
*bar
11236 = x_window_to_scroll_bar (event
.xbutton
.window
);
11239 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
11240 #endif /* not USE_TOOLKIT_SCROLL_BARS */
11243 if (event
.type
== ButtonPress
)
11245 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
11246 last_mouse_frame
= f
;
11247 /* Ignore any mouse motion that happened
11248 before this event; any subsequent mouse-movement
11249 Emacs events should reflect only motion after
11250 the ButtonPress. */
11252 f
->mouse_moved
= 0;
11255 last_tool_bar_item
= -1;
11259 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
11262 if (numchars
>= 1 && emacs_event
.kind
!= NO_EVENT
)
11264 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
11270 #ifdef USE_X_TOOLKIT
11271 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11272 /* For a down-event in the menu bar,
11273 don't pass it to Xt right now.
11274 Instead, save it away
11275 and we will pass it to Xt from kbd_buffer_get_event.
11276 That way, we can run some Lisp code first. */
11277 if (f
&& event
.type
== ButtonPress
11278 /* Verify the event is really within the menu bar
11279 and not just sent to it due to grabbing. */
11280 && event
.xbutton
.x
>= 0
11281 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
11282 && event
.xbutton
.y
>= 0
11283 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
11284 && event
.xbutton
.same_screen
)
11286 SET_SAVED_BUTTON_EVENT
;
11287 XSETFRAME (last_mouse_press_frame
, f
);
11289 else if (event
.type
== ButtonPress
)
11291 last_mouse_press_frame
= Qnil
;
11295 #ifdef USE_MOTIF /* This should do not harm for Lucid,
11296 but I am trying to be cautious. */
11297 else if (event
.type
== ButtonRelease
)
11299 if (!NILP (last_mouse_press_frame
))
11301 f
= XFRAME (last_mouse_press_frame
);
11302 if (f
->output_data
.x
)
11303 SET_SAVED_BUTTON_EVENT
;
11308 #endif /* USE_MOTIF */
11311 #endif /* USE_X_TOOLKIT */
11315 case CirculateNotify
:
11318 case CirculateRequest
:
11321 case VisibilityNotify
:
11324 case MappingNotify
:
11325 /* Someone has changed the keyboard mapping - update the
11327 switch (event
.xmapping
.request
)
11329 case MappingModifier
:
11330 x_find_modifier_meanings (dpyinfo
);
11331 /* This is meant to fall through. */
11332 case MappingKeyboard
:
11333 XRefreshKeyboardMapping (&event
.xmapping
);
11339 #ifdef USE_X_TOOLKIT
11341 XtDispatchEvent (&event
);
11343 #endif /* USE_X_TOOLKIT */
11351 /* On some systems, an X bug causes Emacs to get no more events
11352 when the window is destroyed. Detect that. (1994.) */
11355 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
11356 One XNOOP in 100 loops will make Emacs terminate.
11357 B. Bretthauer, 1994 */
11359 if (x_noop_count
>= 100)
11363 if (next_noop_dpyinfo
== 0)
11364 next_noop_dpyinfo
= x_display_list
;
11366 XNoOp (next_noop_dpyinfo
->display
);
11368 /* Each time we get here, cycle through the displays now open. */
11369 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
11373 /* If the focus was just given to an auto-raising frame,
11375 /* ??? This ought to be able to handle more than one such frame. */
11376 if (pending_autoraise_frame
)
11378 x_raise_frame (pending_autoraise_frame
);
11379 pending_autoraise_frame
= 0;
11390 /***********************************************************************
11392 ***********************************************************************/
11394 /* Notice when the text cursor of window W has been completely
11395 overwritten by a drawing operation that outputs glyphs in AREA
11396 starting at X0 and ending at X1 in the line starting at Y0 and
11397 ending at Y1. X coordinates are area-relative. X1 < 0 means all
11398 the rest of the line after X0 has been written. Y coordinates
11399 are window-relative. */
11402 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
11404 enum glyph_row_area area
;
11405 int x0
, y0
, x1
, y1
;
11407 if (area
== TEXT_AREA
&& w
->phys_cursor_on_p
)
11409 int cx0
= w
->phys_cursor
.x
;
11410 int cx1
= cx0
+ w
->phys_cursor_width
;
11411 int cy0
= w
->phys_cursor
.y
;
11412 int cy1
= cy0
+ w
->phys_cursor_height
;
11414 if (x0
<= cx0
&& (x1
< 0 || x1
>= cx1
))
11416 /* The cursor image will be completely removed from the
11417 screen if the output area intersects the cursor area in
11418 y-direction. When we draw in [y0 y1[, and some part of
11419 the cursor is at y < y0, that part must have been drawn
11420 before. When scrolling, the cursor is erased before
11421 actually scrolling, so we don't come here. When not
11422 scrolling, the rows above the old cursor row must have
11423 changed, and in this case these rows must have written
11424 over the cursor image.
11426 Likewise if part of the cursor is below y1, with the
11427 exception of the cursor being in the first blank row at
11428 the buffer and window end because update_text_area
11429 doesn't draw that row. (Except when it does, but
11430 that's handled in update_text_area.) */
11432 if (((y0
>= cy0
&& y0
< cy1
) || (y1
> cy0
&& y1
< cy1
))
11433 && w
->current_matrix
->rows
[w
->phys_cursor
.vpos
].displays_text_p
)
11434 w
->phys_cursor_on_p
= 0;
11440 /* Set clipping for output in glyph row ROW. W is the window in which
11441 we operate. GC is the graphics context to set clipping in.
11442 WHOLE_LINE_P non-zero means include the areas used for truncation
11443 mark display and alike in the clipping rectangle.
11445 ROW may be a text row or, e.g., a mode line. Text rows must be
11446 clipped to the interior of the window dedicated to text display,
11447 mode lines must be clipped to the whole window. */
11450 x_clip_to_row (w
, row
, gc
, whole_line_p
)
11452 struct glyph_row
*row
;
11456 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11457 XRectangle clip_rect
;
11458 int window_x
, window_y
, window_width
, window_height
;
11460 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
11462 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
11463 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
11464 clip_rect
.y
= max (clip_rect
.y
, window_y
);
11465 clip_rect
.width
= window_width
;
11466 clip_rect
.height
= row
->visible_height
;
11468 /* If clipping to the whole line, including trunc marks, extend
11469 the rectangle to the left and increase its width. */
11472 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
11473 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
11476 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
11480 /* Draw a hollow box cursor on window W in glyph row ROW. */
11483 x_draw_hollow_cursor (w
, row
)
11485 struct glyph_row
*row
;
11487 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11488 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11489 Display
*dpy
= FRAME_X_DISPLAY (f
);
11492 struct glyph
*cursor_glyph
;
11495 /* Compute frame-relative coordinates from window-relative
11497 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11498 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
11499 + row
->ascent
- w
->phys_cursor_ascent
);
11500 h
= row
->height
- 1;
11502 /* Get the glyph the cursor is on. If we can't tell because
11503 the current matrix is invalid or such, give up. */
11504 cursor_glyph
= get_phys_cursor_glyph (w
);
11505 if (cursor_glyph
== NULL
)
11508 /* Compute the width of the rectangle to draw. If on a stretch
11509 glyph, and `x-stretch-block-cursor' is nil, don't draw a
11510 rectangle as wide as the glyph, but use a canonical character
11512 wd
= cursor_glyph
->pixel_width
- 1;
11513 if (cursor_glyph
->type
== STRETCH_GLYPH
11514 && !x_stretch_cursor_p
)
11515 wd
= min (CANON_X_UNIT (f
), wd
);
11516 w
->phys_cursor_width
= wd
;
11518 /* The foreground of cursor_gc is typically the same as the normal
11519 background color, which can cause the cursor box to be invisible. */
11520 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11521 if (dpyinfo
->scratch_cursor_gc
)
11522 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11524 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11525 GCForeground
, &xgcv
);
11526 gc
= dpyinfo
->scratch_cursor_gc
;
11528 /* Set clipping, draw the rectangle, and reset clipping again. */
11529 x_clip_to_row (w
, row
, gc
, 0);
11530 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11531 XSetClipMask (dpy
, gc
, None
);
11535 /* Draw a bar cursor on window W in glyph row ROW.
11537 Implementation note: One would like to draw a bar cursor with an
11538 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11539 Unfortunately, I didn't find a font yet that has this property set.
11543 x_draw_bar_cursor (w
, row
, width
, kind
)
11545 struct glyph_row
*row
;
11547 enum text_cursor_kinds kind
;
11549 struct frame
*f
= XFRAME (w
->frame
);
11550 struct glyph
*cursor_glyph
;
11552 /* If cursor is out of bounds, don't draw garbage. This can happen
11553 in mini-buffer windows when switching between echo area glyphs
11554 and mini-buffer. */
11555 cursor_glyph
= get_phys_cursor_glyph (w
);
11556 if (cursor_glyph
== NULL
)
11559 /* If on an image, draw like a normal cursor. That's usually better
11560 visible than drawing a bar, esp. if the image is large so that
11561 the bar might not be in the window. */
11562 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11564 struct glyph_row
*row
;
11565 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11566 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11570 Display
*dpy
= FRAME_X_DISPLAY (f
);
11571 Window window
= FRAME_X_WINDOW (f
);
11572 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11573 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11574 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
11577 /* If the glyph's background equals the color we normally draw
11578 the bar cursor in, the bar cursor in its normal color is
11579 invisible. Use the glyph's foreground color instead in this
11580 case, on the assumption that the glyph's colors are chosen so
11581 that the glyph is legible. */
11582 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
11583 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
11585 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11586 xgcv
.graphics_exposures
= 0;
11589 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11592 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11593 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11597 width
= f
->output_data
.x
->cursor_width
;
11598 width
= min (cursor_glyph
->pixel_width
, width
);
11600 w
->phys_cursor_width
= width
;
11601 x_clip_to_row (w
, row
, gc
, 0);
11603 if (kind
== BAR_CURSOR
)
11604 XFillRectangle (dpy
, window
, gc
,
11605 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11606 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11607 width
, row
->height
);
11609 XFillRectangle (dpy
, window
, gc
,
11610 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11611 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
11612 row
->height
- width
),
11613 cursor_glyph
->pixel_width
,
11616 XSetClipMask (dpy
, gc
, None
);
11621 /* Clear the cursor of window W to background color, and mark the
11622 cursor as not shown. This is used when the text where the cursor
11623 is is about to be rewritten. */
11629 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11630 x_update_window_cursor (w
, 0);
11634 /* Draw the cursor glyph of window W in glyph row ROW. See the
11635 comment of x_draw_glyphs for the meaning of HL. */
11638 x_draw_phys_cursor_glyph (w
, row
, hl
)
11640 struct glyph_row
*row
;
11641 enum draw_glyphs_face hl
;
11643 /* If cursor hpos is out of bounds, don't draw garbage. This can
11644 happen in mini-buffer windows when switching between echo area
11645 glyphs and mini-buffer. */
11646 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11648 int on_p
= w
->phys_cursor_on_p
;
11651 x1
= x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11652 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11654 w
->phys_cursor_on_p
= on_p
;
11656 if (hl
== DRAW_CURSOR
)
11657 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
11659 /* When we erase the cursor, and ROW is overlapped by other
11660 rows, make sure that these overlapping parts of other rows
11662 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11664 if (row
> w
->current_matrix
->rows
11665 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11666 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11668 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11669 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11670 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11676 /* Erase the image of a cursor of window W from the screen. */
11679 x_erase_phys_cursor (w
)
11682 struct frame
*f
= XFRAME (w
->frame
);
11683 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11684 int hpos
= w
->phys_cursor
.hpos
;
11685 int vpos
= w
->phys_cursor
.vpos
;
11686 int mouse_face_here_p
= 0;
11687 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11688 struct glyph_row
*cursor_row
;
11689 struct glyph
*cursor_glyph
;
11690 enum draw_glyphs_face hl
;
11692 /* No cursor displayed or row invalidated => nothing to do on the
11694 if (w
->phys_cursor_type
== NO_CURSOR
)
11695 goto mark_cursor_off
;
11697 /* VPOS >= active_glyphs->nrows means that window has been resized.
11698 Don't bother to erase the cursor. */
11699 if (vpos
>= active_glyphs
->nrows
)
11700 goto mark_cursor_off
;
11702 /* If row containing cursor is marked invalid, there is nothing we
11704 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11705 if (!cursor_row
->enabled_p
)
11706 goto mark_cursor_off
;
11708 /* If row is completely invisible, don't attempt to delete a cursor which
11709 isn't there. This can happen if cursor is at top of a window, and
11710 we switch to a buffer with a header line in that window. */
11711 if (cursor_row
->visible_height
<= 0)
11712 goto mark_cursor_off
;
11714 /* This can happen when the new row is shorter than the old one.
11715 In this case, either x_draw_glyphs or clear_end_of_line
11716 should have cleared the cursor. Note that we wouldn't be
11717 able to erase the cursor in this case because we don't have a
11718 cursor glyph at hand. */
11719 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11720 goto mark_cursor_off
;
11722 /* If the cursor is in the mouse face area, redisplay that when
11723 we clear the cursor. */
11724 if (! NILP (dpyinfo
->mouse_face_window
)
11725 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11726 && (vpos
> dpyinfo
->mouse_face_beg_row
11727 || (vpos
== dpyinfo
->mouse_face_beg_row
11728 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11729 && (vpos
< dpyinfo
->mouse_face_end_row
11730 || (vpos
== dpyinfo
->mouse_face_end_row
11731 && hpos
< dpyinfo
->mouse_face_end_col
))
11732 /* Don't redraw the cursor's spot in mouse face if it is at the
11733 end of a line (on a newline). The cursor appears there, but
11734 mouse highlighting does not. */
11735 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11736 mouse_face_here_p
= 1;
11738 /* Maybe clear the display under the cursor. */
11739 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11742 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11744 cursor_glyph
= get_phys_cursor_glyph (w
);
11745 if (cursor_glyph
== NULL
)
11746 goto mark_cursor_off
;
11748 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11750 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11752 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11754 cursor_glyph
->pixel_width
,
11755 cursor_row
->visible_height
,
11759 /* Erase the cursor by redrawing the character underneath it. */
11760 if (mouse_face_here_p
)
11761 hl
= DRAW_MOUSE_FACE
;
11763 hl
= DRAW_NORMAL_TEXT
;
11764 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11767 w
->phys_cursor_on_p
= 0;
11768 w
->phys_cursor_type
= NO_CURSOR
;
11772 /* Non-zero if physical cursor of window W is within mouse face. */
11775 cursor_in_mouse_face_p (w
)
11778 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
11779 int in_mouse_face
= 0;
11781 if (WINDOWP (dpyinfo
->mouse_face_window
)
11782 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
11784 int hpos
= w
->phys_cursor
.hpos
;
11785 int vpos
= w
->phys_cursor
.vpos
;
11787 if (vpos
>= dpyinfo
->mouse_face_beg_row
11788 && vpos
<= dpyinfo
->mouse_face_end_row
11789 && (vpos
> dpyinfo
->mouse_face_beg_row
11790 || hpos
>= dpyinfo
->mouse_face_beg_col
)
11791 && (vpos
< dpyinfo
->mouse_face_end_row
11792 || hpos
< dpyinfo
->mouse_face_end_col
11793 || dpyinfo
->mouse_face_past_end
))
11797 return in_mouse_face
;
11801 /* Display or clear cursor of window W. If ON is zero, clear the
11802 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11803 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11806 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11808 int on
, hpos
, vpos
, x
, y
;
11810 struct frame
*f
= XFRAME (w
->frame
);
11811 int new_cursor_type
;
11812 int new_cursor_width
;
11813 int cursor_off_state
= 0;
11814 struct glyph_matrix
*current_glyphs
;
11815 struct glyph_row
*glyph_row
;
11816 struct glyph
*glyph
;
11818 /* This is pointless on invisible frames, and dangerous on garbaged
11819 windows and frames; in the latter case, the frame or window may
11820 be in the midst of changing its size, and x and y may be off the
11822 if (! FRAME_VISIBLE_P (f
)
11823 || FRAME_GARBAGED_P (f
)
11824 || vpos
>= w
->current_matrix
->nrows
11825 || hpos
>= w
->current_matrix
->matrix_w
)
11828 /* If cursor is off and we want it off, return quickly. */
11829 if (!on
&& !w
->phys_cursor_on_p
)
11832 current_glyphs
= w
->current_matrix
;
11833 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11834 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11836 /* If cursor row is not enabled, we don't really know where to
11837 display the cursor. */
11838 if (!glyph_row
->enabled_p
)
11840 w
->phys_cursor_on_p
= 0;
11844 xassert (interrupt_input_blocked
);
11846 /* Set new_cursor_type to the cursor we want to be displayed. In a
11847 mini-buffer window, we want the cursor only to appear if we are
11848 reading input from this window. For the selected window, we want
11849 the cursor type given by the frame parameter. If explicitly
11850 marked off, draw no cursor. In all other cases, we want a hollow
11852 new_cursor_width
= -1;
11853 new_cursor_type
= -2;
11856 if (cursor_in_echo_area
11857 && FRAME_HAS_MINIBUF_P (f
)
11858 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11860 if (w
== XWINDOW (echo_area_window
))
11861 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11862 else if (NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
11864 new_cursor_type
= NO_CURSOR
;
11866 cursor_off_state
= 1;
11869 /* Nonselected window or nonselected frame. */
11870 else if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11871 || w
!= XWINDOW (f
->selected_window
))
11873 if ((MINI_WINDOW_P (w
) && minibuf_level
== 0)
11874 || NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
11876 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11877 new_cursor_type
= NO_CURSOR
;
11879 cursor_off_state
= 1;
11882 /* If new_cursor_type isn't decided yet, decide it now. */
11883 if (new_cursor_type
== -2)
11885 struct buffer
*b
= XBUFFER (w
->buffer
);
11887 if (EQ (b
->cursor_type
, Qt
))
11889 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11890 new_cursor_width
= FRAME_CURSOR_WIDTH (f
);
11893 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11894 &new_cursor_width
);
11897 /* Dim out or hollow out the cursor,
11898 if it has blinked off or for nonselected windows. */
11899 if (w
->cursor_off_p
|| cursor_off_state
)
11901 if (new_cursor_type
== FILLED_BOX_CURSOR
)
11902 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11903 else if (new_cursor_type
== BAR_CURSOR
&& new_cursor_width
> 1)
11904 new_cursor_width
= 1;
11906 new_cursor_type
= NO_CURSOR
;
11909 /* Now new_cursor_type is correct. */
11911 /* If cursor is currently being shown and we don't want it to be or
11912 it is in the wrong place, or the cursor type is not what we want,
11914 if (w
->phys_cursor_on_p
11916 || w
->phys_cursor
.x
!= x
11917 || w
->phys_cursor
.y
!= y
11918 || new_cursor_type
!= w
->phys_cursor_type
11919 || (new_cursor_type
== BAR_CURSOR
11920 && new_cursor_width
!= w
->phys_cursor_width
)))
11921 x_erase_phys_cursor (w
);
11923 /* Don't check phys_cursor_on_p here because that flag is only set
11924 to zero in some cases where we know that the cursor has been
11925 completely erased, to avoid the extra work of erasing the cursor
11926 twice. In other words, phys_cursor_on_p can be 1 and the cursor
11927 still not be visible, or it has only been partly erased. */
11930 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11931 w
->phys_cursor_height
= glyph_row
->height
;
11933 /* Set phys_cursor_.* before x_draw_.* is called because some
11934 of them may need the information. */
11935 w
->phys_cursor
.x
= x
;
11936 w
->phys_cursor
.y
= glyph_row
->y
;
11937 w
->phys_cursor
.hpos
= hpos
;
11938 w
->phys_cursor
.vpos
= vpos
;
11939 w
->phys_cursor_type
= new_cursor_type
;
11940 w
->phys_cursor_on_p
= 1;
11942 switch (new_cursor_type
)
11944 case HOLLOW_BOX_CURSOR
:
11945 x_draw_hollow_cursor (w
, glyph_row
);
11948 case FILLED_BOX_CURSOR
:
11949 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11953 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
, BAR_CURSOR
);
11957 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
, HBAR_CURSOR
);
11961 w
->phys_cursor_width
= 0;
11969 if (w
== XWINDOW (f
->selected_window
))
11970 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11971 xic_set_preeditarea (w
, x
, y
);
11976 if (updating_frame
!= f
)
11977 XFlush (FRAME_X_DISPLAY (f
));
11982 /* Display the cursor on window W, or clear it. X and Y are window
11983 relative pixel coordinates. HPOS and VPOS are glyph matrix
11984 positions. If W is not the selected window, display a hollow
11985 cursor. ON non-zero means display the cursor at X, Y which
11986 correspond to HPOS, VPOS, otherwise it is cleared. */
11989 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11991 int on
, hpos
, vpos
, x
, y
;
11994 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11999 /* Display the cursor on window W, or clear it, according to ON_P.
12000 Don't change the cursor's position. */
12003 x_update_cursor (f
, on_p
)
12006 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
12010 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
12011 in the window tree rooted at W. */
12014 x_update_cursor_in_window_tree (w
, on_p
)
12020 if (!NILP (w
->hchild
))
12021 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
12022 else if (!NILP (w
->vchild
))
12023 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
12025 x_update_window_cursor (w
, on_p
);
12027 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
12032 /* Switch the display of W's cursor on or off, according to the value
12036 x_update_window_cursor (w
, on
)
12040 /* Don't update cursor in windows whose frame is in the process
12041 of being deleted. */
12042 if (w
->current_matrix
)
12045 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
12046 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
12056 /* Make the x-window of frame F use the gnu icon bitmap. */
12059 x_bitmap_icon (f
, file
)
12065 if (FRAME_X_WINDOW (f
) == 0)
12068 /* Free up our existing icon bitmap if any. */
12069 if (f
->output_data
.x
->icon_bitmap
> 0)
12070 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
12071 f
->output_data
.x
->icon_bitmap
= 0;
12073 if (STRINGP (file
))
12074 bitmap_id
= x_create_bitmap_from_file (f
, file
);
12077 /* Create the GNU bitmap if necessary. */
12078 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
12079 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
12080 = x_create_bitmap_from_data (f
, gnu_bits
,
12081 gnu_width
, gnu_height
);
12083 /* The first time we create the GNU bitmap,
12084 this increments the ref-count one extra time.
12085 As a result, the GNU bitmap is never freed.
12086 That way, we don't have to worry about allocating it again. */
12087 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
12089 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
12092 x_wm_set_icon_pixmap (f
, bitmap_id
);
12093 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
12099 /* Make the x-window of frame F use a rectangle with text.
12100 Use ICON_NAME as the text. */
12103 x_text_icon (f
, icon_name
)
12107 if (FRAME_X_WINDOW (f
) == 0)
12112 XTextProperty text
;
12113 text
.value
= (unsigned char *) icon_name
;
12114 text
.encoding
= XA_STRING
;
12116 text
.nitems
= strlen (icon_name
);
12117 #ifdef USE_X_TOOLKIT
12118 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12120 #else /* not USE_X_TOOLKIT */
12121 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
12122 #endif /* not USE_X_TOOLKIT */
12124 #else /* not HAVE_X11R4 */
12125 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
12126 #endif /* not HAVE_X11R4 */
12128 if (f
->output_data
.x
->icon_bitmap
> 0)
12129 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
12130 f
->output_data
.x
->icon_bitmap
= 0;
12131 x_wm_set_icon_pixmap (f
, 0);
12136 #define X_ERROR_MESSAGE_SIZE 200
12138 /* If non-nil, this should be a string.
12139 It means catch X errors and store the error message in this string. */
12141 static Lisp_Object x_error_message_string
;
12143 /* An X error handler which stores the error message in
12144 x_error_message_string. This is called from x_error_handler if
12145 x_catch_errors is in effect. */
12148 x_error_catcher (display
, error
)
12150 XErrorEvent
*error
;
12152 XGetErrorText (display
, error
->error_code
,
12153 SDATA (x_error_message_string
),
12154 X_ERROR_MESSAGE_SIZE
);
12157 /* Begin trapping X errors for display DPY. Actually we trap X errors
12158 for all displays, but DPY should be the display you are actually
12161 After calling this function, X protocol errors no longer cause
12162 Emacs to exit; instead, they are recorded in the string
12163 stored in x_error_message_string.
12165 Calling x_check_errors signals an Emacs error if an X error has
12166 occurred since the last call to x_catch_errors or x_check_errors.
12168 Calling x_uncatch_errors resumes the normal error handling. */
12170 void x_check_errors ();
12171 static Lisp_Object
x_catch_errors_unwind ();
12174 x_catch_errors (dpy
)
12177 int count
= SPECPDL_INDEX ();
12179 /* Make sure any errors from previous requests have been dealt with. */
12180 XSync (dpy
, False
);
12182 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
12184 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
12185 SSET (x_error_message_string
, 0, 0);
12190 /* Unbind the binding that we made to check for X errors. */
12193 x_catch_errors_unwind (old_val
)
12194 Lisp_Object old_val
;
12196 x_error_message_string
= old_val
;
12200 /* If any X protocol errors have arrived since the last call to
12201 x_catch_errors or x_check_errors, signal an Emacs error using
12202 sprintf (a buffer, FORMAT, the x error message text) as the text. */
12205 x_check_errors (dpy
, format
)
12209 /* Make sure to catch any errors incurred so far. */
12210 XSync (dpy
, False
);
12212 if (SREF (x_error_message_string
, 0))
12213 error (format
, SDATA (x_error_message_string
));
12216 /* Nonzero if we had any X protocol errors
12217 since we did x_catch_errors on DPY. */
12220 x_had_errors_p (dpy
)
12223 /* Make sure to catch any errors incurred so far. */
12224 XSync (dpy
, False
);
12226 return SREF (x_error_message_string
, 0) != 0;
12229 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
12232 x_clear_errors (dpy
)
12235 SSET (x_error_message_string
, 0, 0);
12238 /* Stop catching X protocol errors and let them make Emacs die.
12239 DPY should be the display that was passed to x_catch_errors.
12240 COUNT should be the value that was returned by
12241 the corresponding call to x_catch_errors. */
12244 x_uncatch_errors (dpy
, count
)
12248 unbind_to (count
, Qnil
);
12252 static unsigned int x_wire_count
;
12255 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
12260 /* Handle SIGPIPE, which can happen when the connection to a server
12261 simply goes away. SIGPIPE is handled by x_connection_signal.
12262 Don't need to do anything, because the write which caused the
12263 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
12264 which will do the appropriate cleanup for us. */
12267 x_connection_signal (signalnum
) /* If we don't have an argument, */
12268 int signalnum
; /* some compilers complain in signal calls. */
12271 /* USG systems forget handlers when they are used;
12272 must reestablish each time */
12273 signal (signalnum
, x_connection_signal
);
12278 /************************************************************************
12280 ************************************************************************/
12282 /* Error message passed to x_connection_closed. */
12284 static char *error_msg
;
12286 /* Function installed as fatal_error_signal_hook in
12287 x_connection_closed. Print the X error message, and exit normally,
12288 instead of dumping core when XtCloseDisplay fails. */
12291 x_fatal_error_signal ()
12293 fprintf (stderr
, "%s\n", error_msg
);
12297 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
12298 the text of an error message that lead to the connection loss. */
12301 x_connection_closed (dpy
, error_message
)
12303 char *error_message
;
12305 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
12306 Lisp_Object frame
, tail
;
12309 error_msg
= (char *) alloca (strlen (error_message
) + 1);
12310 strcpy (error_msg
, error_message
);
12311 handling_signal
= 0;
12313 /* Prevent being called recursively because of an error condition
12314 below. Otherwise, we might end up with printing ``can't find per
12315 display information'' in the recursive call instead of printing
12316 the original message here. */
12317 count
= x_catch_errors (dpy
);
12319 /* We have to close the display to inform Xt that it doesn't
12320 exist anymore. If we don't, Xt will continue to wait for
12321 events from the display. As a consequence, a sequence of
12323 M-x make-frame-on-display RET :1 RET
12324 ...kill the new frame, so that we get an IO error...
12325 M-x make-frame-on-display RET :1 RET
12327 will indefinitely wait in Xt for events for display `:1', opened
12328 in the first class to make-frame-on-display.
12330 Closing the display is reported to lead to a bus error on
12331 OpenWindows in certain situations. I suspect that is a bug
12332 in OpenWindows. I don't know how to cicumvent it here. */
12334 #ifdef USE_X_TOOLKIT
12335 /* If DPYINFO is null, this means we didn't open the display
12336 in the first place, so don't try to close it. */
12339 extern void (*fatal_error_signal_hook
) P_ ((void));
12340 fatal_error_signal_hook
= x_fatal_error_signal
;
12341 XtCloseDisplay (dpy
);
12342 fatal_error_signal_hook
= NULL
;
12346 /* Indicate that this display is dead. */
12348 dpyinfo
->display
= 0;
12350 /* First delete frames whose mini-buffers are on frames
12351 that are on the dead display. */
12352 FOR_EACH_FRAME (tail
, frame
)
12354 Lisp_Object minibuf_frame
;
12356 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
12357 if (FRAME_X_P (XFRAME (frame
))
12358 && FRAME_X_P (XFRAME (minibuf_frame
))
12359 && ! EQ (frame
, minibuf_frame
)
12360 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
12361 Fdelete_frame (frame
, Qt
);
12364 /* Now delete all remaining frames on the dead display.
12365 We are now sure none of these is used as the mini-buffer
12366 for another frame that we need to delete. */
12367 FOR_EACH_FRAME (tail
, frame
)
12368 if (FRAME_X_P (XFRAME (frame
))
12369 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
12371 /* Set this to t so that Fdelete_frame won't get confused
12372 trying to find a replacement. */
12373 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
12374 Fdelete_frame (frame
, Qt
);
12378 x_delete_display (dpyinfo
);
12380 x_uncatch_errors (dpy
, count
);
12382 if (x_display_list
== 0)
12384 fprintf (stderr
, "%s\n", error_msg
);
12385 shut_down_emacs (0, 0, Qnil
);
12389 /* Ordinary stack unwind doesn't deal with these. */
12391 sigunblock (sigmask (SIGIO
));
12393 sigunblock (sigmask (SIGALRM
));
12394 TOTALLY_UNBLOCK_INPUT
;
12396 clear_waiting_for_input ();
12397 error ("%s", error_msg
);
12401 /* This is the usual handler for X protocol errors.
12402 It kills all frames on the display that we got the error for.
12403 If that was the only one, it prints an error message and kills Emacs. */
12406 x_error_quitter (display
, error
)
12408 XErrorEvent
*error
;
12410 char buf
[256], buf1
[356];
12412 /* Note that there is no real way portable across R3/R4 to get the
12413 original error handler. */
12415 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
12416 sprintf (buf1
, "X protocol error: %s on protocol request %d",
12417 buf
, error
->request_code
);
12418 x_connection_closed (display
, buf1
);
12422 /* This is the first-level handler for X protocol errors.
12423 It calls x_error_quitter or x_error_catcher. */
12426 x_error_handler (display
, error
)
12428 XErrorEvent
*error
;
12430 if (! NILP (x_error_message_string
))
12431 x_error_catcher (display
, error
);
12433 x_error_quitter (display
, error
);
12437 /* This is the handler for X IO errors, always.
12438 It kills all frames on the display that we lost touch with.
12439 If that was the only one, it prints an error message and kills Emacs. */
12442 x_io_error_quitter (display
)
12447 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
12448 x_connection_closed (display
, buf
);
12452 /* Changing the font of the frame. */
12454 /* Give frame F the font named FONTNAME as its default font, and
12455 return the full name of that font. FONTNAME may be a wildcard
12456 pattern; in that case, we choose some font that fits the pattern.
12457 The return value shows which font we chose. */
12460 x_new_font (f
, fontname
)
12462 register char *fontname
;
12464 struct font_info
*fontp
12465 = FS_LOAD_FONT (f
, 0, fontname
, -1);
12470 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
12471 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
12472 f
->output_data
.x
->fontset
= -1;
12474 x_compute_fringe_widths (f
, 1);
12476 /* Compute the scroll bar width in character columns. */
12477 if (f
->scroll_bar_pixel_width
> 0)
12479 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12480 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
12484 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12485 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
12488 /* Now make the frame display the given font. */
12489 if (FRAME_X_WINDOW (f
) != 0)
12491 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
12492 f
->output_data
.x
->font
->fid
);
12493 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
12494 f
->output_data
.x
->font
->fid
);
12495 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
12496 f
->output_data
.x
->font
->fid
);
12498 frame_update_line_height (f
);
12500 /* Don't change the size of a tip frame; there's no point in
12501 doing it because it's done in Fx_show_tip, and it leads to
12502 problems because the tip frame has no widget. */
12503 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
12504 x_set_window_size (f
, 0, f
->width
, f
->height
);
12507 /* If we are setting a new frame's font for the first time,
12508 there are no faces yet, so this font's height is the line height. */
12509 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
12511 return build_string (fontp
->full_name
);
12514 /* Give frame F the fontset named FONTSETNAME as its default font, and
12515 return the full name of that fontset. FONTSETNAME may be a wildcard
12516 pattern; in that case, we choose some fontset that fits the pattern.
12517 The return value shows which fontset we chose. */
12520 x_new_fontset (f
, fontsetname
)
12524 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
12525 Lisp_Object result
;
12530 if (f
->output_data
.x
->fontset
== fontset
)
12531 /* This fontset is already set in frame F. There's nothing more
12533 return fontset_name (fontset
);
12535 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
12537 if (!STRINGP (result
))
12538 /* Can't load ASCII font. */
12541 /* Since x_new_font doesn't update any fontset information, do it now. */
12542 f
->output_data
.x
->fontset
= fontset
;
12546 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
12547 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
12550 return build_string (fontsetname
);
12553 /* Compute actual fringe widths */
12556 x_compute_fringe_widths (f
, redraw
)
12560 int o_left
= f
->output_data
.x
->left_fringe_width
;
12561 int o_right
= f
->output_data
.x
->right_fringe_width
;
12562 int o_cols
= f
->output_data
.x
->fringe_cols
;
12564 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
12565 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
12566 int left_fringe_width
, right_fringe_width
;
12568 if (!NILP (left_fringe
))
12569 left_fringe
= Fcdr (left_fringe
);
12570 if (!NILP (right_fringe
))
12571 right_fringe
= Fcdr (right_fringe
);
12573 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
12574 XINT (left_fringe
));
12575 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
12576 XINT (right_fringe
));
12578 if (left_fringe_width
|| right_fringe_width
)
12580 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
12581 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
12582 int conf_wid
= left_wid
+ right_wid
;
12583 int font_wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12584 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
12585 int real_wid
= cols
* font_wid
;
12586 if (left_wid
&& right_wid
)
12588 if (left_fringe_width
< 0)
12590 /* Left fringe width is fixed, adjust right fringe if necessary */
12591 f
->output_data
.x
->left_fringe_width
= left_wid
;
12592 f
->output_data
.x
->right_fringe_width
= real_wid
- left_wid
;
12594 else if (right_fringe_width
< 0)
12596 /* Right fringe width is fixed, adjust left fringe if necessary */
12597 f
->output_data
.x
->left_fringe_width
= real_wid
- right_wid
;
12598 f
->output_data
.x
->right_fringe_width
= right_wid
;
12602 /* Adjust both fringes with an equal amount.
12603 Note that we are doing integer arithmetic here, so don't
12604 lose a pixel if the total width is an odd number. */
12605 int fill
= real_wid
- conf_wid
;
12606 f
->output_data
.x
->left_fringe_width
= left_wid
+ fill
/2;
12607 f
->output_data
.x
->right_fringe_width
= right_wid
+ fill
- fill
/2;
12610 else if (left_fringe_width
)
12612 f
->output_data
.x
->left_fringe_width
= real_wid
;
12613 f
->output_data
.x
->right_fringe_width
= 0;
12617 f
->output_data
.x
->left_fringe_width
= 0;
12618 f
->output_data
.x
->right_fringe_width
= real_wid
;
12620 f
->output_data
.x
->fringe_cols
= cols
;
12621 f
->output_data
.x
->fringes_extra
= real_wid
;
12625 f
->output_data
.x
->left_fringe_width
= 0;
12626 f
->output_data
.x
->right_fringe_width
= 0;
12627 f
->output_data
.x
->fringe_cols
= 0;
12628 f
->output_data
.x
->fringes_extra
= 0;
12631 if (redraw
&& FRAME_VISIBLE_P (f
))
12632 if (o_left
!= f
->output_data
.x
->left_fringe_width
||
12633 o_right
!= f
->output_data
.x
->right_fringe_width
||
12634 o_cols
!= f
->output_data
.x
->fringe_cols
)
12638 /***********************************************************************
12640 ***********************************************************************/
12646 /* XIM destroy callback function, which is called whenever the
12647 connection to input method XIM dies. CLIENT_DATA contains a
12648 pointer to the x_display_info structure corresponding to XIM. */
12651 xim_destroy_callback (xim
, client_data
, call_data
)
12653 XPointer client_data
;
12654 XPointer call_data
;
12656 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
12657 Lisp_Object frame
, tail
;
12661 /* No need to call XDestroyIC.. */
12662 FOR_EACH_FRAME (tail
, frame
)
12664 struct frame
*f
= XFRAME (frame
);
12665 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
12667 FRAME_XIC (f
) = NULL
;
12668 if (FRAME_XIC_FONTSET (f
))
12670 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
12671 FRAME_XIC_FONTSET (f
) = NULL
;
12676 /* No need to call XCloseIM. */
12677 dpyinfo
->xim
= NULL
;
12678 XFree (dpyinfo
->xim_styles
);
12682 #endif /* HAVE_X11R6 */
12684 /* Open the connection to the XIM server on display DPYINFO.
12685 RESOURCE_NAME is the resource name Emacs uses. */
12688 xim_open_dpy (dpyinfo
, resource_name
)
12689 struct x_display_info
*dpyinfo
;
12690 char *resource_name
;
12695 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
12696 dpyinfo
->xim
= xim
;
12701 XIMCallback destroy
;
12704 /* Get supported styles and XIM values. */
12705 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
12708 destroy
.callback
= xim_destroy_callback
;
12709 destroy
.client_data
= (XPointer
)dpyinfo
;
12710 /* This isn't prototyped in OSF 5.0. */
12711 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
12715 #else /* not USE_XIM */
12716 dpyinfo
->xim
= NULL
;
12717 #endif /* not USE_XIM */
12721 #ifdef HAVE_X11R6_XIM
12725 struct x_display_info
*dpyinfo
;
12726 char *resource_name
;
12729 /* XIM instantiate callback function, which is called whenever an XIM
12730 server is available. DISPLAY is teh display of the XIM.
12731 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12732 when the callback was registered. */
12735 xim_instantiate_callback (display
, client_data
, call_data
)
12737 XPointer client_data
;
12738 XPointer call_data
;
12740 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12741 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12743 /* We don't support multiple XIM connections. */
12747 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12749 /* Create XIC for the existing frames on the same display, as long
12750 as they have no XIC. */
12751 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12753 Lisp_Object tail
, frame
;
12756 FOR_EACH_FRAME (tail
, frame
)
12758 struct frame
*f
= XFRAME (frame
);
12760 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12761 if (FRAME_XIC (f
) == NULL
)
12763 create_frame_xic (f
);
12764 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12765 xic_set_statusarea (f
);
12766 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12768 struct window
*w
= XWINDOW (f
->selected_window
);
12769 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12778 #endif /* HAVE_X11R6_XIM */
12781 /* Open a connection to the XIM server on display DPYINFO.
12782 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12783 connection only at the first time. On X11R6, open the connection
12784 in the XIM instantiate callback function. */
12787 xim_initialize (dpyinfo
, resource_name
)
12788 struct x_display_info
*dpyinfo
;
12789 char *resource_name
;
12792 #ifdef HAVE_X11R6_XIM
12793 struct xim_inst_t
*xim_inst
;
12796 dpyinfo
->xim
= NULL
;
12797 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12798 xim_inst
->dpyinfo
= dpyinfo
;
12799 len
= strlen (resource_name
);
12800 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12801 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12802 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12803 resource_name
, EMACS_CLASS
,
12804 xim_instantiate_callback
,
12805 /* Fixme: This is XPointer in
12806 XFree86 but (XPointer *) on
12807 Tru64, at least. */
12808 (XPointer
) xim_inst
);
12809 #else /* not HAVE_X11R6_XIM */
12810 dpyinfo
->xim
= NULL
;
12811 xim_open_dpy (dpyinfo
, resource_name
);
12812 #endif /* not HAVE_X11R6_XIM */
12814 #else /* not USE_XIM */
12815 dpyinfo
->xim
= NULL
;
12816 #endif /* not USE_XIM */
12820 /* Close the connection to the XIM server on display DPYINFO. */
12823 xim_close_dpy (dpyinfo
)
12824 struct x_display_info
*dpyinfo
;
12827 #ifdef HAVE_X11R6_XIM
12828 if (dpyinfo
->display
)
12829 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12831 xim_instantiate_callback
, NULL
);
12832 #endif /* not HAVE_X11R6_XIM */
12833 if (dpyinfo
->display
)
12834 XCloseIM (dpyinfo
->xim
);
12835 dpyinfo
->xim
= NULL
;
12836 XFree (dpyinfo
->xim_styles
);
12837 #endif /* USE_XIM */
12840 #endif /* not HAVE_X11R6_XIM */
12844 /* Calculate the absolute position in frame F
12845 from its current recorded position values and gravity. */
12848 x_calc_absolute_position (f
)
12852 int win_x
= 0, win_y
= 0;
12853 int flags
= f
->output_data
.x
->size_hint_flags
;
12856 /* We have nothing to do if the current position
12857 is already for the top-left corner. */
12858 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12861 #ifdef USE_X_TOOLKIT
12862 this_window
= XtWindow (f
->output_data
.x
->widget
);
12864 this_window
= FRAME_X_WINDOW (f
);
12867 /* Find the position of the outside upper-left corner of
12868 the inner window, with respect to the outer window.
12869 But do this only if we will need the results. */
12870 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12875 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12878 x_clear_errors (FRAME_X_DISPLAY (f
));
12879 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12881 /* From-window, to-window. */
12883 f
->output_data
.x
->parent_desc
,
12885 /* From-position, to-position. */
12886 0, 0, &win_x
, &win_y
,
12888 /* Child of win. */
12890 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12892 Window newroot
, newparent
= 0xdeadbeef;
12893 Window
*newchildren
;
12894 unsigned int nchildren
;
12896 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12897 &newparent
, &newchildren
, &nchildren
))
12900 XFree ((char *) newchildren
);
12902 f
->output_data
.x
->parent_desc
= newparent
;
12908 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12912 /* Treat negative positions as relative to the leftmost bottommost
12913 position that fits on the screen. */
12914 if (flags
& XNegative
)
12915 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12916 - 2 * f
->output_data
.x
->border_width
- win_x
12918 + f
->output_data
.x
->left_pos
);
12921 int height
= PIXEL_HEIGHT (f
);
12923 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12924 /* Something is fishy here. When using Motif, starting Emacs with
12925 `-g -0-0', the frame appears too low by a few pixels.
12927 This seems to be so because initially, while Emacs is starting,
12928 the column widget's height and the frame's pixel height are
12929 different. The column widget's height is the right one. In
12930 later invocations, when Emacs is up, the frame's pixel height
12933 It's not obvious where the initial small difference comes from.
12934 2000-12-01, gerd. */
12936 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12939 if (flags
& YNegative
)
12940 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12941 - 2 * f
->output_data
.x
->border_width
12944 + f
->output_data
.x
->top_pos
);
12947 /* The left_pos and top_pos
12948 are now relative to the top and left screen edges,
12949 so the flags should correspond. */
12950 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12953 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12954 to really change the position, and 0 when calling from
12955 x_make_frame_visible (in that case, XOFF and YOFF are the current
12956 position values). It is -1 when calling from x_set_frame_parameters,
12957 which means, do adjust for borders but don't change the gravity. */
12960 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12962 register int xoff
, yoff
;
12963 int change_gravity
;
12965 int modified_top
, modified_left
;
12967 if (change_gravity
> 0)
12969 f
->output_data
.x
->top_pos
= yoff
;
12970 f
->output_data
.x
->left_pos
= xoff
;
12971 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12973 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12975 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12976 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12978 x_calc_absolute_position (f
);
12981 x_wm_set_size_hint (f
, (long) 0, 0);
12983 modified_left
= f
->output_data
.x
->left_pos
;
12984 modified_top
= f
->output_data
.x
->top_pos
;
12985 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12986 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12987 /* It is a mystery why we need to add the border_width here
12988 when the frame is already visible, but experiment says we do. */
12989 if (change_gravity
!= 0)
12991 modified_left
+= f
->output_data
.x
->border_width
;
12992 modified_top
+= f
->output_data
.x
->border_width
;
12996 #ifdef USE_X_TOOLKIT
12997 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12998 modified_left
, modified_top
);
12999 #else /* not USE_X_TOOLKIT */
13000 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13001 modified_left
, modified_top
);
13002 #endif /* not USE_X_TOOLKIT */
13006 /* Check if we need to resize the frame due to a fullscreen request.
13007 If so needed, resize the frame. */
13009 x_check_fullscreen (f
)
13012 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
13014 int width
, height
, ign
;
13016 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
13017 &f
->output_data
.x
->top_pos
);
13019 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
13021 /* We do not need to move the window, it shall be taken care of
13022 when setting WM manager hints.
13023 If the frame is visible already, the position is checked by
13024 x_check_fullscreen_move. */
13025 if (f
->width
!= width
|| f
->height
!= height
)
13027 change_frame_size (f
, height
, width
, 0, 1, 0);
13028 SET_FRAME_GARBAGED (f
);
13029 cancel_mouse_face (f
);
13031 /* Wait for the change of frame size to occur */
13032 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
13038 /* If frame parameters are set after the frame is mapped, we need to move
13039 the window. This is done in xfns.c.
13040 Some window managers moves the window to the right position, some
13041 moves the outer window manager window to the specified position.
13042 Here we check that we are in the right spot. If not, make a second
13043 move, assuming we are dealing with the second kind of window manager. */
13045 x_check_fullscreen_move (f
)
13048 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
13050 int expect_top
= f
->output_data
.x
->top_pos
;
13051 int expect_left
= f
->output_data
.x
->left_pos
;
13053 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
13055 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
13058 if (expect_top
!= f
->output_data
.x
->top_pos
13059 || expect_left
!= f
->output_data
.x
->left_pos
)
13060 x_set_offset (f
, expect_left
, expect_top
, 1);
13062 /* Just do this once */
13063 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
13068 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
13069 wanted positions of the WM window (not emacs window).
13070 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
13071 window (FRAME_X_WINDOW).
13074 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
13081 int newwidth
= f
->width
, newheight
= f
->height
;
13083 *top_pos
= f
->output_data
.x
->top_pos
;
13084 *left_pos
= f
->output_data
.x
->left_pos
;
13086 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
13090 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
13091 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
13092 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
13093 - f
->output_data
.x
->y_pixels_diff
;
13094 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
13098 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
13102 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
13103 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
13104 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
13105 - f
->output_data
.x
->x_pixels_diff
;
13106 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
13111 *height
= newheight
;
13115 /* Change the size of frame F's X window to COLS/ROWS in the case F
13116 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
13117 top-left-corner window gravity for this size change and subsequent
13118 size changes. Otherwise we leave the window gravity unchanged. */
13121 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
13123 int change_gravity
;
13126 int pixelwidth
, pixelheight
;
13128 check_frame_size (f
, &rows
, &cols
);
13129 f
->output_data
.x
->vertical_scroll_bar_extra
13130 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
13132 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
13133 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
13134 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
13136 x_compute_fringe_widths (f
, 0);
13138 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
13139 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
13141 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
13142 x_wm_set_size_hint (f
, (long) 0, 0);
13144 XSync (FRAME_X_DISPLAY (f
), False
);
13145 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13146 pixelwidth
, pixelheight
);
13148 /* Now, strictly speaking, we can't be sure that this is accurate,
13149 but the window manager will get around to dealing with the size
13150 change request eventually, and we'll hear how it went when the
13151 ConfigureNotify event gets here.
13153 We could just not bother storing any of this information here,
13154 and let the ConfigureNotify event set everything up, but that
13155 might be kind of confusing to the Lisp code, since size changes
13156 wouldn't be reported in the frame parameters until some random
13157 point in the future when the ConfigureNotify event arrives.
13159 We pass 1 for DELAY since we can't run Lisp code inside of
13161 change_frame_size (f
, rows
, cols
, 0, 1, 0);
13162 PIXEL_WIDTH (f
) = pixelwidth
;
13163 PIXEL_HEIGHT (f
) = pixelheight
;
13165 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
13166 receive in the ConfigureNotify event; if we get what we asked
13167 for, then the event won't cause the screen to become garbaged, so
13168 we have to make sure to do it here. */
13169 SET_FRAME_GARBAGED (f
);
13171 XFlush (FRAME_X_DISPLAY (f
));
13175 /* Call this to change the size of frame F's x-window.
13176 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
13177 for this size change and subsequent size changes.
13178 Otherwise we leave the window gravity unchanged. */
13181 x_set_window_size (f
, change_gravity
, cols
, rows
)
13183 int change_gravity
;
13188 #ifdef USE_X_TOOLKIT
13190 if (f
->output_data
.x
->widget
!= NULL
)
13192 /* The x and y position of the widget is clobbered by the
13193 call to XtSetValues within EmacsFrameSetCharSize.
13194 This is a real kludge, but I don't understand Xt so I can't
13195 figure out a correct fix. Can anyone else tell me? -- rms. */
13196 int xpos
= f
->output_data
.x
->widget
->core
.x
;
13197 int ypos
= f
->output_data
.x
->widget
->core
.y
;
13198 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
13199 f
->output_data
.x
->widget
->core
.x
= xpos
;
13200 f
->output_data
.x
->widget
->core
.y
= ypos
;
13203 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13205 #else /* not USE_X_TOOLKIT */
13207 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13209 #endif /* not USE_X_TOOLKIT */
13211 /* If cursor was outside the new size, mark it as off. */
13212 mark_window_cursors_off (XWINDOW (f
->root_window
));
13214 /* Clear out any recollection of where the mouse highlighting was,
13215 since it might be in a place that's outside the new frame size.
13216 Actually checking whether it is outside is a pain in the neck,
13217 so don't try--just let the highlighting be done afresh with new size. */
13218 cancel_mouse_face (f
);
13223 /* Mouse warping. */
13226 x_set_mouse_position (f
, x
, y
)
13232 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
13233 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
13235 if (pix_x
< 0) pix_x
= 0;
13236 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
13238 if (pix_y
< 0) pix_y
= 0;
13239 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
13243 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13244 0, 0, 0, 0, pix_x
, pix_y
);
13248 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
13251 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
13257 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13258 0, 0, 0, 0, pix_x
, pix_y
);
13262 /* focus shifting, raising and lowering. */
13265 x_focus_on_frame (f
)
13268 #if 0 /* This proves to be unpleasant. */
13272 /* I don't think that the ICCCM allows programs to do things like this
13273 without the interaction of the window manager. Whatever you end up
13274 doing with this code, do it to x_unfocus_frame too. */
13275 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13276 RevertToPointerRoot
, CurrentTime
);
13281 x_unfocus_frame (f
)
13285 /* Look at the remarks in x_focus_on_frame. */
13286 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
13287 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
13288 RevertToPointerRoot
, CurrentTime
);
13292 /* Raise frame F. */
13298 if (f
->async_visible
)
13301 #ifdef USE_X_TOOLKIT
13302 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13303 #else /* not USE_X_TOOLKIT */
13304 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13305 #endif /* not USE_X_TOOLKIT */
13306 XFlush (FRAME_X_DISPLAY (f
));
13311 /* Lower frame F. */
13317 if (f
->async_visible
)
13320 #ifdef USE_X_TOOLKIT
13321 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13322 #else /* not USE_X_TOOLKIT */
13323 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13324 #endif /* not USE_X_TOOLKIT */
13325 XFlush (FRAME_X_DISPLAY (f
));
13331 XTframe_raise_lower (f
, raise_flag
)
13341 /* Change of visibility. */
13343 /* This tries to wait until the frame is really visible.
13344 However, if the window manager asks the user where to position
13345 the frame, this will return before the user finishes doing that.
13346 The frame will not actually be visible at that time,
13347 but it will become visible later when the window manager
13348 finishes with it. */
13351 x_make_frame_visible (f
)
13355 int original_top
, original_left
;
13356 int retry_count
= 2;
13362 type
= x_icon_type (f
);
13364 x_bitmap_icon (f
, type
);
13366 if (! FRAME_VISIBLE_P (f
))
13368 /* We test FRAME_GARBAGED_P here to make sure we don't
13369 call x_set_offset a second time
13370 if we get to x_make_frame_visible a second time
13371 before the window gets really visible. */
13372 if (! FRAME_ICONIFIED_P (f
)
13373 && ! f
->output_data
.x
->asked_for_visible
)
13374 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13376 f
->output_data
.x
->asked_for_visible
= 1;
13378 if (! EQ (Vx_no_window_manager
, Qt
))
13379 x_wm_set_window_state (f
, NormalState
);
13380 #ifdef USE_X_TOOLKIT
13381 /* This was XtPopup, but that did nothing for an iconified frame. */
13382 XtMapWidget (f
->output_data
.x
->widget
);
13383 #else /* not USE_X_TOOLKIT */
13384 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13385 #endif /* not USE_X_TOOLKIT */
13386 #if 0 /* This seems to bring back scroll bars in the wrong places
13387 if the window configuration has changed. They seem
13388 to come back ok without this. */
13389 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
13390 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13394 XFlush (FRAME_X_DISPLAY (f
));
13396 /* Synchronize to ensure Emacs knows the frame is visible
13397 before we do anything else. We do this loop with input not blocked
13398 so that incoming events are handled. */
13402 /* This must be before UNBLOCK_INPUT
13403 since events that arrive in response to the actions above
13404 will set it when they are handled. */
13405 int previously_visible
= f
->output_data
.x
->has_been_visible
;
13407 original_left
= f
->output_data
.x
->left_pos
;
13408 original_top
= f
->output_data
.x
->top_pos
;
13410 /* This must come after we set COUNT. */
13413 /* We unblock here so that arriving X events are processed. */
13415 /* Now move the window back to where it was "supposed to be".
13416 But don't do it if the gravity is negative.
13417 When the gravity is negative, this uses a position
13418 that is 3 pixels too low. Perhaps that's really the border width.
13420 Don't do this if the window has never been visible before,
13421 because the window manager may choose the position
13422 and we don't want to override it. */
13424 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
13425 && f
->output_data
.x
->win_gravity
== NorthWestGravity
13426 && previously_visible
)
13430 unsigned int width
, height
, border
, depth
;
13434 /* On some window managers (such as FVWM) moving an existing
13435 window, even to the same place, causes the window manager
13436 to introduce an offset. This can cause the window to move
13437 to an unexpected location. Check the geometry (a little
13438 slow here) and then verify that the window is in the right
13439 place. If the window is not in the right place, move it
13440 there, and take the potential window manager hit. */
13441 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13442 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
13444 if (original_left
!= x
|| original_top
!= y
)
13445 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13446 original_left
, original_top
);
13451 XSETFRAME (frame
, f
);
13453 /* Wait until the frame is visible. Process X events until a
13454 MapNotify event has been seen, or until we think we won't get a
13455 MapNotify at all.. */
13456 for (count
= input_signal_count
+ 10;
13457 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
13459 /* Force processing of queued events. */
13462 /* Machines that do polling rather than SIGIO have been
13463 observed to go into a busy-wait here. So we'll fake an
13464 alarm signal to let the handler know that there's something
13465 to be read. We used to raise a real alarm, but it seems
13466 that the handler isn't always enabled here. This is
13468 if (input_polling_used ())
13470 /* It could be confusing if a real alarm arrives while
13471 processing the fake one. Turn it off and let the
13472 handler reset it. */
13473 extern void poll_for_input_1
P_ ((void));
13474 int old_poll_suppress_count
= poll_suppress_count
;
13475 poll_suppress_count
= 1;
13476 poll_for_input_1 ();
13477 poll_suppress_count
= old_poll_suppress_count
;
13480 /* See if a MapNotify event has been processed. */
13481 FRAME_SAMPLE_VISIBILITY (f
);
13486 (let ((f (selected-frame)))
13490 the frame is not raised with various window managers on
13491 FreeBSD, Linux and Solaris. It turns out that, for some
13492 unknown reason, the call to XtMapWidget is completely ignored.
13493 Mapping the widget a second time works. */
13495 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
13500 /* Change from mapped state to withdrawn state. */
13502 /* Make the frame visible (mapped and not iconified). */
13505 x_make_frame_invisible (f
)
13510 #ifdef USE_X_TOOLKIT
13511 /* Use the frame's outermost window, not the one we normally draw on. */
13512 window
= XtWindow (f
->output_data
.x
->widget
);
13513 #else /* not USE_X_TOOLKIT */
13514 window
= FRAME_X_WINDOW (f
);
13515 #endif /* not USE_X_TOOLKIT */
13517 /* Don't keep the highlight on an invisible frame. */
13518 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13519 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13521 #if 0/* This might add unreliability; I don't trust it -- rms. */
13522 if (! f
->async_visible
&& ! f
->async_iconified
)
13528 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
13529 that the current position of the window is user-specified, rather than
13530 program-specified, so that when the window is mapped again, it will be
13531 placed at the same location, without forcing the user to position it
13532 by hand again (they have already done that once for this window.) */
13533 x_wm_set_size_hint (f
, (long) 0, 1);
13537 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
13538 DefaultScreen (FRAME_X_DISPLAY (f
))))
13540 UNBLOCK_INPUT_RESIGNAL
;
13541 error ("Can't notify window manager of window withdrawal");
13543 #else /* ! defined (HAVE_X11R4) */
13545 /* Tell the window manager what we're going to do. */
13546 if (! EQ (Vx_no_window_manager
, Qt
))
13550 unmap
.xunmap
.type
= UnmapNotify
;
13551 unmap
.xunmap
.window
= window
;
13552 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
13553 unmap
.xunmap
.from_configure
= False
;
13554 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13555 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13557 SubstructureRedirectMaskSubstructureNotifyMask
,
13560 UNBLOCK_INPUT_RESIGNAL
;
13561 error ("Can't notify window manager of withdrawal");
13565 /* Unmap the window ourselves. Cheeky! */
13566 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
13567 #endif /* ! defined (HAVE_X11R4) */
13569 /* We can't distinguish this from iconification
13570 just by the event that we get from the server.
13571 So we can't win using the usual strategy of letting
13572 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
13573 and synchronize with the server to make sure we agree. */
13575 FRAME_ICONIFIED_P (f
) = 0;
13576 f
->async_visible
= 0;
13577 f
->async_iconified
= 0;
13584 /* Change window state from mapped to iconified. */
13587 x_iconify_frame (f
)
13593 /* Don't keep the highlight on an invisible frame. */
13594 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13595 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13597 if (f
->async_iconified
)
13602 FRAME_SAMPLE_VISIBILITY (f
);
13604 type
= x_icon_type (f
);
13606 x_bitmap_icon (f
, type
);
13608 #ifdef USE_X_TOOLKIT
13610 if (! FRAME_VISIBLE_P (f
))
13612 if (! EQ (Vx_no_window_manager
, Qt
))
13613 x_wm_set_window_state (f
, IconicState
);
13614 /* This was XtPopup, but that did nothing for an iconified frame. */
13615 XtMapWidget (f
->output_data
.x
->widget
);
13616 /* The server won't give us any event to indicate
13617 that an invisible frame was changed to an icon,
13618 so we have to record it here. */
13621 f
->async_iconified
= 1;
13622 f
->async_visible
= 0;
13627 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
13628 XtWindow (f
->output_data
.x
->widget
),
13629 DefaultScreen (FRAME_X_DISPLAY (f
)));
13633 error ("Can't notify window manager of iconification");
13635 f
->async_iconified
= 1;
13636 f
->async_visible
= 0;
13640 XFlush (FRAME_X_DISPLAY (f
));
13642 #else /* not USE_X_TOOLKIT */
13644 /* Make sure the X server knows where the window should be positioned,
13645 in case the user deiconifies with the window manager. */
13646 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
13647 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13649 /* Since we don't know which revision of X we're running, we'll use both
13650 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
13652 /* X11R4: send a ClientMessage to the window manager using the
13653 WM_CHANGE_STATE type. */
13657 message
.xclient
.window
= FRAME_X_WINDOW (f
);
13658 message
.xclient
.type
= ClientMessage
;
13659 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
13660 message
.xclient
.format
= 32;
13661 message
.xclient
.data
.l
[0] = IconicState
;
13663 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13664 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13666 SubstructureRedirectMask
| SubstructureNotifyMask
,
13669 UNBLOCK_INPUT_RESIGNAL
;
13670 error ("Can't notify window manager of iconification");
13674 /* X11R3: set the initial_state field of the window manager hints to
13676 x_wm_set_window_state (f
, IconicState
);
13678 if (!FRAME_VISIBLE_P (f
))
13680 /* If the frame was withdrawn, before, we must map it. */
13681 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13684 f
->async_iconified
= 1;
13685 f
->async_visible
= 0;
13687 XFlush (FRAME_X_DISPLAY (f
));
13689 #endif /* not USE_X_TOOLKIT */
13693 /* Free X resources of frame F. */
13696 x_free_frame_resources (f
)
13699 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13701 struct scroll_bar
*b
;
13705 /* If a display connection is dead, don't try sending more
13706 commands to the X server. */
13707 if (dpyinfo
->display
)
13709 if (f
->output_data
.x
->icon_desc
)
13710 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
13712 #ifdef USE_X_TOOLKIT
13713 /* Explicitly destroy the scroll bars of the frame. Without
13714 this, we get "BadDrawable" errors from the toolkit later on,
13715 presumably from expose events generated for the disappearing
13716 toolkit scroll bars. */
13717 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
13719 b
= XSCROLL_BAR (bar
);
13720 x_scroll_bar_remove (b
);
13726 free_frame_xic (f
);
13729 #ifdef USE_X_TOOLKIT
13730 if (f
->output_data
.x
->widget
)
13732 XtDestroyWidget (f
->output_data
.x
->widget
);
13733 f
->output_data
.x
->widget
= NULL
;
13735 /* Tooltips don't have widgets, only a simple X window, even if
13736 we are using a toolkit. */
13737 else if (FRAME_X_WINDOW (f
))
13738 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13740 free_frame_menubar (f
);
13741 #else /* !USE_X_TOOLKIT */
13742 if (FRAME_X_WINDOW (f
))
13743 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13744 #endif /* !USE_X_TOOLKIT */
13746 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
13747 unload_color (f
, f
->output_data
.x
->background_pixel
);
13748 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
13749 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
13750 unload_color (f
, f
->output_data
.x
->border_pixel
);
13751 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
13753 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
13754 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
13755 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
13756 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
13757 #ifdef USE_TOOLKIT_SCROLL_BARS
13758 /* Scrollbar shadow colors. */
13759 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
13760 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
13761 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
13762 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
13763 #endif /* USE_TOOLKIT_SCROLL_BARS */
13764 if (f
->output_data
.x
->white_relief
.allocated_p
)
13765 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
13766 if (f
->output_data
.x
->black_relief
.allocated_p
)
13767 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
13769 if (FRAME_FACE_CACHE (f
))
13770 free_frame_faces (f
);
13773 XFlush (FRAME_X_DISPLAY (f
));
13776 if (f
->output_data
.x
->saved_menu_event
)
13777 xfree (f
->output_data
.x
->saved_menu_event
);
13779 xfree (f
->output_data
.x
);
13780 f
->output_data
.x
= NULL
;
13782 if (f
== dpyinfo
->x_focus_frame
)
13783 dpyinfo
->x_focus_frame
= 0;
13784 if (f
== dpyinfo
->x_focus_event_frame
)
13785 dpyinfo
->x_focus_event_frame
= 0;
13786 if (f
== dpyinfo
->x_highlight_frame
)
13787 dpyinfo
->x_highlight_frame
= 0;
13789 if (f
== dpyinfo
->mouse_face_mouse_frame
)
13791 dpyinfo
->mouse_face_beg_row
13792 = dpyinfo
->mouse_face_beg_col
= -1;
13793 dpyinfo
->mouse_face_end_row
13794 = dpyinfo
->mouse_face_end_col
= -1;
13795 dpyinfo
->mouse_face_window
= Qnil
;
13796 dpyinfo
->mouse_face_deferred_gc
= 0;
13797 dpyinfo
->mouse_face_mouse_frame
= 0;
13804 /* Destroy the X window of frame F. */
13807 x_destroy_window (f
)
13810 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13812 /* If a display connection is dead, don't try sending more
13813 commands to the X server. */
13814 if (dpyinfo
->display
!= 0)
13815 x_free_frame_resources (f
);
13817 dpyinfo
->reference_count
--;
13821 /* Setting window manager hints. */
13823 /* Set the normal size hints for the window manager, for frame F.
13824 FLAGS is the flags word to use--or 0 meaning preserve the flags
13825 that the window now has.
13826 If USER_POSITION is nonzero, we set the USPosition
13827 flag (this is useful when FLAGS is 0). */
13830 x_wm_set_size_hint (f
, flags
, user_position
)
13835 XSizeHints size_hints
;
13837 #ifdef USE_X_TOOLKIT
13840 Dimension widget_width
, widget_height
;
13841 Window window
= XtWindow (f
->output_data
.x
->widget
);
13842 #else /* not USE_X_TOOLKIT */
13843 Window window
= FRAME_X_WINDOW (f
);
13844 #endif /* not USE_X_TOOLKIT */
13846 /* Setting PMaxSize caused various problems. */
13847 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
13849 size_hints
.x
= f
->output_data
.x
->left_pos
;
13850 size_hints
.y
= f
->output_data
.x
->top_pos
;
13852 #ifdef USE_X_TOOLKIT
13853 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
13854 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
13855 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
13856 size_hints
.height
= widget_height
;
13857 size_hints
.width
= widget_width
;
13858 #else /* not USE_X_TOOLKIT */
13859 size_hints
.height
= PIXEL_HEIGHT (f
);
13860 size_hints
.width
= PIXEL_WIDTH (f
);
13861 #endif /* not USE_X_TOOLKIT */
13863 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13864 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13865 size_hints
.max_width
13866 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13867 size_hints
.max_height
13868 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13870 /* Calculate the base and minimum sizes.
13872 (When we use the X toolkit, we don't do it here.
13873 Instead we copy the values that the widgets are using, below.) */
13874 #ifndef USE_X_TOOLKIT
13876 int base_width
, base_height
;
13877 int min_rows
= 0, min_cols
= 0;
13879 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13880 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13882 check_frame_size (f
, &min_rows
, &min_cols
);
13884 /* The window manager uses the base width hints to calculate the
13885 current number of rows and columns in the frame while
13886 resizing; min_width and min_height aren't useful for this
13887 purpose, since they might not give the dimensions for a
13888 zero-row, zero-column frame.
13890 We use the base_width and base_height members if we have
13891 them; otherwise, we set the min_width and min_height members
13892 to the size for a zero x zero frame. */
13895 size_hints
.flags
|= PBaseSize
;
13896 size_hints
.base_width
= base_width
;
13897 size_hints
.base_height
= base_height
;
13898 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13899 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13901 size_hints
.min_width
= base_width
;
13902 size_hints
.min_height
= base_height
;
13906 /* If we don't need the old flags, we don't need the old hint at all. */
13909 size_hints
.flags
|= flags
;
13912 #endif /* not USE_X_TOOLKIT */
13915 XSizeHints hints
; /* Sometimes I hate X Windows... */
13916 long supplied_return
;
13920 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13923 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13926 #ifdef USE_X_TOOLKIT
13927 size_hints
.base_height
= hints
.base_height
;
13928 size_hints
.base_width
= hints
.base_width
;
13929 size_hints
.min_height
= hints
.min_height
;
13930 size_hints
.min_width
= hints
.min_width
;
13934 size_hints
.flags
|= flags
;
13939 if (hints
.flags
& PSize
)
13940 size_hints
.flags
|= PSize
;
13941 if (hints
.flags
& PPosition
)
13942 size_hints
.flags
|= PPosition
;
13943 if (hints
.flags
& USPosition
)
13944 size_hints
.flags
|= USPosition
;
13945 if (hints
.flags
& USSize
)
13946 size_hints
.flags
|= USSize
;
13950 #ifndef USE_X_TOOLKIT
13955 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
13956 size_hints
.flags
|= PWinGravity
;
13960 size_hints
.flags
&= ~ PPosition
;
13961 size_hints
.flags
|= USPosition
;
13963 #endif /* PWinGravity */
13966 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13968 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13972 /* Used for IconicState or NormalState */
13975 x_wm_set_window_state (f
, state
)
13979 #ifdef USE_X_TOOLKIT
13982 XtSetArg (al
[0], XtNinitialState
, state
);
13983 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13984 #else /* not USE_X_TOOLKIT */
13985 Window window
= FRAME_X_WINDOW (f
);
13987 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
13988 f
->output_data
.x
->wm_hints
.initial_state
= state
;
13990 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13991 #endif /* not USE_X_TOOLKIT */
13995 x_wm_set_icon_pixmap (f
, pixmap_id
)
13999 Pixmap icon_pixmap
;
14001 #ifndef USE_X_TOOLKIT
14002 Window window
= FRAME_X_WINDOW (f
);
14007 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
14008 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
14012 /* It seems there is no way to turn off use of an icon pixmap.
14013 The following line does it, only if no icon has yet been created,
14014 for some window managers. But with mwm it crashes.
14015 Some people say it should clear the IconPixmapHint bit in this case,
14016 but that doesn't work, and the X consortium said it isn't the
14017 right thing at all. Since there is no way to win,
14018 best to explicitly give up. */
14020 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
14026 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
14030 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
14031 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
14034 #else /* not USE_X_TOOLKIT */
14036 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
14037 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
14039 #endif /* not USE_X_TOOLKIT */
14043 x_wm_set_icon_position (f
, icon_x
, icon_y
)
14045 int icon_x
, icon_y
;
14047 #ifdef USE_X_TOOLKIT
14048 Window window
= XtWindow (f
->output_data
.x
->widget
);
14050 Window window
= FRAME_X_WINDOW (f
);
14053 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
14054 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
14055 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
14057 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
14061 /***********************************************************************
14063 ***********************************************************************/
14065 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
14068 x_get_font_info (f
, font_idx
)
14072 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
14076 /* Return a list of names of available fonts matching PATTERN on frame F.
14078 If SIZE is > 0, it is the size (maximum bounds width) of fonts
14081 SIZE < 0 means include scalable fonts.
14083 Frame F null means we have not yet created any frame on X, and
14084 consult the first display in x_display_list. MAXNAMES sets a limit
14085 on how many fonts to match. */
14088 x_list_fonts (f
, pattern
, size
, maxnames
)
14090 Lisp_Object pattern
;
14094 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
14095 Lisp_Object tem
, second_best
;
14096 struct x_display_info
*dpyinfo
14097 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
14098 Display
*dpy
= dpyinfo
->display
;
14099 int try_XLoadQueryFont
= 0;
14101 int allow_scalable_fonts_p
= 0;
14105 allow_scalable_fonts_p
= 1;
14109 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
14110 if (NILP (patterns
))
14111 patterns
= Fcons (pattern
, Qnil
);
14113 if (maxnames
== 1 && !size
)
14114 /* We can return any single font matching PATTERN. */
14115 try_XLoadQueryFont
= 1;
14117 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
14120 char **names
= NULL
;
14122 pattern
= XCAR (patterns
);
14123 /* See if we cached the result for this particular query.
14124 The cache is an alist of the form:
14125 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
14126 tem
= XCDR (dpyinfo
->name_list_element
);
14127 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
14128 allow_scalable_fonts_p
? Qt
: Qnil
);
14129 list
= Fassoc (key
, tem
);
14132 list
= Fcdr_safe (list
);
14133 /* We have a cashed list. Don't have to get the list again. */
14137 /* At first, put PATTERN in the cache. */
14140 count
= x_catch_errors (dpy
);
14142 if (try_XLoadQueryFont
)
14145 unsigned long value
;
14147 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
14148 if (x_had_errors_p (dpy
))
14150 /* This error is perhaps due to insufficient memory on X
14151 server. Let's just ignore it. */
14153 x_clear_errors (dpy
);
14157 && XGetFontProperty (font
, XA_FONT
, &value
))
14159 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
14160 int len
= strlen (name
);
14163 /* If DXPC (a Differential X Protocol Compressor)
14164 Ver.3.7 is running, XGetAtomName will return null
14165 string. We must avoid such a name. */
14167 try_XLoadQueryFont
= 0;
14171 names
= (char **) alloca (sizeof (char *));
14172 /* Some systems only allow alloca assigned to a
14174 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
14175 bcopy (name
, names
[0], len
+ 1);
14180 try_XLoadQueryFont
= 0;
14183 XFreeFont (dpy
, font
);
14186 if (!try_XLoadQueryFont
)
14188 /* We try at least 10 fonts because XListFonts will return
14189 auto-scaled fonts at the head. */
14190 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
14192 if (x_had_errors_p (dpy
))
14194 /* This error is perhaps due to insufficient memory on X
14195 server. Let's just ignore it. */
14197 x_clear_errors (dpy
);
14201 x_uncatch_errors (dpy
, count
);
14208 /* Make a list of all the fonts we got back.
14209 Store that in the font cache for the display. */
14210 for (i
= 0; i
< num_fonts
; i
++)
14213 char *p
= names
[i
];
14214 int average_width
= -1, dashes
= 0;
14216 /* Count the number of dashes in NAMES[I]. If there are
14217 14 dashes, and the field value following 12th dash
14218 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
14219 is usually too ugly to be used for editing. Let's
14225 if (dashes
== 7) /* PIXEL_SIZE field */
14227 else if (dashes
== 12) /* AVERAGE_WIDTH field */
14228 average_width
= atoi (p
);
14231 if (allow_scalable_fonts_p
14232 || dashes
< 14 || average_width
!= 0)
14234 tem
= build_string (names
[i
]);
14235 if (NILP (Fassoc (tem
, list
)))
14237 if (STRINGP (Vx_pixel_size_width_font_regexp
)
14238 && ((fast_c_string_match_ignore_case
14239 (Vx_pixel_size_width_font_regexp
, names
[i
]))
14241 /* We can set the value of PIXEL_SIZE to the
14242 width of this font. */
14243 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
14245 /* For the moment, width is not known. */
14246 list
= Fcons (Fcons (tem
, Qnil
), list
);
14251 if (!try_XLoadQueryFont
)
14254 XFreeFontNames (names
);
14259 /* Now store the result in the cache. */
14260 XSETCDR (dpyinfo
->name_list_element
,
14261 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
14264 if (NILP (list
)) continue; /* Try the remaining alternatives. */
14266 newlist
= second_best
= Qnil
;
14267 /* Make a list of the fonts that have the right width. */
14268 for (; CONSP (list
); list
= XCDR (list
))
14274 if (!CONSP (tem
) || NILP (XCAR (tem
)))
14278 newlist
= Fcons (XCAR (tem
), newlist
);
14282 if (!INTEGERP (XCDR (tem
)))
14284 /* Since we have not yet known the size of this font, we
14285 must try slow function call XLoadQueryFont. */
14286 XFontStruct
*thisinfo
;
14289 count
= x_catch_errors (dpy
);
14290 thisinfo
= XLoadQueryFont (dpy
,
14291 SDATA (XCAR (tem
)));
14292 if (x_had_errors_p (dpy
))
14294 /* This error is perhaps due to insufficient memory on X
14295 server. Let's just ignore it. */
14297 x_clear_errors (dpy
);
14299 x_uncatch_errors (dpy
, count
);
14305 (thisinfo
->min_bounds
.width
== 0
14307 : make_number (thisinfo
->max_bounds
.width
)));
14309 XFreeFont (dpy
, thisinfo
);
14313 /* For unknown reason, the previous call of XListFont had
14314 returned a font which can't be opened. Record the size
14315 as 0 not to try to open it again. */
14316 XSETCDR (tem
, make_number (0));
14319 found_size
= XINT (XCDR (tem
));
14320 if (found_size
== size
)
14321 newlist
= Fcons (XCAR (tem
), newlist
);
14322 else if (found_size
> 0)
14324 if (NILP (second_best
))
14326 else if (found_size
< size
)
14328 if (XINT (XCDR (second_best
)) > size
14329 || XINT (XCDR (second_best
)) < found_size
)
14334 if (XINT (XCDR (second_best
)) > size
14335 && XINT (XCDR (second_best
)) > found_size
)
14340 if (!NILP (newlist
))
14342 else if (!NILP (second_best
))
14344 newlist
= Fcons (XCAR (second_best
), Qnil
);
14355 /* Check that FONT is valid on frame F. It is if it can be found in F's
14359 x_check_font (f
, font
)
14364 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14366 xassert (font
!= NULL
);
14368 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14369 if (dpyinfo
->font_table
[i
].name
14370 && font
== dpyinfo
->font_table
[i
].font
)
14373 xassert (i
< dpyinfo
->n_fonts
);
14376 #endif /* GLYPH_DEBUG != 0 */
14378 /* Set *W to the minimum width, *H to the minimum font height of FONT.
14379 Note: There are (broken) X fonts out there with invalid XFontStruct
14380 min_bounds contents. For example, handa@etl.go.jp reports that
14381 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
14382 have font->min_bounds.width == 0. */
14385 x_font_min_bounds (font
, w
, h
)
14389 *h
= FONT_HEIGHT (font
);
14390 *w
= font
->min_bounds
.width
;
14392 /* Try to handle the case where FONT->min_bounds has invalid
14393 contents. Since the only font known to have invalid min_bounds
14394 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
14396 *w
= font
->max_bounds
.width
;
14400 /* Compute the smallest character width and smallest font height over
14401 all fonts available on frame F. Set the members smallest_char_width
14402 and smallest_font_height in F's x_display_info structure to
14403 the values computed. Value is non-zero if smallest_font_height or
14404 smallest_char_width become smaller than they were before. */
14407 x_compute_min_glyph_bounds (f
)
14411 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14413 int old_width
= dpyinfo
->smallest_char_width
;
14414 int old_height
= dpyinfo
->smallest_font_height
;
14416 dpyinfo
->smallest_font_height
= 100000;
14417 dpyinfo
->smallest_char_width
= 100000;
14419 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14420 if (dpyinfo
->font_table
[i
].name
)
14422 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
14425 font
= (XFontStruct
*) fontp
->font
;
14426 xassert (font
!= (XFontStruct
*) ~0);
14427 x_font_min_bounds (font
, &w
, &h
);
14429 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
14430 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
14433 xassert (dpyinfo
->smallest_char_width
> 0
14434 && dpyinfo
->smallest_font_height
> 0);
14436 return (dpyinfo
->n_fonts
== 1
14437 || dpyinfo
->smallest_char_width
< old_width
14438 || dpyinfo
->smallest_font_height
< old_height
);
14442 /* Load font named FONTNAME of the size SIZE for frame F, and return a
14443 pointer to the structure font_info while allocating it dynamically.
14444 If SIZE is 0, load any size of font.
14445 If loading is failed, return NULL. */
14448 x_load_font (f
, fontname
, size
)
14450 register char *fontname
;
14453 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14454 Lisp_Object font_names
;
14457 /* Get a list of all the fonts that match this name. Once we
14458 have a list of matching fonts, we compare them against the fonts
14459 we already have by comparing names. */
14460 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
14462 if (!NILP (font_names
))
14467 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14468 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
14469 if (dpyinfo
->font_table
[i
].name
14470 && (!strcmp (dpyinfo
->font_table
[i
].name
,
14471 SDATA (XCAR (tail
)))
14472 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
14473 SDATA (XCAR (tail
)))))
14474 return (dpyinfo
->font_table
+ i
);
14477 /* Load the font and add it to the table. */
14481 struct font_info
*fontp
;
14482 unsigned long value
;
14485 /* If we have found fonts by x_list_font, load one of them. If
14486 not, we still try to load a font by the name given as FONTNAME
14487 because XListFonts (called in x_list_font) of some X server has
14488 a bug of not finding a font even if the font surely exists and
14489 is loadable by XLoadQueryFont. */
14490 if (size
> 0 && !NILP (font_names
))
14491 fontname
= (char *) SDATA (XCAR (font_names
));
14494 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
14495 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
14496 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
14498 /* This error is perhaps due to insufficient memory on X
14499 server. Let's just ignore it. */
14501 x_clear_errors (FRAME_X_DISPLAY (f
));
14503 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
14508 /* Find a free slot in the font table. */
14509 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14510 if (dpyinfo
->font_table
[i
].name
== NULL
)
14513 /* If no free slot found, maybe enlarge the font table. */
14514 if (i
== dpyinfo
->n_fonts
14515 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
14518 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
14519 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
14520 dpyinfo
->font_table
14521 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
14524 fontp
= dpyinfo
->font_table
+ i
;
14525 if (i
== dpyinfo
->n_fonts
)
14526 ++dpyinfo
->n_fonts
;
14528 /* Now fill in the slots of *FONTP. */
14530 fontp
->font
= font
;
14531 fontp
->font_idx
= i
;
14532 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
14533 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
14535 /* Try to get the full name of FONT. Put it in FULL_NAME. */
14537 if (XGetFontProperty (font
, XA_FONT
, &value
))
14539 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
14543 /* Count the number of dashes in the "full name".
14544 If it is too few, this isn't really the font's full name,
14546 In X11R4, the fonts did not come with their canonical names
14557 full_name
= (char *) xmalloc (p
- name
+ 1);
14558 bcopy (name
, full_name
, p
- name
+ 1);
14564 if (full_name
!= 0)
14565 fontp
->full_name
= full_name
;
14567 fontp
->full_name
= fontp
->name
;
14569 fontp
->size
= font
->max_bounds
.width
;
14570 fontp
->height
= FONT_HEIGHT (font
);
14572 if (NILP (font_names
))
14574 /* We come here because of a bug of XListFonts mentioned at
14575 the head of this block. Let's store this information in
14576 the cache for x_list_fonts. */
14577 Lisp_Object lispy_name
= build_string (fontname
);
14578 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
14579 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
14582 XSETCDR (dpyinfo
->name_list_element
,
14584 Fcons (Fcons (lispy_full_name
,
14585 make_number (fontp
->size
)),
14587 XCDR (dpyinfo
->name_list_element
)));
14590 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
14592 XSETCDR (dpyinfo
->name_list_element
,
14594 Fcons (Fcons (lispy_full_name
,
14595 make_number (fontp
->size
)),
14597 XCDR (dpyinfo
->name_list_element
)));
14601 /* The slot `encoding' specifies how to map a character
14602 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
14603 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
14604 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
14605 2:0xA020..0xFF7F). For the moment, we don't know which charset
14606 uses this font. So, we set information in fontp->encoding[1]
14607 which is never used by any charset. If mapping can't be
14608 decided, set FONT_ENCODING_NOT_DECIDED. */
14610 = (font
->max_byte1
== 0
14612 ? (font
->min_char_or_byte2
< 0x80
14613 ? (font
->max_char_or_byte2
< 0x80
14614 ? 0 /* 0x20..0x7F */
14615 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
14616 : 1) /* 0xA0..0xFF */
14618 : (font
->min_byte1
< 0x80
14619 ? (font
->max_byte1
< 0x80
14620 ? (font
->min_char_or_byte2
< 0x80
14621 ? (font
->max_char_or_byte2
< 0x80
14622 ? 0 /* 0x2020..0x7F7F */
14623 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
14624 : 3) /* 0x20A0..0x7FFF */
14625 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
14626 : (font
->min_char_or_byte2
< 0x80
14627 ? (font
->max_char_or_byte2
< 0x80
14628 ? 2 /* 0xA020..0xFF7F */
14629 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
14630 : 1))); /* 0xA0A0..0xFFFF */
14632 fontp
->baseline_offset
14633 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
14634 ? (long) value
: 0);
14635 fontp
->relative_compose
14636 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
14637 ? (long) value
: 0);
14638 fontp
->default_ascent
14639 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
14640 ? (long) value
: 0);
14642 /* Set global flag fonts_changed_p to non-zero if the font loaded
14643 has a character with a smaller width than any other character
14644 before, or if the font loaded has a smaller height than any
14645 other font loaded before. If this happens, it will make a
14646 glyph matrix reallocation necessary. */
14647 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
14654 /* Return a pointer to struct font_info of a font named FONTNAME for
14655 frame F. If no such font is loaded, return NULL. */
14658 x_query_font (f
, fontname
)
14660 register char *fontname
;
14662 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14665 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14666 if (dpyinfo
->font_table
[i
].name
14667 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
14668 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
14669 return (dpyinfo
->font_table
+ i
);
14674 /* Find a CCL program for a font specified by FONTP, and set the member
14675 `encoder' of the structure. */
14678 x_find_ccl_program (fontp
)
14679 struct font_info
*fontp
;
14681 Lisp_Object list
, elt
;
14684 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
14688 && STRINGP (XCAR (elt
))
14689 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
14691 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
14698 struct ccl_program
*ccl
14699 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
14701 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
14704 fontp
->font_encoder
= ccl
;
14710 /***********************************************************************
14712 ***********************************************************************/
14714 #ifdef USE_X_TOOLKIT
14715 static XrmOptionDescRec emacs_options
[] = {
14716 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
14717 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
14719 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
14720 XrmoptionSepArg
, NULL
},
14721 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
14723 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14724 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14725 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14726 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14727 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14728 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
14729 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
14731 #endif /* USE_X_TOOLKIT */
14733 static int x_initialized
;
14735 #ifdef MULTI_KBOARD
14736 /* Test whether two display-name strings agree up to the dot that separates
14737 the screen number from the server number. */
14739 same_x_server (name1
, name2
)
14740 const char *name1
, *name2
;
14742 int seen_colon
= 0;
14743 const unsigned char *system_name
= SDATA (Vsystem_name
);
14744 int system_name_length
= strlen (system_name
);
14745 int length_until_period
= 0;
14747 while (system_name
[length_until_period
] != 0
14748 && system_name
[length_until_period
] != '.')
14749 length_until_period
++;
14751 /* Treat `unix' like an empty host name. */
14752 if (! strncmp (name1
, "unix:", 5))
14754 if (! strncmp (name2
, "unix:", 5))
14756 /* Treat this host's name like an empty host name. */
14757 if (! strncmp (name1
, system_name
, system_name_length
)
14758 && name1
[system_name_length
] == ':')
14759 name1
+= system_name_length
;
14760 if (! strncmp (name2
, system_name
, system_name_length
)
14761 && name2
[system_name_length
] == ':')
14762 name2
+= system_name_length
;
14763 /* Treat this host's domainless name like an empty host name. */
14764 if (! strncmp (name1
, system_name
, length_until_period
)
14765 && name1
[length_until_period
] == ':')
14766 name1
+= length_until_period
;
14767 if (! strncmp (name2
, system_name
, length_until_period
)
14768 && name2
[length_until_period
] == ':')
14769 name2
+= length_until_period
;
14771 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
14775 if (seen_colon
&& *name1
== '.')
14779 && (*name1
== '.' || *name1
== '\0')
14780 && (*name2
== '.' || *name2
== '\0'));
14784 struct x_display_info
*
14785 x_term_init (display_name
, xrm_option
, resource_name
)
14786 Lisp_Object display_name
;
14788 char *resource_name
;
14792 struct x_display_info
*dpyinfo
;
14797 if (!x_initialized
)
14803 #ifdef USE_X_TOOLKIT
14804 /* weiner@footloose.sps.mot.com reports that this causes
14806 X protocol error: BadAtom (invalid Atom parameter)
14807 on protocol request 18skiloaf.
14808 So let's not use it until R6. */
14809 #ifdef HAVE_X11XTR6
14810 XtSetLanguageProc (NULL
, NULL
, NULL
);
14821 argv
[argc
++] = "-xrm";
14822 argv
[argc
++] = xrm_option
;
14825 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
14826 resource_name
, EMACS_CLASS
,
14827 emacs_options
, XtNumber (emacs_options
),
14831 #ifdef HAVE_X11XTR6
14832 /* I think this is to compensate for XtSetLanguageProc. */
14837 #else /* not USE_X_TOOLKIT */
14839 XSetLocaleModifiers ("");
14841 dpy
= XOpenDisplay (SDATA (display_name
));
14842 #endif /* not USE_X_TOOLKIT */
14844 /* Detect failure. */
14851 /* We have definitely succeeded. Record the new connection. */
14853 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
14854 bzero (dpyinfo
, sizeof *dpyinfo
);
14856 #ifdef MULTI_KBOARD
14858 struct x_display_info
*share
;
14861 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
14862 share
= share
->next
, tail
= XCDR (tail
))
14863 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
14864 SDATA (display_name
)))
14867 dpyinfo
->kboard
= share
->kboard
;
14870 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
14871 init_kboard (dpyinfo
->kboard
);
14872 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
14874 char *vendor
= ServerVendor (dpy
);
14876 dpyinfo
->kboard
->Vsystem_key_alist
14877 = call1 (Qvendor_specific_keysyms
,
14878 build_string (vendor
? vendor
: ""));
14882 dpyinfo
->kboard
->next_kboard
= all_kboards
;
14883 all_kboards
= dpyinfo
->kboard
;
14884 /* Don't let the initial kboard remain current longer than necessary.
14885 That would cause problems if a file loaded on startup tries to
14886 prompt in the mini-buffer. */
14887 if (current_kboard
== initial_kboard
)
14888 current_kboard
= dpyinfo
->kboard
;
14890 dpyinfo
->kboard
->reference_count
++;
14894 /* Put this display on the chain. */
14895 dpyinfo
->next
= x_display_list
;
14896 x_display_list
= dpyinfo
;
14898 /* Put it on x_display_name_list as well, to keep them parallel. */
14899 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
14900 x_display_name_list
);
14901 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
14903 dpyinfo
->display
= dpy
;
14906 XSetAfterFunction (x_current_display
, x_trace_wire
);
14910 = (char *) xmalloc (SBYTES (Vinvocation_name
)
14911 + SBYTES (Vsystem_name
)
14913 sprintf (dpyinfo
->x_id_name
, "%s@%s",
14914 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
14916 /* Figure out which modifier bits mean what. */
14917 x_find_modifier_meanings (dpyinfo
);
14919 /* Get the scroll bar cursor. */
14920 dpyinfo
->vertical_scroll_bar_cursor
14921 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
14923 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
14924 resource_name
, EMACS_CLASS
);
14925 #ifdef HAVE_XRMSETDATABASE
14926 XrmSetDatabase (dpyinfo
->display
, xrdb
);
14928 dpyinfo
->display
->db
= xrdb
;
14930 /* Put the rdb where we can find it in a way that works on
14932 dpyinfo
->xrdb
= xrdb
;
14934 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
14935 DefaultScreen (dpyinfo
->display
));
14936 select_visual (dpyinfo
);
14937 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
14938 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
14939 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
14940 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
14941 dpyinfo
->grabbed
= 0;
14942 dpyinfo
->reference_count
= 0;
14943 dpyinfo
->icon_bitmap_id
= -1;
14944 dpyinfo
->font_table
= NULL
;
14945 dpyinfo
->n_fonts
= 0;
14946 dpyinfo
->font_table_size
= 0;
14947 dpyinfo
->bitmaps
= 0;
14948 dpyinfo
->bitmaps_size
= 0;
14949 dpyinfo
->bitmaps_last
= 0;
14950 dpyinfo
->scratch_cursor_gc
= 0;
14951 dpyinfo
->mouse_face_mouse_frame
= 0;
14952 dpyinfo
->mouse_face_deferred_gc
= 0;
14953 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
14954 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
14955 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
14956 dpyinfo
->mouse_face_window
= Qnil
;
14957 dpyinfo
->mouse_face_overlay
= Qnil
;
14958 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
14959 dpyinfo
->mouse_face_defer
= 0;
14960 dpyinfo
->mouse_face_hidden
= 0;
14961 dpyinfo
->x_focus_frame
= 0;
14962 dpyinfo
->x_focus_event_frame
= 0;
14963 dpyinfo
->x_highlight_frame
= 0;
14964 dpyinfo
->image_cache
= make_image_cache ();
14966 /* See if a private colormap is requested. */
14967 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
14969 if (dpyinfo
->visual
->class == PseudoColor
)
14972 value
= display_x_get_resource (dpyinfo
,
14973 build_string ("privateColormap"),
14974 build_string ("PrivateColormap"),
14976 if (STRINGP (value
)
14977 && (!strcmp (SDATA (value
), "true")
14978 || !strcmp (SDATA (value
), "on")))
14979 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
14983 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
14984 dpyinfo
->visual
, AllocNone
);
14987 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
14988 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
14989 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
14990 dpyinfo
->resy
= pixels
* 25.4 / mm
;
14991 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
14992 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
14993 dpyinfo
->resx
= pixels
* 25.4 / mm
;
14996 dpyinfo
->Xatom_wm_protocols
14997 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
14998 dpyinfo
->Xatom_wm_take_focus
14999 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
15000 dpyinfo
->Xatom_wm_save_yourself
15001 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
15002 dpyinfo
->Xatom_wm_delete_window
15003 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
15004 dpyinfo
->Xatom_wm_change_state
15005 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
15006 dpyinfo
->Xatom_wm_configure_denied
15007 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
15008 dpyinfo
->Xatom_wm_window_moved
15009 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
15010 dpyinfo
->Xatom_editres
15011 = XInternAtom (dpyinfo
->display
, "Editres", False
);
15012 dpyinfo
->Xatom_CLIPBOARD
15013 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
15014 dpyinfo
->Xatom_TIMESTAMP
15015 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
15016 dpyinfo
->Xatom_TEXT
15017 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
15018 dpyinfo
->Xatom_COMPOUND_TEXT
15019 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
15020 dpyinfo
->Xatom_UTF8_STRING
15021 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
15022 dpyinfo
->Xatom_DELETE
15023 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
15024 dpyinfo
->Xatom_MULTIPLE
15025 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
15026 dpyinfo
->Xatom_INCR
15027 = XInternAtom (dpyinfo
->display
, "INCR", False
);
15028 dpyinfo
->Xatom_EMACS_TMP
15029 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
15030 dpyinfo
->Xatom_TARGETS
15031 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
15032 dpyinfo
->Xatom_NULL
15033 = XInternAtom (dpyinfo
->display
, "NULL", False
);
15034 dpyinfo
->Xatom_ATOM_PAIR
15035 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
15036 /* For properties of font. */
15037 dpyinfo
->Xatom_PIXEL_SIZE
15038 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
15039 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
15040 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
15041 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
15042 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
15043 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
15044 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
15046 /* Ghostscript support. */
15047 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
15048 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
15050 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
15053 dpyinfo
->cut_buffers_initialized
= 0;
15055 connection
= ConnectionNumber (dpyinfo
->display
);
15056 dpyinfo
->connection
= connection
;
15061 null_bits
[0] = 0x00;
15063 dpyinfo
->null_pixel
15064 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
15065 null_bits
, 1, 1, (long) 0, (long) 0,
15070 extern int gray_bitmap_width
, gray_bitmap_height
;
15071 extern char *gray_bitmap_bits
;
15073 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
15075 gray_bitmap_width
, gray_bitmap_height
,
15076 (unsigned long) 1, (unsigned long) 0, 1);
15080 xim_initialize (dpyinfo
, resource_name
);
15083 #ifdef subprocesses
15084 /* This is only needed for distinguishing keyboard and process input. */
15085 if (connection
!= 0)
15086 add_keyboard_wait_descriptor (connection
);
15089 #ifndef F_SETOWN_BUG
15091 #ifdef F_SETOWN_SOCK_NEG
15092 /* stdin is a socket here */
15093 fcntl (connection
, F_SETOWN
, -getpid ());
15094 #else /* ! defined (F_SETOWN_SOCK_NEG) */
15095 fcntl (connection
, F_SETOWN
, getpid ());
15096 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
15097 #endif /* ! defined (F_SETOWN) */
15098 #endif /* F_SETOWN_BUG */
15101 if (interrupt_input
)
15102 init_sigio (connection
);
15103 #endif /* ! defined (SIGIO) */
15106 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
15107 /* Make sure that we have a valid font for dialog boxes
15108 so that Xt does not crash. */
15110 Display
*dpy
= dpyinfo
->display
;
15111 XrmValue d
, fr
, to
;
15115 d
.addr
= (XPointer
)&dpy
;
15116 d
.size
= sizeof (Display
*);
15117 fr
.addr
= XtDefaultFont
;
15118 fr
.size
= sizeof (XtDefaultFont
);
15119 to
.size
= sizeof (Font
*);
15120 to
.addr
= (XPointer
)&font
;
15121 count
= x_catch_errors (dpy
);
15122 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
15124 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
15125 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
15126 x_uncatch_errors (dpy
, count
);
15131 /* See if we should run in synchronous mode. This is useful
15132 for debugging X code. */
15135 value
= display_x_get_resource (dpyinfo
,
15136 build_string ("synchronous"),
15137 build_string ("Synchronous"),
15139 if (STRINGP (value
)
15140 && (!strcmp (SDATA (value
), "true")
15141 || !strcmp (SDATA (value
), "on")))
15142 XSynchronize (dpyinfo
->display
, True
);
15150 /* Get rid of display DPYINFO, assuming all frames are already gone,
15151 and without sending any more commands to the X server. */
15154 x_delete_display (dpyinfo
)
15155 struct x_display_info
*dpyinfo
;
15157 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
15159 /* Discard this display from x_display_name_list and x_display_list.
15160 We can't use Fdelq because that can quit. */
15161 if (! NILP (x_display_name_list
)
15162 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
15163 x_display_name_list
= XCDR (x_display_name_list
);
15168 tail
= x_display_name_list
;
15169 while (CONSP (tail
) && CONSP (XCDR (tail
)))
15171 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
15173 XSETCDR (tail
, XCDR (XCDR (tail
)));
15176 tail
= XCDR (tail
);
15180 if (next_noop_dpyinfo
== dpyinfo
)
15181 next_noop_dpyinfo
= dpyinfo
->next
;
15183 if (x_display_list
== dpyinfo
)
15184 x_display_list
= dpyinfo
->next
;
15187 struct x_display_info
*tail
;
15189 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
15190 if (tail
->next
== dpyinfo
)
15191 tail
->next
= tail
->next
->next
;
15194 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
15195 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
15196 XrmDestroyDatabase (dpyinfo
->xrdb
);
15199 #ifdef MULTI_KBOARD
15200 if (--dpyinfo
->kboard
->reference_count
== 0)
15201 delete_kboard (dpyinfo
->kboard
);
15205 xim_close_dpy (dpyinfo
);
15208 xfree (dpyinfo
->font_table
);
15209 xfree (dpyinfo
->x_id_name
);
15210 xfree (dpyinfo
->color_cells
);
15215 /* Set up use of X before we make the first connection. */
15217 static struct redisplay_interface x_redisplay_interface
=
15222 x_clear_end_of_line
,
15224 x_after_update_window_line
,
15225 x_update_window_begin
,
15226 x_update_window_end
,
15229 x_clear_mouse_face
,
15230 x_get_glyph_overhangs
,
15231 x_fix_overlapping_area
15237 rif
= &x_redisplay_interface
;
15239 clear_frame_hook
= x_clear_frame
;
15240 ins_del_lines_hook
= x_ins_del_lines
;
15241 delete_glyphs_hook
= x_delete_glyphs
;
15242 ring_bell_hook
= XTring_bell
;
15243 reset_terminal_modes_hook
= XTreset_terminal_modes
;
15244 set_terminal_modes_hook
= XTset_terminal_modes
;
15245 update_begin_hook
= x_update_begin
;
15246 update_end_hook
= x_update_end
;
15247 set_terminal_window_hook
= XTset_terminal_window
;
15248 read_socket_hook
= XTread_socket
;
15249 frame_up_to_date_hook
= XTframe_up_to_date
;
15250 mouse_position_hook
= XTmouse_position
;
15251 frame_rehighlight_hook
= XTframe_rehighlight
;
15252 frame_raise_lower_hook
= XTframe_raise_lower
;
15253 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
15254 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
15255 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
15256 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
15257 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
15259 scroll_region_ok
= 1; /* we'll scroll partial frames */
15260 char_ins_del_ok
= 1;
15261 line_ins_del_ok
= 1; /* we'll just blt 'em */
15262 fast_clear_end_of_line
= 1; /* X does this well */
15263 memory_below_frame
= 0; /* we don't remember what scrolls
15268 last_tool_bar_item
= -1;
15269 any_help_event_p
= 0;
15271 /* Try to use interrupt input; if we can't, then start polling. */
15272 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
15274 #ifdef USE_X_TOOLKIT
15275 XtToolkitInitialize ();
15277 Xt_app_con
= XtCreateApplicationContext ();
15279 /* Register a converter from strings to pixels, which uses
15280 Emacs' color allocation infrastructure. */
15281 XtAppSetTypeConverter (Xt_app_con
,
15282 XtRString
, XtRPixel
, cvt_string_to_pixel
,
15283 cvt_string_to_pixel_args
,
15284 XtNumber (cvt_string_to_pixel_args
),
15285 XtCacheByDisplay
, cvt_pixel_dtor
);
15287 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
15289 /* Install an asynchronous timer that processes Xt timeout events
15290 every 0.1s. This is necessary because some widget sets use
15291 timeouts internally, for example the LessTif menu bar, or the
15292 Xaw3d scroll bar. When Xt timouts aren't processed, these
15293 widgets don't behave normally. */
15295 EMACS_TIME interval
;
15296 EMACS_SET_SECS_USECS (interval
, 0, 100000);
15297 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
15301 #ifdef USE_TOOLKIT_SCROLL_BARS
15302 xaw3d_arrow_scroll
= False
;
15303 xaw3d_pick_top
= True
;
15306 /* Note that there is no real way portable across R3/R4 to get the
15307 original error handler. */
15308 XSetErrorHandler (x_error_handler
);
15309 XSetIOErrorHandler (x_io_error_quitter
);
15311 /* Disable Window Change signals; they are handled by X events. */
15313 signal (SIGWINCH
, SIG_DFL
);
15314 #endif /* SIGWINCH */
15316 signal (SIGPIPE
, x_connection_signal
);
15319 x_session_initialize ();
15327 staticpro (&x_error_message_string
);
15328 x_error_message_string
= Qnil
;
15330 staticpro (&x_display_name_list
);
15331 x_display_name_list
= Qnil
;
15333 staticpro (&last_mouse_scroll_bar
);
15334 last_mouse_scroll_bar
= Qnil
;
15336 staticpro (&Qvendor_specific_keysyms
);
15337 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
15339 staticpro (&Qutf_8
);
15340 Qutf_8
= intern ("utf-8");
15341 staticpro (&Qlatin_1
);
15342 Qlatin_1
= intern ("latin-1");
15344 staticpro (&last_mouse_press_frame
);
15345 last_mouse_press_frame
= Qnil
;
15348 staticpro (&help_echo
);
15349 help_echo_object
= Qnil
;
15350 staticpro (&help_echo_object
);
15351 help_echo_window
= Qnil
;
15352 staticpro (&help_echo_window
);
15353 previous_help_echo
= Qnil
;
15354 staticpro (&previous_help_echo
);
15355 help_echo_pos
= -1;
15357 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
15358 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
15359 mouse_autoselect_window
= 0;
15361 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
15362 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
15363 For example, if a block cursor is over a tab, it will be drawn as
15364 wide as that tab on the display. */);
15365 x_stretch_cursor_p
= 0;
15367 DEFVAR_BOOL ("x-use-underline-position-properties",
15368 &x_use_underline_position_properties
,
15369 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
15370 nil means ignore them. If you encounter fonts with bogus
15371 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
15372 to 4.1, set this to nil. */);
15373 x_use_underline_position_properties
= 1;
15375 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
15376 doc
: /* What X toolkit scroll bars Emacs uses.
15377 A value of nil means Emacs doesn't use X toolkit scroll bars.
15378 Otherwise, value is a symbol describing the X toolkit. */);
15379 #ifdef USE_TOOLKIT_SCROLL_BARS
15381 Vx_toolkit_scroll_bars
= intern ("motif");
15382 #elif defined HAVE_XAW3D
15383 Vx_toolkit_scroll_bars
= intern ("xaw3d");
15385 Vx_toolkit_scroll_bars
= intern ("xaw");
15388 Vx_toolkit_scroll_bars
= Qnil
;
15391 staticpro (&last_mouse_motion_frame
);
15392 last_mouse_motion_frame
= Qnil
;
15394 Qmodifier_value
= intern ("modifier-value");
15395 Qalt
= intern ("alt");
15396 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
15397 Qhyper
= intern ("hyper");
15398 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
15399 Qmeta
= intern ("meta");
15400 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
15401 Qsuper
= intern ("super");
15402 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
15404 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
15405 doc
: /* Which keys Emacs uses for the alt modifier.
15406 This should be one of the symbols `alt', `hyper', `meta', `super'.
15407 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
15408 is nil, which is the same as `alt'. */);
15409 Vx_alt_keysym
= Qnil
;
15411 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
15412 doc
: /* Which keys Emacs uses for the hyper modifier.
15413 This should be one of the symbols `alt', `hyper', `meta', `super'.
15414 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
15415 default is nil, which is the same as `hyper'. */);
15416 Vx_hyper_keysym
= Qnil
;
15418 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
15419 doc
: /* Which keys Emacs uses for the meta modifier.
15420 This should be one of the symbols `alt', `hyper', `meta', `super'.
15421 For example, `meta' means use the Meta_L and Meta_R keysyms. The
15422 default is nil, which is the same as `meta'. */);
15423 Vx_meta_keysym
= Qnil
;
15425 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
15426 doc
: /* Which keys Emacs uses for the super modifier.
15427 This should be one of the symbols `alt', `hyper', `meta', `super'.
15428 For example, `super' means use the Super_L and Super_R keysyms. The
15429 default is nil, which is the same as `super'. */);
15430 Vx_super_keysym
= Qnil
;
15434 #endif /* HAVE_X_WINDOWS */