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
105 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
106 extern void xlwmenu_redisplay
P_ ((Widget
));
109 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
111 extern void free_frame_menubar
P_ ((struct frame
*));
112 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
117 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
119 extern void _XEditResCheckMessages ();
120 #endif /* not NO_EDITRES */
122 /* Include toolkit specific headers for the scroll bar widget. */
124 #ifdef USE_TOOLKIT_SCROLL_BARS
125 #if defined USE_MOTIF
126 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
127 #include <Xm/ScrollBar.h>
128 #else /* !USE_MOTIF i.e. use Xaw */
131 #include <X11/Xaw3d/Simple.h>
132 #include <X11/Xaw3d/Scrollbar.h>
133 #define ARROW_SCROLLBAR
134 #include <X11/Xaw3d/ScrollbarP.h>
135 #else /* !HAVE_XAW3D */
136 #include <X11/Xaw/Simple.h>
137 #include <X11/Xaw/Scrollbar.h>
138 #endif /* !HAVE_XAW3D */
140 #define XtNpickTop "pickTop"
141 #endif /* !XtNpickTop */
142 #endif /* !USE_MOTIF */
143 #endif /* USE_TOOLKIT_SCROLL_BARS */
145 #endif /* USE_X_TOOLKIT */
147 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
148 #define x_any_window_to_frame x_window_to_frame
149 #define x_top_window_to_frame x_window_to_frame
154 #ifndef XtNinitialState
155 #define XtNinitialState "initialState"
159 #define abs(x) ((x) < 0 ? -(x) : (x))
161 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
165 extern Lisp_Object Qhelp_echo
;
167 /* Non-nil means Emacs uses toolkit scroll bars. */
169 Lisp_Object Vx_toolkit_scroll_bars
;
171 /* If a string, XTread_socket generates an event to display that string.
172 (The display is done in read_char.) */
174 static Lisp_Object help_echo
;
175 static Lisp_Object help_echo_window
;
176 static Lisp_Object help_echo_object
;
177 static int help_echo_pos
;
179 /* Temporary variable for XTread_socket. */
181 static Lisp_Object previous_help_echo
;
183 /* Non-zero means that a HELP_EVENT has been generated since Emacs
186 static int any_help_event_p
;
188 /* Non-zero means autoselect window with the mouse cursor. */
190 int mouse_autoselect_window
;
192 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
193 static Lisp_Object last_window
;
195 /* Non-zero means draw block and hollow cursor as wide as the glyph
196 under it. For example, if a block cursor is over a tab, it will be
197 drawn as wide as that tab on the display. */
199 int x_stretch_cursor_p
;
201 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
203 int x_use_underline_position_properties
;
205 /* This is a chain of structures for all the X displays currently in
208 struct x_display_info
*x_display_list
;
210 /* This is a list of cons cells, each of the form (NAME
211 . FONT-LIST-CACHE), one for each element of x_display_list and in
212 the same order. NAME is the name of the frame. FONT-LIST-CACHE
213 records previous values returned by x-list-fonts. */
215 Lisp_Object x_display_name_list
;
217 /* Frame being updated by update_frame. This is declared in term.c.
218 This is set by update_begin and looked at by all the XT functions.
219 It is zero while not inside an update. In that case, the XT
220 functions assume that `selected_frame' is the frame to apply to. */
222 extern struct frame
*updating_frame
;
224 /* This is a frame waiting to be auto-raised, within XTread_socket. */
226 struct frame
*pending_autoraise_frame
;
229 /* The application context for Xt use. */
230 XtAppContext Xt_app_con
;
231 static String Xt_default_resources
[] = {0};
232 #endif /* USE_X_TOOLKIT */
234 /* Nominal cursor position -- where to draw output.
235 HPOS and VPOS are window relative glyph matrix coordinates.
236 X and Y are window relative pixel coordinates. */
238 struct cursor_pos output_cursor
;
240 /* Non-zero means user is interacting with a toolkit scroll bar. */
242 static int toolkit_scroll_bar_interaction
;
246 Formerly, we used PointerMotionHintMask (in standard_event_mask)
247 so that we would have to call XQueryPointer after each MotionNotify
248 event to ask for another such event. However, this made mouse tracking
249 slow, and there was a bug that made it eventually stop.
251 Simply asking for MotionNotify all the time seems to work better.
253 In order to avoid asking for motion events and then throwing most
254 of them away or busy-polling the server for mouse positions, we ask
255 the server for pointer motion hints. This means that we get only
256 one event per group of mouse movements. "Groups" are delimited by
257 other kinds of events (focus changes and button clicks, for
258 example), or by XQueryPointer calls; when one of these happens, we
259 get another MotionNotify event the next time the mouse moves. This
260 is at least as efficient as getting motion events when mouse
261 tracking is on, and I suspect only negligibly worse when tracking
264 /* Where the mouse was last time we reported a mouse event. */
266 FRAME_PTR last_mouse_frame
;
267 static XRectangle last_mouse_glyph
;
268 static Lisp_Object last_mouse_press_frame
;
270 /* The scroll bar in which the last X motion event occurred.
272 If the last X motion event occurred in a scroll bar, we set this so
273 XTmouse_position can know whether to report a scroll bar motion or
276 If the last X motion event didn't occur in a scroll bar, we set
277 this to Qnil, to tell XTmouse_position to return an ordinary motion
280 static Lisp_Object last_mouse_scroll_bar
;
282 /* This is a hack. We would really prefer that XTmouse_position would
283 return the time associated with the position it returns, but there
284 doesn't seem to be any way to wrest the time-stamp from the server
285 along with the position query. So, we just keep track of the time
286 of the last movement we received, and return that in hopes that
287 it's somewhat accurate. */
289 static Time last_mouse_movement_time
;
291 /* Incremented by XTread_socket whenever it really tries to read
295 static int volatile input_signal_count
;
297 static int input_signal_count
;
300 /* Used locally within XTread_socket. */
302 static int x_noop_count
;
304 /* Initial values of argv and argc. */
306 extern char **initial_argv
;
307 extern int initial_argc
;
309 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
311 /* Tells if a window manager is present or not. */
313 extern Lisp_Object Vx_no_window_manager
;
315 extern Lisp_Object Qface
, Qmouse_face
, Qeql
;
319 /* A mask of extra modifier bits to put into every keyboard char. */
321 extern EMACS_INT extra_keyboard_modifiers
;
323 /* The keysyms to use for the various modifiers. */
325 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
326 Lisp_Object Vx_keysym_table
;
327 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
329 static Lisp_Object Qvendor_specific_keysyms
;
330 static Lisp_Object Qlatin_1
, Qutf_8
;
332 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
333 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
336 /* Enumeration for overriding/changing the face to use for drawing
337 glyphs in x_draw_glyphs. */
339 enum draw_glyphs_face
349 static int cursor_in_mouse_face_p
P_ ((struct window
*));
350 static int clear_mouse_face
P_ ((struct x_display_info
*));
351 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
352 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
353 static const XColor
*x_color_cells
P_ ((Display
*, int *));
354 static void x_update_window_end
P_ ((struct window
*, int, int));
355 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
356 void x_delete_display
P_ ((struct x_display_info
*));
357 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
359 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
360 int *, int *, Lisp_Object
));
361 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
362 int *, int *, int *, int *, int));
363 static void set_output_cursor
P_ ((struct cursor_pos
*));
364 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
365 int *, int *, int *, int));
366 static void note_mode_line_or_margin_highlight
P_ ((struct window
*, int,
368 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
369 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
370 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
371 static void show_mouse_face
P_ ((struct x_display_info
*,
372 enum draw_glyphs_face
));
373 static int x_io_error_quitter
P_ ((Display
*));
374 int x_catch_errors
P_ ((Display
*));
375 void x_uncatch_errors
P_ ((Display
*, int));
376 void x_lower_frame
P_ ((struct frame
*));
377 void x_scroll_bar_clear
P_ ((struct frame
*));
378 int x_had_errors_p
P_ ((Display
*));
379 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
380 void x_raise_frame
P_ ((struct frame
*));
381 void x_set_window_size
P_ ((struct frame
*, int, int, int));
382 void x_wm_set_window_state
P_ ((struct frame
*, int));
383 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
384 void x_initialize
P_ ((void));
385 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
386 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
387 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
389 enum draw_glyphs_face
));
390 static void x_update_end
P_ ((struct frame
*));
391 static void XTframe_up_to_date
P_ ((struct frame
*));
392 static void XTset_terminal_modes
P_ ((void));
393 static void XTreset_terminal_modes
P_ ((void));
394 static void XTcursor_to
P_ ((int, int, int, int));
395 static void x_write_glyphs
P_ ((struct glyph
*, int));
396 static void x_clear_end_of_line
P_ ((int));
397 static void x_clear_frame
P_ ((void));
398 static void x_clear_cursor
P_ ((struct window
*));
399 static void frame_highlight
P_ ((struct frame
*));
400 static void frame_unhighlight
P_ ((struct frame
*));
401 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
402 static int x_focus_changed
P_ ((int,
404 struct x_display_info
*,
406 struct input_event
*,
408 static int x_detect_focus_change
P_ ((struct x_display_info
*,
410 struct input_event
*,
412 static void XTframe_rehighlight
P_ ((struct frame
*));
413 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
414 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
415 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
416 enum text_cursor_kinds
));
417 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
419 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
420 static int expose_window_tree
P_ ((struct window
*, XRectangle
*));
421 static void expose_overlaps
P_ ((struct window
*, struct glyph_row
*,
422 struct glyph_row
*));
423 static int expose_window
P_ ((struct window
*, XRectangle
*));
424 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
425 XRectangle
*, enum glyph_row_area
));
426 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
428 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
429 static void x_update_window_cursor
P_ ((struct window
*, int));
430 static void x_erase_phys_cursor
P_ ((struct window
*));
431 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
433 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
435 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
436 static void notice_overwritten_cursor
P_ ((struct window
*, enum glyph_row_area
,
437 int, int, int, int));
438 static void x_flush
P_ ((struct frame
*f
));
439 static void x_update_begin
P_ ((struct frame
*));
440 static void x_update_window_begin
P_ ((struct window
*));
441 static void x_draw_vertical_border
P_ ((struct window
*));
442 static void x_after_update_window_line
P_ ((struct glyph_row
*));
443 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
444 static void x_produce_stretch_glyph
P_ ((struct it
*));
445 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
446 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
447 enum scroll_bar_part
*,
448 Lisp_Object
*, Lisp_Object
*,
450 static void x_check_fullscreen
P_ ((struct frame
*));
451 static void x_check_fullscreen_move
P_ ((struct frame
*));
452 static int handle_one_xevent
P_ ((struct x_display_info
*,
454 struct input_event
**,
459 /* Flush display of frame F, or of all frames if F is null. */
468 Lisp_Object rest
, frame
;
469 FOR_EACH_FRAME (rest
, frame
)
470 x_flush (XFRAME (frame
));
472 else if (FRAME_X_P (f
))
473 XFlush (FRAME_X_DISPLAY (f
));
478 /* Remove calls to XFlush by defining XFlush to an empty replacement.
479 Calls to XFlush should be unnecessary because the X output buffer
480 is flushed automatically as needed by calls to XPending,
481 XNextEvent, or XWindowEvent according to the XFlush man page.
482 XTread_socket calls XPending. Removing XFlush improves
485 #define XFlush(DISPLAY) (void) 0
488 /***********************************************************************
490 ***********************************************************************/
494 /* This is a function useful for recording debugging information about
495 the sequence of occurrences in this file. */
503 struct record event_record
[100];
505 int event_record_index
;
507 record_event (locus
, type
)
511 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
512 event_record_index
= 0;
514 event_record
[event_record_index
].locus
= locus
;
515 event_record
[event_record_index
].type
= type
;
516 event_record_index
++;
523 /* Return the struct x_display_info corresponding to DPY. */
525 struct x_display_info
*
526 x_display_info_for_display (dpy
)
529 struct x_display_info
*dpyinfo
;
531 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
532 if (dpyinfo
->display
== dpy
)
540 /***********************************************************************
541 Starting and ending an update
542 ***********************************************************************/
544 /* Start an update of frame F. This function is installed as a hook
545 for update_begin, i.e. it is called when update_begin is called.
546 This function is called prior to calls to x_update_window_begin for
547 each window being updated. Currently, there is nothing to do here
548 because all interesting stuff is done on a window basis. */
558 /* Start update of window W. Set the global variable updated_window
559 to the window being updated and set output_cursor to the cursor
563 x_update_window_begin (w
)
566 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
567 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
570 set_output_cursor (&w
->cursor
);
574 if (f
== display_info
->mouse_face_mouse_frame
)
576 /* Don't do highlighting for mouse motion during the update. */
577 display_info
->mouse_face_defer
= 1;
579 /* If F needs to be redrawn, simply forget about any prior mouse
581 if (FRAME_GARBAGED_P (f
))
582 display_info
->mouse_face_window
= Qnil
;
584 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
585 their mouse_face_p flag set, which means that they are always
586 unequal to rows in a desired matrix which never have that
587 flag set. So, rows containing mouse-face glyphs are never
588 scrolled, and we don't have to switch the mouse highlight off
589 here to prevent it from being scrolled. */
591 /* Can we tell that this update does not affect the window
592 where the mouse highlight is? If so, no need to turn off.
593 Likewise, don't do anything if the frame is garbaged;
594 in that case, the frame's current matrix that we would use
595 is all wrong, and we will redisplay that line anyway. */
596 if (!NILP (display_info
->mouse_face_window
)
597 && w
== XWINDOW (display_info
->mouse_face_window
))
601 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
602 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
605 if (i
< w
->desired_matrix
->nrows
)
606 clear_mouse_face (display_info
);
615 /* Draw a vertical window border to the right of window W if W doesn't
616 have vertical scroll bars. */
619 x_draw_vertical_border (w
)
622 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
624 /* Redraw borders between horizontally adjacent windows. Don't
625 do it for frames with vertical scroll bars because either the
626 right scroll bar of a window, or the left scroll bar of its
627 neighbor will suffice as a border. */
628 if (!WINDOW_RIGHTMOST_P (w
)
629 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
633 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
634 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
637 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
638 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
643 /* End update of window W (which is equal to updated_window).
645 Draw vertical borders between horizontally adjacent windows, and
646 display W's cursor if CURSOR_ON_P is non-zero.
648 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
649 glyphs in mouse-face were overwritten. In that case we have to
650 make sure that the mouse-highlight is properly redrawn.
652 W may be a menu bar pseudo-window in case we don't have X toolkit
653 support. Such windows don't have a cursor, so don't display it
657 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
659 int cursor_on_p
, mouse_face_overwritten_p
;
661 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
663 if (!w
->pseudo_window_p
)
668 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
670 output_cursor
.x
, output_cursor
.y
);
672 x_draw_vertical_border (w
);
676 /* If a row with mouse-face was overwritten, arrange for
677 XTframe_up_to_date to redisplay the mouse highlight. */
678 if (mouse_face_overwritten_p
)
680 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
681 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
682 dpyinfo
->mouse_face_window
= Qnil
;
685 updated_window
= NULL
;
689 /* End update of frame F. This function is installed as a hook in
696 /* Mouse highlight may be displayed again. */
697 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
700 XFlush (FRAME_X_DISPLAY (f
));
705 /* This function is called from various places in xdisp.c whenever a
706 complete update has been performed. The global variable
707 updated_window is not available here. */
710 XTframe_up_to_date (f
)
715 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
717 if (dpyinfo
->mouse_face_deferred_gc
718 || f
== dpyinfo
->mouse_face_mouse_frame
)
721 if (dpyinfo
->mouse_face_mouse_frame
)
722 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
723 dpyinfo
->mouse_face_mouse_x
,
724 dpyinfo
->mouse_face_mouse_y
);
725 dpyinfo
->mouse_face_deferred_gc
= 0;
732 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
733 arrow bitmaps, or clear the fringes if no bitmaps are required
734 before DESIRED_ROW is made current. The window being updated is
735 found in updated_window. This function It is called from
736 update_window_line only if it is known that there are differences
737 between bitmaps to be drawn between current row and DESIRED_ROW. */
740 x_after_update_window_line (desired_row
)
741 struct glyph_row
*desired_row
;
743 struct window
*w
= updated_window
;
749 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
752 draw_row_fringe_bitmaps (w
, desired_row
);
756 /* When a window has disappeared, make sure that no rest of
757 full-width rows stays visible in the internal border. Could
758 check here if updated_window is the leftmost/rightmost window,
759 but I guess it's not worth doing since vertically split windows
760 are almost never used, internal border is rarely set, and the
761 overhead is very small. */
762 if (windows_or_buffers_changed
763 && desired_row
->full_width_p
764 && (f
= XFRAME (w
->frame
),
765 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
767 && (height
= desired_row
->visible_height
,
770 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
772 /* Internal border is drawn below the tool bar. */
773 if (WINDOWP (f
->tool_bar_window
)
774 && w
== XWINDOW (f
->tool_bar_window
))
778 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
779 0, y
, width
, height
, False
);
780 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
781 f
->output_data
.x
->pixel_width
- width
,
782 y
, width
, height
, False
);
788 x_draw_fringe_bitmap (w
, row
, p
)
790 struct glyph_row
*row
;
791 struct draw_fringe_bitmap_params
*p
;
793 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
794 Display
*display
= FRAME_X_DISPLAY (f
);
795 Window window
= FRAME_X_WINDOW (f
);
796 GC gc
= f
->output_data
.x
->normal_gc
;
797 struct face
*face
= p
->face
;
799 /* Must clip because of partially visible lines. */
800 x_clip_to_row (w
, row
, gc
, 1);
804 /* In case the same realized face is used for fringes and
805 for something displayed in the text (e.g. face `region' on
806 mono-displays, the fill style may have been changed to
807 FillSolid in x_draw_glyph_string_background. */
809 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
811 XSetForeground (display
, face
->gc
, face
->background
);
813 XFillRectangle (display
, window
, face
->gc
,
814 p
->bx
, p
->by
, p
->nx
, p
->ny
);
817 XSetForeground (display
, face
->gc
, face
->foreground
);
820 if (p
->which
!= NO_FRINGE_BITMAP
)
822 unsigned char *bits
= fringe_bitmaps
[p
->which
].bits
+ p
->dh
;
824 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
826 /* Draw the bitmap. I believe these small pixmaps can be cached
828 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
830 face
->background
, depth
);
831 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
832 p
->wd
, p
->h
, p
->x
, p
->y
);
833 XFreePixmap (display
, pixmap
);
836 XSetClipMask (display
, gc
, None
);
841 /* This is called when starting Emacs and when restarting after
842 suspend. When starting Emacs, no X window is mapped. And nothing
843 must be done to Emacs's own window if it is suspended (though that
847 XTset_terminal_modes ()
851 /* This is called when exiting or suspending Emacs. Exiting will make
852 the X-windows go away, and suspending requires no action. */
855 XTreset_terminal_modes ()
861 /***********************************************************************
863 ***********************************************************************/
865 /* Set the global variable output_cursor to CURSOR. All cursor
866 positions are relative to updated_window. */
869 set_output_cursor (cursor
)
870 struct cursor_pos
*cursor
;
872 output_cursor
.hpos
= cursor
->hpos
;
873 output_cursor
.vpos
= cursor
->vpos
;
874 output_cursor
.x
= cursor
->x
;
875 output_cursor
.y
= cursor
->y
;
879 /* Set a nominal cursor position.
881 HPOS and VPOS are column/row positions in a window glyph matrix. X
882 and Y are window text area relative pixel positions.
884 If this is done during an update, updated_window will contain the
885 window that is being updated and the position is the future output
886 cursor position for that window. If updated_window is null, use
887 selected_window and display the cursor at the given position. */
890 XTcursor_to (vpos
, hpos
, y
, x
)
891 int vpos
, hpos
, y
, x
;
895 /* If updated_window is not set, work on selected_window. */
899 w
= XWINDOW (selected_window
);
901 /* Set the output cursor. */
902 output_cursor
.hpos
= hpos
;
903 output_cursor
.vpos
= vpos
;
907 /* If not called as part of an update, really display the cursor.
908 This will also set the cursor position of W. */
909 if (updated_window
== NULL
)
912 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
913 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
920 /***********************************************************************
922 ***********************************************************************/
924 /* Function prototypes of this page. */
926 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
930 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
933 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
934 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
935 static void x_append_glyph
P_ ((struct it
*));
936 static void x_append_composite_glyph
P_ ((struct it
*));
937 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
939 static void x_produce_glyphs
P_ ((struct it
*));
940 static void x_produce_image_glyph
P_ ((struct it
*it
));
943 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
944 is not contained in the font. */
946 static INLINE XCharStruct
*
947 x_per_char_metric (font
, char2b
)
951 /* The result metric information. */
952 XCharStruct
*pcm
= NULL
;
954 xassert (font
&& char2b
);
956 if (font
->per_char
!= NULL
)
958 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
960 /* min_char_or_byte2 specifies the linear character index
961 corresponding to the first element of the per_char array,
962 max_char_or_byte2 is the index of the last character. A
963 character with non-zero CHAR2B->byte1 is not in the font.
964 A character with byte2 less than min_char_or_byte2 or
965 greater max_char_or_byte2 is not in the font. */
966 if (char2b
->byte1
== 0
967 && char2b
->byte2
>= font
->min_char_or_byte2
968 && char2b
->byte2
<= font
->max_char_or_byte2
)
969 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
973 /* If either min_byte1 or max_byte1 are nonzero, both
974 min_char_or_byte2 and max_char_or_byte2 are less than
975 256, and the 2-byte character index values corresponding
976 to the per_char array element N (counting from 0) are:
978 byte1 = N/D + min_byte1
979 byte2 = N\D + min_char_or_byte2
983 D = max_char_or_byte2 - min_char_or_byte2 + 1
985 \ = integer modulus */
986 if (char2b
->byte1
>= font
->min_byte1
987 && char2b
->byte1
<= font
->max_byte1
988 && char2b
->byte2
>= font
->min_char_or_byte2
989 && char2b
->byte2
<= font
->max_char_or_byte2
)
991 pcm
= (font
->per_char
992 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
993 * (char2b
->byte1
- font
->min_byte1
))
994 + (char2b
->byte2
- font
->min_char_or_byte2
));
1000 /* If the per_char pointer is null, all glyphs between the first
1001 and last character indexes inclusive have the same
1002 information, as given by both min_bounds and max_bounds. */
1003 if (char2b
->byte2
>= font
->min_char_or_byte2
1004 && char2b
->byte2
<= font
->max_char_or_byte2
)
1005 pcm
= &font
->max_bounds
;
1008 return ((pcm
== NULL
1009 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1014 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1015 the two-byte form of C. Encoding is returned in *CHAR2B. */
1018 x_encode_char (c
, char2b
, font_info
)
1021 struct font_info
*font_info
;
1023 int charset
= CHAR_CHARSET (c
);
1024 XFontStruct
*font
= font_info
->font
;
1026 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1027 This may be either a program in a special encoder language or a
1029 if (font_info
->font_encoder
)
1031 /* It's a program. */
1032 struct ccl_program
*ccl
= font_info
->font_encoder
;
1034 if (CHARSET_DIMENSION (charset
) == 1)
1036 ccl
->reg
[0] = charset
;
1037 ccl
->reg
[1] = char2b
->byte2
;
1042 ccl
->reg
[0] = charset
;
1043 ccl
->reg
[1] = char2b
->byte1
;
1044 ccl
->reg
[2] = char2b
->byte2
;
1047 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1049 /* We assume that MSBs are appropriately set/reset by CCL
1051 if (font
->max_byte1
== 0) /* 1-byte font */
1052 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1054 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1056 else if (font_info
->encoding
[charset
])
1058 /* Fixed encoding scheme. See fontset.h for the meaning of the
1059 encoding numbers. */
1060 int enc
= font_info
->encoding
[charset
];
1062 if ((enc
== 1 || enc
== 2)
1063 && CHARSET_DIMENSION (charset
) == 2)
1064 char2b
->byte1
|= 0x80;
1066 if (enc
== 1 || enc
== 3)
1067 char2b
->byte2
|= 0x80;
1072 /* Get face and two-byte form of character C in face FACE_ID on frame
1073 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1074 means we want to display multibyte text. DISPLAY_P non-zero means
1075 make sure that X resources for the face returned are allocated.
1076 Value is a pointer to a realized face that is ready for display if
1077 DISPLAY_P is non-zero. */
1079 static INLINE
struct face
*
1080 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
1084 int multibyte_p
, display_p
;
1086 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1090 /* Unibyte case. We don't have to encode, but we have to make
1091 sure to use a face suitable for unibyte. */
1094 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1095 face
= FACE_FROM_ID (f
, face_id
);
1097 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1099 /* Case of ASCII in a face known to fit ASCII. */
1105 int c1
, c2
, charset
;
1107 /* Split characters into bytes. If c2 is -1 afterwards, C is
1108 really a one-byte character so that byte1 is zero. */
1109 SPLIT_CHAR (c
, charset
, c1
, c2
);
1111 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1113 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1115 /* Maybe encode the character in *CHAR2B. */
1116 if (face
->font
!= NULL
)
1118 struct font_info
*font_info
1119 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1121 x_encode_char (c
, char2b
, font_info
);
1125 /* Make sure X resources of the face are allocated. */
1128 xassert (face
!= NULL
);
1129 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1136 /* Get face and two-byte form of character glyph GLYPH on frame F.
1137 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1138 a pointer to a realized face that is ready for display. */
1140 static INLINE
struct face
*
1141 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1143 struct glyph
*glyph
;
1149 xassert (glyph
->type
== CHAR_GLYPH
);
1150 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1155 if (!glyph
->multibyte_p
)
1157 /* Unibyte case. We don't have to encode, but we have to make
1158 sure to use a face suitable for unibyte. */
1160 char2b
->byte2
= glyph
->u
.ch
;
1162 else if (glyph
->u
.ch
< 128
1163 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1165 /* Case of ASCII in a face known to fit ASCII. */
1167 char2b
->byte2
= glyph
->u
.ch
;
1171 int c1
, c2
, charset
;
1173 /* Split characters into bytes. If c2 is -1 afterwards, C is
1174 really a one-byte character so that byte1 is zero. */
1175 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1177 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1179 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1181 /* Maybe encode the character in *CHAR2B. */
1182 if (charset
!= CHARSET_ASCII
)
1184 struct font_info
*font_info
1185 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1188 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1191 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1196 /* Make sure X resources of the face are allocated. */
1197 xassert (face
!= NULL
);
1198 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1203 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1204 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1210 struct glyph
*glyph
;
1211 enum glyph_row_area area
= it
->area
;
1213 xassert (it
->glyph_row
);
1214 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1216 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1217 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1219 glyph
->charpos
= CHARPOS (it
->position
);
1220 glyph
->object
= it
->object
;
1221 glyph
->pixel_width
= it
->pixel_width
;
1222 glyph
->voffset
= it
->voffset
;
1223 glyph
->type
= CHAR_GLYPH
;
1224 glyph
->multibyte_p
= it
->multibyte_p
;
1225 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1226 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1227 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1228 || it
->phys_descent
> it
->descent
);
1229 glyph
->padding_p
= 0;
1230 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1231 glyph
->face_id
= it
->face_id
;
1232 glyph
->u
.ch
= it
->char_to_display
;
1233 ++it
->glyph_row
->used
[area
];
1237 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1238 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1241 x_append_composite_glyph (it
)
1244 struct glyph
*glyph
;
1245 enum glyph_row_area area
= it
->area
;
1247 xassert (it
->glyph_row
);
1249 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1250 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1252 glyph
->charpos
= CHARPOS (it
->position
);
1253 glyph
->object
= it
->object
;
1254 glyph
->pixel_width
= it
->pixel_width
;
1255 glyph
->voffset
= it
->voffset
;
1256 glyph
->type
= COMPOSITE_GLYPH
;
1257 glyph
->multibyte_p
= it
->multibyte_p
;
1258 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1259 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1260 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1261 || it
->phys_descent
> it
->descent
);
1262 glyph
->padding_p
= 0;
1263 glyph
->glyph_not_available_p
= 0;
1264 glyph
->face_id
= it
->face_id
;
1265 glyph
->u
.cmp_id
= it
->cmp_id
;
1266 ++it
->glyph_row
->used
[area
];
1271 /* Change IT->ascent and IT->height according to the setting of
1275 take_vertical_position_into_account (it
)
1280 if (it
->voffset
< 0)
1281 /* Increase the ascent so that we can display the text higher
1283 it
->ascent
+= abs (it
->voffset
);
1285 /* Increase the descent so that we can display the text lower
1287 it
->descent
+= it
->voffset
;
1292 /* Produce glyphs/get display metrics for the image IT is loaded with.
1293 See the description of struct display_iterator in dispextern.h for
1294 an overview of struct display_iterator. */
1297 x_produce_image_glyph (it
)
1303 xassert (it
->what
== IT_IMAGE
);
1305 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1306 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1309 /* Make sure X resources of the face and image are loaded. */
1310 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1311 prepare_image_for_display (it
->f
, img
);
1313 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1314 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1315 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1319 if (face
->box
!= FACE_NO_BOX
)
1321 if (face
->box_line_width
> 0)
1323 it
->ascent
+= face
->box_line_width
;
1324 it
->descent
+= face
->box_line_width
;
1327 if (it
->start_of_box_run_p
)
1328 it
->pixel_width
+= abs (face
->box_line_width
);
1329 if (it
->end_of_box_run_p
)
1330 it
->pixel_width
+= abs (face
->box_line_width
);
1333 take_vertical_position_into_account (it
);
1337 struct glyph
*glyph
;
1338 enum glyph_row_area area
= it
->area
;
1340 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1341 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1343 glyph
->charpos
= CHARPOS (it
->position
);
1344 glyph
->object
= it
->object
;
1345 glyph
->pixel_width
= it
->pixel_width
;
1346 glyph
->voffset
= it
->voffset
;
1347 glyph
->type
= IMAGE_GLYPH
;
1348 glyph
->multibyte_p
= it
->multibyte_p
;
1349 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1350 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1351 glyph
->overlaps_vertically_p
= 0;
1352 glyph
->padding_p
= 0;
1353 glyph
->glyph_not_available_p
= 0;
1354 glyph
->face_id
= it
->face_id
;
1355 glyph
->u
.img_id
= img
->id
;
1356 ++it
->glyph_row
->used
[area
];
1362 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1363 of the glyph, WIDTH and HEIGHT are the width and height of the
1364 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1365 ascent of the glyph (0 <= ASCENT <= 1). */
1368 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1374 struct glyph
*glyph
;
1375 enum glyph_row_area area
= it
->area
;
1377 xassert (ascent
>= 0 && ascent
<= 1);
1379 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1380 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1382 glyph
->charpos
= CHARPOS (it
->position
);
1383 glyph
->object
= object
;
1384 glyph
->pixel_width
= width
;
1385 glyph
->voffset
= it
->voffset
;
1386 glyph
->type
= STRETCH_GLYPH
;
1387 glyph
->multibyte_p
= it
->multibyte_p
;
1388 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1389 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1390 glyph
->overlaps_vertically_p
= 0;
1391 glyph
->padding_p
= 0;
1392 glyph
->glyph_not_available_p
= 0;
1393 glyph
->face_id
= it
->face_id
;
1394 glyph
->u
.stretch
.ascent
= height
* ascent
;
1395 glyph
->u
.stretch
.height
= height
;
1396 ++it
->glyph_row
->used
[area
];
1401 /* Produce a stretch glyph for iterator IT. IT->object is the value
1402 of the glyph property displayed. The value must be a list
1403 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1406 1. `:width WIDTH' specifies that the space should be WIDTH *
1407 canonical char width wide. WIDTH may be an integer or floating
1410 2. `:relative-width FACTOR' specifies that the width of the stretch
1411 should be computed from the width of the first character having the
1412 `glyph' property, and should be FACTOR times that width.
1414 3. `:align-to HPOS' specifies that the space should be wide enough
1415 to reach HPOS, a value in canonical character units.
1417 Exactly one of the above pairs must be present.
1419 4. `:height HEIGHT' specifies that the height of the stretch produced
1420 should be HEIGHT, measured in canonical character units.
1422 5. `:relative-height FACTOR' specifies that the height of the
1423 stretch should be FACTOR times the height of the characters having
1426 Either none or exactly one of 4 or 5 must be present.
1428 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1429 of the stretch should be used for the ascent of the stretch.
1430 ASCENT must be in the range 0 <= ASCENT <= 100. */
1433 ((INTEGERP (X) || FLOATP (X)) \
1439 x_produce_stretch_glyph (it
)
1442 /* (space :width WIDTH :height HEIGHT. */
1444 extern Lisp_Object Qspace
;
1446 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1447 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1448 extern Lisp_Object QCalign_to
;
1449 Lisp_Object prop
, plist
;
1450 double width
= 0, height
= 0, ascent
= 0;
1451 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1452 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1454 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1456 /* List should start with `space'. */
1457 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1458 plist
= XCDR (it
->object
);
1460 /* Compute the width of the stretch. */
1461 if (prop
= Fplist_get (plist
, QCwidth
),
1463 /* Absolute width `:width WIDTH' specified and valid. */
1464 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1465 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1468 /* Relative width `:relative-width FACTOR' specified and valid.
1469 Compute the width of the characters having the `glyph'
1472 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1475 if (it
->multibyte_p
)
1477 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1478 - IT_BYTEPOS (*it
));
1479 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1482 it2
.c
= *p
, it2
.len
= 1;
1484 it2
.glyph_row
= NULL
;
1485 it2
.what
= IT_CHARACTER
;
1486 x_produce_glyphs (&it2
);
1487 width
= NUMVAL (prop
) * it2
.pixel_width
;
1489 else if (prop
= Fplist_get (plist
, QCalign_to
),
1491 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1493 /* Nothing specified -> width defaults to canonical char width. */
1494 width
= CANON_X_UNIT (it
->f
);
1496 /* Compute height. */
1497 if (prop
= Fplist_get (plist
, QCheight
),
1499 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1500 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1502 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1504 height
= FONT_HEIGHT (font
);
1506 /* Compute percentage of height used for ascent. If
1507 `:ascent ASCENT' is present and valid, use that. Otherwise,
1508 derive the ascent from the font in use. */
1509 if (prop
= Fplist_get (plist
, QCascent
),
1510 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1511 ascent
= NUMVAL (prop
) / 100.0;
1513 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1522 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1523 if (!STRINGP (object
))
1524 object
= it
->w
->buffer
;
1525 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1528 it
->pixel_width
= width
;
1529 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1530 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1533 if (face
->box
!= FACE_NO_BOX
)
1535 if (face
->box_line_width
> 0)
1537 it
->ascent
+= face
->box_line_width
;
1538 it
->descent
+= face
->box_line_width
;
1541 if (it
->start_of_box_run_p
)
1542 it
->pixel_width
+= abs (face
->box_line_width
);
1543 if (it
->end_of_box_run_p
)
1544 it
->pixel_width
+= abs (face
->box_line_width
);
1547 take_vertical_position_into_account (it
);
1550 /* Return proper value to be used as baseline offset of font that has
1551 ASCENT and DESCENT to draw characters by the font at the vertical
1552 center of the line of frame F.
1554 Here, out task is to find the value of BOFF in the following figure;
1556 -------------------------+-----------+-
1557 -+-+---------+-+ | |
1559 | | | | F_ASCENT F_HEIGHT
1562 | | |-|-+------+-----------|------- baseline
1564 | |---------|-+-+ | |
1566 -+-+---------+-+ F_DESCENT |
1567 -------------------------+-----------+-
1569 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1570 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1571 DESCENT = FONT->descent
1572 HEIGHT = FONT_HEIGHT (FONT)
1573 F_DESCENT = (F->output_data.x->font->descent
1574 - F->output_data.x->baseline_offset)
1575 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1578 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1580 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1581 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1582 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1584 /* Produce glyphs/get display metrics for the display element IT is
1585 loaded with. See the description of struct display_iterator in
1586 dispextern.h for an overview of struct display_iterator. */
1589 x_produce_glyphs (it
)
1592 it
->glyph_not_available_p
= 0;
1594 if (it
->what
== IT_CHARACTER
)
1598 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1600 int font_not_found_p
;
1601 struct font_info
*font_info
;
1602 int boff
; /* baseline offset */
1603 /* We may change it->multibyte_p upon unibyte<->multibyte
1604 conversion. So, save the current value now and restore it
1607 Note: It seems that we don't have to record multibyte_p in
1608 struct glyph because the character code itself tells if or
1609 not the character is multibyte. Thus, in the future, we must
1610 consider eliminating the field `multibyte_p' in the struct
1612 int saved_multibyte_p
= it
->multibyte_p
;
1614 /* Maybe translate single-byte characters to multibyte, or the
1616 it
->char_to_display
= it
->c
;
1617 if (!ASCII_BYTE_P (it
->c
))
1619 if (unibyte_display_via_language_environment
1620 && SINGLE_BYTE_CHAR_P (it
->c
)
1622 || !NILP (Vnonascii_translation_table
)))
1624 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1625 it
->multibyte_p
= 1;
1626 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1627 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1629 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1630 && !it
->multibyte_p
)
1632 it
->multibyte_p
= 1;
1633 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1634 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1638 /* Get font to use. Encode IT->char_to_display. */
1639 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1640 it
->face_id
, &char2b
,
1641 it
->multibyte_p
, 0);
1644 /* When no suitable font found, use the default font. */
1645 font_not_found_p
= font
== NULL
;
1646 if (font_not_found_p
)
1648 font
= FRAME_FONT (it
->f
);
1649 boff
= it
->f
->output_data
.x
->baseline_offset
;
1654 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1655 boff
= font_info
->baseline_offset
;
1656 if (font_info
->vertical_centering
)
1657 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1660 if (it
->char_to_display
>= ' '
1661 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1663 /* Either unibyte or ASCII. */
1668 pcm
= x_per_char_metric (font
, &char2b
);
1669 it
->ascent
= font
->ascent
+ boff
;
1670 it
->descent
= font
->descent
- boff
;
1674 it
->phys_ascent
= pcm
->ascent
+ boff
;
1675 it
->phys_descent
= pcm
->descent
- boff
;
1676 it
->pixel_width
= pcm
->width
;
1680 it
->glyph_not_available_p
= 1;
1681 it
->phys_ascent
= font
->ascent
+ boff
;
1682 it
->phys_descent
= font
->descent
- boff
;
1683 it
->pixel_width
= FONT_WIDTH (font
);
1686 /* If this is a space inside a region of text with
1687 `space-width' property, change its width. */
1688 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1690 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1692 /* If face has a box, add the box thickness to the character
1693 height. If character has a box line to the left and/or
1694 right, add the box line width to the character's width. */
1695 if (face
->box
!= FACE_NO_BOX
)
1697 int thick
= face
->box_line_width
;
1701 it
->ascent
+= thick
;
1702 it
->descent
+= thick
;
1707 if (it
->start_of_box_run_p
)
1708 it
->pixel_width
+= thick
;
1709 if (it
->end_of_box_run_p
)
1710 it
->pixel_width
+= thick
;
1713 /* If face has an overline, add the height of the overline
1714 (1 pixel) and a 1 pixel margin to the character height. */
1715 if (face
->overline_p
)
1718 take_vertical_position_into_account (it
);
1720 /* If we have to actually produce glyphs, do it. */
1725 /* Translate a space with a `space-width' property
1726 into a stretch glyph. */
1727 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1728 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1729 it
->ascent
+ it
->descent
, ascent
);
1732 x_append_glyph (it
);
1734 /* If characters with lbearing or rbearing are displayed
1735 in this line, record that fact in a flag of the
1736 glyph row. This is used to optimize X output code. */
1737 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1738 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1741 else if (it
->char_to_display
== '\n')
1743 /* A newline has no width but we need the height of the line. */
1744 it
->pixel_width
= 0;
1746 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1747 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1749 if (face
->box
!= FACE_NO_BOX
1750 && face
->box_line_width
> 0)
1752 it
->ascent
+= face
->box_line_width
;
1753 it
->descent
+= face
->box_line_width
;
1756 else if (it
->char_to_display
== '\t')
1758 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1759 int x
= it
->current_x
+ it
->continuation_lines_width
;
1760 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1762 /* If the distance from the current position to the next tab
1763 stop is less than a canonical character width, use the
1764 tab stop after that. */
1765 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1766 next_tab_x
+= tab_width
;
1768 it
->pixel_width
= next_tab_x
- x
;
1770 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1771 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1775 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1776 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1777 it
->ascent
+ it
->descent
, ascent
);
1782 /* A multi-byte character. Assume that the display width of the
1783 character is the width of the character multiplied by the
1784 width of the font. */
1786 /* If we found a font, this font should give us the right
1787 metrics. If we didn't find a font, use the frame's
1788 default font and calculate the width of the character
1789 from the charset width; this is what old redisplay code
1791 pcm
= x_per_char_metric (font
, &char2b
);
1792 if (font_not_found_p
|| !pcm
)
1794 int charset
= CHAR_CHARSET (it
->char_to_display
);
1796 it
->glyph_not_available_p
= 1;
1797 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1798 * CHARSET_WIDTH (charset
));
1799 it
->phys_ascent
= font
->ascent
+ boff
;
1800 it
->phys_descent
= font
->descent
- boff
;
1804 it
->pixel_width
= pcm
->width
;
1805 it
->phys_ascent
= pcm
->ascent
+ boff
;
1806 it
->phys_descent
= pcm
->descent
- boff
;
1808 && (pcm
->lbearing
< 0
1809 || pcm
->rbearing
> pcm
->width
))
1810 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1813 it
->ascent
= font
->ascent
+ boff
;
1814 it
->descent
= font
->descent
- boff
;
1815 if (face
->box
!= FACE_NO_BOX
)
1817 int thick
= face
->box_line_width
;
1821 it
->ascent
+= thick
;
1822 it
->descent
+= thick
;
1827 if (it
->start_of_box_run_p
)
1828 it
->pixel_width
+= thick
;
1829 if (it
->end_of_box_run_p
)
1830 it
->pixel_width
+= thick
;
1833 /* If face has an overline, add the height of the overline
1834 (1 pixel) and a 1 pixel margin to the character height. */
1835 if (face
->overline_p
)
1838 take_vertical_position_into_account (it
);
1841 x_append_glyph (it
);
1843 it
->multibyte_p
= saved_multibyte_p
;
1845 else if (it
->what
== IT_COMPOSITION
)
1847 /* Note: A composition is represented as one glyph in the
1848 glyph matrix. There are no padding glyphs. */
1851 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1853 int font_not_found_p
;
1854 struct font_info
*font_info
;
1855 int boff
; /* baseline offset */
1856 struct composition
*cmp
= composition_table
[it
->cmp_id
];
1858 /* Maybe translate single-byte characters to multibyte. */
1859 it
->char_to_display
= it
->c
;
1860 if (unibyte_display_via_language_environment
1861 && SINGLE_BYTE_CHAR_P (it
->c
)
1864 && !NILP (Vnonascii_translation_table
))))
1866 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1869 /* Get face and font to use. Encode IT->char_to_display. */
1870 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1871 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1872 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1873 it
->face_id
, &char2b
, it
->multibyte_p
, 0);
1876 /* When no suitable font found, use the default font. */
1877 font_not_found_p
= font
== NULL
;
1878 if (font_not_found_p
)
1880 font
= FRAME_FONT (it
->f
);
1881 boff
= it
->f
->output_data
.x
->baseline_offset
;
1886 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1887 boff
= font_info
->baseline_offset
;
1888 if (font_info
->vertical_centering
)
1889 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1892 /* There are no padding glyphs, so there is only one glyph to
1893 produce for the composition. Important is that pixel_width,
1894 ascent and descent are the values of what is drawn by
1895 draw_glyphs (i.e. the values of the overall glyphs composed). */
1898 /* If we have not yet calculated pixel size data of glyphs of
1899 the composition for the current face font, calculate them
1900 now. Theoretically, we have to check all fonts for the
1901 glyphs, but that requires much time and memory space. So,
1902 here we check only the font of the first glyph. This leads
1903 to incorrect display very rarely, and C-l (recenter) can
1904 correct the display anyway. */
1905 if (cmp
->font
!= (void *) font
)
1907 /* Ascent and descent of the font of the first character of
1908 this composition (adjusted by baseline offset). Ascent
1909 and descent of overall glyphs should not be less than
1910 them respectively. */
1911 int font_ascent
= font
->ascent
+ boff
;
1912 int font_descent
= font
->descent
- boff
;
1913 /* Bounding box of the overall glyphs. */
1914 int leftmost
, rightmost
, lowest
, highest
;
1915 int i
, width
, ascent
, descent
;
1917 cmp
->font
= (void *) font
;
1919 /* Initialize the bounding box. */
1921 && (pcm
= x_per_char_metric (font
, &char2b
)))
1924 ascent
= pcm
->ascent
;
1925 descent
= pcm
->descent
;
1929 width
= FONT_WIDTH (font
);
1930 ascent
= font
->ascent
;
1931 descent
= font
->descent
;
1935 lowest
= - descent
+ boff
;
1936 highest
= ascent
+ boff
;
1940 && font_info
->default_ascent
1941 && CHAR_TABLE_P (Vuse_default_ascent
)
1942 && !NILP (Faref (Vuse_default_ascent
,
1943 make_number (it
->char_to_display
))))
1944 highest
= font_info
->default_ascent
+ boff
;
1946 /* Draw the first glyph at the normal position. It may be
1947 shifted to right later if some other glyphs are drawn at
1949 cmp
->offsets
[0] = 0;
1950 cmp
->offsets
[1] = boff
;
1952 /* Set cmp->offsets for the remaining glyphs. */
1953 for (i
= 1; i
< cmp
->glyph_len
; i
++)
1955 int left
, right
, btm
, top
;
1956 int ch
= COMPOSITION_GLYPH (cmp
, i
);
1957 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
1959 face
= FACE_FROM_ID (it
->f
, face_id
);
1960 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
1961 it
->multibyte_p
, 0);
1965 font
= FRAME_FONT (it
->f
);
1966 boff
= it
->f
->output_data
.x
->baseline_offset
;
1972 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1973 boff
= font_info
->baseline_offset
;
1974 if (font_info
->vertical_centering
)
1975 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1979 && (pcm
= x_per_char_metric (font
, &char2b
)))
1982 ascent
= pcm
->ascent
;
1983 descent
= pcm
->descent
;
1987 width
= FONT_WIDTH (font
);
1992 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
1994 /* Relative composition with or without
1996 left
= (leftmost
+ rightmost
- width
) / 2;
1997 btm
= - descent
+ boff
;
1998 if (font_info
&& font_info
->relative_compose
1999 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2000 || NILP (Faref (Vignore_relative_composition
,
2001 make_number (ch
)))))
2004 if (- descent
>= font_info
->relative_compose
)
2005 /* One extra pixel between two glyphs. */
2007 else if (ascent
<= 0)
2008 /* One extra pixel between two glyphs. */
2009 btm
= lowest
- 1 - ascent
- descent
;
2014 /* A composition rule is specified by an integer
2015 value that encodes global and new reference
2016 points (GREF and NREF). GREF and NREF are
2017 specified by numbers as below:
2025 ---3---4---5--- baseline
2027 6---7---8 -- descent
2029 int rule
= COMPOSITION_RULE (cmp
, i
);
2030 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2032 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2033 grefx
= gref
% 3, nrefx
= nref
% 3;
2034 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2037 + grefx
* (rightmost
- leftmost
) / 2
2038 - nrefx
* width
/ 2);
2039 btm
= ((grefy
== 0 ? highest
2041 : grefy
== 2 ? lowest
2042 : (highest
+ lowest
) / 2)
2043 - (nrefy
== 0 ? ascent
+ descent
2044 : nrefy
== 1 ? descent
- boff
2046 : (ascent
+ descent
) / 2));
2049 cmp
->offsets
[i
* 2] = left
;
2050 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2052 /* Update the bounding box of the overall glyphs. */
2053 right
= left
+ width
;
2054 top
= btm
+ descent
+ ascent
;
2055 if (left
< leftmost
)
2057 if (right
> rightmost
)
2065 /* If there are glyphs whose x-offsets are negative,
2066 shift all glyphs to the right and make all x-offsets
2070 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2071 cmp
->offsets
[i
* 2] -= leftmost
;
2072 rightmost
-= leftmost
;
2075 cmp
->pixel_width
= rightmost
;
2076 cmp
->ascent
= highest
;
2077 cmp
->descent
= - lowest
;
2078 if (cmp
->ascent
< font_ascent
)
2079 cmp
->ascent
= font_ascent
;
2080 if (cmp
->descent
< font_descent
)
2081 cmp
->descent
= font_descent
;
2084 it
->pixel_width
= cmp
->pixel_width
;
2085 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2086 it
->descent
= it
->phys_descent
= cmp
->descent
;
2088 if (face
->box
!= FACE_NO_BOX
)
2090 int thick
= face
->box_line_width
;
2094 it
->ascent
+= thick
;
2095 it
->descent
+= thick
;
2100 if (it
->start_of_box_run_p
)
2101 it
->pixel_width
+= thick
;
2102 if (it
->end_of_box_run_p
)
2103 it
->pixel_width
+= thick
;
2106 /* If face has an overline, add the height of the overline
2107 (1 pixel) and a 1 pixel margin to the character height. */
2108 if (face
->overline_p
)
2111 take_vertical_position_into_account (it
);
2114 x_append_composite_glyph (it
);
2116 else if (it
->what
== IT_IMAGE
)
2117 x_produce_image_glyph (it
);
2118 else if (it
->what
== IT_STRETCH
)
2119 x_produce_stretch_glyph (it
);
2121 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2122 because this isn't true for images with `:ascent 100'. */
2123 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2124 if (it
->area
== TEXT_AREA
)
2125 it
->current_x
+= it
->pixel_width
;
2127 it
->descent
+= it
->extra_line_spacing
;
2129 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2130 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2131 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2132 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2136 /* Estimate the pixel height of the mode or top line on frame F.
2137 FACE_ID specifies what line's height to estimate. */
2140 x_estimate_mode_line_height (f
, face_id
)
2142 enum face_id face_id
;
2144 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2146 /* This function is called so early when Emacs starts that the face
2147 cache and mode line face are not yet initialized. */
2148 if (FRAME_FACE_CACHE (f
))
2150 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2154 height
= FONT_HEIGHT (face
->font
);
2155 if (face
->box_line_width
> 0)
2156 height
+= 2 * face
->box_line_width
;
2164 /***********************************************************************
2166 ***********************************************************************/
2168 /* A sequence of glyphs to be drawn in the same face.
2170 This data structure is not really completely X specific, so it
2171 could possibly, at least partially, be useful for other systems. It
2172 is currently not part of the external redisplay interface because
2173 it's not clear what other systems will need. */
2177 /* X-origin of the string. */
2180 /* Y-origin and y-position of the base line of this string. */
2183 /* The width of the string, not including a face extension. */
2186 /* The width of the string, including a face extension. */
2187 int background_width
;
2189 /* The height of this string. This is the height of the line this
2190 string is drawn in, and can be different from the height of the
2191 font the string is drawn in. */
2194 /* Number of pixels this string overwrites in front of its x-origin.
2195 This number is zero if the string has an lbearing >= 0; it is
2196 -lbearing, if the string has an lbearing < 0. */
2199 /* Number of pixels this string overwrites past its right-most
2200 nominal x-position, i.e. x + width. Zero if the string's
2201 rbearing is <= its nominal width, rbearing - width otherwise. */
2204 /* The frame on which the glyph string is drawn. */
2207 /* The window on which the glyph string is drawn. */
2210 /* X display and window for convenience. */
2214 /* The glyph row for which this string was built. It determines the
2215 y-origin and height of the string. */
2216 struct glyph_row
*row
;
2218 /* The area within row. */
2219 enum glyph_row_area area
;
2221 /* Characters to be drawn, and number of characters. */
2225 /* A face-override for drawing cursors, mouse face and similar. */
2226 enum draw_glyphs_face hl
;
2228 /* Face in which this string is to be drawn. */
2231 /* Font in which this string is to be drawn. */
2234 /* Font info for this string. */
2235 struct font_info
*font_info
;
2237 /* Non-null means this string describes (part of) a composition.
2238 All characters from char2b are drawn composed. */
2239 struct composition
*cmp
;
2241 /* Index of this glyph string's first character in the glyph
2242 definition of CMP. If this is zero, this glyph string describes
2243 the first character of a composition. */
2246 /* 1 means this glyph strings face has to be drawn to the right end
2247 of the window's drawing area. */
2248 unsigned extends_to_end_of_line_p
: 1;
2250 /* 1 means the background of this string has been drawn. */
2251 unsigned background_filled_p
: 1;
2253 /* 1 means glyph string must be drawn with 16-bit functions. */
2254 unsigned two_byte_p
: 1;
2256 /* 1 means that the original font determined for drawing this glyph
2257 string could not be loaded. The member `font' has been set to
2258 the frame's default font in this case. */
2259 unsigned font_not_found_p
: 1;
2261 /* 1 means that the face in which this glyph string is drawn has a
2263 unsigned stippled_p
: 1;
2265 /* 1 means only the foreground of this glyph string must be drawn,
2266 and we should use the physical height of the line this glyph
2267 string appears in as clip rect. */
2268 unsigned for_overlaps_p
: 1;
2270 /* The GC to use for drawing this glyph string. */
2273 /* A pointer to the first glyph in the string. This glyph
2274 corresponds to char2b[0]. Needed to draw rectangles if
2275 font_not_found_p is 1. */
2276 struct glyph
*first_glyph
;
2278 /* Image, if any. */
2281 struct glyph_string
*next
, *prev
;
2288 x_dump_glyph_string (s
)
2289 struct glyph_string
*s
;
2291 fprintf (stderr
, "glyph string\n");
2292 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2293 s
->x
, s
->y
, s
->width
, s
->height
);
2294 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2295 fprintf (stderr
, " hl = %d\n", s
->hl
);
2296 fprintf (stderr
, " left overhang = %d, right = %d\n",
2297 s
->left_overhang
, s
->right_overhang
);
2298 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2299 fprintf (stderr
, " extends to end of line = %d\n",
2300 s
->extends_to_end_of_line_p
);
2301 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2302 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2305 #endif /* GLYPH_DEBUG */
2309 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2310 struct glyph_string
**,
2311 struct glyph_string
*,
2312 struct glyph_string
*));
2313 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2314 struct glyph_string
**,
2315 struct glyph_string
*,
2316 struct glyph_string
*));
2317 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2318 struct glyph_string
**,
2319 struct glyph_string
*));
2320 static int x_left_overwritten
P_ ((struct glyph_string
*));
2321 static int x_left_overwriting
P_ ((struct glyph_string
*));
2322 static int x_right_overwritten
P_ ((struct glyph_string
*));
2323 static int x_right_overwriting
P_ ((struct glyph_string
*));
2324 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2326 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2327 XChar2b
*, struct window
*,
2329 enum glyph_row_area
, int,
2330 enum draw_glyphs_face
));
2331 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2332 enum glyph_row_area
, int, int,
2333 enum draw_glyphs_face
, int));
2334 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2335 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2336 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2338 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2339 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2340 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2341 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2342 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2343 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2344 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2345 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2346 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2348 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2349 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2350 unsigned long *, double, int));
2351 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2352 double, int, unsigned long));
2353 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2354 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2355 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2356 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2357 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2358 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2359 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2361 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2362 int, int, int, int, XRectangle
*));
2363 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2364 int, int, int, XRectangle
*));
2365 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2366 enum glyph_row_area
));
2367 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2369 enum glyph_row_area
, int, int));
2372 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2376 /* Append the list of glyph strings with head H and tail T to the list
2377 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2380 x_append_glyph_string_lists (head
, tail
, h
, t
)
2381 struct glyph_string
**head
, **tail
;
2382 struct glyph_string
*h
, *t
;
2396 /* Prepend the list of glyph strings with head H and tail T to the
2397 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2401 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2402 struct glyph_string
**head
, **tail
;
2403 struct glyph_string
*h
, *t
;
2417 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2418 Set *HEAD and *TAIL to the resulting list. */
2421 x_append_glyph_string (head
, tail
, s
)
2422 struct glyph_string
**head
, **tail
;
2423 struct glyph_string
*s
;
2425 s
->next
= s
->prev
= NULL
;
2426 x_append_glyph_string_lists (head
, tail
, s
, s
);
2430 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2435 struct glyph_string
*s
;
2437 if (s
->font
== FRAME_FONT (s
->f
)
2438 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2439 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2441 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2444 /* Cursor on non-default face: must merge. */
2448 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2449 xgcv
.foreground
= s
->face
->background
;
2451 /* If the glyph would be invisible, try a different foreground. */
2452 if (xgcv
.foreground
== xgcv
.background
)
2453 xgcv
.foreground
= s
->face
->foreground
;
2454 if (xgcv
.foreground
== xgcv
.background
)
2455 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2456 if (xgcv
.foreground
== xgcv
.background
)
2457 xgcv
.foreground
= s
->face
->foreground
;
2459 /* Make sure the cursor is distinct from text in this face. */
2460 if (xgcv
.background
== s
->face
->background
2461 && xgcv
.foreground
== s
->face
->foreground
)
2463 xgcv
.background
= s
->face
->foreground
;
2464 xgcv
.foreground
= s
->face
->background
;
2467 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2468 xgcv
.font
= s
->font
->fid
;
2469 xgcv
.graphics_exposures
= False
;
2470 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2472 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2473 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2476 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2477 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2479 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2484 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2487 x_set_mouse_face_gc (s
)
2488 struct glyph_string
*s
;
2493 /* What face has to be used last for the mouse face? */
2494 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2495 face
= FACE_FROM_ID (s
->f
, face_id
);
2497 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2499 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2500 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2502 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2503 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2504 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2506 /* If font in this face is same as S->font, use it. */
2507 if (s
->font
== s
->face
->font
)
2508 s
->gc
= s
->face
->gc
;
2511 /* Otherwise construct scratch_cursor_gc with values from FACE
2516 xgcv
.background
= s
->face
->background
;
2517 xgcv
.foreground
= s
->face
->foreground
;
2518 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2519 xgcv
.font
= s
->font
->fid
;
2520 xgcv
.graphics_exposures
= False
;
2521 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2523 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2524 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2527 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2528 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2530 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2533 xassert (s
->gc
!= 0);
2537 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2538 Faces to use in the mode line have already been computed when the
2539 matrix was built, so there isn't much to do, here. */
2542 x_set_mode_line_face_gc (s
)
2543 struct glyph_string
*s
;
2545 s
->gc
= s
->face
->gc
;
2549 /* Set S->gc of glyph string S for drawing that glyph string. Set
2550 S->stippled_p to a non-zero value if the face of S has a stipple
2554 x_set_glyph_string_gc (s
)
2555 struct glyph_string
*s
;
2557 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2559 if (s
->hl
== DRAW_NORMAL_TEXT
)
2561 s
->gc
= s
->face
->gc
;
2562 s
->stippled_p
= s
->face
->stipple
!= 0;
2564 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2566 x_set_mode_line_face_gc (s
);
2567 s
->stippled_p
= s
->face
->stipple
!= 0;
2569 else if (s
->hl
== DRAW_CURSOR
)
2571 x_set_cursor_gc (s
);
2574 else if (s
->hl
== DRAW_MOUSE_FACE
)
2576 x_set_mouse_face_gc (s
);
2577 s
->stippled_p
= s
->face
->stipple
!= 0;
2579 else if (s
->hl
== DRAW_IMAGE_RAISED
2580 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2582 s
->gc
= s
->face
->gc
;
2583 s
->stippled_p
= s
->face
->stipple
!= 0;
2587 s
->gc
= s
->face
->gc
;
2588 s
->stippled_p
= s
->face
->stipple
!= 0;
2591 /* GC must have been set. */
2592 xassert (s
->gc
!= 0);
2596 /* Return in *R the clipping rectangle for glyph string S. */
2599 x_get_glyph_string_clip_rect (s
, r
)
2600 struct glyph_string
*s
;
2603 if (s
->row
->full_width_p
)
2605 /* Draw full-width. X coordinates are relative to S->w->left. */
2606 int canon_x
= CANON_X_UNIT (s
->f
);
2608 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2609 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2611 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2613 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2614 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2618 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2620 /* Unless displaying a mode or menu bar line, which are always
2621 fully visible, clip to the visible part of the row. */
2622 if (s
->w
->pseudo_window_p
)
2623 r
->height
= s
->row
->visible_height
;
2625 r
->height
= s
->height
;
2629 /* This is a text line that may be partially visible. */
2630 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2631 r
->width
= window_box_width (s
->w
, s
->area
);
2632 r
->height
= s
->row
->visible_height
;
2635 /* If S draws overlapping rows, it's sufficient to use the top and
2636 bottom of the window for clipping because this glyph string
2637 intentionally draws over other lines. */
2638 if (s
->for_overlaps_p
)
2640 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2641 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2645 /* Don't use S->y for clipping because it doesn't take partially
2646 visible lines into account. For example, it can be negative for
2647 partially visible lines at the top of a window. */
2648 if (!s
->row
->full_width_p
2649 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2650 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2652 r
->y
= max (0, s
->row
->y
);
2654 /* If drawing a tool-bar window, draw it over the internal border
2655 at the top of the window. */
2656 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2657 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2660 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2664 /* Set clipping for output of glyph string S. S may be part of a mode
2665 line or menu if we don't have X toolkit support. */
2668 x_set_glyph_string_clipping (s
)
2669 struct glyph_string
*s
;
2672 x_get_glyph_string_clip_rect (s
, &r
);
2673 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2677 /* Compute left and right overhang of glyph string S. If S is a glyph
2678 string for a composition, assume overhangs don't exist. */
2681 x_compute_glyph_string_overhangs (s
)
2682 struct glyph_string
*s
;
2685 && s
->first_glyph
->type
== CHAR_GLYPH
)
2688 int direction
, font_ascent
, font_descent
;
2689 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2690 &font_ascent
, &font_descent
, &cs
);
2691 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2692 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2697 /* Compute overhangs and x-positions for glyph string S and its
2698 predecessors, or successors. X is the starting x-position for S.
2699 BACKWARD_P non-zero means process predecessors. */
2702 x_compute_overhangs_and_x (s
, x
, backward_p
)
2703 struct glyph_string
*s
;
2711 x_compute_glyph_string_overhangs (s
);
2721 x_compute_glyph_string_overhangs (s
);
2730 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2731 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2732 assumed to be zero. */
2735 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2736 struct glyph
*glyph
;
2742 if (glyph
->type
== CHAR_GLYPH
)
2746 struct font_info
*font_info
;
2750 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2752 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2754 && (pcm
= x_per_char_metric (font
, &char2b
)))
2756 if (pcm
->rbearing
> pcm
->width
)
2757 *right
= pcm
->rbearing
- pcm
->width
;
2758 if (pcm
->lbearing
< 0)
2759 *left
= -pcm
->lbearing
;
2765 /* Return the index of the first glyph preceding glyph string S that
2766 is overwritten by S because of S's left overhang. Value is -1
2767 if no glyphs are overwritten. */
2770 x_left_overwritten (s
)
2771 struct glyph_string
*s
;
2775 if (s
->left_overhang
)
2778 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2779 int first
= s
->first_glyph
- glyphs
;
2781 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2782 x
-= glyphs
[i
].pixel_width
;
2793 /* Return the index of the first glyph preceding glyph string S that
2794 is overwriting S because of its right overhang. Value is -1 if no
2795 glyph in front of S overwrites S. */
2798 x_left_overwriting (s
)
2799 struct glyph_string
*s
;
2802 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2803 int first
= s
->first_glyph
- glyphs
;
2807 for (i
= first
- 1; i
>= 0; --i
)
2810 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2813 x
-= glyphs
[i
].pixel_width
;
2820 /* Return the index of the last glyph following glyph string S that is
2821 not overwritten by S because of S's right overhang. Value is -1 if
2822 no such glyph is found. */
2825 x_right_overwritten (s
)
2826 struct glyph_string
*s
;
2830 if (s
->right_overhang
)
2833 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2834 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2835 int end
= s
->row
->used
[s
->area
];
2837 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
2838 x
+= glyphs
[i
].pixel_width
;
2847 /* Return the index of the last glyph following glyph string S that
2848 overwrites S because of its left overhang. Value is negative
2849 if no such glyph is found. */
2852 x_right_overwriting (s
)
2853 struct glyph_string
*s
;
2856 int end
= s
->row
->used
[s
->area
];
2857 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2858 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2862 for (i
= first
; i
< end
; ++i
)
2865 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2868 x
+= glyphs
[i
].pixel_width
;
2875 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2878 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2879 struct glyph_string
*s
;
2883 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
2884 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2885 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2886 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2890 /* Draw the background of glyph_string S. If S->background_filled_p
2891 is non-zero don't draw it. FORCE_P non-zero means draw the
2892 background even if it wouldn't be drawn normally. This is used
2893 when a string preceding S draws into the background of S, or S
2894 contains the first component of a composition. */
2897 x_draw_glyph_string_background (s
, force_p
)
2898 struct glyph_string
*s
;
2901 /* Nothing to do if background has already been drawn or if it
2902 shouldn't be drawn in the first place. */
2903 if (!s
->background_filled_p
)
2905 int box_line_width
= max (s
->face
->box_line_width
, 0);
2909 /* Fill background with a stipple pattern. */
2910 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2911 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2912 s
->y
+ box_line_width
,
2913 s
->background_width
,
2914 s
->height
- 2 * box_line_width
);
2915 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2916 s
->background_filled_p
= 1;
2918 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
2919 || s
->font_not_found_p
2920 || s
->extends_to_end_of_line_p
2923 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
2924 s
->background_width
,
2925 s
->height
- 2 * box_line_width
);
2926 s
->background_filled_p
= 1;
2932 /* Draw the foreground of glyph string S. */
2935 x_draw_glyph_string_foreground (s
)
2936 struct glyph_string
*s
;
2940 /* If first glyph of S has a left box line, start drawing the text
2941 of S to the right of that box line. */
2942 if (s
->face
->box
!= FACE_NO_BOX
2943 && s
->first_glyph
->left_box_line_p
)
2944 x
= s
->x
+ abs (s
->face
->box_line_width
);
2948 /* Draw characters of S as rectangles if S's font could not be
2950 if (s
->font_not_found_p
)
2952 for (i
= 0; i
< s
->nchars
; ++i
)
2954 struct glyph
*g
= s
->first_glyph
+ i
;
2955 XDrawRectangle (s
->display
, s
->window
,
2956 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
2958 x
+= g
->pixel_width
;
2963 char *char1b
= (char *) s
->char2b
;
2964 int boff
= s
->font_info
->baseline_offset
;
2966 if (s
->font_info
->vertical_centering
)
2967 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
2969 /* If we can use 8-bit functions, condense S->char2b. */
2971 for (i
= 0; i
< s
->nchars
; ++i
)
2972 char1b
[i
] = s
->char2b
[i
].byte2
;
2974 /* Draw text with XDrawString if background has already been
2975 filled. Otherwise, use XDrawImageString. (Note that
2976 XDrawImageString is usually faster than XDrawString.) Always
2977 use XDrawImageString when drawing the cursor so that there is
2978 no chance that characters under a box cursor are invisible. */
2979 if (s
->for_overlaps_p
2980 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
2982 /* Draw characters with 16-bit or 8-bit functions. */
2984 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
2985 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
2987 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
2988 s
->ybase
- boff
, char1b
, s
->nchars
);
2993 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
2994 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
2996 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
2997 s
->ybase
- boff
, char1b
, s
->nchars
);
3000 if (s
->face
->overstrike
)
3002 /* For overstriking (to simulate bold-face), draw the
3003 characters again shifted to the right by one pixel. */
3005 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
3006 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3008 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
3009 s
->ybase
- boff
, char1b
, s
->nchars
);
3014 /* Draw the foreground of composite glyph string S. */
3017 x_draw_composite_glyph_string_foreground (s
)
3018 struct glyph_string
*s
;
3022 /* If first glyph of S has a left box line, start drawing the text
3023 of S to the right of that box line. */
3024 if (s
->face
->box
!= FACE_NO_BOX
3025 && s
->first_glyph
->left_box_line_p
)
3026 x
= s
->x
+ abs (s
->face
->box_line_width
);
3030 /* S is a glyph string for a composition. S->gidx is the index of
3031 the first character drawn for glyphs of this composition.
3032 S->gidx == 0 means we are drawing the very first character of
3033 this composition. */
3035 /* Draw a rectangle for the composition if the font for the very
3036 first character of the composition could not be loaded. */
3037 if (s
->font_not_found_p
)
3040 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3041 s
->width
- 1, s
->height
- 1);
3045 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3047 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3048 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3049 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3051 if (s
->face
->overstrike
)
3052 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3053 x
+ s
->cmp
->offsets
[s
->gidx
* 2] + 1,
3054 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3061 #ifdef USE_X_TOOLKIT
3063 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3064 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3065 XrmValue
*, XrmValue
*, XtPointer
*));
3066 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3067 XrmValue
*, Cardinal
*));
3070 /* Return the frame on which widget WIDGET is used.. Abort if frame
3071 cannot be determined. */
3073 static struct frame
*
3074 x_frame_of_widget (widget
)
3077 struct x_display_info
*dpyinfo
;
3081 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3083 /* Find the top-level shell of the widget. Note that this function
3084 can be called when the widget is not yet realized, so XtWindow
3085 (widget) == 0. That's the reason we can't simply use
3086 x_any_window_to_frame. */
3087 while (!XtIsTopLevelShell (widget
))
3088 widget
= XtParent (widget
);
3090 /* Look for a frame with that top-level widget. Allocate the color
3091 on that frame to get the right gamma correction value. */
3092 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3093 if (GC_FRAMEP (XCAR (tail
))
3094 && (f
= XFRAME (XCAR (tail
)),
3095 (f
->output_data
.nothing
!= 1
3096 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3097 && f
->output_data
.x
->widget
== widget
)
3104 /* Allocate the color COLOR->pixel on the screen and display of
3105 widget WIDGET in colormap CMAP. If an exact match cannot be
3106 allocated, try the nearest color available. Value is non-zero
3107 if successful. This is called from lwlib. */
3110 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3115 struct frame
*f
= x_frame_of_widget (widget
);
3116 return x_alloc_nearest_color (f
, cmap
, color
);
3120 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3121 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3122 If this produces the same color as PIXEL, try a color where all RGB
3123 values have DELTA added. Return the allocated color in *PIXEL.
3124 DISPLAY is the X display, CMAP is the colormap to operate on.
3125 Value is non-zero if successful. */
3128 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3132 unsigned long *pixel
;
3136 struct frame
*f
= x_frame_of_widget (widget
);
3137 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3141 /* Structure specifying which arguments should be passed by Xt to
3142 cvt_string_to_pixel. We want the widget's screen and colormap. */
3144 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3146 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3148 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3153 /* The address of this variable is returned by
3154 cvt_string_to_pixel. */
3156 static Pixel cvt_string_to_pixel_value
;
3159 /* Convert a color name to a pixel color.
3161 DPY is the display we are working on.
3163 ARGS is an array of *NARGS XrmValue structures holding additional
3164 information about the widget for which the conversion takes place.
3165 The contents of this array are determined by the specification
3166 in cvt_string_to_pixel_args.
3168 FROM is a pointer to an XrmValue which points to the color name to
3169 convert. TO is an XrmValue in which to return the pixel color.
3171 CLOSURE_RET is a pointer to user-data, in which we record if
3172 we allocated the color or not.
3174 Value is True if successful, False otherwise. */
3177 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3181 XrmValue
*from
, *to
;
3182 XtPointer
*closure_ret
;
3192 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3193 "wrongParameters", "cvt_string_to_pixel",
3195 "Screen and colormap args required", NULL
, NULL
);
3199 screen
= *(Screen
**) args
[0].addr
;
3200 cmap
= *(Colormap
*) args
[1].addr
;
3201 color_name
= (String
) from
->addr
;
3203 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3205 *closure_ret
= (XtPointer
) False
;
3206 pixel
= WhitePixelOfScreen (screen
);
3208 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3210 *closure_ret
= (XtPointer
) False
;
3211 pixel
= BlackPixelOfScreen (screen
);
3213 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3214 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3216 pixel
= color
.pixel
;
3217 *closure_ret
= (XtPointer
) True
;
3222 Cardinal nparams
= 1;
3224 params
[0] = color_name
;
3225 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3226 "badValue", "cvt_string_to_pixel",
3227 "XtToolkitError", "Invalid color `%s'",
3232 if (to
->addr
!= NULL
)
3234 if (to
->size
< sizeof (Pixel
))
3236 to
->size
= sizeof (Pixel
);
3240 *(Pixel
*) to
->addr
= pixel
;
3244 cvt_string_to_pixel_value
= pixel
;
3245 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3248 to
->size
= sizeof (Pixel
);
3253 /* Free a pixel color which was previously allocated via
3254 cvt_string_to_pixel. This is registered as the destructor
3255 for this type of resource via XtSetTypeConverter.
3257 APP is the application context in which we work.
3259 TO is a pointer to an XrmValue holding the color to free.
3260 CLOSURE is the value we stored in CLOSURE_RET for this color
3261 in cvt_string_to_pixel.
3263 ARGS and NARGS are like for cvt_string_to_pixel. */
3266 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3275 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3277 "Screen and colormap arguments required",
3280 else if (closure
!= NULL
)
3282 /* We did allocate the pixel, so free it. */
3283 Screen
*screen
= *(Screen
**) args
[0].addr
;
3284 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3285 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3286 (Pixel
*) to
->addr
, 1);
3291 #endif /* USE_X_TOOLKIT */
3294 /* Value is an array of XColor structures for the contents of the
3295 color map of display DPY. Set *NCELLS to the size of the array.
3296 Note that this probably shouldn't be called for large color maps,
3297 say a 24-bit TrueColor map. */
3299 static const XColor
*
3300 x_color_cells (dpy
, ncells
)
3304 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3306 if (dpyinfo
->color_cells
== NULL
)
3308 Screen
*screen
= dpyinfo
->screen
;
3311 dpyinfo
->ncolor_cells
3312 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3313 dpyinfo
->color_cells
3314 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3315 * sizeof *dpyinfo
->color_cells
);
3317 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3318 dpyinfo
->color_cells
[i
].pixel
= i
;
3320 XQueryColors (dpy
, dpyinfo
->cmap
,
3321 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3324 *ncells
= dpyinfo
->ncolor_cells
;
3325 return dpyinfo
->color_cells
;
3329 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3330 colors in COLORS. Use cached information, if available. */
3333 x_query_colors (f
, colors
, ncolors
)
3338 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3340 if (dpyinfo
->color_cells
)
3343 for (i
= 0; i
< ncolors
; ++i
)
3345 unsigned long pixel
= colors
[i
].pixel
;
3346 xassert (pixel
< dpyinfo
->ncolor_cells
);
3347 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3348 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3352 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3356 /* On frame F, translate pixel color to RGB values for the color in
3357 COLOR. Use cached information, if available. */
3360 x_query_color (f
, color
)
3364 x_query_colors (f
, color
, 1);
3368 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3369 exact match can't be allocated, try the nearest color available.
3370 Value is non-zero if successful. Set *COLOR to the color
3374 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3381 rc
= XAllocColor (dpy
, cmap
, color
);
3384 /* If we got to this point, the colormap is full, so we're going
3385 to try to get the next closest color. The algorithm used is
3386 a least-squares matching, which is what X uses for closest
3387 color matching with StaticColor visuals. */
3389 unsigned long nearest_delta
= ~0;
3391 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3393 for (nearest
= i
= 0; i
< ncells
; ++i
)
3395 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3396 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3397 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3398 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3400 if (delta
< nearest_delta
)
3403 nearest_delta
= delta
;
3407 color
->red
= cells
[nearest
].red
;
3408 color
->green
= cells
[nearest
].green
;
3409 color
->blue
= cells
[nearest
].blue
;
3410 rc
= XAllocColor (dpy
, cmap
, color
);
3414 /* If allocation succeeded, and the allocated pixel color is not
3415 equal to a cached pixel color recorded earlier, there was a
3416 change in the colormap, so clear the color cache. */
3417 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3418 XColor
*cached_color
;
3420 if (dpyinfo
->color_cells
3421 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3422 (cached_color
->red
!= color
->red
3423 || cached_color
->blue
!= color
->blue
3424 || cached_color
->green
!= color
->green
)))
3426 xfree (dpyinfo
->color_cells
);
3427 dpyinfo
->color_cells
= NULL
;
3428 dpyinfo
->ncolor_cells
= 0;
3432 #ifdef DEBUG_X_COLORS
3434 register_color (color
->pixel
);
3435 #endif /* DEBUG_X_COLORS */
3441 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3442 exact match can't be allocated, try the nearest color available.
3443 Value is non-zero if successful. Set *COLOR to the color
3447 x_alloc_nearest_color (f
, cmap
, color
)
3452 gamma_correct (f
, color
);
3453 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3457 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3458 It's necessary to do this instead of just using PIXEL directly to
3459 get color reference counts right. */
3462 x_copy_color (f
, pixel
)
3464 unsigned long pixel
;
3468 color
.pixel
= pixel
;
3470 x_query_color (f
, &color
);
3471 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3473 #ifdef DEBUG_X_COLORS
3474 register_color (pixel
);
3480 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3481 It's necessary to do this instead of just using PIXEL directly to
3482 get color reference counts right. */
3485 x_copy_dpy_color (dpy
, cmap
, pixel
)
3488 unsigned long pixel
;
3492 color
.pixel
= pixel
;
3494 XQueryColor (dpy
, cmap
, &color
);
3495 XAllocColor (dpy
, cmap
, &color
);
3497 #ifdef DEBUG_X_COLORS
3498 register_color (pixel
);
3504 /* Brightness beyond which a color won't have its highlight brightness
3507 Nominally, highlight colors for `3d' faces are calculated by
3508 brightening an object's color by a constant scale factor, but this
3509 doesn't yield good results for dark colors, so for colors who's
3510 brightness is less than this value (on a scale of 0-65535) have an
3511 use an additional additive factor.
3513 The value here is set so that the default menu-bar/mode-line color
3514 (grey75) will not have its highlights changed at all. */
3515 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3518 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3519 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3520 If this produces the same color as PIXEL, try a color where all RGB
3521 values have DELTA added. Return the allocated color in *PIXEL.
3522 DISPLAY is the X display, CMAP is the colormap to operate on.
3523 Value is non-zero if successful. */
3526 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3530 unsigned long *pixel
;
3538 /* Get RGB color values. */
3539 color
.pixel
= *pixel
;
3540 x_query_color (f
, &color
);
3542 /* Change RGB values by specified FACTOR. Avoid overflow! */
3543 xassert (factor
>= 0);
3544 new.red
= min (0xffff, factor
* color
.red
);
3545 new.green
= min (0xffff, factor
* color
.green
);
3546 new.blue
= min (0xffff, factor
* color
.blue
);
3548 /* Calculate brightness of COLOR. */
3549 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3551 /* We only boost colors that are darker than
3552 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3553 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3554 /* Make an additive adjustment to NEW, because it's dark enough so
3555 that scaling by FACTOR alone isn't enough. */
3557 /* How far below the limit this color is (0 - 1, 1 being darker). */
3558 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3559 /* The additive adjustment. */
3560 int min_delta
= delta
* dimness
* factor
/ 2;
3564 new.red
= max (0, new.red
- min_delta
);
3565 new.green
= max (0, new.green
- min_delta
);
3566 new.blue
= max (0, new.blue
- min_delta
);
3570 new.red
= min (0xffff, min_delta
+ new.red
);
3571 new.green
= min (0xffff, min_delta
+ new.green
);
3572 new.blue
= min (0xffff, min_delta
+ new.blue
);
3576 /* Try to allocate the color. */
3577 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3580 if (new.pixel
== *pixel
)
3582 /* If we end up with the same color as before, try adding
3583 delta to the RGB values. */
3584 x_free_colors (f
, &new.pixel
, 1);
3586 new.red
= min (0xffff, delta
+ color
.red
);
3587 new.green
= min (0xffff, delta
+ color
.green
);
3588 new.blue
= min (0xffff, delta
+ color
.blue
);
3589 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3600 /* Set up the foreground color for drawing relief lines of glyph
3601 string S. RELIEF is a pointer to a struct relief containing the GC
3602 with which lines will be drawn. Use a color that is FACTOR or
3603 DELTA lighter or darker than the relief's background which is found
3604 in S->f->output_data.x->relief_background. If such a color cannot
3605 be allocated, use DEFAULT_PIXEL, instead. */
3608 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3610 struct relief
*relief
;
3613 unsigned long default_pixel
;
3616 struct x_output
*di
= f
->output_data
.x
;
3617 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3618 unsigned long pixel
;
3619 unsigned long background
= di
->relief_background
;
3620 Colormap cmap
= FRAME_X_COLORMAP (f
);
3621 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3622 Display
*dpy
= FRAME_X_DISPLAY (f
);
3624 xgcv
.graphics_exposures
= False
;
3625 xgcv
.line_width
= 1;
3627 /* Free previously allocated color. The color cell will be reused
3628 when it has been freed as many times as it was allocated, so this
3629 doesn't affect faces using the same colors. */
3631 && relief
->allocated_p
)
3633 x_free_colors (f
, &relief
->pixel
, 1);
3634 relief
->allocated_p
= 0;
3637 /* Allocate new color. */
3638 xgcv
.foreground
= default_pixel
;
3640 if (dpyinfo
->n_planes
!= 1
3641 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3643 relief
->allocated_p
= 1;
3644 xgcv
.foreground
= relief
->pixel
= pixel
;
3647 if (relief
->gc
== 0)
3649 xgcv
.stipple
= dpyinfo
->gray
;
3651 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3654 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3658 /* Set up colors for the relief lines around glyph string S. */
3661 x_setup_relief_colors (s
)
3662 struct glyph_string
*s
;
3664 struct x_output
*di
= s
->f
->output_data
.x
;
3665 unsigned long color
;
3667 if (s
->face
->use_box_color_for_shadows_p
)
3668 color
= s
->face
->box_color
;
3669 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3671 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3672 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3677 /* Get the background color of the face. */
3678 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3679 color
= xgcv
.background
;
3682 if (di
->white_relief
.gc
== 0
3683 || color
!= di
->relief_background
)
3685 di
->relief_background
= color
;
3686 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3687 WHITE_PIX_DEFAULT (s
->f
));
3688 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3689 BLACK_PIX_DEFAULT (s
->f
));
3694 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3695 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3696 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3697 relief. LEFT_P non-zero means draw a relief on the left side of
3698 the rectangle. RIGHT_P non-zero means draw a relief on the right
3699 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3703 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3704 raised_p
, left_p
, right_p
, clip_rect
)
3706 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
, raised_p
;
3707 XRectangle
*clip_rect
;
3709 Display
*dpy
= FRAME_X_DISPLAY (f
);
3710 Window window
= FRAME_X_WINDOW (f
);
3715 gc
= f
->output_data
.x
->white_relief
.gc
;
3717 gc
= f
->output_data
.x
->black_relief
.gc
;
3718 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3721 for (i
= 0; i
< width
; ++i
)
3722 XDrawLine (dpy
, window
, gc
,
3723 left_x
+ i
* left_p
, top_y
+ i
,
3724 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3728 for (i
= 0; i
< width
; ++i
)
3729 XDrawLine (dpy
, window
, gc
,
3730 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3732 XSetClipMask (dpy
, gc
, None
);
3734 gc
= f
->output_data
.x
->black_relief
.gc
;
3736 gc
= f
->output_data
.x
->white_relief
.gc
;
3737 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3740 for (i
= 0; i
< width
; ++i
)
3741 XDrawLine (dpy
, window
, gc
,
3742 left_x
+ i
* left_p
, bottom_y
- i
,
3743 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3747 for (i
= 0; i
< width
; ++i
)
3748 XDrawLine (dpy
, window
, gc
,
3749 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3751 XSetClipMask (dpy
, gc
, None
);
3755 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3756 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3757 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3758 left side of the rectangle. RIGHT_P non-zero means draw a line
3759 on the right side of the rectangle. CLIP_RECT is the clipping
3760 rectangle to use when drawing. */
3763 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3764 left_p
, right_p
, clip_rect
)
3765 struct glyph_string
*s
;
3766 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
3767 XRectangle
*clip_rect
;
3771 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3772 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3773 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3776 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3777 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3781 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3782 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3785 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3786 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3790 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3791 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3793 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3794 XSetClipMask (s
->display
, s
->gc
, None
);
3798 /* Draw a box around glyph string S. */
3801 x_draw_glyph_string_box (s
)
3802 struct glyph_string
*s
;
3804 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3805 int left_p
, right_p
;
3806 struct glyph
*last_glyph
;
3807 XRectangle clip_rect
;
3809 last_x
= window_box_right (s
->w
, s
->area
);
3810 if (s
->row
->full_width_p
3811 && !s
->w
->pseudo_window_p
)
3813 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
3814 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3815 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3818 /* The glyph that may have a right box line. */
3819 last_glyph
= (s
->cmp
|| s
->img
3821 : s
->first_glyph
+ s
->nchars
- 1);
3823 width
= abs (s
->face
->box_line_width
);
3824 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3826 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3828 : min (last_x
, s
->x
+ s
->background_width
) - 1);
3830 bottom_y
= top_y
+ s
->height
- 1;
3832 left_p
= (s
->first_glyph
->left_box_line_p
3833 || (s
->hl
== DRAW_MOUSE_FACE
3835 || s
->prev
->hl
!= s
->hl
)));
3836 right_p
= (last_glyph
->right_box_line_p
3837 || (s
->hl
== DRAW_MOUSE_FACE
3839 || s
->next
->hl
!= s
->hl
)));
3841 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3843 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3844 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3845 left_p
, right_p
, &clip_rect
);
3848 x_setup_relief_colors (s
);
3849 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3850 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3855 /* Draw foreground of image glyph string S. */
3858 x_draw_image_foreground (s
)
3859 struct glyph_string
*s
;
3862 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3864 /* If first glyph of S has a left box line, start drawing it to the
3865 right of that line. */
3866 if (s
->face
->box
!= FACE_NO_BOX
3867 && s
->first_glyph
->left_box_line_p
)
3868 x
= s
->x
+ abs (s
->face
->box_line_width
);
3872 /* If there is a margin around the image, adjust x- and y-position
3874 x
+= s
->img
->hmargin
;
3875 y
+= s
->img
->vmargin
;
3881 /* We can't set both a clip mask and use XSetClipRectangles
3882 because the latter also sets a clip mask. We also can't
3883 trust on the shape extension to be available
3884 (XShapeCombineRegion). So, compute the rectangle to draw
3886 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3889 XRectangle clip_rect
, image_rect
, r
;
3891 xgcv
.clip_mask
= s
->img
->mask
;
3892 xgcv
.clip_x_origin
= x
;
3893 xgcv
.clip_y_origin
= y
;
3894 xgcv
.function
= GXcopy
;
3895 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3897 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3900 image_rect
.width
= s
->img
->width
;
3901 image_rect
.height
= s
->img
->height
;
3902 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3903 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3904 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3908 XRectangle clip_rect
, image_rect
, r
;
3910 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3913 image_rect
.width
= s
->img
->width
;
3914 image_rect
.height
= s
->img
->height
;
3915 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3916 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3917 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3919 /* When the image has a mask, we can expect that at
3920 least part of a mouse highlight or a block cursor will
3921 be visible. If the image doesn't have a mask, make
3922 a block cursor visible by drawing a rectangle around
3923 the image. I believe it's looking better if we do
3924 nothing here for mouse-face. */
3925 if (s
->hl
== DRAW_CURSOR
)
3927 int r
= s
->img
->relief
;
3929 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
3930 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
3935 /* Draw a rectangle if image could not be loaded. */
3936 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3937 s
->img
->width
- 1, s
->img
->height
- 1);
3941 /* Draw a relief around the image glyph string S. */
3944 x_draw_image_relief (s
)
3945 struct glyph_string
*s
;
3947 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3950 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3952 /* If first glyph of S has a left box line, start drawing it to the
3953 right of that line. */
3954 if (s
->face
->box
!= FACE_NO_BOX
3955 && s
->first_glyph
->left_box_line_p
)
3956 x
= s
->x
+ abs (s
->face
->box_line_width
);
3960 /* If there is a margin around the image, adjust x- and y-position
3962 x
+= s
->img
->hmargin
;
3963 y
+= s
->img
->vmargin
;
3965 if (s
->hl
== DRAW_IMAGE_SUNKEN
3966 || s
->hl
== DRAW_IMAGE_RAISED
)
3968 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3969 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3973 thick
= abs (s
->img
->relief
);
3974 raised_p
= s
->img
->relief
> 0;
3979 x1
= x
+ s
->img
->width
+ thick
- 1;
3980 y1
= y
+ s
->img
->height
+ thick
- 1;
3982 x_setup_relief_colors (s
);
3983 x_get_glyph_string_clip_rect (s
, &r
);
3984 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3988 /* Draw the foreground of image glyph string S to PIXMAP. */
3991 x_draw_image_foreground_1 (s
, pixmap
)
3992 struct glyph_string
*s
;
3996 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3998 /* If first glyph of S has a left box line, start drawing it to the
3999 right of that line. */
4000 if (s
->face
->box
!= FACE_NO_BOX
4001 && s
->first_glyph
->left_box_line_p
)
4002 x
= abs (s
->face
->box_line_width
);
4006 /* If there is a margin around the image, adjust x- and y-position
4008 x
+= s
->img
->hmargin
;
4009 y
+= s
->img
->vmargin
;
4015 /* We can't set both a clip mask and use XSetClipRectangles
4016 because the latter also sets a clip mask. We also can't
4017 trust on the shape extension to be available
4018 (XShapeCombineRegion). So, compute the rectangle to draw
4020 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4024 xgcv
.clip_mask
= s
->img
->mask
;
4025 xgcv
.clip_x_origin
= x
;
4026 xgcv
.clip_y_origin
= y
;
4027 xgcv
.function
= GXcopy
;
4028 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4030 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4031 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4032 XSetClipMask (s
->display
, s
->gc
, None
);
4036 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4037 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4039 /* When the image has a mask, we can expect that at
4040 least part of a mouse highlight or a block cursor will
4041 be visible. If the image doesn't have a mask, make
4042 a block cursor visible by drawing a rectangle around
4043 the image. I believe it's looking better if we do
4044 nothing here for mouse-face. */
4045 if (s
->hl
== DRAW_CURSOR
)
4047 int r
= s
->img
->relief
;
4049 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
4050 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4055 /* Draw a rectangle if image could not be loaded. */
4056 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4057 s
->img
->width
- 1, s
->img
->height
- 1);
4061 /* Draw part of the background of glyph string S. X, Y, W, and H
4062 give the rectangle to draw. */
4065 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4066 struct glyph_string
*s
;
4071 /* Fill background with a stipple pattern. */
4072 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4073 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4074 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4077 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4081 /* Draw image glyph string S.
4084 s->x +-------------------------
4087 | +-------------------------
4090 | | +-------------------
4096 x_draw_image_glyph_string (s
)
4097 struct glyph_string
*s
;
4100 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4101 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4103 Pixmap pixmap
= None
;
4105 height
= s
->height
- 2 * box_line_vwidth
;
4108 /* Fill background with face under the image. Do it only if row is
4109 taller than image or if image has a clip mask to reduce
4111 s
->stippled_p
= s
->face
->stipple
!= 0;
4112 if (height
> s
->img
->height
4116 || s
->img
->pixmap
== 0
4117 || s
->width
!= s
->background_width
)
4119 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4120 x
= s
->x
+ box_line_hwidth
;
4124 y
= s
->y
+ box_line_vwidth
;
4128 /* Create a pixmap as large as the glyph string. Fill it
4129 with the background color. Copy the image to it, using
4130 its mask. Copy the temporary pixmap to the display. */
4131 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4132 int depth
= DefaultDepthOfScreen (screen
);
4134 /* Create a pixmap as large as the glyph string. */
4135 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4136 s
->background_width
,
4139 /* Don't clip in the following because we're working on the
4141 XSetClipMask (s
->display
, s
->gc
, None
);
4143 /* Fill the pixmap with the background color/stipple. */
4146 /* Fill background with a stipple pattern. */
4147 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4148 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4149 0, 0, s
->background_width
, s
->height
);
4150 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4155 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4157 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4158 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4159 0, 0, s
->background_width
, s
->height
);
4160 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4164 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4166 s
->background_filled_p
= 1;
4169 /* Draw the foreground. */
4172 x_draw_image_foreground_1 (s
, pixmap
);
4173 x_set_glyph_string_clipping (s
);
4174 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4175 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4176 XFreePixmap (s
->display
, pixmap
);
4179 x_draw_image_foreground (s
);
4181 /* If we must draw a relief around the image, do it. */
4183 || s
->hl
== DRAW_IMAGE_RAISED
4184 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4185 x_draw_image_relief (s
);
4189 /* Draw stretch glyph string S. */
4192 x_draw_stretch_glyph_string (s
)
4193 struct glyph_string
*s
;
4195 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4196 s
->stippled_p
= s
->face
->stipple
!= 0;
4198 if (s
->hl
== DRAW_CURSOR
4199 && !x_stretch_cursor_p
)
4201 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4202 as wide as the stretch glyph. */
4203 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4206 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4208 /* Clear rest using the GC of the original non-cursor face. */
4209 if (width
< s
->background_width
)
4211 int x
= s
->x
+ width
, y
= s
->y
;
4212 int w
= s
->background_width
- width
, h
= s
->height
;
4216 if (s
->row
->mouse_face_p
4217 && cursor_in_mouse_face_p (s
->w
))
4219 x_set_mouse_face_gc (s
);
4225 x_get_glyph_string_clip_rect (s
, &r
);
4226 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4228 if (s
->face
->stipple
)
4230 /* Fill background with a stipple pattern. */
4231 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4232 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4233 XSetFillStyle (s
->display
, gc
, FillSolid
);
4238 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4239 XSetForeground (s
->display
, gc
, xgcv
.background
);
4240 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4241 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4245 else if (!s
->background_filled_p
)
4246 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4249 s
->background_filled_p
= 1;
4253 /* Draw glyph string S. */
4256 x_draw_glyph_string (s
)
4257 struct glyph_string
*s
;
4259 int relief_drawn_p
= 0;
4261 /* If S draws into the background of its successor, draw the
4262 background of the successor first so that S can draw into it.
4263 This makes S->next use XDrawString instead of XDrawImageString. */
4264 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4266 xassert (s
->next
->img
== NULL
);
4267 x_set_glyph_string_gc (s
->next
);
4268 x_set_glyph_string_clipping (s
->next
);
4269 x_draw_glyph_string_background (s
->next
, 1);
4272 /* Set up S->gc, set clipping and draw S. */
4273 x_set_glyph_string_gc (s
);
4275 /* Draw relief (if any) in advance for char/composition so that the
4276 glyph string can be drawn over it. */
4277 if (!s
->for_overlaps_p
4278 && s
->face
->box
!= FACE_NO_BOX
4279 && (s
->first_glyph
->type
== CHAR_GLYPH
4280 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4283 x_set_glyph_string_clipping (s
);
4284 x_draw_glyph_string_background (s
, 1);
4285 x_draw_glyph_string_box (s
);
4286 x_set_glyph_string_clipping (s
);
4290 x_set_glyph_string_clipping (s
);
4292 switch (s
->first_glyph
->type
)
4295 x_draw_image_glyph_string (s
);
4299 x_draw_stretch_glyph_string (s
);
4303 if (s
->for_overlaps_p
)
4304 s
->background_filled_p
= 1;
4306 x_draw_glyph_string_background (s
, 0);
4307 x_draw_glyph_string_foreground (s
);
4310 case COMPOSITE_GLYPH
:
4311 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4312 s
->background_filled_p
= 1;
4314 x_draw_glyph_string_background (s
, 1);
4315 x_draw_composite_glyph_string_foreground (s
);
4322 if (!s
->for_overlaps_p
)
4324 /* Draw underline. */
4325 if (s
->face
->underline_p
)
4327 unsigned long tem
, h
;
4330 /* Get the underline thickness. Default is 1 pixel. */
4331 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4334 /* Get the underline position. This is the recommended
4335 vertical offset in pixels from the baseline to the top of
4336 the underline. This is a signed value according to the
4337 specs, and its default is
4339 ROUND ((maximum descent) / 2), with
4340 ROUND(x) = floor (x + 0.5) */
4342 if (x_use_underline_position_properties
4343 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4344 y
= s
->ybase
+ (long) tem
;
4345 else if (s
->face
->font
)
4346 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4348 y
= s
->y
+ s
->height
- h
;
4350 if (s
->face
->underline_defaulted_p
)
4351 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4352 s
->x
, y
, s
->width
, h
);
4356 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4357 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4358 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4359 s
->x
, y
, s
->width
, h
);
4360 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4364 /* Draw overline. */
4365 if (s
->face
->overline_p
)
4367 unsigned long dy
= 0, h
= 1;
4369 if (s
->face
->overline_color_defaulted_p
)
4370 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4375 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4376 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4377 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4379 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4383 /* Draw strike-through. */
4384 if (s
->face
->strike_through_p
)
4386 unsigned long h
= 1;
4387 unsigned long dy
= (s
->height
- h
) / 2;
4389 if (s
->face
->strike_through_color_defaulted_p
)
4390 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4395 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4396 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4397 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4399 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4403 /* Draw relief if not yet drawn. */
4404 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4405 x_draw_glyph_string_box (s
);
4408 /* Reset clipping. */
4409 XSetClipMask (s
->display
, s
->gc
, None
);
4413 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4414 struct face
**, int));
4417 /* Fill glyph string S with composition components specified by S->cmp.
4419 FACES is an array of faces for all components of this composition.
4420 S->gidx is the index of the first component for S.
4421 OVERLAPS_P non-zero means S should draw the foreground only, and
4422 use its physical height for clipping.
4424 Value is the index of a component not in S. */
4427 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4428 struct glyph_string
*s
;
4429 struct face
**faces
;
4436 s
->for_overlaps_p
= overlaps_p
;
4438 s
->face
= faces
[s
->gidx
];
4439 s
->font
= s
->face
->font
;
4440 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4442 /* For all glyphs of this composition, starting at the offset
4443 S->gidx, until we reach the end of the definition or encounter a
4444 glyph that requires the different face, add it to S. */
4446 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4449 /* All glyph strings for the same composition has the same width,
4450 i.e. the width set for the first component of the composition. */
4452 s
->width
= s
->first_glyph
->pixel_width
;
4454 /* If the specified font could not be loaded, use the frame's
4455 default font, but record the fact that we couldn't load it in
4456 the glyph string so that we can draw rectangles for the
4457 characters of the glyph string. */
4458 if (s
->font
== NULL
)
4460 s
->font_not_found_p
= 1;
4461 s
->font
= FRAME_FONT (s
->f
);
4464 /* Adjust base line for subscript/superscript text. */
4465 s
->ybase
+= s
->first_glyph
->voffset
;
4467 xassert (s
->face
&& s
->face
->gc
);
4469 /* This glyph string must always be drawn with 16-bit functions. */
4472 return s
->gidx
+ s
->nchars
;
4476 /* Fill glyph string S from a sequence of character glyphs.
4478 FACE_ID is the face id of the string. START is the index of the
4479 first glyph to consider, END is the index of the last + 1.
4480 OVERLAPS_P non-zero means S should draw the foreground only, and
4481 use its physical height for clipping.
4483 Value is the index of the first glyph not in S. */
4486 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4487 struct glyph_string
*s
;
4489 int start
, end
, overlaps_p
;
4491 struct glyph
*glyph
, *last
;
4493 int glyph_not_available_p
;
4495 xassert (s
->f
== XFRAME (s
->w
->frame
));
4496 xassert (s
->nchars
== 0);
4497 xassert (start
>= 0 && end
> start
);
4499 s
->for_overlaps_p
= overlaps_p
,
4500 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4501 last
= s
->row
->glyphs
[s
->area
] + end
;
4502 voffset
= glyph
->voffset
;
4504 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4507 && glyph
->type
== CHAR_GLYPH
4508 && glyph
->voffset
== voffset
4509 /* Same face id implies same font, nowadays. */
4510 && glyph
->face_id
== face_id
4511 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4515 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4516 s
->char2b
+ s
->nchars
,
4518 s
->two_byte_p
= two_byte_p
;
4520 xassert (s
->nchars
<= end
- start
);
4521 s
->width
+= glyph
->pixel_width
;
4525 s
->font
= s
->face
->font
;
4526 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4528 /* If the specified font could not be loaded, use the frame's font,
4529 but record the fact that we couldn't load it in
4530 S->font_not_found_p so that we can draw rectangles for the
4531 characters of the glyph string. */
4532 if (s
->font
== NULL
|| glyph_not_available_p
)
4534 s
->font_not_found_p
= 1;
4535 s
->font
= FRAME_FONT (s
->f
);
4538 /* Adjust base line for subscript/superscript text. */
4539 s
->ybase
+= voffset
;
4541 xassert (s
->face
&& s
->face
->gc
);
4542 return glyph
- s
->row
->glyphs
[s
->area
];
4546 /* Fill glyph string S from image glyph S->first_glyph. */
4549 x_fill_image_glyph_string (s
)
4550 struct glyph_string
*s
;
4552 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4553 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4555 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4556 s
->font
= s
->face
->font
;
4557 s
->width
= s
->first_glyph
->pixel_width
;
4559 /* Adjust base line for subscript/superscript text. */
4560 s
->ybase
+= s
->first_glyph
->voffset
;
4564 /* Fill glyph string S from a sequence of stretch glyphs.
4566 ROW is the glyph row in which the glyphs are found, AREA is the
4567 area within the row. START is the index of the first glyph to
4568 consider, END is the index of the last + 1.
4570 Value is the index of the first glyph not in S. */
4573 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4574 struct glyph_string
*s
;
4575 struct glyph_row
*row
;
4576 enum glyph_row_area area
;
4579 struct glyph
*glyph
, *last
;
4580 int voffset
, face_id
;
4582 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4584 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4585 last
= s
->row
->glyphs
[s
->area
] + end
;
4586 face_id
= glyph
->face_id
;
4587 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4588 s
->font
= s
->face
->font
;
4589 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4590 s
->width
= glyph
->pixel_width
;
4591 voffset
= glyph
->voffset
;
4595 && glyph
->type
== STRETCH_GLYPH
4596 && glyph
->voffset
== voffset
4597 && glyph
->face_id
== face_id
);
4599 s
->width
+= glyph
->pixel_width
;
4601 /* Adjust base line for subscript/superscript text. */
4602 s
->ybase
+= voffset
;
4604 /* The case that face->gc == 0 is handled when drawing the glyph
4605 string by calling PREPARE_FACE_FOR_DISPLAY. */
4607 return glyph
- s
->row
->glyphs
[s
->area
];
4611 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4612 of XChar2b structures for S; it can't be allocated in
4613 x_init_glyph_string because it must be allocated via `alloca'. W
4614 is the window on which S is drawn. ROW and AREA are the glyph row
4615 and area within the row from which S is constructed. START is the
4616 index of the first glyph structure covered by S. HL is a
4617 face-override for drawing S. */
4620 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4621 struct glyph_string
*s
;
4624 struct glyph_row
*row
;
4625 enum glyph_row_area area
;
4627 enum draw_glyphs_face hl
;
4629 bzero (s
, sizeof *s
);
4631 s
->f
= XFRAME (w
->frame
);
4632 s
->display
= FRAME_X_DISPLAY (s
->f
);
4633 s
->window
= FRAME_X_WINDOW (s
->f
);
4638 s
->first_glyph
= row
->glyphs
[area
] + start
;
4639 s
->height
= row
->height
;
4640 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4642 /* Display the internal border below the tool-bar window. */
4643 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4644 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4646 s
->ybase
= s
->y
+ row
->ascent
;
4650 /* Set background width of glyph string S. START is the index of the
4651 first glyph following S. LAST_X is the right-most x-position + 1
4652 in the drawing area. */
4655 x_set_glyph_string_background_width (s
, start
, last_x
)
4656 struct glyph_string
*s
;
4660 /* If the face of this glyph string has to be drawn to the end of
4661 the drawing area, set S->extends_to_end_of_line_p. */
4662 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4664 if (start
== s
->row
->used
[s
->area
]
4665 && s
->area
== TEXT_AREA
4666 && ((s
->hl
== DRAW_NORMAL_TEXT
4667 && (s
->row
->fill_line_p
4668 || s
->face
->background
!= default_face
->background
4669 || s
->face
->stipple
!= default_face
->stipple
4670 || s
->row
->mouse_face_p
))
4671 || s
->hl
== DRAW_MOUSE_FACE
4672 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4673 && s
->row
->fill_line_p
)))
4674 s
->extends_to_end_of_line_p
= 1;
4676 /* If S extends its face to the end of the line, set its
4677 background_width to the distance to the right edge of the drawing
4679 if (s
->extends_to_end_of_line_p
)
4680 s
->background_width
= last_x
- s
->x
+ 1;
4682 s
->background_width
= s
->width
;
4686 /* Add a glyph string for a stretch glyph to the list of strings
4687 between HEAD and TAIL. START is the index of the stretch glyph in
4688 row area AREA of glyph row ROW. END is the index of the last glyph
4689 in that glyph row area. X is the current output position assigned
4690 to the new glyph string constructed. HL overrides that face of the
4691 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4692 is the right-most x-position of the drawing area. */
4694 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4695 and below -- keep them on one line. */
4696 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4699 s = (struct glyph_string *) alloca (sizeof *s); \
4700 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4701 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4702 x_append_glyph_string (&HEAD, &TAIL, s); \
4708 /* Add a glyph string for an image glyph to the list of strings
4709 between HEAD and TAIL. START is the index of the image glyph in
4710 row area AREA of glyph row ROW. END is the index of the last glyph
4711 in that glyph row area. X is the current output position assigned
4712 to the new glyph string constructed. HL overrides that face of the
4713 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4714 is the right-most x-position of the drawing area. */
4716 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4719 s = (struct glyph_string *) alloca (sizeof *s); \
4720 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4721 x_fill_image_glyph_string (s); \
4722 x_append_glyph_string (&HEAD, &TAIL, s); \
4729 /* Add a glyph string for a sequence of character glyphs to the list
4730 of strings between HEAD and TAIL. START is the index of the first
4731 glyph in row area AREA of glyph row ROW that is part of the new
4732 glyph string. END is the index of the last glyph in that glyph row
4733 area. X is the current output position assigned to the new glyph
4734 string constructed. HL overrides that face of the glyph; e.g. it
4735 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4736 right-most x-position of the drawing area. */
4738 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4744 c = (ROW)->glyphs[AREA][START].u.ch; \
4745 face_id = (ROW)->glyphs[AREA][START].face_id; \
4747 s = (struct glyph_string *) alloca (sizeof *s); \
4748 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4749 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4750 x_append_glyph_string (&HEAD, &TAIL, s); \
4752 START = x_fill_glyph_string (s, face_id, START, END, \
4758 /* Add a glyph string for a composite sequence to the list of strings
4759 between HEAD and TAIL. START is the index of the first glyph in
4760 row area AREA of glyph row ROW that is part of the new glyph
4761 string. END is the index of the last glyph in that glyph row area.
4762 X is the current output position assigned to the new glyph string
4763 constructed. HL overrides that face of the glyph; e.g. it is
4764 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4765 x-position of the drawing area. */
4767 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4769 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4770 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4771 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4772 struct composition *cmp = composition_table[cmp_id]; \
4773 int glyph_len = cmp->glyph_len; \
4775 struct face **faces; \
4776 struct glyph_string *first_s = NULL; \
4779 base_face = base_face->ascii_face; \
4780 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4781 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4782 /* At first, fill in `char2b' and `faces'. */ \
4783 for (n = 0; n < glyph_len; n++) \
4785 int c = COMPOSITION_GLYPH (cmp, n); \
4786 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4787 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4788 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4789 this_face_id, char2b + n, 1, 1); \
4792 /* Make glyph_strings for each glyph sequence that is drawable by \
4793 the same face, and append them to HEAD/TAIL. */ \
4794 for (n = 0; n < cmp->glyph_len;) \
4796 s = (struct glyph_string *) alloca (sizeof *s); \
4797 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4798 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4806 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4814 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4815 of AREA of glyph row ROW on window W between indices START and END.
4816 HL overrides the face for drawing glyph strings, e.g. it is
4817 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4818 x-positions of the drawing area.
4820 This is an ugly monster macro construct because we must use alloca
4821 to allocate glyph strings (because x_draw_glyphs can be called
4824 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4827 HEAD = TAIL = NULL; \
4828 while (START < END) \
4830 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4831 switch (first_glyph->type) \
4834 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4835 TAIL, HL, X, LAST_X, \
4839 case COMPOSITE_GLYPH: \
4840 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4841 HEAD, TAIL, HL, X, LAST_X,\
4845 case STRETCH_GLYPH: \
4846 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4847 HEAD, TAIL, HL, X, LAST_X); \
4851 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4852 TAIL, HL, X, LAST_X); \
4859 x_set_glyph_string_background_width (s, START, LAST_X); \
4866 /* Draw glyphs between START and END in AREA of ROW on window W,
4867 starting at x-position X. X is relative to AREA in W. HL is a
4868 face-override with the following meaning:
4870 DRAW_NORMAL_TEXT draw normally
4871 DRAW_CURSOR draw in cursor face
4872 DRAW_MOUSE_FACE draw in mouse face.
4873 DRAW_INVERSE_VIDEO draw in mode line face
4874 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4875 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4877 If OVERLAPS_P is non-zero, draw only the foreground of characters
4878 and clip to the physical height of ROW.
4880 Value is the x-position reached, relative to AREA of W. */
4883 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
4886 struct glyph_row
*row
;
4887 enum glyph_row_area area
;
4889 enum draw_glyphs_face hl
;
4892 struct glyph_string
*head
, *tail
;
4893 struct glyph_string
*s
;
4894 int last_x
, area_width
;
4898 /* Let's rather be paranoid than getting a SEGV. */
4899 end
= min (end
, row
->used
[area
]);
4900 start
= max (0, start
);
4901 start
= min (end
, start
);
4903 /* Translate X to frame coordinates. Set last_x to the right
4904 end of the drawing area. */
4905 if (row
->full_width_p
)
4907 /* X is relative to the left edge of W, without scroll bars
4909 struct frame
*f
= XFRAME (w
->frame
);
4910 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4913 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4914 last_x
= window_left_x
+ area_width
;
4916 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4918 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4919 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4925 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4926 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4930 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4931 area_width
= window_box_width (w
, area
);
4932 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4935 /* Build a doubly-linked list of glyph_string structures between
4936 head and tail from what we have to draw. Note that the macro
4937 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4938 the reason we use a separate variable `i'. */
4940 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4943 x_reached
= tail
->x
+ tail
->background_width
;
4947 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4948 the row, redraw some glyphs in front or following the glyph
4949 strings built above. */
4950 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4953 struct glyph_string
*h
, *t
;
4955 /* Compute overhangs for all glyph strings. */
4956 for (s
= head
; s
; s
= s
->next
)
4957 x_compute_glyph_string_overhangs (s
);
4959 /* Prepend glyph strings for glyphs in front of the first glyph
4960 string that are overwritten because of the first glyph
4961 string's left overhang. The background of all strings
4962 prepended must be drawn because the first glyph string
4964 i
= x_left_overwritten (head
);
4968 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4969 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4972 x_compute_overhangs_and_x (t
, head
->x
, 1);
4973 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4976 /* Prepend glyph strings for glyphs in front of the first glyph
4977 string that overwrite that glyph string because of their
4978 right overhang. For these strings, only the foreground must
4979 be drawn, because it draws over the glyph string at `head'.
4980 The background must not be drawn because this would overwrite
4981 right overhangs of preceding glyphs for which no glyph
4983 i
= x_left_overwriting (head
);
4986 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4987 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4989 for (s
= h
; s
; s
= s
->next
)
4990 s
->background_filled_p
= 1;
4991 x_compute_overhangs_and_x (t
, head
->x
, 1);
4992 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4995 /* Append glyphs strings for glyphs following the last glyph
4996 string tail that are overwritten by tail. The background of
4997 these strings has to be drawn because tail's foreground draws
4999 i
= x_right_overwritten (tail
);
5002 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5003 DRAW_NORMAL_TEXT
, x
, last_x
,
5005 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5006 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5009 /* Append glyph strings for glyphs following the last glyph
5010 string tail that overwrite tail. The foreground of such
5011 glyphs has to be drawn because it writes into the background
5012 of tail. The background must not be drawn because it could
5013 paint over the foreground of following glyphs. */
5014 i
= x_right_overwriting (tail
);
5017 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5018 DRAW_NORMAL_TEXT
, x
, last_x
,
5020 for (s
= h
; s
; s
= s
->next
)
5021 s
->background_filled_p
= 1;
5022 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5023 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5027 /* Draw all strings. */
5028 for (s
= head
; s
; s
= s
->next
)
5029 x_draw_glyph_string (s
);
5031 if (area
== TEXT_AREA
5032 && !row
->full_width_p
5033 /* When drawing overlapping rows, only the glyph strings'
5034 foreground is drawn, which doesn't erase a cursor
5038 int x0
= head
? head
->x
: x
;
5039 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5041 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5042 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5044 if (XFASTINT (w
->left_margin_width
) != 0)
5046 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5047 x0
-= left_area_width
;
5048 x1
-= left_area_width
;
5051 notice_overwritten_cursor (w
, area
, x0
, x1
,
5052 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5055 /* Value is the x-position up to which drawn, relative to AREA of W.
5056 This doesn't include parts drawn because of overhangs. */
5057 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5058 if (!row
->full_width_p
)
5060 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
5061 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5062 if (area
> TEXT_AREA
)
5063 x_reached
-= window_box_width (w
, TEXT_AREA
);
5070 /* Fix the display of area AREA of overlapping row ROW in window W. */
5073 x_fix_overlapping_area (w
, row
, area
)
5075 struct glyph_row
*row
;
5076 enum glyph_row_area area
;
5082 if (area
== LEFT_MARGIN_AREA
)
5084 else if (area
== TEXT_AREA
)
5085 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5087 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5088 + window_box_width (w
, TEXT_AREA
));
5090 for (i
= 0; i
< row
->used
[area
];)
5092 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5094 int start
= i
, start_x
= x
;
5098 x
+= row
->glyphs
[area
][i
].pixel_width
;
5101 while (i
< row
->used
[area
]
5102 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5104 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5105 DRAW_NORMAL_TEXT
, 1);
5109 x
+= row
->glyphs
[area
][i
].pixel_width
;
5118 /* Output LEN glyphs starting at START at the nominal cursor position.
5119 Advance the nominal cursor over the text. The global variable
5120 updated_window contains the window being updated, updated_row is
5121 the glyph row being updated, and updated_area is the area of that
5122 row being updated. */
5125 x_write_glyphs (start
, len
)
5126 struct glyph
*start
;
5131 xassert (updated_window
&& updated_row
);
5136 hpos
= start
- updated_row
->glyphs
[updated_area
];
5137 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5138 updated_row
, updated_area
,
5140 DRAW_NORMAL_TEXT
, 0);
5142 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
5143 if (updated_area
== TEXT_AREA
5144 && updated_window
->phys_cursor_on_p
5145 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
5146 && updated_window
->phys_cursor
.hpos
>= hpos
5147 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
5148 updated_window
->phys_cursor_on_p
= 0;
5152 /* Advance the output cursor. */
5153 output_cursor
.hpos
+= len
;
5154 output_cursor
.x
= x
;
5158 /* Insert LEN glyphs from START at the nominal cursor position. */
5161 x_insert_glyphs (start
, len
)
5162 struct glyph
*start
;
5167 int line_height
, shift_by_width
, shifted_region_width
;
5168 struct glyph_row
*row
;
5169 struct glyph
*glyph
;
5170 int frame_x
, frame_y
, hpos
;
5172 xassert (updated_window
&& updated_row
);
5175 f
= XFRAME (WINDOW_FRAME (w
));
5177 /* Get the height of the line we are in. */
5179 line_height
= row
->height
;
5181 /* Get the width of the glyphs to insert. */
5183 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5184 shift_by_width
+= glyph
->pixel_width
;
5186 /* Get the width of the region to shift right. */
5187 shifted_region_width
= (window_box_width (w
, updated_area
)
5192 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5193 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5194 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5195 f
->output_data
.x
->normal_gc
,
5197 shifted_region_width
, line_height
,
5198 frame_x
+ shift_by_width
, frame_y
);
5200 /* Write the glyphs. */
5201 hpos
= start
- row
->glyphs
[updated_area
];
5202 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5203 DRAW_NORMAL_TEXT
, 0);
5205 /* Advance the output cursor. */
5206 output_cursor
.hpos
+= len
;
5207 output_cursor
.x
+= shift_by_width
;
5212 /* Delete N glyphs at the nominal cursor position. Not implemented
5223 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5224 If they are <= 0, this is probably an error. */
5227 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5234 xassert (width
> 0 && height
> 0);
5235 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5239 /* Erase the current text line from the nominal cursor position
5240 (inclusive) to pixel column TO_X (exclusive). The idea is that
5241 everything from TO_X onward is already erased.
5243 TO_X is a pixel position relative to updated_area of
5244 updated_window. TO_X == -1 means clear to the end of this area. */
5247 x_clear_end_of_line (to_x
)
5251 struct window
*w
= updated_window
;
5252 int max_x
, min_y
, max_y
;
5253 int from_x
, from_y
, to_y
;
5255 xassert (updated_window
&& updated_row
);
5256 f
= XFRAME (w
->frame
);
5258 if (updated_row
->full_width_p
)
5260 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5261 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5262 && !w
->pseudo_window_p
)
5263 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5266 max_x
= window_box_width (w
, updated_area
);
5267 max_y
= window_text_bottom_y (w
);
5269 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5270 of window. For TO_X > 0, truncate to end of drawing area. */
5276 to_x
= min (to_x
, max_x
);
5278 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5280 /* Notice if the cursor will be cleared by this operation. */
5281 if (!updated_row
->full_width_p
)
5282 notice_overwritten_cursor (w
, updated_area
,
5283 output_cursor
.x
, -1,
5285 MATRIX_ROW_BOTTOM_Y (updated_row
));
5287 from_x
= output_cursor
.x
;
5289 /* Translate to frame coordinates. */
5290 if (updated_row
->full_width_p
)
5292 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5293 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5297 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5298 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5301 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5302 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5303 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5305 /* Prevent inadvertently clearing to end of the X window. */
5306 if (to_x
> from_x
&& to_y
> from_y
)
5309 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5310 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5317 /* Clear entire frame. If updating_frame is non-null, clear that
5318 frame. Otherwise clear the selected frame. */
5328 f
= SELECTED_FRAME ();
5330 /* Clearing the frame will erase any cursor, so mark them all as no
5332 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5333 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5334 output_cursor
.x
= -1;
5336 /* We don't set the output cursor here because there will always
5337 follow an explicit cursor_to. */
5339 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5341 /* We have to clear the scroll bars, too. If we have changed
5342 colors or something like that, then they should be notified. */
5343 x_scroll_bar_clear (f
);
5345 XFlush (FRAME_X_DISPLAY (f
));
5351 /* Invert the middle quarter of the frame for .15 sec. */
5353 /* We use the select system call to do the waiting, so we have to make
5354 sure it's available. If it isn't, we just won't do visual bells. */
5356 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5359 /* Subtract the `struct timeval' values X and Y, storing the result in
5360 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5363 timeval_subtract (result
, x
, y
)
5364 struct timeval
*result
, x
, y
;
5366 /* Perform the carry for the later subtraction by updating y. This
5367 is safer because on some systems the tv_sec member is unsigned. */
5368 if (x
.tv_usec
< y
.tv_usec
)
5370 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5371 y
.tv_usec
-= 1000000 * nsec
;
5375 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5377 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5378 y
.tv_usec
+= 1000000 * nsec
;
5382 /* Compute the time remaining to wait. tv_usec is certainly
5384 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5385 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5387 /* Return indication of whether the result should be considered
5389 return x
.tv_sec
< y
.tv_sec
;
5401 /* Create a GC that will use the GXxor function to flip foreground
5402 pixels into background pixels. */
5406 values
.function
= GXxor
;
5407 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5408 ^ f
->output_data
.x
->background_pixel
);
5410 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5411 GCFunction
| GCForeground
, &values
);
5415 /* Get the height not including a menu bar widget. */
5416 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5417 /* Height of each line to flash. */
5418 int flash_height
= FRAME_LINE_HEIGHT (f
);
5419 /* These will be the left and right margins of the rectangles. */
5420 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5421 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5425 /* Don't flash the area between a scroll bar and the frame
5426 edge it is next to. */
5427 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5429 case vertical_scroll_bar_left
:
5430 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5433 case vertical_scroll_bar_right
:
5434 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5441 width
= flash_right
- flash_left
;
5443 /* If window is tall, flash top and bottom line. */
5444 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5446 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5448 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5449 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5450 width
, flash_height
);
5451 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5453 (height
- flash_height
5454 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5455 width
, flash_height
);
5458 /* If it is short, flash it all. */
5459 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5460 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5461 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5466 struct timeval wakeup
;
5468 EMACS_GET_TIME (wakeup
);
5470 /* Compute time to wait until, propagating carry from usecs. */
5471 wakeup
.tv_usec
+= 150000;
5472 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5473 wakeup
.tv_usec
%= 1000000;
5475 /* Keep waiting until past the time wakeup or any input gets
5477 while (! detect_input_pending ())
5479 struct timeval current
;
5480 struct timeval timeout
;
5482 EMACS_GET_TIME (current
);
5484 /* Break if result would be negative. */
5485 if (timeval_subtract (¤t
, wakeup
, current
))
5488 /* How long `select' should wait. */
5490 timeout
.tv_usec
= 10000;
5492 /* Try to wait that long--but we might wake up sooner. */
5493 select (0, NULL
, NULL
, NULL
, &timeout
);
5497 /* If window is tall, flash top and bottom line. */
5498 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5500 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5502 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5503 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5504 width
, flash_height
);
5505 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5507 (height
- flash_height
5508 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5509 width
, flash_height
);
5512 /* If it is short, flash it all. */
5513 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5514 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5515 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5517 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5525 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5528 /* Make audible bell. */
5533 struct frame
*f
= SELECTED_FRAME ();
5535 if (FRAME_X_DISPLAY (f
))
5537 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5544 XBell (FRAME_X_DISPLAY (f
), 0);
5545 XFlush (FRAME_X_DISPLAY (f
));
5552 /* Specify how many text lines, from the top of the window,
5553 should be affected by insert-lines and delete-lines operations.
5554 This, and those operations, are used only within an update
5555 that is bounded by calls to x_update_begin and x_update_end. */
5558 XTset_terminal_window (n
)
5561 /* This function intentionally left blank. */
5566 /***********************************************************************
5568 ***********************************************************************/
5570 /* Perform an insert-lines or delete-lines operation, inserting N
5571 lines or deleting -N lines at vertical position VPOS. */
5574 x_ins_del_lines (vpos
, n
)
5581 /* Scroll part of the display as described by RUN. */
5584 x_scroll_run (w
, run
)
5588 struct frame
*f
= XFRAME (w
->frame
);
5589 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5591 /* Get frame-relative bounding box of the text display area of W,
5592 without mode lines. Include in this box the left and right
5594 window_box (w
, -1, &x
, &y
, &width
, &height
);
5595 width
+= FRAME_X_FRINGE_WIDTH (f
);
5596 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5598 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5599 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5600 bottom_y
= y
+ height
;
5604 /* Scrolling up. Make sure we don't copy part of the mode
5605 line at the bottom. */
5606 if (from_y
+ run
->height
> bottom_y
)
5607 height
= bottom_y
- from_y
;
5609 height
= run
->height
;
5613 /* Scolling down. Make sure we don't copy over the mode line.
5615 if (to_y
+ run
->height
> bottom_y
)
5616 height
= bottom_y
- to_y
;
5618 height
= run
->height
;
5623 /* Cursor off. Will be switched on again in x_update_window_end. */
5627 XCopyArea (FRAME_X_DISPLAY (f
),
5628 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5629 f
->output_data
.x
->normal_gc
,
5639 /***********************************************************************
5641 ***********************************************************************/
5643 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5644 corner of the exposed rectangle. W and H are width and height of
5645 the exposed area. All are pixel values. W or H zero means redraw
5646 the entire frame. */
5649 expose_frame (f
, x
, y
, w
, h
)
5654 int mouse_face_overwritten_p
= 0;
5656 TRACE ((stderr
, "expose_frame "));
5658 /* No need to redraw if frame will be redrawn soon. */
5659 if (FRAME_GARBAGED_P (f
))
5661 TRACE ((stderr
, " garbaged\n"));
5665 /* If basic faces haven't been realized yet, there is no point in
5666 trying to redraw anything. This can happen when we get an expose
5667 event while Emacs is starting, e.g. by moving another window. */
5668 if (FRAME_FACE_CACHE (f
) == NULL
5669 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5671 TRACE ((stderr
, " no faces\n"));
5675 if (w
== 0 || h
== 0)
5678 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5679 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5689 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5690 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5692 if (WINDOWP (f
->tool_bar_window
))
5693 mouse_face_overwritten_p
5694 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5696 #ifndef USE_X_TOOLKIT
5697 if (WINDOWP (f
->menu_bar_window
))
5698 mouse_face_overwritten_p
5699 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5700 #endif /* not USE_X_TOOLKIT */
5702 /* Some window managers support a focus-follows-mouse style with
5703 delayed raising of frames. Imagine a partially obscured frame,
5704 and moving the mouse into partially obscured mouse-face on that
5705 frame. The visible part of the mouse-face will be highlighted,
5706 then the WM raises the obscured frame. With at least one WM, KDE
5707 2.1, Emacs is not getting any event for the raising of the frame
5708 (even tried with SubstructureRedirectMask), only Expose events.
5709 These expose events will draw text normally, i.e. not
5710 highlighted. Which means we must redo the highlight here.
5711 Subsume it under ``we love X''. --gerd 2001-08-15 */
5712 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5714 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5715 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5717 int x
= dpyinfo
->mouse_face_mouse_x
;
5718 int y
= dpyinfo
->mouse_face_mouse_y
;
5719 clear_mouse_face (dpyinfo
);
5720 note_mouse_highlight (f
, x
, y
);
5726 /* Redraw (parts) of all windows in the window tree rooted at W that
5727 intersect R. R contains frame pixel coordinates. Value is
5728 non-zero if the exposure overwrites mouse-face. */
5731 expose_window_tree (w
, r
)
5735 struct frame
*f
= XFRAME (w
->frame
);
5736 int mouse_face_overwritten_p
= 0;
5738 while (w
&& !FRAME_GARBAGED_P (f
))
5740 if (!NILP (w
->hchild
))
5741 mouse_face_overwritten_p
5742 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5743 else if (!NILP (w
->vchild
))
5744 mouse_face_overwritten_p
5745 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5747 mouse_face_overwritten_p
|= expose_window (w
, r
);
5749 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5752 return mouse_face_overwritten_p
;
5756 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5757 which intersects rectangle R. R is in window-relative coordinates. */
5760 expose_area (w
, row
, r
, area
)
5762 struct glyph_row
*row
;
5764 enum glyph_row_area area
;
5766 struct glyph
*first
= row
->glyphs
[area
];
5767 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5769 int first_x
, start_x
, x
;
5771 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5772 /* If row extends face to end of line write the whole line. */
5773 x_draw_glyphs (w
, 0, row
, area
, 0, row
->used
[area
],
5774 DRAW_NORMAL_TEXT
, 0);
5777 /* Set START_X to the window-relative start position for drawing glyphs of
5778 AREA. The first glyph of the text area can be partially visible.
5779 The first glyphs of other areas cannot. */
5780 if (area
== LEFT_MARGIN_AREA
)
5782 else if (area
== TEXT_AREA
)
5783 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5785 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5786 + window_box_width (w
, TEXT_AREA
));
5789 /* Find the first glyph that must be redrawn. */
5791 && x
+ first
->pixel_width
< r
->x
)
5793 x
+= first
->pixel_width
;
5797 /* Find the last one. */
5801 && x
< r
->x
+ r
->width
)
5803 x
+= last
->pixel_width
;
5809 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5810 first
- row
->glyphs
[area
],
5811 last
- row
->glyphs
[area
],
5812 DRAW_NORMAL_TEXT
, 0);
5817 /* Redraw the parts of the glyph row ROW on window W intersecting
5818 rectangle R. R is in window-relative coordinates. Value is
5819 non-zero if mouse-face was overwritten. */
5822 expose_line (w
, row
, r
)
5824 struct glyph_row
*row
;
5827 xassert (row
->enabled_p
);
5829 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5830 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5831 DRAW_NORMAL_TEXT
, 0);
5834 if (row
->used
[LEFT_MARGIN_AREA
])
5835 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5836 if (row
->used
[TEXT_AREA
])
5837 expose_area (w
, row
, r
, TEXT_AREA
);
5838 if (row
->used
[RIGHT_MARGIN_AREA
])
5839 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5840 draw_row_fringe_bitmaps (w
, row
);
5843 return row
->mouse_face_p
;
5847 /* Return non-zero if W's cursor intersects rectangle R. */
5850 x_phys_cursor_in_rect_p (w
, r
)
5854 XRectangle cr
, result
;
5855 struct glyph
*cursor_glyph
;
5857 cursor_glyph
= get_phys_cursor_glyph (w
);
5860 cr
.x
= w
->phys_cursor
.x
;
5861 cr
.y
= w
->phys_cursor
.y
;
5862 cr
.width
= cursor_glyph
->pixel_width
;
5863 cr
.height
= w
->phys_cursor_height
;
5864 return x_intersect_rectangles (&cr
, r
, &result
);
5871 /* Redraw those parts of glyphs rows during expose event handling that
5872 overlap other rows. Redrawing of an exposed line writes over parts
5873 of lines overlapping that exposed line; this function fixes that.
5875 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
5876 row in W's current matrix that is exposed and overlaps other rows.
5877 LAST_OVERLAPPING_ROW is the last such row. */
5880 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
5882 struct glyph_row
*first_overlapping_row
;
5883 struct glyph_row
*last_overlapping_row
;
5885 struct glyph_row
*row
;
5887 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
5888 if (row
->overlapping_p
)
5890 xassert (row
->enabled_p
&& !row
->mode_line_p
);
5892 if (row
->used
[LEFT_MARGIN_AREA
])
5893 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
5895 if (row
->used
[TEXT_AREA
])
5896 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
5898 if (row
->used
[RIGHT_MARGIN_AREA
])
5899 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
5904 /* Redraw the part of window W intersection rectangle FR. Pixel
5905 coordinates in FR are frame-relative. Call this function with
5906 input blocked. Value is non-zero if the exposure overwrites
5910 expose_window (w
, fr
)
5914 struct frame
*f
= XFRAME (w
->frame
);
5916 int mouse_face_overwritten_p
= 0;
5918 /* If window is not yet fully initialized, do nothing. This can
5919 happen when toolkit scroll bars are used and a window is split.
5920 Reconfiguring the scroll bar will generate an expose for a newly
5922 if (w
->current_matrix
== NULL
)
5925 /* When we're currently updating the window, display and current
5926 matrix usually don't agree. Arrange for a thorough display
5928 if (w
== updated_window
)
5930 SET_FRAME_GARBAGED (f
);
5934 /* Frame-relative pixel rectangle of W. */
5935 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
5936 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
5937 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5938 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
5940 if (x_intersect_rectangles (fr
, &wr
, &r
))
5942 int yb
= window_text_bottom_y (w
);
5943 struct glyph_row
*row
;
5944 int cursor_cleared_p
;
5945 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
5947 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5948 r
.x
, r
.y
, r
.width
, r
.height
));
5950 /* Convert to window coordinates. */
5951 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
5952 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
5954 /* Turn off the cursor. */
5955 if (!w
->pseudo_window_p
5956 && x_phys_cursor_in_rect_p (w
, &r
))
5959 cursor_cleared_p
= 1;
5962 cursor_cleared_p
= 0;
5964 /* Update lines intersecting rectangle R. */
5965 first_overlapping_row
= last_overlapping_row
= NULL
;
5966 for (row
= w
->current_matrix
->rows
;
5971 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
5973 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
5974 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
5975 || (r
.y
>= y0
&& r
.y
< y1
)
5976 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
5978 if (row
->overlapping_p
)
5980 if (first_overlapping_row
== NULL
)
5981 first_overlapping_row
= row
;
5982 last_overlapping_row
= row
;
5985 if (expose_line (w
, row
, &r
))
5986 mouse_face_overwritten_p
= 1;
5993 /* Display the mode line if there is one. */
5994 if (WINDOW_WANTS_MODELINE_P (w
)
5995 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5997 && row
->y
< r
.y
+ r
.height
)
5999 if (expose_line (w
, row
, &r
))
6000 mouse_face_overwritten_p
= 1;
6003 if (!w
->pseudo_window_p
)
6005 /* Fix the display of overlapping rows. */
6006 if (first_overlapping_row
)
6007 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
6009 /* Draw border between windows. */
6010 x_draw_vertical_border (w
);
6012 /* Turn the cursor on again. */
6013 if (cursor_cleared_p
)
6014 x_update_window_cursor (w
, 1);
6018 return mouse_face_overwritten_p
;
6022 /* Determine the intersection of two rectangles R1 and R2. Return
6023 the intersection in *RESULT. Value is non-zero if RESULT is not
6027 x_intersect_rectangles (r1
, r2
, result
)
6028 XRectangle
*r1
, *r2
, *result
;
6030 XRectangle
*left
, *right
;
6031 XRectangle
*upper
, *lower
;
6032 int intersection_p
= 0;
6034 /* Rearrange so that R1 is the left-most rectangle. */
6036 left
= r1
, right
= r2
;
6038 left
= r2
, right
= r1
;
6040 /* X0 of the intersection is right.x0, if this is inside R1,
6041 otherwise there is no intersection. */
6042 if (right
->x
<= left
->x
+ left
->width
)
6044 result
->x
= right
->x
;
6046 /* The right end of the intersection is the minimum of the
6047 the right ends of left and right. */
6048 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6051 /* Same game for Y. */
6053 upper
= r1
, lower
= r2
;
6055 upper
= r2
, lower
= r1
;
6057 /* The upper end of the intersection is lower.y0, if this is inside
6058 of upper. Otherwise, there is no intersection. */
6059 if (lower
->y
<= upper
->y
+ upper
->height
)
6061 result
->y
= lower
->y
;
6063 /* The lower end of the intersection is the minimum of the lower
6064 ends of upper and lower. */
6065 result
->height
= (min (lower
->y
+ lower
->height
,
6066 upper
->y
+ upper
->height
)
6072 return intersection_p
;
6083 /* We used to only do this if Vx_no_window_manager was non-nil, but
6084 the ICCCM (section 4.1.6) says that the window's border pixmap
6085 and border pixel are window attributes which are "private to the
6086 client", so we can always change it to whatever we want. */
6088 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6089 f
->output_data
.x
->border_pixel
);
6091 x_update_cursor (f
, 1);
6095 frame_unhighlight (f
)
6098 /* We used to only do this if Vx_no_window_manager was non-nil, but
6099 the ICCCM (section 4.1.6) says that the window's border pixmap
6100 and border pixel are window attributes which are "private to the
6101 client", so we can always change it to whatever we want. */
6103 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6104 f
->output_data
.x
->border_tile
);
6106 x_update_cursor (f
, 1);
6109 /* The focus has changed. Update the frames as necessary to reflect
6110 the new situation. Note that we can't change the selected frame
6111 here, because the Lisp code we are interrupting might become confused.
6112 Each event gets marked with the frame in which it occurred, so the
6113 Lisp code can tell when the switch took place by examining the events. */
6116 x_new_focus_frame (dpyinfo
, frame
)
6117 struct x_display_info
*dpyinfo
;
6118 struct frame
*frame
;
6120 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6122 if (frame
!= dpyinfo
->x_focus_frame
)
6124 /* Set this before calling other routines, so that they see
6125 the correct value of x_focus_frame. */
6126 dpyinfo
->x_focus_frame
= frame
;
6128 if (old_focus
&& old_focus
->auto_lower
)
6129 x_lower_frame (old_focus
);
6132 selected_frame
= frame
;
6133 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6135 Fselect_window (selected_frame
->selected_window
);
6136 choose_minibuf_frame ();
6139 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6140 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6142 pending_autoraise_frame
= 0;
6145 x_frame_rehighlight (dpyinfo
);
6148 /* Handle FocusIn and FocusOut state changes for FRAME.
6149 If FRAME has focus and there exists more than one frame, puts
6150 a FOCUS_IN_EVENT into BUFP.
6151 Returns number of events inserted into BUFP. */
6154 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
, numchars
)
6157 struct x_display_info
*dpyinfo
;
6158 struct frame
*frame
;
6159 struct input_event
*bufp
;
6164 if (type
== FocusIn
)
6166 if (dpyinfo
->x_focus_event_frame
!= frame
)
6168 x_new_focus_frame (dpyinfo
, frame
);
6169 dpyinfo
->x_focus_event_frame
= frame
;
6171 /* Don't stop displaying the initial startup message
6172 for a switch-frame event we don't need. */
6174 && GC_NILP (Vterminal_frame
)
6175 && GC_CONSP (Vframe_list
)
6176 && !GC_NILP (XCDR (Vframe_list
)))
6178 bufp
->kind
= FOCUS_IN_EVENT
;
6179 XSETFRAME (bufp
->frame_or_window
, frame
);
6187 frame
->output_data
.x
->focus_state
|= state
;
6190 if (FRAME_XIC (frame
))
6191 XSetICFocus (FRAME_XIC (frame
));
6194 else if (type
== FocusOut
)
6196 frame
->output_data
.x
->focus_state
&= ~state
;
6198 if (dpyinfo
->x_focus_event_frame
== frame
)
6200 dpyinfo
->x_focus_event_frame
= 0;
6201 x_new_focus_frame (dpyinfo
, 0);
6205 if (FRAME_XIC (frame
))
6206 XUnsetICFocus (FRAME_XIC (frame
));
6213 /* The focus may have changed. Figure out if it is a real focus change,
6214 by checking both FocusIn/Out and Enter/LeaveNotify events.
6216 Returns number of events inserted into BUFP. */
6219 x_detect_focus_change (dpyinfo
, event
, bufp
, numchars
)
6220 struct x_display_info
*dpyinfo
;
6222 struct input_event
*bufp
;
6225 struct frame
*frame
;
6228 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
6229 if (! frame
) return nr_events
;
6231 switch (event
->type
)
6235 if (event
->xcrossing
.detail
!= NotifyInferior
6236 && event
->xcrossing
.focus
6237 && ! (frame
->output_data
.x
->focus_state
& FOCUS_EXPLICIT
))
6238 nr_events
= x_focus_changed ((event
->type
== EnterNotify
6239 ? FocusIn
: FocusOut
),
6249 nr_events
= x_focus_changed (event
->type
,
6250 (event
->xfocus
.detail
== NotifyPointer
6251 ? FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
6263 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6266 x_mouse_leave (dpyinfo
)
6267 struct x_display_info
*dpyinfo
;
6269 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6272 /* The focus has changed, or we have redirected a frame's focus to
6273 another frame (this happens when a frame uses a surrogate
6274 mini-buffer frame). Shift the highlight as appropriate.
6276 The FRAME argument doesn't necessarily have anything to do with which
6277 frame is being highlighted or un-highlighted; we only use it to find
6278 the appropriate X display info. */
6281 XTframe_rehighlight (frame
)
6282 struct frame
*frame
;
6284 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6288 x_frame_rehighlight (dpyinfo
)
6289 struct x_display_info
*dpyinfo
;
6291 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6293 if (dpyinfo
->x_focus_frame
)
6295 dpyinfo
->x_highlight_frame
6296 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6297 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6298 : dpyinfo
->x_focus_frame
);
6299 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6301 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6302 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6306 dpyinfo
->x_highlight_frame
= 0;
6308 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6311 frame_unhighlight (old_highlight
);
6312 if (dpyinfo
->x_highlight_frame
)
6313 frame_highlight (dpyinfo
->x_highlight_frame
);
6319 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6321 /* Initialize mode_switch_bit and modifier_meaning. */
6323 x_find_modifier_meanings (dpyinfo
)
6324 struct x_display_info
*dpyinfo
;
6326 int min_code
, max_code
;
6329 XModifierKeymap
*mods
;
6331 dpyinfo
->meta_mod_mask
= 0;
6332 dpyinfo
->shift_lock_mask
= 0;
6333 dpyinfo
->alt_mod_mask
= 0;
6334 dpyinfo
->super_mod_mask
= 0;
6335 dpyinfo
->hyper_mod_mask
= 0;
6338 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6340 min_code
= dpyinfo
->display
->min_keycode
;
6341 max_code
= dpyinfo
->display
->max_keycode
;
6344 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6345 min_code
, max_code
- min_code
+ 1,
6347 mods
= XGetModifierMapping (dpyinfo
->display
);
6349 /* Scan the modifier table to see which modifier bits the Meta and
6350 Alt keysyms are on. */
6352 int row
, col
; /* The row and column in the modifier table. */
6354 for (row
= 3; row
< 8; row
++)
6355 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6358 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6360 /* Zeroes are used for filler. Skip them. */
6364 /* Are any of this keycode's keysyms a meta key? */
6368 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6370 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6376 dpyinfo
->meta_mod_mask
|= (1 << row
);
6381 dpyinfo
->alt_mod_mask
|= (1 << row
);
6386 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6391 dpyinfo
->super_mod_mask
|= (1 << row
);
6395 /* Ignore this if it's not on the lock modifier. */
6396 if ((1 << row
) == LockMask
)
6397 dpyinfo
->shift_lock_mask
= LockMask
;
6405 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6406 if (! dpyinfo
->meta_mod_mask
)
6408 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6409 dpyinfo
->alt_mod_mask
= 0;
6412 /* If some keys are both alt and meta,
6413 make them just meta, not alt. */
6414 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6416 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6419 XFree ((char *) syms
);
6420 XFreeModifiermap (mods
);
6423 /* Convert between the modifier bits X uses and the modifier bits
6427 x_x_to_emacs_modifiers (dpyinfo
, state
)
6428 struct x_display_info
*dpyinfo
;
6431 EMACS_UINT mod_meta
= meta_modifier
;
6432 EMACS_UINT mod_alt
= alt_modifier
;
6433 EMACS_UINT mod_hyper
= hyper_modifier
;
6434 EMACS_UINT mod_super
= super_modifier
;
6437 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6438 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6439 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6440 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6441 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6442 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6443 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6444 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6447 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6448 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6449 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
6450 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
6451 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
6452 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
6456 x_emacs_to_x_modifiers (dpyinfo
, state
)
6457 struct x_display_info
*dpyinfo
;
6460 EMACS_UINT mod_meta
= meta_modifier
;
6461 EMACS_UINT mod_alt
= alt_modifier
;
6462 EMACS_UINT mod_hyper
= hyper_modifier
;
6463 EMACS_UINT mod_super
= super_modifier
;
6467 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6468 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6469 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6470 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6471 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6472 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6473 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6474 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6477 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
6478 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
6479 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
6480 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6481 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6482 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
6485 /* Convert a keysym to its name. */
6488 x_get_keysym_name (keysym
)
6494 value
= XKeysymToString (keysym
);
6502 /* Mouse clicks and mouse movement. Rah. */
6504 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6505 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6506 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6507 not force the value into range. */
6510 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6512 register int pix_x
, pix_y
;
6513 register int *x
, *y
;
6517 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6518 even for negative values. */
6520 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6522 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6524 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6525 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6529 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6530 bounds
->height
= f
->output_data
.x
->line_height
;
6531 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6532 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6539 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6540 pix_x
= FRAME_WINDOW_WIDTH (f
);
6544 else if (pix_y
> f
->height
)
6553 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6554 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6555 can't tell the positions because W's display is not up to date,
6559 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6562 int *frame_x
, *frame_y
;
6566 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6567 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6569 if (display_completed
)
6571 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6572 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6573 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6579 *frame_x
+= glyph
->pixel_width
;
6587 *frame_y
= *frame_x
= 0;
6591 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6592 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6597 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6599 If the event is a button press, then note that we have grabbed
6603 construct_mouse_click (result
, event
, f
)
6604 struct input_event
*result
;
6605 XButtonEvent
*event
;
6608 /* Make the event type NO_EVENT; we'll change that when we decide
6610 result
->kind
= MOUSE_CLICK_EVENT
;
6611 result
->code
= event
->button
- Button1
;
6612 result
->timestamp
= event
->time
;
6613 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6615 | (event
->type
== ButtonRelease
6619 XSETINT (result
->x
, event
->x
);
6620 XSETINT (result
->y
, event
->y
);
6621 XSETFRAME (result
->frame_or_window
, f
);
6627 /* Function to report a mouse movement to the mainstream Emacs code.
6628 The input handler calls this.
6630 We have received a mouse movement event, which is given in *event.
6631 If the mouse is over a different glyph than it was last time, tell
6632 the mainstream emacs code by setting mouse_moved. If not, ask for
6633 another motion event, so we can check again the next time it moves. */
6635 static XMotionEvent last_mouse_motion_event
;
6636 static Lisp_Object last_mouse_motion_frame
;
6639 note_mouse_movement (frame
, event
)
6641 XMotionEvent
*event
;
6643 last_mouse_movement_time
= event
->time
;
6644 last_mouse_motion_event
= *event
;
6645 XSETFRAME (last_mouse_motion_frame
, frame
);
6647 if (event
->window
!= FRAME_X_WINDOW (frame
))
6649 frame
->mouse_moved
= 1;
6650 last_mouse_scroll_bar
= Qnil
;
6651 note_mouse_highlight (frame
, -1, -1);
6654 /* Has the mouse moved off the glyph it was on at the last sighting? */
6655 else if (event
->x
< last_mouse_glyph
.x
6656 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6657 || event
->y
< last_mouse_glyph
.y
6658 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6660 frame
->mouse_moved
= 1;
6661 last_mouse_scroll_bar
= Qnil
;
6662 note_mouse_highlight (frame
, event
->x
, event
->y
);
6667 /************************************************************************
6669 ************************************************************************/
6671 /* Find the glyph under window-relative coordinates X/Y in window W.
6672 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6673 strings. Return in *HPOS and *VPOS the row and column number of
6674 the glyph found. Return in *AREA the glyph area containing X.
6675 Value is a pointer to the glyph found or null if X/Y is not on
6676 text, or we can't tell because W's current matrix is not up to
6679 static struct glyph
*
6680 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6683 int *hpos
, *vpos
, *area
;
6686 struct glyph
*glyph
, *end
;
6687 struct glyph_row
*row
= NULL
;
6688 int x0
, i
, left_area_width
;
6690 /* Find row containing Y. Give up if some row is not enabled. */
6691 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6693 row
= MATRIX_ROW (w
->current_matrix
, i
);
6694 if (!row
->enabled_p
)
6696 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6703 /* Give up if Y is not in the window. */
6704 if (i
== w
->current_matrix
->nrows
)
6707 /* Get the glyph area containing X. */
6708 if (w
->pseudo_window_p
)
6715 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6716 if (x
< left_area_width
)
6718 *area
= LEFT_MARGIN_AREA
;
6721 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6724 x0
= row
->x
+ left_area_width
;
6728 *area
= RIGHT_MARGIN_AREA
;
6729 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6733 /* Find glyph containing X. */
6734 glyph
= row
->glyphs
[*area
];
6735 end
= glyph
+ row
->used
[*area
];
6738 if (x
< x0
+ glyph
->pixel_width
)
6740 if (w
->pseudo_window_p
)
6742 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6746 x0
+= glyph
->pixel_width
;
6753 *hpos
= glyph
- row
->glyphs
[*area
];
6758 /* Convert frame-relative x/y to coordinates relative to window W.
6759 Takes pseudo-windows into account. */
6762 frame_to_window_pixel_xy (w
, x
, y
)
6766 if (w
->pseudo_window_p
)
6768 /* A pseudo-window is always full-width, and starts at the
6769 left edge of the frame, plus a frame border. */
6770 struct frame
*f
= XFRAME (w
->frame
);
6771 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6772 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6776 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6777 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6782 /* Take proper action when mouse has moved to the mode or header line
6783 or marginal area of window W, x-position X and y-position Y. Area
6784 is 1, 3, 6 or 7 for the mode line, header line, left and right
6785 marginal area respectively. X is relative to the start of the text
6786 display area of W, so the width of bitmap areas and scroll bars
6787 must be subtracted to get a position relative to the start of the
6791 note_mode_line_or_margin_highlight (w
, x
, y
, portion
)
6795 struct frame
*f
= XFRAME (w
->frame
);
6796 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6797 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6799 Lisp_Object string
, help
, map
, pos
;
6801 if (portion
== 1 || portion
== 3)
6802 string
= mode_line_string (w
, x
, y
, portion
== 1, &charpos
);
6804 string
= marginal_area_string (w
, x
, y
, portion
, &charpos
);
6806 if (STRINGP (string
))
6808 pos
= make_number (charpos
);
6810 /* If we're on a string with `help-echo' text property, arrange
6811 for the help to be displayed. This is done by setting the
6812 global variable help_echo to the help string. */
6813 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
6817 XSETWINDOW (help_echo_window
, w
);
6818 help_echo_object
= string
;
6819 help_echo_pos
= charpos
;
6822 /* Change the mouse pointer according to what is under X/Y. */
6823 map
= Fget_text_property (pos
, Qlocal_map
, string
);
6825 map
= Fget_text_property (pos
, Qkeymap
, string
);
6827 cursor
= f
->output_data
.x
->nontext_cursor
;
6830 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6834 /* Take proper action when the mouse has moved to position X, Y on
6835 frame F as regards highlighting characters that have mouse-face
6836 properties. Also de-highlighting chars where the mouse was before.
6837 X and Y can be negative or out of range. */
6840 note_mouse_highlight (f
, x
, y
)
6844 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6848 Cursor cursor
= None
;
6851 /* When a menu is active, don't highlight because this looks odd. */
6852 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6853 if (popup_activated ())
6857 if (NILP (Vmouse_highlight
)
6858 || !f
->glyphs_initialized_p
)
6861 dpyinfo
->mouse_face_mouse_x
= x
;
6862 dpyinfo
->mouse_face_mouse_y
= y
;
6863 dpyinfo
->mouse_face_mouse_frame
= f
;
6865 if (dpyinfo
->mouse_face_defer
)
6870 dpyinfo
->mouse_face_deferred_gc
= 1;
6874 /* Which window is that in? */
6875 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6877 /* If we were displaying active text in another window, clear that. */
6878 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6879 clear_mouse_face (dpyinfo
);
6881 /* Not on a window -> return. */
6882 if (!WINDOWP (window
))
6885 /* Convert to window-relative pixel coordinates. */
6886 w
= XWINDOW (window
);
6887 frame_to_window_pixel_xy (w
, &x
, &y
);
6889 /* Handle tool-bar window differently since it doesn't display a
6891 if (EQ (window
, f
->tool_bar_window
))
6893 note_tool_bar_highlight (f
, x
, y
);
6897 /* Mouse is on the mode, header line or margin? */
6898 if (portion
== 1 || portion
== 3 || portion
== 6 || portion
== 7)
6900 note_mode_line_or_margin_highlight (w
, x
, y
, portion
);
6905 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6907 cursor
= f
->output_data
.x
->text_cursor
;
6909 /* Are we in a window whose display is up to date?
6910 And verify the buffer's text has not changed. */
6911 b
= XBUFFER (w
->buffer
);
6912 if (/* Within text portion of the window. */
6914 && EQ (w
->window_end_valid
, w
->buffer
)
6915 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6916 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6918 int hpos
, vpos
, pos
, i
, area
;
6919 struct glyph
*glyph
;
6921 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6922 Lisp_Object
*overlay_vec
= NULL
;
6924 struct buffer
*obuf
;
6925 int obegv
, ozv
, same_region
;
6927 /* Find the glyph under X/Y. */
6928 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6930 /* Clear mouse face if X/Y not over text. */
6932 || area
!= TEXT_AREA
6933 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6935 if (clear_mouse_face (dpyinfo
))
6940 pos
= glyph
->charpos
;
6941 object
= glyph
->object
;
6942 if (!STRINGP (object
) && !BUFFERP (object
))
6945 /* If we get an out-of-range value, return now; avoid an error. */
6946 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6949 /* Make the window's buffer temporarily current for
6950 overlays_at and compute_char_face. */
6951 obuf
= current_buffer
;
6958 /* Is this char mouse-active or does it have help-echo? */
6959 position
= make_number (pos
);
6961 if (BUFFERP (object
))
6963 /* Put all the overlays we want in a vector in overlay_vec.
6964 Store the length in len. If there are more than 10, make
6965 enough space for all, and try again. */
6967 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6968 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6969 if (noverlays
> len
)
6972 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6973 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6976 /* Sort overlays into increasing priority order. */
6977 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6982 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
6983 && vpos
>= dpyinfo
->mouse_face_beg_row
6984 && vpos
<= dpyinfo
->mouse_face_end_row
6985 && (vpos
> dpyinfo
->mouse_face_beg_row
6986 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6987 && (vpos
< dpyinfo
->mouse_face_end_row
6988 || hpos
< dpyinfo
->mouse_face_end_col
6989 || dpyinfo
->mouse_face_past_end
));
6994 /* Check mouse-face highlighting. */
6996 /* If there exists an overlay with mouse-face overlapping
6997 the one we are currently highlighting, we have to
6998 check if we enter the overlapping overlay, and then
6999 highlight only that. */
7000 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
7001 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
7003 /* Find the highest priority overlay that has a mouse-face
7006 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
7008 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
7009 if (!NILP (mouse_face
))
7010 overlay
= overlay_vec
[i
];
7013 /* If we're actually highlighting the same overlay as
7014 before, there's no need to do that again. */
7016 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
7017 goto check_help_echo
;
7019 dpyinfo
->mouse_face_overlay
= overlay
;
7021 /* Clear the display of the old active region, if any. */
7022 if (clear_mouse_face (dpyinfo
))
7025 /* If no overlay applies, get a text property. */
7027 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7029 /* Handle the overlay case. */
7030 if (!NILP (overlay
))
7032 /* Find the range of text around this char that
7033 should be active. */
7034 Lisp_Object before
, after
;
7037 before
= Foverlay_start (overlay
);
7038 after
= Foverlay_end (overlay
);
7039 /* Record this as the current active region. */
7040 fast_find_position (w
, XFASTINT (before
),
7041 &dpyinfo
->mouse_face_beg_col
,
7042 &dpyinfo
->mouse_face_beg_row
,
7043 &dpyinfo
->mouse_face_beg_x
,
7044 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7046 dpyinfo
->mouse_face_past_end
7047 = !fast_find_position (w
, XFASTINT (after
),
7048 &dpyinfo
->mouse_face_end_col
,
7049 &dpyinfo
->mouse_face_end_row
,
7050 &dpyinfo
->mouse_face_end_x
,
7051 &dpyinfo
->mouse_face_end_y
, Qnil
);
7052 dpyinfo
->mouse_face_window
= window
;
7053 dpyinfo
->mouse_face_face_id
7054 = face_at_buffer_position (w
, pos
, 0, 0,
7056 !dpyinfo
->mouse_face_hidden
);
7058 /* Display it as active. */
7059 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7062 /* Handle the text property case. */
7063 else if (!NILP (mouse_face
) && BUFFERP (object
))
7065 /* Find the range of text around this char that
7066 should be active. */
7067 Lisp_Object before
, after
, beginning
, end
;
7070 beginning
= Fmarker_position (w
->start
);
7071 end
= make_number (BUF_Z (XBUFFER (object
))
7072 - XFASTINT (w
->window_end_pos
));
7074 = Fprevious_single_property_change (make_number (pos
+ 1),
7078 = Fnext_single_property_change (position
, Qmouse_face
,
7081 /* Record this as the current active region. */
7082 fast_find_position (w
, XFASTINT (before
),
7083 &dpyinfo
->mouse_face_beg_col
,
7084 &dpyinfo
->mouse_face_beg_row
,
7085 &dpyinfo
->mouse_face_beg_x
,
7086 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7087 dpyinfo
->mouse_face_past_end
7088 = !fast_find_position (w
, XFASTINT (after
),
7089 &dpyinfo
->mouse_face_end_col
,
7090 &dpyinfo
->mouse_face_end_row
,
7091 &dpyinfo
->mouse_face_end_x
,
7092 &dpyinfo
->mouse_face_end_y
, Qnil
);
7093 dpyinfo
->mouse_face_window
= window
;
7095 if (BUFFERP (object
))
7096 dpyinfo
->mouse_face_face_id
7097 = face_at_buffer_position (w
, pos
, 0, 0,
7099 !dpyinfo
->mouse_face_hidden
);
7101 /* Display it as active. */
7102 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7105 else if (!NILP (mouse_face
) && STRINGP (object
))
7110 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7113 e
= Fnext_single_property_change (position
, Qmouse_face
,
7116 b
= make_number (0);
7118 e
= make_number (SCHARS (object
) - 1);
7119 fast_find_string_pos (w
, XINT (b
), object
,
7120 &dpyinfo
->mouse_face_beg_col
,
7121 &dpyinfo
->mouse_face_beg_row
,
7122 &dpyinfo
->mouse_face_beg_x
,
7123 &dpyinfo
->mouse_face_beg_y
, 0);
7124 fast_find_string_pos (w
, XINT (e
), object
,
7125 &dpyinfo
->mouse_face_end_col
,
7126 &dpyinfo
->mouse_face_end_row
,
7127 &dpyinfo
->mouse_face_end_x
,
7128 &dpyinfo
->mouse_face_end_y
, 1);
7129 dpyinfo
->mouse_face_past_end
= 0;
7130 dpyinfo
->mouse_face_window
= window
;
7131 dpyinfo
->mouse_face_face_id
7132 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7134 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7137 else if (STRINGP (object
) && NILP (mouse_face
))
7139 /* A string which doesn't have mouse-face, but
7140 the text ``under'' it might have. */
7141 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7142 int start
= MATRIX_ROW_START_CHARPOS (r
);
7144 pos
= string_buffer_position (w
, object
, start
);
7146 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7150 if (!NILP (mouse_face
) && !NILP (overlay
))
7152 Lisp_Object before
= Foverlay_start (overlay
);
7153 Lisp_Object after
= Foverlay_end (overlay
);
7156 /* Note that we might not be able to find position
7157 BEFORE in the glyph matrix if the overlay is
7158 entirely covered by a `display' property. In
7159 this case, we overshoot. So let's stop in
7160 the glyph matrix before glyphs for OBJECT. */
7161 fast_find_position (w
, XFASTINT (before
),
7162 &dpyinfo
->mouse_face_beg_col
,
7163 &dpyinfo
->mouse_face_beg_row
,
7164 &dpyinfo
->mouse_face_beg_x
,
7165 &dpyinfo
->mouse_face_beg_y
,
7168 dpyinfo
->mouse_face_past_end
7169 = !fast_find_position (w
, XFASTINT (after
),
7170 &dpyinfo
->mouse_face_end_col
,
7171 &dpyinfo
->mouse_face_end_row
,
7172 &dpyinfo
->mouse_face_end_x
,
7173 &dpyinfo
->mouse_face_end_y
,
7175 dpyinfo
->mouse_face_window
= window
;
7176 dpyinfo
->mouse_face_face_id
7177 = face_at_buffer_position (w
, pos
, 0, 0,
7179 !dpyinfo
->mouse_face_hidden
);
7181 /* Display it as active. */
7182 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7190 /* Look for a `help-echo' property. */
7192 Lisp_Object help
, overlay
;
7194 /* Check overlays first. */
7195 help
= overlay
= Qnil
;
7196 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7198 overlay
= overlay_vec
[i
];
7199 help
= Foverlay_get (overlay
, Qhelp_echo
);
7205 help_echo_window
= window
;
7206 help_echo_object
= overlay
;
7207 help_echo_pos
= pos
;
7211 Lisp_Object object
= glyph
->object
;
7212 int charpos
= glyph
->charpos
;
7214 /* Try text properties. */
7215 if (STRINGP (object
)
7217 && charpos
< SCHARS (object
))
7219 help
= Fget_text_property (make_number (charpos
),
7220 Qhelp_echo
, object
);
7223 /* If the string itself doesn't specify a help-echo,
7224 see if the buffer text ``under'' it does. */
7226 = MATRIX_ROW (w
->current_matrix
, vpos
);
7227 int start
= MATRIX_ROW_START_CHARPOS (r
);
7228 int pos
= string_buffer_position (w
, object
, start
);
7231 help
= Fget_char_property (make_number (pos
),
7232 Qhelp_echo
, w
->buffer
);
7241 else if (BUFFERP (object
)
7244 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7250 help_echo_window
= window
;
7251 help_echo_object
= object
;
7252 help_echo_pos
= charpos
;
7259 current_buffer
= obuf
;
7265 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7269 redo_mouse_highlight ()
7271 if (!NILP (last_mouse_motion_frame
)
7272 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7273 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7274 last_mouse_motion_event
.x
,
7275 last_mouse_motion_event
.y
);
7280 /***********************************************************************
7282 ***********************************************************************/
7284 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7285 struct glyph
**, int *, int *, int *));
7287 /* Tool-bar item index of the item on which a mouse button was pressed
7290 static int last_tool_bar_item
;
7293 /* Get information about the tool-bar item at position X/Y on frame F.
7294 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7295 the current matrix of the tool-bar window of F, or NULL if not
7296 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7297 item in F->tool_bar_items. Value is
7299 -1 if X/Y is not on a tool-bar item
7300 0 if X/Y is on the same item that was highlighted before.
7304 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7307 struct glyph
**glyph
;
7308 int *hpos
, *vpos
, *prop_idx
;
7310 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7311 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7314 /* Find the glyph under X/Y. */
7315 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7319 /* Get the start of this tool-bar item's properties in
7320 f->tool_bar_items. */
7321 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7324 /* Is mouse on the highlighted item? */
7325 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7326 && *vpos
>= dpyinfo
->mouse_face_beg_row
7327 && *vpos
<= dpyinfo
->mouse_face_end_row
7328 && (*vpos
> dpyinfo
->mouse_face_beg_row
7329 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7330 && (*vpos
< dpyinfo
->mouse_face_end_row
7331 || *hpos
< dpyinfo
->mouse_face_end_col
7332 || dpyinfo
->mouse_face_past_end
))
7339 /* Handle mouse button event on the tool-bar of frame F, at
7340 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
7344 x_handle_tool_bar_click (f
, button_event
)
7346 XButtonEvent
*button_event
;
7348 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7349 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7350 int hpos
, vpos
, prop_idx
;
7351 struct glyph
*glyph
;
7352 Lisp_Object enabled_p
;
7353 int x
= button_event
->x
;
7354 int y
= button_event
->y
;
7356 /* If not on the highlighted tool-bar item, return. */
7357 frame_to_window_pixel_xy (w
, &x
, &y
);
7358 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7361 /* If item is disabled, do nothing. */
7362 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7363 if (NILP (enabled_p
))
7366 if (button_event
->type
== ButtonPress
)
7368 /* Show item in pressed state. */
7369 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7370 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7371 last_tool_bar_item
= prop_idx
;
7375 Lisp_Object key
, frame
;
7376 struct input_event event
;
7378 /* Show item in released state. */
7379 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7380 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7382 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7384 XSETFRAME (frame
, f
);
7385 event
.kind
= TOOL_BAR_EVENT
;
7386 event
.frame_or_window
= frame
;
7388 kbd_buffer_store_event (&event
);
7390 event
.kind
= TOOL_BAR_EVENT
;
7391 event
.frame_or_window
= frame
;
7393 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7394 button_event
->state
);
7395 kbd_buffer_store_event (&event
);
7396 last_tool_bar_item
= -1;
7401 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7402 tool-bar window-relative coordinates X/Y. Called from
7403 note_mouse_highlight. */
7406 note_tool_bar_highlight (f
, x
, y
)
7410 Lisp_Object window
= f
->tool_bar_window
;
7411 struct window
*w
= XWINDOW (window
);
7412 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7414 struct glyph
*glyph
;
7415 struct glyph_row
*row
;
7417 Lisp_Object enabled_p
;
7419 enum draw_glyphs_face draw
;
7420 int mouse_down_p
, rc
;
7422 /* Function note_mouse_highlight is called with negative x(y
7423 values when mouse moves outside of the frame. */
7424 if (x
<= 0 || y
<= 0)
7426 clear_mouse_face (dpyinfo
);
7430 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7433 /* Not on tool-bar item. */
7434 clear_mouse_face (dpyinfo
);
7440 clear_mouse_face (dpyinfo
);
7442 /* Mouse is down, but on different tool-bar item? */
7443 mouse_down_p
= (dpyinfo
->grabbed
7444 && f
== last_mouse_frame
7445 && FRAME_LIVE_P (f
));
7447 && last_tool_bar_item
!= prop_idx
)
7450 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7451 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7453 /* If tool-bar item is not enabled, don't highlight it. */
7454 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7455 if (!NILP (enabled_p
))
7457 /* Compute the x-position of the glyph. In front and past the
7458 image is a space. We include this is the highlighted area. */
7459 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7460 for (i
= x
= 0; i
< hpos
; ++i
)
7461 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7463 /* Record this as the current active region. */
7464 dpyinfo
->mouse_face_beg_col
= hpos
;
7465 dpyinfo
->mouse_face_beg_row
= vpos
;
7466 dpyinfo
->mouse_face_beg_x
= x
;
7467 dpyinfo
->mouse_face_beg_y
= row
->y
;
7468 dpyinfo
->mouse_face_past_end
= 0;
7470 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7471 dpyinfo
->mouse_face_end_row
= vpos
;
7472 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7473 dpyinfo
->mouse_face_end_y
= row
->y
;
7474 dpyinfo
->mouse_face_window
= window
;
7475 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7477 /* Display it as active. */
7478 show_mouse_face (dpyinfo
, draw
);
7479 dpyinfo
->mouse_face_image_state
= draw
;
7484 /* Set help_echo to a help string to display for this tool-bar item.
7485 XTread_socket does the rest. */
7486 help_echo_object
= help_echo_window
= Qnil
;
7488 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7489 if (NILP (help_echo
))
7490 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7495 /* Find the glyph matrix position of buffer position CHARPOS in window
7496 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7497 current glyphs must be up to date. If CHARPOS is above window
7498 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7499 of last line in W. In the row containing CHARPOS, stop before glyphs
7500 having STOP as object. */
7502 #if 0 /* This is a version of fast_find_position that's more correct
7503 in the presence of hscrolling, for example. I didn't install
7504 it right away because the problem fixed is minor, it failed
7505 in 20.x as well, and I think it's too risky to install
7506 so near the release of 21.1. 2001-09-25 gerd. */
7509 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7512 int *hpos
, *vpos
, *x
, *y
;
7515 struct glyph_row
*row
, *first
;
7516 struct glyph
*glyph
, *end
;
7517 int i
, past_end
= 0;
7519 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7520 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7523 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7525 *x
= *y
= *hpos
= *vpos
= 0;
7530 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7537 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7539 glyph
= row
->glyphs
[TEXT_AREA
];
7540 end
= glyph
+ row
->used
[TEXT_AREA
];
7542 /* Skip over glyphs not having an object at the start of the row.
7543 These are special glyphs like truncation marks on terminal
7545 if (row
->displays_text_p
)
7547 && INTEGERP (glyph
->object
)
7548 && !EQ (stop
, glyph
->object
)
7549 && glyph
->charpos
< 0)
7551 *x
+= glyph
->pixel_width
;
7556 && !INTEGERP (glyph
->object
)
7557 && !EQ (stop
, glyph
->object
)
7558 && (!BUFFERP (glyph
->object
)
7559 || glyph
->charpos
< charpos
))
7561 *x
+= glyph
->pixel_width
;
7565 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7572 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7575 int *hpos
, *vpos
, *x
, *y
;
7580 int maybe_next_line_p
= 0;
7581 int line_start_position
;
7582 int yb
= window_text_bottom_y (w
);
7583 struct glyph_row
*row
, *best_row
;
7584 int row_vpos
, best_row_vpos
;
7587 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7588 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7592 if (row
->used
[TEXT_AREA
])
7593 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7595 line_start_position
= 0;
7597 if (line_start_position
> pos
)
7599 /* If the position sought is the end of the buffer,
7600 don't include the blank lines at the bottom of the window. */
7601 else if (line_start_position
== pos
7602 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7604 maybe_next_line_p
= 1;
7607 else if (line_start_position
> 0)
7610 best_row_vpos
= row_vpos
;
7613 if (row
->y
+ row
->height
>= yb
)
7620 /* Find the right column within BEST_ROW. */
7622 current_x
= best_row
->x
;
7623 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7625 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7626 int charpos
= glyph
->charpos
;
7628 if (BUFFERP (glyph
->object
))
7633 *vpos
= best_row_vpos
;
7638 else if (charpos
> pos
)
7641 else if (EQ (glyph
->object
, stop
))
7646 current_x
+= glyph
->pixel_width
;
7649 /* If we're looking for the end of the buffer,
7650 and we didn't find it in the line we scanned,
7651 use the start of the following line. */
7652 if (maybe_next_line_p
)
7657 current_x
= best_row
->x
;
7660 *vpos
= best_row_vpos
;
7661 *hpos
= lastcol
+ 1;
7670 /* Find the position of the glyph for position POS in OBJECT in
7671 window W's current matrix, and return in *X, *Y the pixel
7672 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
7674 RIGHT_P non-zero means return the position of the right edge of the
7675 glyph, RIGHT_P zero means return the left edge position.
7677 If no glyph for POS exists in the matrix, return the position of
7678 the glyph with the next smaller position that is in the matrix, if
7679 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7680 exists in the matrix, return the position of the glyph with the
7681 next larger position in OBJECT.
7683 Value is non-zero if a glyph was found. */
7686 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7690 int *hpos
, *vpos
, *x
, *y
;
7693 int yb
= window_text_bottom_y (w
);
7694 struct glyph_row
*r
;
7695 struct glyph
*best_glyph
= NULL
;
7696 struct glyph_row
*best_row
= NULL
;
7699 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7700 r
->enabled_p
&& r
->y
< yb
;
7703 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7704 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7707 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7708 if (EQ (g
->object
, object
))
7710 if (g
->charpos
== pos
)
7717 else if (best_glyph
== NULL
7718 || ((abs (g
->charpos
- pos
)
7719 < abs (best_glyph
->charpos
- pos
))
7722 : g
->charpos
> pos
)))
7736 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7740 *x
+= best_glyph
->pixel_width
;
7745 *vpos
= best_row
- w
->current_matrix
->rows
;
7748 return best_glyph
!= NULL
;
7752 /* Display the active region described by mouse_face_*
7753 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7756 show_mouse_face (dpyinfo
, draw
)
7757 struct x_display_info
*dpyinfo
;
7758 enum draw_glyphs_face draw
;
7760 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7761 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7763 if (/* If window is in the process of being destroyed, don't bother
7765 w
->current_matrix
!= NULL
7766 /* Don't update mouse highlight if hidden */
7767 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
7768 /* Recognize when we are called to operate on rows that don't exist
7769 anymore. This can happen when a window is split. */
7770 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7772 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7773 struct glyph_row
*row
, *first
, *last
;
7775 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7776 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7778 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7780 int start_hpos
, end_hpos
, start_x
;
7782 /* For all but the first row, the highlight starts at column 0. */
7785 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7786 start_x
= dpyinfo
->mouse_face_beg_x
;
7795 end_hpos
= dpyinfo
->mouse_face_end_col
;
7797 end_hpos
= row
->used
[TEXT_AREA
];
7799 if (end_hpos
> start_hpos
)
7801 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7802 start_hpos
, end_hpos
, draw
, 0);
7805 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
7809 /* When we've written over the cursor, arrange for it to
7810 be displayed again. */
7811 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
7812 x_display_cursor (w
, 1,
7813 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
7814 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
7817 /* Change the mouse cursor. */
7818 if (draw
== DRAW_NORMAL_TEXT
)
7819 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7820 f
->output_data
.x
->text_cursor
);
7821 else if (draw
== DRAW_MOUSE_FACE
)
7822 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7823 f
->output_data
.x
->cross_cursor
);
7825 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7826 f
->output_data
.x
->nontext_cursor
);
7829 /* Clear out the mouse-highlighted active region.
7830 Redraw it un-highlighted first. Value is non-zero if mouse
7831 face was actually drawn unhighlighted. */
7834 clear_mouse_face (dpyinfo
)
7835 struct x_display_info
*dpyinfo
;
7839 if (!NILP (dpyinfo
->mouse_face_window
))
7841 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7845 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7846 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7847 dpyinfo
->mouse_face_window
= Qnil
;
7848 dpyinfo
->mouse_face_overlay
= Qnil
;
7853 /* Clear any mouse-face on window W. This function is part of the
7854 redisplay interface, and is called from try_window_id and similar
7855 functions to ensure the mouse-highlight is off. */
7858 x_clear_mouse_face (w
)
7861 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7865 XSETWINDOW (window
, w
);
7866 if (EQ (window
, dpyinfo
->mouse_face_window
))
7867 clear_mouse_face (dpyinfo
);
7872 /* Just discard the mouse face information for frame F, if any.
7873 This is used when the size of F is changed. */
7876 cancel_mouse_face (f
)
7880 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7882 window
= dpyinfo
->mouse_face_window
;
7883 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7885 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7886 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7887 dpyinfo
->mouse_face_window
= Qnil
;
7892 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7895 /* Try to determine frame pixel position and size of the glyph under
7896 frame pixel coordinates X/Y on frame F . Return the position and
7897 size in *RECT. Value is non-zero if we could compute these
7901 glyph_rect (f
, x
, y
, rect
)
7907 int part
, found
= 0;
7909 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7912 struct window
*w
= XWINDOW (window
);
7913 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7914 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7916 frame_to_window_pixel_xy (w
, &x
, &y
);
7918 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7921 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7922 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7925 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7928 rect
->width
= g
->pixel_width
;
7929 rect
->height
= r
->height
;
7930 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7931 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7941 /* Return the current position of the mouse.
7942 *FP should be a frame which indicates which display to ask about.
7944 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7945 and *PART to the frame, window, and scroll bar part that the mouse
7946 is over. Set *X and *Y to the portion and whole of the mouse's
7947 position on the scroll bar.
7949 If the mouse movement started elsewhere, set *FP to the frame the
7950 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7953 Set *TIME to the server time-stamp for the time at which the mouse
7954 was at this position.
7956 Don't store anything if we don't have a valid set of values to report.
7958 This clears the mouse_moved flag, so we can wait for the next mouse
7962 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7965 Lisp_Object
*bar_window
;
7966 enum scroll_bar_part
*part
;
7968 unsigned long *time
;
7974 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7975 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7981 Window dummy_window
;
7984 Lisp_Object frame
, tail
;
7986 /* Clear the mouse-moved flag for every frame on this display. */
7987 FOR_EACH_FRAME (tail
, frame
)
7988 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7989 XFRAME (frame
)->mouse_moved
= 0;
7991 last_mouse_scroll_bar
= Qnil
;
7993 /* Figure out which root window we're on. */
7994 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7995 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7997 /* The root window which contains the pointer. */
8000 /* Trash which we can't trust if the pointer is on
8001 a different screen. */
8004 /* The position on that root window. */
8007 /* More trash we can't trust. */
8010 /* Modifier keys and pointer buttons, about which
8012 (unsigned int *) &dummy
);
8014 /* Now we have a position on the root; find the innermost window
8015 containing the pointer. */
8019 int parent_x
= 0, parent_y
= 0;
8024 /* XTranslateCoordinates can get errors if the window
8025 structure is changing at the same time this function
8026 is running. So at least we must not crash from them. */
8028 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
8030 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
8031 && FRAME_LIVE_P (last_mouse_frame
))
8033 /* If mouse was grabbed on a frame, give coords for that frame
8034 even if the mouse is now outside it. */
8035 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8037 /* From-window, to-window. */
8038 root
, FRAME_X_WINDOW (last_mouse_frame
),
8040 /* From-position, to-position. */
8041 root_x
, root_y
, &win_x
, &win_y
,
8045 f1
= last_mouse_frame
;
8051 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8053 /* From-window, to-window. */
8056 /* From-position, to-position. */
8057 root_x
, root_y
, &win_x
, &win_y
,
8062 if (child
== None
|| child
== win
)
8070 /* Now we know that:
8071 win is the innermost window containing the pointer
8072 (XTC says it has no child containing the pointer),
8073 win_x and win_y are the pointer's position in it
8074 (XTC did this the last time through), and
8075 parent_x and parent_y are the pointer's position in win's parent.
8076 (They are what win_x and win_y were when win was child.
8077 If win is the root window, it has no parent, and
8078 parent_{x,y} are invalid, but that's okay, because we'll
8079 never use them in that case.) */
8081 /* Is win one of our frames? */
8082 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
8084 #ifdef USE_X_TOOLKIT
8085 /* If we end up with the menu bar window, say it's not
8088 && f1
->output_data
.x
->menubar_widget
8089 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
8091 #endif /* USE_X_TOOLKIT */
8094 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
8097 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
8099 /* If not, is it one of our scroll bars? */
8102 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
8106 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8112 if (f1
== 0 && insist
> 0)
8113 f1
= SELECTED_FRAME ();
8117 /* Ok, we found a frame. Store all the values.
8118 last_mouse_glyph is a rectangle used to reduce the
8119 generation of mouse events. To not miss any motion
8120 events, we must divide the frame into rectangles of the
8121 size of the smallest character that could be displayed
8122 on it, i.e. into the same rectangles that matrices on
8123 the frame are divided into. */
8125 int width
, height
, gx
, gy
;
8128 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
8129 last_mouse_glyph
= rect
;
8132 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8133 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8137 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8138 round down even for negative values. */
8143 gx
= (gx
+ width
- 1) / width
* width
;
8144 gy
= (gy
+ height
- 1) / height
* height
;
8146 last_mouse_glyph
.width
= width
;
8147 last_mouse_glyph
.height
= height
;
8148 last_mouse_glyph
.x
= gx
;
8149 last_mouse_glyph
.y
= gy
;
8155 XSETINT (*x
, win_x
);
8156 XSETINT (*y
, win_y
);
8157 *time
= last_mouse_movement_time
;
8166 #ifdef USE_X_TOOLKIT
8168 /* Atimer callback function for TIMER. Called every 0.1s to process
8169 Xt timeouts, if needed. We must avoid calling XtAppPending as
8170 much as possible because that function does an implicit XFlush
8171 that slows us down. */
8174 x_process_timeouts (timer
)
8175 struct atimer
*timer
;
8177 if (toolkit_scroll_bar_interaction
|| popup_activated ())
8180 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8181 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8186 #endif /* USE_X_TOOLKIT */
8189 /* Scroll bar support. */
8191 /* Given an X window ID, find the struct scroll_bar which manages it.
8192 This can be called in GC, so we have to make sure to strip off mark
8195 static struct scroll_bar
*
8196 x_window_to_scroll_bar (window_id
)
8202 window_id
= (Window
) xg_get_scroll_id_for_window (window_id
);
8203 #endif /* USE_GTK */
8205 for (tail
= Vframe_list
;
8206 XGCTYPE (tail
) == Lisp_Cons
;
8209 Lisp_Object frame
, bar
, condemned
;
8211 frame
= XCAR (tail
);
8212 /* All elements of Vframe_list should be frames. */
8213 if (! GC_FRAMEP (frame
))
8216 /* Scan this frame's scroll bar list for a scroll bar with the
8218 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8219 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8220 /* This trick allows us to search both the ordinary and
8221 condemned scroll bar lists with one loop. */
8222 ! GC_NILP (bar
) || (bar
= condemned
,
8225 bar
= XSCROLL_BAR (bar
)->next
)
8226 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8227 return XSCROLL_BAR (bar
);
8234 #if defined USE_LUCID
8236 /* Return the Lucid menu bar WINDOW is part of. Return null
8237 if WINDOW is not part of a menu bar. */
8240 x_window_to_menu_bar (window
)
8245 for (tail
= Vframe_list
;
8246 XGCTYPE (tail
) == Lisp_Cons
;
8249 Lisp_Object frame
= XCAR (tail
);
8250 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8252 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8259 #endif /* USE_LUCID */
8262 /************************************************************************
8264 ************************************************************************/
8266 #ifdef USE_TOOLKIT_SCROLL_BARS
8268 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8269 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8270 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8271 struct scroll_bar
*));
8272 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8276 /* Lisp window being scrolled. Set when starting to interact with
8277 a toolkit scroll bar, reset to nil when ending the interaction. */
8279 static Lisp_Object window_being_scrolled
;
8281 /* Last scroll bar part sent in xm_scroll_callback. */
8283 static int last_scroll_bar_part
;
8285 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8286 that movements of 1/20 of the screen size are mapped to up/down. */
8289 /* Id of action hook installed for scroll bars. */
8291 static XtActionHookId action_hook_id
;
8293 static Boolean xaw3d_arrow_scroll
;
8295 /* Whether the drag scrolling maintains the mouse at the top of the
8296 thumb. If not, resizing the thumb needs to be done more carefully
8297 to avoid jerkyness. */
8299 static Boolean xaw3d_pick_top
;
8302 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8303 bars are used.. The hook is responsible for detecting when
8304 the user ends an interaction with the scroll bar, and generates
8305 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
8308 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8311 XtPointer client_data
;
8315 Cardinal
*num_params
;
8321 scroll_bar_p
= XmIsScrollBar (widget
);
8322 end_action
= "Release";
8323 #else /* !USE_MOTIF i.e. use Xaw */
8324 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8325 end_action
= "EndScroll";
8326 #endif /* USE_MOTIF */
8329 && strcmp (action_name
, end_action
) == 0
8330 && WINDOWP (window_being_scrolled
))
8334 x_send_scroll_bar_event (window_being_scrolled
,
8335 scroll_bar_end_scroll
, 0, 0);
8336 w
= XWINDOW (window_being_scrolled
);
8337 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8338 window_being_scrolled
= Qnil
;
8339 last_scroll_bar_part
= -1;
8341 /* Xt timeouts no longer needed. */
8342 toolkit_scroll_bar_interaction
= 0;
8345 #endif /* not USE_GTK */
8347 /* A vector of windows used for communication between
8348 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8350 static struct window
**scroll_bar_windows
;
8351 static int scroll_bar_windows_size
;
8354 /* Send a client message with message type Xatom_Scrollbar for a
8355 scroll action to the frame of WINDOW. PART is a value identifying
8356 the part of the scroll bar that was clicked on. PORTION is the
8357 amount to scroll of a whole of WHOLE. */
8360 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8362 int part
, portion
, whole
;
8365 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8366 struct window
*w
= XWINDOW (window
);
8367 struct frame
*f
= XFRAME (w
->frame
);
8372 /* Construct a ClientMessage event to send to the frame. */
8373 ev
->type
= ClientMessage
;
8374 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8375 ev
->display
= FRAME_X_DISPLAY (f
);
8376 ev
->window
= FRAME_X_WINDOW (f
);
8379 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8380 not enough to store a pointer or Lisp_Object on a 64 bit system.
8381 So, store the window in scroll_bar_windows and pass the index
8382 into that array in the event. */
8383 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8384 if (scroll_bar_windows
[i
] == NULL
)
8387 if (i
== scroll_bar_windows_size
)
8389 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8390 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8391 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8393 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8395 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8396 scroll_bar_windows_size
= new_size
;
8399 scroll_bar_windows
[i
] = w
;
8400 ev
->data
.l
[0] = (long) i
;
8401 ev
->data
.l
[1] = (long) part
;
8402 ev
->data
.l
[2] = (long) 0;
8403 ev
->data
.l
[3] = (long) portion
;
8404 ev
->data
.l
[4] = (long) whole
;
8406 /* Make Xt timeouts work while the scroll bar is active. */
8407 toolkit_scroll_bar_interaction
= 1;
8409 /* Setting the event mask to zero means that the message will
8410 be sent to the client that created the window, and if that
8411 window no longer exists, no event will be sent. */
8412 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8417 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8421 x_scroll_bar_to_input_event (event
, ievent
)
8423 struct input_event
*ievent
;
8425 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8430 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8431 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8433 XSETWINDOW (window
, w
);
8434 f
= XFRAME (w
->frame
);
8436 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
8437 ievent
->frame_or_window
= window
;
8440 ievent
->timestamp
= CurrentTime
;
8442 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8444 ievent
->part
= ev
->data
.l
[1];
8445 ievent
->code
= ev
->data
.l
[2];
8446 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8447 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8448 ievent
->modifiers
= 0;
8454 /* Minimum and maximum values used for Motif scroll bars. */
8457 #define XM_SB_MAX 10000000
8458 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8461 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8462 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8463 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
8466 xm_scroll_callback (widget
, client_data
, call_data
)
8468 XtPointer client_data
, call_data
;
8470 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8471 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8472 int part
= -1, whole
= 0, portion
= 0;
8476 case XmCR_DECREMENT
:
8477 bar
->dragging
= Qnil
;
8478 part
= scroll_bar_up_arrow
;
8481 case XmCR_INCREMENT
:
8482 bar
->dragging
= Qnil
;
8483 part
= scroll_bar_down_arrow
;
8486 case XmCR_PAGE_DECREMENT
:
8487 bar
->dragging
= Qnil
;
8488 part
= scroll_bar_above_handle
;
8491 case XmCR_PAGE_INCREMENT
:
8492 bar
->dragging
= Qnil
;
8493 part
= scroll_bar_below_handle
;
8497 bar
->dragging
= Qnil
;
8498 part
= scroll_bar_to_top
;
8501 case XmCR_TO_BOTTOM
:
8502 bar
->dragging
= Qnil
;
8503 part
= scroll_bar_to_bottom
;
8509 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8510 && XINT (bar
->dragging
) <= cs
->value
);
8512 /* Get the slider size. */
8514 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8517 whole
= XM_SB_RANGE
- slider_size
;
8518 portion
= min (cs
->value
- XM_SB_MIN
, whole
);
8519 part
= scroll_bar_handle
;
8520 bar
->dragging
= make_number (cs
->value
);
8524 case XmCR_VALUE_CHANGED
:
8530 window_being_scrolled
= bar
->window
;
8531 last_scroll_bar_part
= part
;
8532 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8537 #else /* !USE_MOTIF, i.e. Xaw or GTK */
8539 /* Scroll bar callback for Gtk scroll bars. WIDGET is the scroll
8540 bar adjustment widget. DATA is a pointer to the scroll_bar structure. */
8543 xg_scroll_callback (widget
, data
)
8547 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
8553 int part
= -1, whole
= 0, portion
= 0;
8554 GtkAdjustment
*adj
= GTK_ADJUSTMENT (widget
);
8556 if (xg_ignore_gtk_scrollbar
) return;
8558 position
= gtk_adjustment_get_value (adj
);
8560 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
8563 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
8565 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
8571 diff
= (int) (position
- previous
);
8573 if (diff
== (int) adj
->step_increment
)
8575 part
= scroll_bar_down_arrow
;
8576 bar
->dragging
= Qnil
;
8578 else if (-diff
== (int) adj
->step_increment
)
8580 part
= scroll_bar_up_arrow
;
8581 bar
->dragging
= Qnil
;
8583 else if (diff
== (int) adj
->page_increment
)
8585 part
= scroll_bar_below_handle
;
8586 bar
->dragging
= Qnil
;
8588 else if (-diff
== (int) adj
->page_increment
)
8590 part
= scroll_bar_above_handle
;
8591 bar
->dragging
= Qnil
;
8595 part
= scroll_bar_handle
;
8596 whole
= adj
->upper
- adj
->page_size
;
8597 portion
= min (position
, whole
);
8598 bar
->dragging
= make_number (portion
);
8603 xg_ignore_next_thumb
= 1;
8604 window_being_scrolled
= bar
->window
;
8605 last_scroll_bar_part
= part
;
8606 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8610 #else /* not USE_GTK */
8612 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8613 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8614 scroll bar struct. CALL_DATA is a pointer to a float saying where
8618 xaw_jump_callback (widget
, client_data
, call_data
)
8620 XtPointer client_data
, call_data
;
8622 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8623 float top
= *(float *) call_data
;
8625 int whole
, portion
, height
;
8628 /* Get the size of the thumb, a value between 0 and 1. */
8630 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8634 portion
= shown
< 1 ? top
* whole
: 0;
8636 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8637 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8638 the bottom, so we force the scrolling whenever we see that we're
8639 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8640 we try to ensure that we always stay two pixels away from the
8642 part
= scroll_bar_down_arrow
;
8644 part
= scroll_bar_handle
;
8646 window_being_scrolled
= bar
->window
;
8647 bar
->dragging
= make_number (portion
);
8648 last_scroll_bar_part
= part
;
8649 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8653 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8654 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8655 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8656 the scroll bar. CALL_DATA is an integer specifying the action that
8657 has taken place. Its magnitude is in the range 0..height of the
8658 scroll bar. Negative values mean scroll towards buffer start.
8659 Values < height of scroll bar mean line-wise movement. */
8662 xaw_scroll_callback (widget
, client_data
, call_data
)
8664 XtPointer client_data
, call_data
;
8666 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8667 /* The position really is stored cast to a pointer. */
8668 int position
= (long) call_data
;
8672 /* Get the height of the scroll bar. */
8674 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8677 if (abs (position
) >= height
)
8678 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8680 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8681 it maps line-movement to call_data = max(5, height/20). */
8682 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8683 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8685 part
= scroll_bar_move_ratio
;
8687 window_being_scrolled
= bar
->window
;
8688 bar
->dragging
= Qnil
;
8689 last_scroll_bar_part
= part
;
8690 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8693 #endif /* not USE_GTK */
8694 #endif /* not USE_MOTIF */
8696 #define SCROLL_BAR_NAME "verticalScrollBar"
8698 /* Create the widget for scroll bar BAR on frame F. Record the widget
8699 and X window of the scroll bar in BAR. */
8703 x_create_toolkit_scroll_bar (f
, bar
)
8705 struct scroll_bar
*bar
;
8707 char *scroll_bar_name
= SCROLL_BAR_NAME
;
8710 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
8715 #else /* not USE_GTK */
8718 x_create_toolkit_scroll_bar (f
, bar
)
8720 struct scroll_bar
*bar
;
8726 char *scroll_bar_name
= SCROLL_BAR_NAME
;
8727 unsigned long pixel
;
8732 /* Set resources. Create the widget. */
8733 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8734 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8735 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8736 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8737 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8738 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8739 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8741 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8744 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8748 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8751 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8755 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8756 scroll_bar_name
, av
, ac
);
8758 /* Add one callback for everything that can happen. */
8759 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8761 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8763 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8765 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8767 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8769 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8771 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8774 /* Realize the widget. Only after that is the X window created. */
8775 XtRealizeWidget (widget
);
8777 /* Set the cursor to an arrow. I didn't find a resource to do that.
8778 And I'm wondering why it hasn't an arrow cursor by default. */
8779 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8780 f
->output_data
.x
->nontext_cursor
);
8782 #else /* !USE_MOTIF i.e. use Xaw */
8784 /* Set resources. Create the widget. The background of the
8785 Xaw3d scroll bar widget is a little bit light for my taste.
8786 We don't alter it here to let users change it according
8787 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8788 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8789 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8790 /* For smoother scrolling with Xaw3d -sm */
8791 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8793 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8796 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8800 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8803 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8807 /* Top/bottom shadow colors. */
8809 /* Allocate them, if necessary. */
8810 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
8812 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8813 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8814 &pixel
, 1.2, 0x8000))
8816 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
8818 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8820 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8821 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8822 &pixel
, 0.6, 0x4000))
8824 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
8827 /* Tell the toolkit about them. */
8828 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
8829 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8830 /* We tried to allocate a color for the top/bottom shadow, and
8831 failed, so tell Xaw3d to use dithering instead. */
8833 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
8837 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
8838 be more consistent with other emacs 3d colors, and since Xaw3d is
8839 not good at dealing with allocation failure. */
8841 /* This tells Xaw3d to use real colors instead of dithering for
8843 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
8846 /* Specify the colors. */
8847 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
8850 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
8853 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
8856 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
8861 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8862 f
->output_data
.x
->edit_widget
, av
, ac
);
8866 char *val
= initial
;
8867 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8868 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8870 { /* ARROW_SCROLL */
8871 xaw3d_arrow_scroll
= True
;
8872 /* Isn't that just a personal preference ? -sm */
8873 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8877 /* Define callbacks. */
8878 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8879 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8882 /* Realize the widget. Only after that is the X window created. */
8883 XtRealizeWidget (widget
);
8885 #endif /* !USE_MOTIF */
8887 /* Install an action hook that lets us detect when the user
8888 finishes interacting with a scroll bar. */
8889 if (action_hook_id
== 0)
8890 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8892 /* Remember X window and widget in the scroll bar vector. */
8893 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8894 xwindow
= XtWindow (widget
);
8895 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8899 #endif /* not USE_GTK */
8902 /* Set the thumb size and position of scroll bar BAR. We are currently
8903 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8907 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8908 struct scroll_bar
*bar
;
8909 int portion
, position
, whole
;
8911 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8914 #else /* not USE_GTK */
8916 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8917 struct scroll_bar
*bar
;
8918 int portion
, position
, whole
;
8920 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8921 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8928 /* We use an estimate of 30 chars per line rather than the real
8929 `portion' value. This has the disadvantage that the thumb size
8930 is not very representative, but it makes our life a lot easier.
8931 Otherwise, we have to constantly adjust the thumb size, which
8932 we can't always do quickly enough: while dragging, the size of
8933 the thumb might prevent the user from dragging the thumb all the
8934 way to the end. but Motif and some versions of Xaw3d don't allow
8935 updating the thumb size while dragging. Also, even if we can update
8936 its size, the update will often happen too late.
8937 If you don't believe it, check out revision 1.650 of xterm.c to see
8938 what hoops we were going through and the still poor behavior we got. */
8939 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
8940 /* When the thumb is at the bottom, position == whole.
8941 So we need to increase `whole' to make space for the thumb. */
8948 top
= (float) position
/ whole
;
8949 shown
= (float) portion
/ whole
;
8952 if (NILP (bar
->dragging
))
8956 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8957 is the scroll bar's maximum and MIN is the scroll bar's minimum
8959 size
= shown
* XM_SB_RANGE
;
8960 size
= min (size
, XM_SB_RANGE
);
8961 size
= max (size
, 1);
8963 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8964 value
= top
* XM_SB_RANGE
;
8965 value
= min (value
, XM_SB_MAX
- size
);
8966 value
= max (value
, XM_SB_MIN
);
8968 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8970 #else /* !USE_MOTIF i.e. use Xaw */
8976 top
= (float) position
/ whole
;
8977 shown
= (float) portion
/ whole
;
8981 float old_top
, old_shown
;
8983 XtVaGetValues (widget
,
8984 XtNtopOfThumb
, &old_top
,
8985 XtNshown
, &old_shown
,
8989 /* Massage the top+shown values. */
8990 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8991 top
= max (0, min (1, top
));
8994 /* Keep two pixels available for moving the thumb down. */
8995 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8997 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8998 check that your system's configuration file contains a define
8999 for `NARROWPROTO'. See s/freebsd.h for an example. */
9000 if (top
!= old_top
|| shown
!= old_shown
)
9002 if (NILP (bar
->dragging
))
9003 XawScrollbarSetThumb (widget
, top
, shown
);
9007 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
9008 int scroll_mode
= 0;
9010 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
9011 if (xaw3d_arrow_scroll
)
9013 /* Xaw3d stupidly ignores resize requests while dragging
9014 so we have to make it believe it's not in dragging mode. */
9015 scroll_mode
= sb
->scrollbar
.scroll_mode
;
9016 if (scroll_mode
== 2)
9017 sb
->scrollbar
.scroll_mode
= 0;
9020 /* Try to make the scrolling a tad smoother. */
9021 if (!xaw3d_pick_top
)
9022 shown
= min (shown
, old_shown
);
9024 XawScrollbarSetThumb (widget
, top
, shown
);
9027 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
9028 sb
->scrollbar
.scroll_mode
= scroll_mode
;
9033 #endif /* !USE_MOTIF */
9037 #endif /* not USE_GTK */
9039 #endif /* USE_TOOLKIT_SCROLL_BARS */
9043 /************************************************************************
9044 Scroll bars, general
9045 ************************************************************************/
9047 /* Create a scroll bar and return the scroll bar vector for it. W is
9048 the Emacs window on which to create the scroll bar. TOP, LEFT,
9049 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
9052 static struct scroll_bar
*
9053 x_scroll_bar_create (w
, top
, left
, width
, height
)
9055 int top
, left
, width
, height
;
9057 struct frame
*f
= XFRAME (w
->frame
);
9058 struct scroll_bar
*bar
9059 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
9063 #ifdef USE_TOOLKIT_SCROLL_BARS
9064 x_create_toolkit_scroll_bar (f
, bar
);
9065 #else /* not USE_TOOLKIT_SCROLL_BARS */
9067 XSetWindowAttributes a
;
9071 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
9072 if (a
.background_pixel
== -1)
9073 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
9075 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
9076 | ButtonMotionMask
| PointerMotionHintMask
9078 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
9080 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
9082 /* Clear the area of W that will serve as a scroll bar. This is
9083 for the case that a window has been split horizontally. In
9084 this case, no clear_frame is generated to reduce flickering. */
9085 if (width
> 0 && height
> 0)
9086 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9088 window_box_height (w
), False
);
9090 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9091 /* Position and size of scroll bar. */
9092 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9094 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9096 /* Border width, depth, class, and visual. */
9103 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
9105 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9107 XSETWINDOW (bar
->window
, w
);
9108 XSETINT (bar
->top
, top
);
9109 XSETINT (bar
->left
, left
);
9110 XSETINT (bar
->width
, width
);
9111 XSETINT (bar
->height
, height
);
9112 XSETINT (bar
->start
, 0);
9113 XSETINT (bar
->end
, 0);
9114 bar
->dragging
= Qnil
;
9116 /* Add bar to its frame's list of scroll bars. */
9117 bar
->next
= FRAME_SCROLL_BARS (f
);
9119 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9120 if (!NILP (bar
->next
))
9121 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9123 /* Map the window/widget. */
9124 #ifdef USE_TOOLKIT_SCROLL_BARS
9127 xg_update_scrollbar_pos (f
,
9128 SCROLL_BAR_X_WINDOW (bar
),
9130 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9131 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9133 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
9134 #else /* not USE_GTK */
9135 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
9136 XtConfigureWidget (scroll_bar
,
9137 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9139 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9140 max (height
, 1), 0);
9141 XtMapWidget (scroll_bar
);
9142 #endif /* not USE_GTK */
9144 #else /* not USE_TOOLKIT_SCROLL_BARS */
9145 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9146 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9153 /* Draw BAR's handle in the proper position.
9155 If the handle is already drawn from START to END, don't bother
9156 redrawing it, unless REBUILD is non-zero; in that case, always
9157 redraw it. (REBUILD is handy for drawing the handle after expose
9160 Normally, we want to constrain the start and end of the handle to
9161 fit inside its rectangle, but if the user is dragging the scroll
9162 bar handle, we want to let them drag it down all the way, so that
9163 the bar's top is as far down as it goes; otherwise, there's no way
9164 to move to the very end of the buffer. */
9166 #ifndef USE_TOOLKIT_SCROLL_BARS
9169 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
9170 struct scroll_bar
*bar
;
9174 int dragging
= ! NILP (bar
->dragging
);
9175 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9176 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9177 GC gc
= f
->output_data
.x
->normal_gc
;
9179 /* If the display is already accurate, do nothing. */
9181 && start
== XINT (bar
->start
)
9182 && end
== XINT (bar
->end
))
9188 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
9189 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9190 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9192 /* Make sure the values are reasonable, and try to preserve
9193 the distance between start and end. */
9195 int length
= end
- start
;
9199 else if (start
> top_range
)
9201 end
= start
+ length
;
9205 else if (end
> top_range
&& ! dragging
)
9209 /* Store the adjusted setting in the scroll bar. */
9210 XSETINT (bar
->start
, start
);
9211 XSETINT (bar
->end
, end
);
9213 /* Clip the end position, just for display. */
9214 if (end
> top_range
)
9217 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
9218 below top positions, to make sure the handle is always at least
9219 that many pixels tall. */
9220 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
9222 /* Draw the empty space above the handle. Note that we can't clear
9223 zero-height areas; that means "clear to end of window." */
9225 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9226 /* x, y, width, height, and exposures. */
9227 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9228 VERTICAL_SCROLL_BAR_TOP_BORDER
,
9229 inside_width
, start
,
9232 /* Change to proper foreground color if one is specified. */
9233 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9234 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9235 f
->output_data
.x
->scroll_bar_foreground_pixel
);
9237 /* Draw the handle itself. */
9238 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9239 /* x, y, width, height */
9240 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9241 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
9242 inside_width
, end
- start
);
9244 /* Restore the foreground color of the GC if we changed it above. */
9245 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9246 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9247 f
->output_data
.x
->foreground_pixel
);
9249 /* Draw the empty space below the handle. Note that we can't
9250 clear zero-height areas; that means "clear to end of window." */
9251 if (end
< inside_height
)
9252 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9253 /* x, y, width, height, and exposures. */
9254 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9255 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
9256 inside_width
, inside_height
- end
,
9264 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9266 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
9270 x_scroll_bar_remove (bar
)
9271 struct scroll_bar
*bar
;
9273 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9276 #ifdef USE_TOOLKIT_SCROLL_BARS
9278 xg_remove_scroll_bar (f
, SCROLL_BAR_X_WINDOW (bar
));
9279 #else /* not USE_GTK */
9280 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
9281 #endif /* not USE_GTK */
9283 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9286 /* Disassociate this scroll bar from its window. */
9287 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
9293 /* Set the handle of the vertical scroll bar for WINDOW to indicate
9294 that we are displaying PORTION characters out of a total of WHOLE
9295 characters, starting at POSITION. If WINDOW has no scroll bar,
9299 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
9301 int portion
, whole
, position
;
9303 struct frame
*f
= XFRAME (w
->frame
);
9304 struct scroll_bar
*bar
;
9305 int top
, height
, left
, sb_left
, width
, sb_width
;
9306 int window_x
, window_y
, window_width
, window_height
;
9308 /* Get window dimensions. */
9309 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9311 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9312 height
= window_height
;
9314 /* Compute the left edge of the scroll bar area. */
9315 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9316 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
9318 left
= XFASTINT (w
->left
);
9319 left
*= CANON_X_UNIT (f
);
9320 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
9322 /* Compute the width of the scroll bar which might be less than
9323 the width of the area reserved for the scroll bar. */
9324 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
9325 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
9329 /* Compute the left edge of the scroll bar. */
9330 #ifdef USE_TOOLKIT_SCROLL_BARS
9331 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9332 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
9334 sb_left
= left
+ (width
- sb_width
) / 2;
9336 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9337 sb_left
= left
+ width
- sb_width
;
9342 /* Does the scroll bar exist yet? */
9343 if (NILP (w
->vertical_scroll_bar
))
9345 if (width
> 0 && height
> 0)
9348 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9349 left
, top
, width
, height
, False
);
9353 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9357 /* It may just need to be moved and resized. */
9358 unsigned int mask
= 0;
9360 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9364 if (sb_left
!= XINT (bar
->left
))
9366 if (top
!= XINT (bar
->top
))
9368 if (sb_width
!= XINT (bar
->width
))
9370 if (height
!= XINT (bar
->height
))
9373 #ifdef USE_TOOLKIT_SCROLL_BARS
9377 xg_update_scrollbar_pos (f
,
9378 SCROLL_BAR_X_WINDOW (bar
),
9380 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9381 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9383 #else /* not USE_GTK */
9385 /* Since toolkit scroll bars are smaller than the space reserved
9386 for them on the frame, we have to clear "under" them. */
9387 if (width
> 0 && height
> 0)
9388 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9389 left
, top
, width
, height
, False
);
9390 /* Move/size the scroll bar widget. */
9392 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9393 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9395 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9396 max (height
, 1), 0);
9398 #endif /* not USE_GTK */
9399 #else /* not USE_TOOLKIT_SCROLL_BARS */
9401 /* Clear areas not covered by the scroll bar because of
9402 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9403 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9405 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9406 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9408 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9409 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9410 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9414 /* Clear areas not covered by the scroll bar because it's not as
9415 wide as the area reserved for it. This makes sure a
9416 previous mode line display is cleared after C-x 2 C-x 1, for
9419 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9420 int rest
= area_width
- sb_width
;
9421 if (rest
> 0 && height
> 0)
9423 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
9424 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9425 left
+ area_width
- rest
, top
,
9426 rest
, height
, False
);
9428 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9429 left
, top
, rest
, height
, False
);
9433 /* Move/size the scroll bar window. */
9438 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9440 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9442 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9446 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9448 /* Remember new settings. */
9449 XSETINT (bar
->left
, sb_left
);
9450 XSETINT (bar
->top
, top
);
9451 XSETINT (bar
->width
, sb_width
);
9452 XSETINT (bar
->height
, height
);
9457 #ifdef USE_TOOLKIT_SCROLL_BARS
9458 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9459 #else /* not USE_TOOLKIT_SCROLL_BARS */
9460 /* Set the scroll bar's current state, unless we're currently being
9462 if (NILP (bar
->dragging
))
9464 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9467 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9470 int start
= ((double) position
* top_range
) / whole
;
9471 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9472 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9475 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9477 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9481 /* The following three hooks are used when we're doing a thorough
9482 redisplay of the frame. We don't explicitly know which scroll bars
9483 are going to be deleted, because keeping track of when windows go
9484 away is a real pain - "Can you say set-window-configuration, boys
9485 and girls?" Instead, we just assert at the beginning of redisplay
9486 that *all* scroll bars are to be removed, and then save a scroll bar
9487 from the fiery pit when we actually redisplay its window. */
9489 /* Arrange for all scroll bars on FRAME to be removed at the next call
9490 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9491 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9494 XTcondemn_scroll_bars (frame
)
9497 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9498 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9501 bar
= FRAME_SCROLL_BARS (frame
);
9502 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9503 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9504 XSCROLL_BAR (bar
)->prev
= Qnil
;
9505 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9506 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9507 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9512 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9513 Note that WINDOW isn't necessarily condemned at all. */
9516 XTredeem_scroll_bar (window
)
9517 struct window
*window
;
9519 struct scroll_bar
*bar
;
9522 /* We can't redeem this window's scroll bar if it doesn't have one. */
9523 if (NILP (window
->vertical_scroll_bar
))
9526 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9528 /* Unlink it from the condemned list. */
9529 f
= XFRAME (WINDOW_FRAME (window
));
9530 if (NILP (bar
->prev
))
9532 /* If the prev pointer is nil, it must be the first in one of
9534 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9535 /* It's not condemned. Everything's fine. */
9537 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9538 window
->vertical_scroll_bar
))
9539 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9541 /* If its prev pointer is nil, it must be at the front of
9542 one or the other! */
9546 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9548 if (! NILP (bar
->next
))
9549 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9551 bar
->next
= FRAME_SCROLL_BARS (f
);
9553 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9554 if (! NILP (bar
->next
))
9555 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9558 /* Remove all scroll bars on FRAME that haven't been saved since the
9559 last call to `*condemn_scroll_bars_hook'. */
9562 XTjudge_scroll_bars (f
)
9565 Lisp_Object bar
, next
;
9567 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9569 /* Clear out the condemned list now so we won't try to process any
9570 more events on the hapless scroll bars. */
9571 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9573 for (; ! NILP (bar
); bar
= next
)
9575 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9577 x_scroll_bar_remove (b
);
9580 b
->next
= b
->prev
= Qnil
;
9583 /* Now there should be no references to the condemned scroll bars,
9584 and they should get garbage-collected. */
9588 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9589 is a no-op when using toolkit scroll bars.
9591 This may be called from a signal handler, so we have to ignore GC
9595 x_scroll_bar_expose (bar
, event
)
9596 struct scroll_bar
*bar
;
9599 #ifndef USE_TOOLKIT_SCROLL_BARS
9601 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9602 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9603 GC gc
= f
->output_data
.x
->normal_gc
;
9604 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9608 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9610 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9611 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9613 /* x, y, width, height */
9615 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9616 XINT (bar
->height
) - 1);
9620 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9623 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9624 is set to something other than NO_EVENT, it is enqueued.
9626 This may be called from a signal handler, so we have to ignore GC
9631 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9632 struct scroll_bar
*bar
;
9634 struct input_event
*emacs_event
;
9636 if (! GC_WINDOWP (bar
->window
))
9639 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
9640 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9641 emacs_event
->modifiers
9642 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9643 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9644 event
->xbutton
.state
)
9645 | (event
->type
== ButtonRelease
9648 emacs_event
->frame_or_window
= bar
->window
;
9649 emacs_event
->arg
= Qnil
;
9650 emacs_event
->timestamp
= event
->xbutton
.time
;
9653 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9655 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9658 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9659 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9662 if (y
> top_range
) y
= top_range
;
9664 if (y
< XINT (bar
->start
))
9665 emacs_event
->part
= scroll_bar_above_handle
;
9666 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9667 emacs_event
->part
= scroll_bar_handle
;
9669 emacs_event
->part
= scroll_bar_below_handle
;
9671 /* Just because the user has clicked on the handle doesn't mean
9672 they want to drag it. Lisp code needs to be able to decide
9673 whether or not we're dragging. */
9675 /* If the user has just clicked on the handle, record where they're
9677 if (event
->type
== ButtonPress
9678 && emacs_event
->part
== scroll_bar_handle
)
9679 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9682 #ifndef USE_TOOLKIT_SCROLL_BARS
9683 /* If the user has released the handle, set it to its final position. */
9684 if (event
->type
== ButtonRelease
9685 && ! NILP (bar
->dragging
))
9687 int new_start
= y
- XINT (bar
->dragging
);
9688 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9690 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9691 bar
->dragging
= Qnil
;
9695 /* Same deal here as the other #if 0. */
9697 /* Clicks on the handle are always reported as occurring at the top of
9699 if (emacs_event
->part
== scroll_bar_handle
)
9700 emacs_event
->x
= bar
->start
;
9702 XSETINT (emacs_event
->x
, y
);
9704 XSETINT (emacs_event
->x
, y
);
9707 XSETINT (emacs_event
->y
, top_range
);
9711 #ifndef USE_TOOLKIT_SCROLL_BARS
9713 /* Handle some mouse motion while someone is dragging the scroll bar.
9715 This may be called from a signal handler, so we have to ignore GC
9719 x_scroll_bar_note_movement (bar
, event
)
9720 struct scroll_bar
*bar
;
9723 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9725 last_mouse_movement_time
= event
->xmotion
.time
;
9728 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9730 /* If we're dragging the bar, display it. */
9731 if (! GC_NILP (bar
->dragging
))
9733 /* Where should the handle be now? */
9734 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9736 if (new_start
!= XINT (bar
->start
))
9738 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9740 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9745 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9747 /* Return information to the user about the current position of the mouse
9748 on the scroll bar. */
9751 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9753 Lisp_Object
*bar_window
;
9754 enum scroll_bar_part
*part
;
9756 unsigned long *time
;
9758 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9759 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9760 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9762 Window dummy_window
;
9764 unsigned int dummy_mask
;
9768 /* Get the mouse's position relative to the scroll bar window, and
9770 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9772 /* Root, child, root x and root y. */
9773 &dummy_window
, &dummy_window
,
9774 &dummy_coord
, &dummy_coord
,
9776 /* Position relative to scroll bar. */
9779 /* Mouse buttons and modifier keys. */
9786 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9789 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9791 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9793 if (! NILP (bar
->dragging
))
9794 win_y
-= XINT (bar
->dragging
);
9798 if (win_y
> top_range
)
9802 *bar_window
= bar
->window
;
9804 if (! NILP (bar
->dragging
))
9805 *part
= scroll_bar_handle
;
9806 else if (win_y
< XINT (bar
->start
))
9807 *part
= scroll_bar_above_handle
;
9808 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9809 *part
= scroll_bar_handle
;
9811 *part
= scroll_bar_below_handle
;
9813 XSETINT (*x
, win_y
);
9814 XSETINT (*y
, top_range
);
9817 last_mouse_scroll_bar
= Qnil
;
9820 *time
= last_mouse_movement_time
;
9826 /* The screen has been cleared so we may have changed foreground or
9827 background colors, and the scroll bars may need to be redrawn.
9828 Clear out the scroll bars, and ask for expose events, so we can
9832 x_scroll_bar_clear (f
)
9835 #ifndef USE_TOOLKIT_SCROLL_BARS
9838 /* We can have scroll bars even if this is 0,
9839 if we just turned off scroll bar mode.
9840 But in that case we should not clear them. */
9841 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9842 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9843 bar
= XSCROLL_BAR (bar
)->next
)
9844 XClearArea (FRAME_X_DISPLAY (f
),
9845 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9847 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9851 /* Define a queue to save up SelectionRequest events for later handling. */
9853 struct selection_event_queue
9856 struct selection_event_queue
*next
;
9859 static struct selection_event_queue
*queue
;
9861 /* Nonzero means queue up certain events--don't process them yet. */
9863 static int x_queue_selection_requests
;
9865 /* Queue up an X event *EVENT, to be processed later. */
9868 x_queue_event (f
, event
)
9872 struct selection_event_queue
*queue_tmp
9873 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9875 if (queue_tmp
!= NULL
)
9877 queue_tmp
->event
= *event
;
9878 queue_tmp
->next
= queue
;
9883 /* Take all the queued events and put them back
9884 so that they get processed afresh. */
9887 x_unqueue_events (display
)
9890 while (queue
!= NULL
)
9892 struct selection_event_queue
*queue_tmp
= queue
;
9893 XPutBackEvent (display
, &queue_tmp
->event
);
9894 queue
= queue_tmp
->next
;
9895 xfree ((char *)queue_tmp
);
9899 /* Start queuing SelectionRequest events. */
9902 x_start_queuing_selection_requests (display
)
9905 x_queue_selection_requests
++;
9908 /* Stop queuing SelectionRequest events. */
9911 x_stop_queuing_selection_requests (display
)
9914 x_queue_selection_requests
--;
9915 x_unqueue_events (display
);
9918 /* The main X event-reading loop - XTread_socket. */
9921 /* Time stamp of enter window event. This is only used by XTread_socket,
9922 but we have to put it out here, since static variables within functions
9923 sometimes don't work. */
9925 static Time enter_timestamp
;
9928 /* This holds the state XLookupString needs to implement dead keys
9929 and other tricks known as "compose processing". _X Window System_
9930 says that a portable program can't use this, but Stephen Gildea assures
9931 me that letting the compiler initialize it to zeros will work okay.
9933 This must be defined outside of XTread_socket, for the same reasons
9934 given for enter_timestamp, above. */
9936 static XComposeStatus compose_status
;
9938 /* Record the last 100 characters stored
9939 to help debug the loss-of-chars-during-GC problem. */
9941 static int temp_index
;
9942 static short temp_buffer
[100];
9944 /* Set this to nonzero to fake an "X I/O error"
9945 on a particular display. */
9947 struct x_display_info
*XTread_socket_fake_io_error
;
9949 /* When we find no input here, we occasionally do a no-op command
9950 to verify that the X server is still running and we can still talk with it.
9951 We try all the open displays, one by one.
9952 This variable is used for cycling thru the displays. */
9954 static struct x_display_info
*next_noop_dpyinfo
;
9956 #define SET_SAVED_MENU_EVENT(size) \
9959 if (f->output_data.x->saved_menu_event == 0) \
9960 f->output_data.x->saved_menu_event \
9961 = (XEvent *) xmalloc (sizeof (XEvent)); \
9962 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9963 if (numchars >= 1) \
9965 bufp->kind = MENU_BAR_ACTIVATE_EVENT; \
9966 XSETFRAME (bufp->frame_or_window, f); \
9975 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9976 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9986 /* Filter events for the current X input method.
9987 DPYINFO is the display this event is for.
9988 EVENT is the X event to filter.
9990 Returns non-zero if the event was filtered, caller shall not process
9992 Returns zero if event is wasn't filtered. */
9996 x_filter_event (dpyinfo
, event
)
9997 struct x_display_info
*dpyinfo
;
10000 /* XFilterEvent returns non-zero if the input method has
10001 consumed the event. We pass the frame's X window to
10002 XFilterEvent because that's the one for which the IC
10005 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
10006 event
->xclient
.window
);
10008 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
10013 static struct x_display_info
*current_dpyinfo
;
10014 static struct input_event
**current_bufp
;
10015 static int *current_numcharsp
;
10016 static int current_count
;
10017 static int current_finish
;
10019 /* This is the filter function invoked by the GTK event loop.
10020 It is invoked before the XEvent is translated to a GdkEvent,
10021 so we have a chanse to act on the event before GTK. */
10022 static GdkFilterReturn
10023 event_handler_gdk (gxev
, ev
, data
)
10028 XEvent
*xev
= (XEvent
*)gxev
;
10030 if (current_numcharsp
)
10033 /* Filter events for the current X input method.
10034 GTK calls XFilterEvent but not for key press and release,
10035 so we do it here. */
10036 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
10037 if (x_filter_event (current_dpyinfo
, xev
))
10038 return GDK_FILTER_REMOVE
;
10040 current_count
+= handle_one_xevent (current_dpyinfo
,
10047 current_finish
= x_dispatch_event (xev
, GDK_DISPLAY ());
10049 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
10050 return GDK_FILTER_REMOVE
;
10052 return GDK_FILTER_CONTINUE
;
10054 #endif /* USE_GTK */
10057 /* Handles the XEvent EVENT on display DPYINFO.
10059 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
10060 *FINISH is zero if caller should continue reading events.
10061 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
10063 Events representing keys are stored in buffer *BUFP_R,
10064 which can hold up to *NUMCHARSP characters.
10065 We return the number of characters stored into the buffer. */
10068 handle_one_xevent (dpyinfo
, eventp
, bufp_r
, numcharsp
, finish
)
10069 struct x_display_info
*dpyinfo
;
10071 /* register */ struct input_event
**bufp_r
;
10072 /* register */ int *numcharsp
;
10078 struct coding_system coding
;
10079 struct input_event
*bufp
= *bufp_r
;
10080 int numchars
= *numcharsp
;
10081 XEvent event
= *eventp
;
10083 *finish
= X_EVENT_NORMAL
;
10085 switch (event
.type
)
10087 case ClientMessage
:
10089 if (event
.xclient
.message_type
10090 == dpyinfo
->Xatom_wm_protocols
10091 && event
.xclient
.format
== 32)
10093 if (event
.xclient
.data
.l
[0]
10094 == dpyinfo
->Xatom_wm_take_focus
)
10096 /* Use x_any_window_to_frame because this
10097 could be the shell widget window
10098 if the frame has no title bar. */
10099 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10101 /* Not quite sure this is needed -pd */
10102 if (f
&& FRAME_XIC (f
))
10103 XSetICFocus (FRAME_XIC (f
));
10105 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
10106 instructs the WM to set the input focus automatically for
10107 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
10108 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
10109 it has set the focus. So, XSetInputFocus below is not
10112 The call to XSetInputFocus below has also caused trouble. In
10113 cases where the XSetInputFocus done by the WM and the one
10114 below are temporally close (on a fast machine), the call
10115 below can generate additional FocusIn events which confuse
10118 /* Since we set WM_TAKE_FOCUS, we must call
10119 XSetInputFocus explicitly. But not if f is null,
10120 since that might be an event for a deleted frame. */
10123 Display
*d
= event
.xclient
.display
;
10124 /* Catch and ignore errors, in case window has been
10125 iconified by a window manager such as GWM. */
10126 int count
= x_catch_errors (d
);
10127 XSetInputFocus (d
, event
.xclient
.window
,
10128 /* The ICCCM says this is
10129 the only valid choice. */
10131 event
.xclient
.data
.l
[1]);
10132 /* This is needed to detect the error
10133 if there is an error. */
10135 x_uncatch_errors (d
, count
);
10137 /* Not certain about handling scroll bars here */
10140 else if (event
.xclient
.data
.l
[0]
10141 == dpyinfo
->Xatom_wm_save_yourself
)
10143 /* Save state modify the WM_COMMAND property to
10144 something which can reinstate us. This notifies
10145 the session manager, who's looking for such a
10146 PropertyNotify. Can restart processing when
10147 a keyboard or mouse event arrives. */
10148 /* If we have a session manager, don't set this.
10149 KDE will then start two Emacsen, one for the
10150 session manager and one for this. */
10153 && ! x_session_have_connection ()
10157 f
= x_top_window_to_frame (dpyinfo
,
10158 event
.xclient
.window
);
10159 /* This is just so we only give real data once
10160 for a single Emacs process. */
10161 if (f
== SELECTED_FRAME ())
10162 XSetCommand (FRAME_X_DISPLAY (f
),
10163 event
.xclient
.window
,
10164 initial_argv
, initial_argc
);
10166 XSetCommand (FRAME_X_DISPLAY (f
),
10167 event
.xclient
.window
,
10171 else if (event
.xclient
.data
.l
[0]
10172 == dpyinfo
->Xatom_wm_delete_window
)
10175 = x_any_window_to_frame (dpyinfo
,
10176 event
.xclient
.window
);
10183 bufp
->kind
= DELETE_WINDOW_EVENT
;
10184 XSETFRAME (bufp
->frame_or_window
, f
);
10192 goto OTHER
; /* May be a dialog that is to be removed */
10195 else if (event
.xclient
.message_type
10196 == dpyinfo
->Xatom_wm_configure_denied
)
10199 else if (event
.xclient
.message_type
10200 == dpyinfo
->Xatom_wm_window_moved
)
10204 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10206 new_x
= event
.xclient
.data
.s
[0];
10207 new_y
= event
.xclient
.data
.s
[1];
10211 f
->output_data
.x
->left_pos
= new_x
;
10212 f
->output_data
.x
->top_pos
= new_y
;
10215 #ifdef HACK_EDITRES
10216 else if (event
.xclient
.message_type
10217 == dpyinfo
->Xatom_editres
)
10220 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10221 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
10224 #endif /* HACK_EDITRES */
10225 else if ((event
.xclient
.message_type
10226 == dpyinfo
->Xatom_DONE
)
10227 || (event
.xclient
.message_type
10228 == dpyinfo
->Xatom_PAGE
))
10230 /* Ghostview job completed. Kill it. We could
10231 reply with "Next" if we received "Page", but we
10232 currently never do because we are interested in
10233 images, only, which should have 1 page. */
10234 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
10236 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10237 x_kill_gs_process (pixmap
, f
);
10238 expose_frame (f
, 0, 0, 0, 0);
10240 #ifdef USE_TOOLKIT_SCROLL_BARS
10241 /* Scroll bar callbacks send a ClientMessage from which
10242 we construct an input_event. */
10243 else if (event
.xclient
.message_type
10244 == dpyinfo
->Xatom_Scrollbar
)
10246 x_scroll_bar_to_input_event (&event
, bufp
);
10247 ++bufp
, ++count
, --numchars
;
10250 #endif /* USE_TOOLKIT_SCROLL_BARS */
10256 case SelectionNotify
:
10257 #ifdef USE_X_TOOLKIT
10258 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
10260 #endif /* not USE_X_TOOLKIT */
10261 x_handle_selection_notify (&event
.xselection
);
10264 case SelectionClear
: /* Someone has grabbed ownership. */
10265 #ifdef USE_X_TOOLKIT
10266 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
10268 #endif /* USE_X_TOOLKIT */
10270 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
10275 bufp
->kind
= SELECTION_CLEAR_EVENT
;
10276 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10277 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10278 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10279 bufp
->frame_or_window
= Qnil
;
10288 case SelectionRequest
: /* Someone wants our selection. */
10289 #ifdef USE_X_TOOLKIT
10290 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
10292 #endif /* USE_X_TOOLKIT */
10293 if (x_queue_selection_requests
)
10294 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
10298 XSelectionRequestEvent
*eventp
10299 = (XSelectionRequestEvent
*) &event
;
10304 bufp
->kind
= SELECTION_REQUEST_EVENT
;
10305 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10306 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
10307 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10308 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
10309 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
10310 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10311 bufp
->frame_or_window
= Qnil
;
10320 case PropertyNotify
:
10321 #if 0 /* This is plain wrong. In the case that we are waiting for a
10322 PropertyNotify used as an ACK in incremental selection
10323 transfer, the property will be on the receiver's window. */
10324 #if defined USE_X_TOOLKIT
10325 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10329 x_handle_property_notify (&event
.xproperty
);
10332 case ReparentNotify
:
10333 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10337 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10338 x_real_positions (f
, &x
, &y
);
10339 f
->output_data
.x
->left_pos
= x
;
10340 f
->output_data
.x
->top_pos
= y
;
10346 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10349 x_check_fullscreen (f
);
10351 if (f
->async_visible
== 0)
10353 f
->async_visible
= 1;
10354 f
->async_iconified
= 0;
10355 f
->output_data
.x
->has_been_visible
= 1;
10356 SET_FRAME_GARBAGED (f
);
10359 expose_frame (x_window_to_frame (dpyinfo
,
10360 event
.xexpose
.window
),
10361 event
.xexpose
.x
, event
.xexpose
.y
,
10362 event
.xexpose
.width
, event
.xexpose
.height
);
10366 #ifndef USE_TOOLKIT_SCROLL_BARS
10367 struct scroll_bar
*bar
;
10369 #if defined USE_LUCID
10370 /* Submenus of the Lucid menu bar aren't widgets
10371 themselves, so there's no way to dispatch events
10372 to them. Recognize this case separately. */
10375 = x_window_to_menu_bar (event
.xexpose
.window
);
10377 xlwmenu_redisplay (widget
);
10379 #endif /* USE_LUCID */
10381 #ifdef USE_TOOLKIT_SCROLL_BARS
10382 /* Dispatch event to the widget. */
10384 #else /* not USE_TOOLKIT_SCROLL_BARS */
10385 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10388 x_scroll_bar_expose (bar
, &event
);
10389 #ifdef USE_X_TOOLKIT
10392 #endif /* USE_X_TOOLKIT */
10393 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10397 case GraphicsExpose
: /* This occurs when an XCopyArea's
10398 source area was obscured or not
10400 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10404 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10405 event
.xgraphicsexpose
.width
,
10406 event
.xgraphicsexpose
.height
);
10408 #ifdef USE_X_TOOLKIT
10411 #endif /* USE_X_TOOLKIT */
10414 case NoExpose
: /* This occurs when an XCopyArea's
10415 source area was completely
10420 /* Redo the mouse-highlight after the tooltip has gone. */
10421 if (event
.xmap
.window
== tip_window
)
10424 redo_mouse_highlight ();
10427 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10428 if (f
) /* F may no longer exist if
10429 the frame was deleted. */
10431 /* While a frame is unmapped, display generation is
10432 disabled; you don't want to spend time updating a
10433 display that won't ever be seen. */
10434 f
->async_visible
= 0;
10435 /* We can't distinguish, from the event, whether the window
10436 has become iconified or invisible. So assume, if it
10437 was previously visible, than now it is iconified.
10438 But x_make_frame_invisible clears both
10439 the visible flag and the iconified flag;
10440 and that way, we know the window is not iconified now. */
10441 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10443 f
->async_iconified
= 1;
10445 bufp
->kind
= ICONIFY_EVENT
;
10446 XSETFRAME (bufp
->frame_or_window
, f
);
10456 if (event
.xmap
.window
== tip_window
)
10457 /* The tooltip has been drawn already. Avoid
10458 the SET_FRAME_GARBAGED below. */
10461 /* We use x_top_window_to_frame because map events can
10462 come for sub-windows and they don't mean that the
10463 frame is visible. */
10464 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10467 /* wait_reading_process_input will notice this and update
10468 the frame's display structures.
10469 If we where iconified, we should not set garbaged,
10470 because that stops redrawing on Expose events. This looks
10471 bad if we are called from a recursive event loop
10472 (x_dispatch_event), for example when a dialog is up. */
10473 if (! f
->async_iconified
)
10474 SET_FRAME_GARBAGED (f
);
10476 f
->async_visible
= 1;
10477 f
->async_iconified
= 0;
10478 f
->output_data
.x
->has_been_visible
= 1;
10482 bufp
->kind
= DEICONIFY_EVENT
;
10483 XSETFRAME (bufp
->frame_or_window
, f
);
10489 else if (! NILP (Vframe_list
)
10490 && ! NILP (XCDR (Vframe_list
)))
10491 /* Force a redisplay sooner or later
10492 to update the frame titles
10493 in case this is the second frame. */
10494 record_asynch_buffer_change ();
10500 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10501 /* Dispatch KeyPress events when in menu. */
10502 if (popup_activated ())
10506 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10508 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
10510 dpyinfo
->mouse_face_hidden
= 1;
10511 clear_mouse_face (dpyinfo
);
10514 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10517 /* Scroll bars consume key events, but we want
10518 the keys to go to the scroll bar's frame. */
10519 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10520 event
.xkey
.window
);
10521 if (widget
&& XmIsScrollBar (widget
))
10523 widget
= XtParent (widget
);
10524 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10527 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10531 KeySym keysym
, orig_keysym
;
10532 /* al%imercury@uunet.uu.net says that making this 81
10533 instead of 80 fixed a bug whereby meta chars made
10536 It seems that some version of XmbLookupString has
10537 a bug of not returning XBufferOverflow in
10538 status_return even if the input is too long to
10539 fit in 81 bytes. So, we must prepare sufficient
10540 bytes for copy_buffer. 513 bytes (256 chars for
10541 two-byte character set) seems to be a fairly good
10542 approximation. -- 2000.8.10 handa@etl.go.jp */
10543 unsigned char copy_buffer
[513];
10544 unsigned char *copy_bufptr
= copy_buffer
;
10545 int copy_bufsiz
= sizeof (copy_buffer
);
10547 Lisp_Object coding_system
= Qlatin_1
;
10550 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10551 extra_keyboard_modifiers
);
10552 modifiers
= event
.xkey
.state
;
10554 /* This will have to go some day... */
10556 /* make_lispy_event turns chars into control chars.
10557 Don't do it here because XLookupString is too eager. */
10558 event
.xkey
.state
&= ~ControlMask
;
10559 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10560 | dpyinfo
->super_mod_mask
10561 | dpyinfo
->hyper_mod_mask
10562 | dpyinfo
->alt_mod_mask
);
10564 /* In case Meta is ComposeCharacter,
10565 clear its status. According to Markus Ehrnsperger
10566 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10567 this enables ComposeCharacter to work whether or
10568 not it is combined with Meta. */
10569 if (modifiers
& dpyinfo
->meta_mod_mask
)
10570 bzero (&compose_status
, sizeof (compose_status
));
10575 Status status_return
;
10577 coding_system
= Vlocale_coding_system
;
10578 nbytes
= XmbLookupString (FRAME_XIC (f
),
10579 &event
.xkey
, copy_bufptr
,
10580 copy_bufsiz
, &keysym
,
10582 if (status_return
== XBufferOverflow
)
10584 copy_bufsiz
= nbytes
+ 1;
10585 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10586 nbytes
= XmbLookupString (FRAME_XIC (f
),
10587 &event
.xkey
, copy_bufptr
,
10588 copy_bufsiz
, &keysym
,
10591 /* Xutf8LookupString is a new but already deprecated interface. -stef */
10592 #if 0 && defined X_HAVE_UTF8_STRING
10593 else if (status_return
== XLookupKeySym
)
10594 { /* Try again but with utf-8. */
10595 coding_system
= Qutf_8
;
10596 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
10597 &event
.xkey
, copy_bufptr
,
10598 copy_bufsiz
, &keysym
,
10600 if (status_return
== XBufferOverflow
)
10602 copy_bufsiz
= nbytes
+ 1;
10603 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10604 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
10607 copy_bufsiz
, &keysym
,
10613 if (status_return
== XLookupNone
)
10615 else if (status_return
== XLookupChars
)
10620 else if (status_return
!= XLookupKeySym
10621 && status_return
!= XLookupBoth
)
10625 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10626 copy_bufsiz
, &keysym
,
10629 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10630 copy_bufsiz
, &keysym
,
10634 orig_keysym
= keysym
;
10640 /* First deal with keysyms which have defined
10641 translations to characters. */
10642 if (keysym
>= 32 && keysym
< 128)
10643 /* Avoid explicitly decoding each ASCII character. */
10645 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
10646 bufp
->code
= keysym
;
10647 XSETFRAME (bufp
->frame_or_window
, f
);
10650 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10652 bufp
->timestamp
= event
.xkey
.time
;
10657 /* Now non-ASCII. */
10658 else if (HASH_TABLE_P (Vx_keysym_table
)
10659 && (NATNUMP (c
= Fgethash (make_number (keysym
),
10663 bufp
->kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
10664 ? ASCII_KEYSTROKE_EVENT
10665 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
10666 bufp
->code
= XFASTINT (c
);
10667 XSETFRAME (bufp
->frame_or_window
, f
);
10670 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10672 bufp
->timestamp
= event
.xkey
.time
;
10677 /* Random non-modifier sorts of keysyms. */
10678 else if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10679 || keysym
== XK_Delete
10680 #ifdef XK_ISO_Left_Tab
10681 || (keysym
>= XK_ISO_Left_Tab
10682 && keysym
<= XK_ISO_Enter
)
10684 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10685 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10687 /* This recognizes the "extended function
10688 keys". It seems there's no cleaner way.
10689 Test IsModifierKey to avoid handling
10690 mode_switch incorrectly. */
10691 || ((unsigned) (keysym
) >= XK_Select
10692 && (unsigned)(keysym
) < XK_KP_Space
)
10694 #ifdef XK_dead_circumflex
10695 || orig_keysym
== XK_dead_circumflex
10697 #ifdef XK_dead_grave
10698 || orig_keysym
== XK_dead_grave
10700 #ifdef XK_dead_tilde
10701 || orig_keysym
== XK_dead_tilde
10703 #ifdef XK_dead_diaeresis
10704 || orig_keysym
== XK_dead_diaeresis
10706 #ifdef XK_dead_macron
10707 || orig_keysym
== XK_dead_macron
10709 #ifdef XK_dead_degree
10710 || orig_keysym
== XK_dead_degree
10712 #ifdef XK_dead_acute
10713 || orig_keysym
== XK_dead_acute
10715 #ifdef XK_dead_cedilla
10716 || orig_keysym
== XK_dead_cedilla
10718 #ifdef XK_dead_breve
10719 || orig_keysym
== XK_dead_breve
10721 #ifdef XK_dead_ogonek
10722 || orig_keysym
== XK_dead_ogonek
10724 #ifdef XK_dead_caron
10725 || orig_keysym
== XK_dead_caron
10727 #ifdef XK_dead_doubleacute
10728 || orig_keysym
== XK_dead_doubleacute
10730 #ifdef XK_dead_abovedot
10731 || orig_keysym
== XK_dead_abovedot
10733 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10734 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10735 /* Any "vendor-specific" key is ok. */
10736 || (orig_keysym
& (1 << 28))
10737 || (keysym
!= NoSymbol
&& nbytes
== 0))
10738 && ! (IsModifierKey (orig_keysym
)
10740 #ifdef XK_Mode_switch
10741 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10744 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10746 #endif /* not HAVE_X11R5 */
10747 /* The symbols from XK_ISO_Lock
10748 to XK_ISO_Last_Group_Lock
10749 don't have real modifiers but
10750 should be treated similarly to
10751 Mode_switch by Emacs. */
10752 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
10753 || ((unsigned)(orig_keysym
)
10755 && (unsigned)(orig_keysym
)
10756 <= XK_ISO_Last_Group_Lock
)
10760 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10762 temp_buffer
[temp_index
++] = keysym
;
10763 /* make_lispy_event will convert this to a symbolic
10765 bufp
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
10766 bufp
->code
= keysym
;
10767 XSETFRAME (bufp
->frame_or_window
, f
);
10770 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10772 bufp
->timestamp
= event
.xkey
.time
;
10777 else if (numchars
> nbytes
)
10778 { /* Raw bytes, not keysym. */
10783 /* The input should be decoded with `coding_system'
10784 which depends on which X*LookupString function
10785 we used just above and the locale. */
10786 setup_coding_system (coding_system
, &coding
);
10787 coding
.src_multibyte
= 0;
10788 coding
.dst_multibyte
= 1;
10789 /* The input is converted to events, thus we can't
10790 handle composition. Anyway, there's no XIM that
10791 gives us composition information. */
10792 coding
.composing
= COMPOSITION_DISABLED
;
10794 for (i
= 0; i
< nbytes
; i
++)
10796 if (temp_index
== (sizeof temp_buffer
10799 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10803 /* Decode the input data. */
10807 require
= decoding_buffer_size (&coding
, nbytes
);
10808 p
= (unsigned char *) alloca (require
);
10809 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10810 /* We explicitely disable composition
10811 handling because key data should
10812 not contain any composition
10814 coding
.composing
= COMPOSITION_DISABLED
;
10815 decode_coding (&coding
, copy_bufptr
, p
,
10817 nbytes
= coding
.produced
;
10818 nchars
= coding
.produced_char
;
10822 /* Convert the input data to a sequence of
10823 character events. */
10824 for (i
= 0; i
< nbytes
; i
+= len
)
10826 if (nchars
== nbytes
)
10827 c
= copy_bufptr
[i
], len
= 1;
10829 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10832 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10833 ? ASCII_KEYSTROKE_EVENT
10834 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
10836 XSETFRAME (bufp
->frame_or_window
, f
);
10839 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10841 bufp
->timestamp
= event
.xkey
.time
;
10846 numchars
-= nchars
;
10848 if (keysym
== NoSymbol
)
10858 /* Don't dispatch this event since XtDispatchEvent calls
10859 XFilterEvent, and two calls in a row may freeze the
10868 /* Don't dispatch this event since XtDispatchEvent calls
10869 XFilterEvent, and two calls in a row may freeze the
10880 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
10883 bufp
+= n
, count
+= n
, numchars
-= n
;
10886 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10889 if (event
.xcrossing
.focus
)
10891 /* Avoid nasty pop/raise loops. */
10892 if (f
&& (!(f
->auto_raise
)
10893 || !(f
->auto_lower
)
10894 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10896 x_new_focus_frame (dpyinfo
, f
);
10897 enter_timestamp
= event
.xcrossing
.time
;
10900 else if (f
== dpyinfo
->x_focus_frame
)
10901 x_new_focus_frame (dpyinfo
, 0);
10904 /* EnterNotify counts as mouse movement,
10905 so update things that depend on mouse position. */
10906 if (f
&& !f
->output_data
.x
->hourglass_p
)
10907 note_mouse_movement (f
, &event
.xmotion
);
10915 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
10918 bufp
+= n
, count
+= n
, numchars
-= n
;
10928 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
10931 bufp
+= n
, count
+= n
, numchars
-= n
;
10935 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10938 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10940 /* If we move outside the frame, then we're
10941 certainly no longer on any text in the frame. */
10942 clear_mouse_face (dpyinfo
);
10943 dpyinfo
->mouse_face_mouse_frame
= 0;
10946 /* Generate a nil HELP_EVENT to cancel a help-echo.
10947 Do it only if there's something to cancel.
10948 Otherwise, the startup message is cleared when
10949 the mouse leaves the frame. */
10950 if (any_help_event_p
)
10955 XSETFRAME (frame
, f
);
10957 n
= gen_help_event (bufp
, numchars
,
10958 Qnil
, frame
, Qnil
, Qnil
, 0);
10959 bufp
+= n
, count
+= n
, numchars
-= n
;
10969 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
10972 bufp
+= n
, count
+= n
, numchars
-= n
;
10980 previous_help_echo
= help_echo
;
10981 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10982 help_echo_pos
= -1;
10984 if (dpyinfo
->grabbed
&& last_mouse_frame
10985 && FRAME_LIVE_P (last_mouse_frame
))
10986 f
= last_mouse_frame
;
10988 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10990 if (dpyinfo
->mouse_face_hidden
)
10992 dpyinfo
->mouse_face_hidden
= 0;
10993 clear_mouse_face (dpyinfo
);
10999 /* Generate SELECT_WINDOW_EVENTs when needed. */
11000 if (mouse_autoselect_window
)
11002 Lisp_Object window
;
11005 window
= window_from_coordinates (f
,
11006 event
.xmotion
.x
, event
.xmotion
.y
,
11009 /* Window will be selected only when it is not selected now and
11010 last mouse movement event was not in it. Minibuffer window
11011 will be selected iff it is active. */
11012 if (WINDOWP(window
)
11013 && !EQ (window
, last_window
)
11014 && !EQ (window
, selected_window
)
11017 bufp
->kind
= SELECT_WINDOW_EVENT
;
11018 bufp
->frame_or_window
= window
;
11020 ++bufp
, ++count
, --numchars
;
11023 last_window
=window
;
11025 note_mouse_movement (f
, &event
.xmotion
);
11029 #ifndef USE_TOOLKIT_SCROLL_BARS
11030 struct scroll_bar
*bar
11031 = x_window_to_scroll_bar (event
.xmotion
.window
);
11034 x_scroll_bar_note_movement (bar
, &event
);
11035 #endif /* USE_TOOLKIT_SCROLL_BARS */
11037 /* If we move outside the frame, then we're
11038 certainly no longer on any text in the frame. */
11039 clear_mouse_face (dpyinfo
);
11042 /* If the contents of the global variable help_echo
11043 has changed, generate a HELP_EVENT. */
11044 if (!NILP (help_echo
)
11045 || !NILP (previous_help_echo
))
11051 XSETFRAME (frame
, f
);
11055 any_help_event_p
= 1;
11056 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
11057 help_echo_window
, help_echo_object
,
11059 bufp
+= n
, count
+= n
, numchars
-= n
;
11065 case ConfigureNotify
:
11066 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
11069 #ifndef USE_X_TOOLKIT
11071 xg_resize_widgets (f
, event
.xconfigure
.width
,
11072 event
.xconfigure
.height
);
11073 #else /* not USE_GTK */
11074 /* If there is a pending resize for fullscreen, don't
11075 do this one, the right one will come later.
11076 The toolkit version doesn't seem to need this, but we
11077 need to reset it below. */
11079 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
11080 && FRAME_NEW_WIDTH (f
) != 0);
11081 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
11082 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
11086 /* In the toolkit version, change_frame_size
11087 is called by the code that handles resizing
11088 of the EmacsFrame widget. */
11090 /* Even if the number of character rows and columns has
11091 not changed, the font size may have changed, so we need
11092 to check the pixel dimensions as well. */
11093 if (columns
!= f
->width
11094 || rows
!= f
->height
11095 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
11096 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
11098 change_frame_size (f
, rows
, columns
, 0, 1, 0);
11099 SET_FRAME_GARBAGED (f
);
11100 cancel_mouse_face (f
);
11102 #endif /* not USE_GTK */
11105 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
11106 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
11109 /* GTK creates windows but doesn't map them.
11110 Only get real positions and check fullscreen when mapped. */
11111 if (FRAME_GTK_OUTER_WIDGET (f
)
11112 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
11115 /* What we have now is the position of Emacs's own window.
11116 Convert that to the position of the window manager window. */
11117 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
11118 &f
->output_data
.x
->top_pos
);
11120 x_check_fullscreen_move (f
);
11121 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
11122 f
->output_data
.x
->want_fullscreen
&=
11123 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
11128 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
11129 xic_set_statusarea (f
);
11132 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11134 /* Since the WM decorations come below top_pos now,
11135 we must put them below top_pos in the future. */
11136 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11137 x_wm_set_size_hint (f
, (long) 0, 0);
11142 case ButtonRelease
:
11145 /* If we decide we want to generate an event to be seen
11146 by the rest of Emacs, we put it here. */
11147 struct input_event emacs_event
;
11148 int tool_bar_p
= 0;
11150 emacs_event
.kind
= NO_EVENT
;
11151 bzero (&compose_status
, sizeof (compose_status
));
11153 if (dpyinfo
->grabbed
11154 && last_mouse_frame
11155 && FRAME_LIVE_P (last_mouse_frame
))
11156 f
= last_mouse_frame
;
11158 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11162 /* Is this in the tool-bar? */
11163 if (WINDOWP (f
->tool_bar_window
)
11164 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
11166 Lisp_Object window
;
11169 x
= event
.xbutton
.x
;
11170 y
= event
.xbutton
.y
;
11173 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
11174 if (EQ (window
, f
->tool_bar_window
))
11176 x_handle_tool_bar_click (f
, &event
.xbutton
);
11182 if (!dpyinfo
->x_focus_frame
11183 || f
== dpyinfo
->x_focus_frame
)
11185 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
11186 if (! popup_activated ())
11188 construct_mouse_click (&emacs_event
, &event
, f
);
11193 struct scroll_bar
*bar
11194 = x_window_to_scroll_bar (event
.xbutton
.window
);
11196 #ifdef USE_TOOLKIT_SCROLL_BARS
11197 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
11199 if (bar
&& event
.xbutton
.state
& ControlMask
)
11201 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
11202 *finish
= X_EVENT_DROP
;
11204 #else /* not USE_TOOLKIT_SCROLL_BARS */
11206 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
11207 #endif /* not USE_TOOLKIT_SCROLL_BARS */
11210 if (event
.type
== ButtonPress
)
11212 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
11213 last_mouse_frame
= f
;
11214 /* Ignore any mouse motion that happened
11215 before this event; any subsequent mouse-movement
11216 Emacs events should reflect only motion after
11217 the ButtonPress. */
11219 f
->mouse_moved
= 0;
11222 last_tool_bar_item
= -1;
11225 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
11227 if (numchars
>= 1 && emacs_event
.kind
!= NO_EVENT
)
11229 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
11235 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
11236 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11237 /* For a down-event in the menu bar,
11238 don't pass it to Xt right now.
11239 Instead, save it away
11240 and we will pass it to Xt from kbd_buffer_get_event.
11241 That way, we can run some Lisp code first. */
11244 ! popup_activated ()
11247 f
&& event
.type
== ButtonPress
11248 /* Verify the event is really within the menu bar
11249 and not just sent to it due to grabbing. */
11250 && event
.xbutton
.x
>= 0
11251 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
11252 && event
.xbutton
.y
>= 0
11253 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
11254 && event
.xbutton
.same_screen
)
11256 SET_SAVED_BUTTON_EVENT
;
11257 XSETFRAME (last_mouse_press_frame
, f
);
11259 *finish
= X_EVENT_DROP
;
11262 else if (event
.type
== ButtonPress
)
11264 last_mouse_press_frame
= Qnil
;
11268 #ifdef USE_MOTIF /* This should do not harm for Lucid,
11269 but I am trying to be cautious. */
11270 else if (event
.type
== ButtonRelease
)
11272 if (!NILP (last_mouse_press_frame
))
11274 f
= XFRAME (last_mouse_press_frame
);
11275 if (f
->output_data
.x
)
11276 SET_SAVED_BUTTON_EVENT
;
11281 #endif /* USE_MOTIF */
11284 #endif /* USE_X_TOOLKIT || USE_GTK */
11288 case CirculateNotify
:
11291 case CirculateRequest
:
11294 case VisibilityNotify
:
11297 case MappingNotify
:
11298 /* Someone has changed the keyboard mapping - update the
11300 switch (event
.xmapping
.request
)
11302 case MappingModifier
:
11303 x_find_modifier_meanings (dpyinfo
);
11304 /* This is meant to fall through. */
11305 case MappingKeyboard
:
11306 XRefreshKeyboardMapping (&event
.xmapping
);
11312 #ifdef USE_X_TOOLKIT
11314 if (*finish
!= X_EVENT_DROP
)
11315 XtDispatchEvent (&event
);
11317 #endif /* USE_X_TOOLKIT */
11324 *finish
= X_EVENT_GOTO_OUT
;
11328 *numcharsp
= numchars
;
11335 /* Handles the XEvent EVENT on display DISPLAY.
11336 This is used for event loops outside the normal event handling,
11337 i.e. looping while a popup menu or a dialog is posted.
11339 Returns the value handle_one_xevent sets in the finish argument. */
11341 x_dispatch_event (event
, display
)
11345 struct x_display_info
*dpyinfo
;
11346 struct input_event bufp
[10];
11347 struct input_event
*bufpp
= bufp
;
11349 int finish
= X_EVENT_NORMAL
;
11351 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
11352 if (dpyinfo
->display
== display
)
11358 events
= handle_one_xevent (dpyinfo
,
11363 for (i
= 0; i
< events
; ++i
)
11364 kbd_buffer_store_event (&bufp
[i
]);
11371 /* Read events coming from the X server.
11372 This routine is called by the SIGIO handler.
11373 We return as soon as there are no more events to be read.
11375 Events representing keys are stored in buffer BUFP,
11376 which can hold up to NUMCHARS characters.
11377 We return the number of characters stored into the buffer,
11378 thus pretending to be `read'.
11380 EXPECTED is nonzero if the caller knows input is available. */
11383 XTread_socket (sd
, bufp
, numchars
, expected
)
11385 /* register */ struct input_event
*bufp
;
11386 /* register */ int numchars
;
11392 int event_found
= 0;
11393 struct x_display_info
*dpyinfo
;
11395 if (interrupt_input_blocked
)
11397 interrupt_input_pending
= 1;
11401 interrupt_input_pending
= 0;
11404 /* So people can tell when we have read the available input. */
11405 input_signal_count
++;
11408 abort (); /* Don't think this happens. */
11412 /* Find the display we are supposed to read input for.
11413 It's the one communicating on descriptor SD. */
11414 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
11416 #if 0 /* This ought to be unnecessary; let's verify it. */
11418 /* If available, Xlib uses FIOSNBIO to make the socket
11419 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
11420 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
11421 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
11422 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
11423 #endif /* ! defined (FIOSNBIO) */
11426 #if 0 /* This code can't be made to work, with multiple displays,
11427 and appears not to be used on any system any more.
11428 Also keyboard.c doesn't turn O_NDELAY on and off
11429 for X connections. */
11431 #ifndef HAVE_SELECT
11432 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
11434 extern int read_alarm_should_throw
;
11435 read_alarm_should_throw
= 1;
11436 XPeekEvent (dpyinfo
->display
, &event
);
11437 read_alarm_should_throw
= 0;
11439 #endif /* HAVE_SELECT */
11443 /* For debugging, this gives a way to fake an I/O error. */
11444 if (dpyinfo
== XTread_socket_fake_io_error
)
11446 XTread_socket_fake_io_error
= 0;
11447 x_io_error_quitter (dpyinfo
->display
);
11452 count
+= x_session_check_input (bufp
, &numchars
);
11457 /* For GTK we must use the GTK event loop. But XEvents gets passed
11458 to our filter function above, and then to the big event switch.
11459 We use a bunch of globals to communicate with our filter function,
11460 that is kind of ugly, but it works. */
11461 current_dpyinfo
= dpyinfo
;
11463 while (gtk_events_pending ())
11466 current_count
= count
;
11467 current_numcharsp
= &numchars
;
11468 current_bufp
= &bufp
;
11470 gtk_main_iteration ();
11472 count
= current_count
;
11474 current_numcharsp
= 0;
11476 if (current_finish
== X_EVENT_GOTO_OUT
)
11480 #else /* not USE_GTK */
11481 while (XPending (dpyinfo
->display
))
11485 XNextEvent (dpyinfo
->display
, &event
);
11488 /* Filter events for the current X input method. */
11489 if (x_filter_event (dpyinfo
, &event
))
11494 count
+= handle_one_xevent (dpyinfo
,
11500 if (finish
== X_EVENT_GOTO_OUT
)
11503 #endif /* USE_GTK */
11508 /* On some systems, an X bug causes Emacs to get no more events
11509 when the window is destroyed. Detect that. (1994.) */
11512 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
11513 One XNOOP in 100 loops will make Emacs terminate.
11514 B. Bretthauer, 1994 */
11516 if (x_noop_count
>= 100)
11520 if (next_noop_dpyinfo
== 0)
11521 next_noop_dpyinfo
= x_display_list
;
11523 XNoOp (next_noop_dpyinfo
->display
);
11525 /* Each time we get here, cycle through the displays now open. */
11526 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
11530 /* If the focus was just given to an auto-raising frame,
11532 /* ??? This ought to be able to handle more than one such frame. */
11533 if (pending_autoraise_frame
)
11535 x_raise_frame (pending_autoraise_frame
);
11536 pending_autoraise_frame
= 0;
11547 /***********************************************************************
11549 ***********************************************************************/
11551 /* Notice when the text cursor of window W has been completely
11552 overwritten by a drawing operation that outputs glyphs in AREA
11553 starting at X0 and ending at X1 in the line starting at Y0 and
11554 ending at Y1. X coordinates are area-relative. X1 < 0 means all
11555 the rest of the line after X0 has been written. Y coordinates
11556 are window-relative. */
11559 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
11561 enum glyph_row_area area
;
11562 int x0
, y0
, x1
, y1
;
11564 if (area
== TEXT_AREA
&& w
->phys_cursor_on_p
)
11566 int cx0
= w
->phys_cursor
.x
;
11567 int cx1
= cx0
+ w
->phys_cursor_width
;
11568 int cy0
= w
->phys_cursor
.y
;
11569 int cy1
= cy0
+ w
->phys_cursor_height
;
11571 if (x0
<= cx0
&& (x1
< 0 || x1
>= cx1
))
11573 /* The cursor image will be completely removed from the
11574 screen if the output area intersects the cursor area in
11575 y-direction. When we draw in [y0 y1[, and some part of
11576 the cursor is at y < y0, that part must have been drawn
11577 before. When scrolling, the cursor is erased before
11578 actually scrolling, so we don't come here. When not
11579 scrolling, the rows above the old cursor row must have
11580 changed, and in this case these rows must have written
11581 over the cursor image.
11583 Likewise if part of the cursor is below y1, with the
11584 exception of the cursor being in the first blank row at
11585 the buffer and window end because update_text_area
11586 doesn't draw that row. (Except when it does, but
11587 that's handled in update_text_area.) */
11589 if (((y0
>= cy0
&& y0
< cy1
) || (y1
> cy0
&& y1
< cy1
))
11590 && w
->current_matrix
->rows
[w
->phys_cursor
.vpos
].displays_text_p
)
11591 w
->phys_cursor_on_p
= 0;
11597 /* Set clipping for output in glyph row ROW. W is the window in which
11598 we operate. GC is the graphics context to set clipping in.
11599 WHOLE_LINE_P non-zero means include the areas used for truncation
11600 mark display and alike in the clipping rectangle.
11602 ROW may be a text row or, e.g., a mode line. Text rows must be
11603 clipped to the interior of the window dedicated to text display,
11604 mode lines must be clipped to the whole window. */
11607 x_clip_to_row (w
, row
, gc
, whole_line_p
)
11609 struct glyph_row
*row
;
11613 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11614 XRectangle clip_rect
;
11615 int window_x
, window_y
, window_width
, window_height
;
11617 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
11619 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
11620 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
11621 clip_rect
.y
= max (clip_rect
.y
, window_y
);
11622 clip_rect
.width
= window_width
;
11623 clip_rect
.height
= row
->visible_height
;
11625 /* If clipping to the whole line, including trunc marks, extend
11626 the rectangle to the left and increase its width. */
11629 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
11630 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
11633 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
11637 /* Draw a hollow box cursor on window W in glyph row ROW. */
11640 x_draw_hollow_cursor (w
, row
)
11642 struct glyph_row
*row
;
11644 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11645 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11646 Display
*dpy
= FRAME_X_DISPLAY (f
);
11649 struct glyph
*cursor_glyph
;
11652 /* Compute frame-relative coordinates from window-relative
11654 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11655 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
11656 + row
->ascent
- w
->phys_cursor_ascent
);
11657 h
= row
->height
- 1;
11659 /* Get the glyph the cursor is on. If we can't tell because
11660 the current matrix is invalid or such, give up. */
11661 cursor_glyph
= get_phys_cursor_glyph (w
);
11662 if (cursor_glyph
== NULL
)
11665 /* Compute the width of the rectangle to draw. If on a stretch
11666 glyph, and `x-stretch-block-cursor' is nil, don't draw a
11667 rectangle as wide as the glyph, but use a canonical character
11669 wd
= cursor_glyph
->pixel_width
- 1;
11670 if (cursor_glyph
->type
== STRETCH_GLYPH
11671 && !x_stretch_cursor_p
)
11672 wd
= min (CANON_X_UNIT (f
), wd
);
11673 w
->phys_cursor_width
= wd
;
11675 /* The foreground of cursor_gc is typically the same as the normal
11676 background color, which can cause the cursor box to be invisible. */
11677 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11678 if (dpyinfo
->scratch_cursor_gc
)
11679 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11681 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11682 GCForeground
, &xgcv
);
11683 gc
= dpyinfo
->scratch_cursor_gc
;
11685 /* Set clipping, draw the rectangle, and reset clipping again. */
11686 x_clip_to_row (w
, row
, gc
, 0);
11687 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11688 XSetClipMask (dpy
, gc
, None
);
11692 /* Draw a bar cursor on window W in glyph row ROW.
11694 Implementation note: One would like to draw a bar cursor with an
11695 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11696 Unfortunately, I didn't find a font yet that has this property set.
11700 x_draw_bar_cursor (w
, row
, width
, kind
)
11702 struct glyph_row
*row
;
11704 enum text_cursor_kinds kind
;
11706 struct frame
*f
= XFRAME (w
->frame
);
11707 struct glyph
*cursor_glyph
;
11709 /* If cursor is out of bounds, don't draw garbage. This can happen
11710 in mini-buffer windows when switching between echo area glyphs
11711 and mini-buffer. */
11712 cursor_glyph
= get_phys_cursor_glyph (w
);
11713 if (cursor_glyph
== NULL
)
11716 /* If on an image, draw like a normal cursor. That's usually better
11717 visible than drawing a bar, esp. if the image is large so that
11718 the bar might not be in the window. */
11719 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11721 struct glyph_row
*row
;
11722 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11723 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11727 Display
*dpy
= FRAME_X_DISPLAY (f
);
11728 Window window
= FRAME_X_WINDOW (f
);
11729 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11730 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11731 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
11734 /* If the glyph's background equals the color we normally draw
11735 the bar cursor in, the bar cursor in its normal color is
11736 invisible. Use the glyph's foreground color instead in this
11737 case, on the assumption that the glyph's colors are chosen so
11738 that the glyph is legible. */
11739 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
11740 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
11742 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11743 xgcv
.graphics_exposures
= 0;
11746 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11749 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11750 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11754 width
= FRAME_CURSOR_WIDTH (f
);
11755 width
= min (cursor_glyph
->pixel_width
, width
);
11757 w
->phys_cursor_width
= width
;
11758 x_clip_to_row (w
, row
, gc
, 0);
11760 if (kind
== BAR_CURSOR
)
11761 XFillRectangle (dpy
, window
, gc
,
11762 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11763 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11764 width
, row
->height
);
11766 XFillRectangle (dpy
, window
, gc
,
11767 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11768 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
11769 row
->height
- width
),
11770 cursor_glyph
->pixel_width
,
11773 XSetClipMask (dpy
, gc
, None
);
11778 /* Clear the cursor of window W to background color, and mark the
11779 cursor as not shown. This is used when the text where the cursor
11780 is is about to be rewritten. */
11786 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11787 x_update_window_cursor (w
, 0);
11791 /* Draw the cursor glyph of window W in glyph row ROW. See the
11792 comment of x_draw_glyphs for the meaning of HL. */
11795 x_draw_phys_cursor_glyph (w
, row
, hl
)
11797 struct glyph_row
*row
;
11798 enum draw_glyphs_face hl
;
11800 /* If cursor hpos is out of bounds, don't draw garbage. This can
11801 happen in mini-buffer windows when switching between echo area
11802 glyphs and mini-buffer. */
11803 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11805 int on_p
= w
->phys_cursor_on_p
;
11808 x1
= x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11809 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11811 w
->phys_cursor_on_p
= on_p
;
11813 if (hl
== DRAW_CURSOR
)
11814 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
11816 /* When we erase the cursor, and ROW is overlapped by other
11817 rows, make sure that these overlapping parts of other rows
11819 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11821 if (row
> w
->current_matrix
->rows
11822 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11823 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11825 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11826 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11827 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11833 /* Erase the image of a cursor of window W from the screen. */
11836 x_erase_phys_cursor (w
)
11839 struct frame
*f
= XFRAME (w
->frame
);
11840 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11841 int hpos
= w
->phys_cursor
.hpos
;
11842 int vpos
= w
->phys_cursor
.vpos
;
11843 int mouse_face_here_p
= 0;
11844 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11845 struct glyph_row
*cursor_row
;
11846 struct glyph
*cursor_glyph
;
11847 enum draw_glyphs_face hl
;
11849 /* No cursor displayed or row invalidated => nothing to do on the
11851 if (w
->phys_cursor_type
== NO_CURSOR
)
11852 goto mark_cursor_off
;
11854 /* VPOS >= active_glyphs->nrows means that window has been resized.
11855 Don't bother to erase the cursor. */
11856 if (vpos
>= active_glyphs
->nrows
)
11857 goto mark_cursor_off
;
11859 /* If row containing cursor is marked invalid, there is nothing we
11861 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11862 if (!cursor_row
->enabled_p
)
11863 goto mark_cursor_off
;
11865 /* If row is completely invisible, don't attempt to delete a cursor which
11866 isn't there. This can happen if cursor is at top of a window, and
11867 we switch to a buffer with a header line in that window. */
11868 if (cursor_row
->visible_height
<= 0)
11869 goto mark_cursor_off
;
11871 /* This can happen when the new row is shorter than the old one.
11872 In this case, either x_draw_glyphs or clear_end_of_line
11873 should have cleared the cursor. Note that we wouldn't be
11874 able to erase the cursor in this case because we don't have a
11875 cursor glyph at hand. */
11876 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11877 goto mark_cursor_off
;
11879 /* If the cursor is in the mouse face area, redisplay that when
11880 we clear the cursor. */
11881 if (! NILP (dpyinfo
->mouse_face_window
)
11882 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11883 && (vpos
> dpyinfo
->mouse_face_beg_row
11884 || (vpos
== dpyinfo
->mouse_face_beg_row
11885 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11886 && (vpos
< dpyinfo
->mouse_face_end_row
11887 || (vpos
== dpyinfo
->mouse_face_end_row
11888 && hpos
< dpyinfo
->mouse_face_end_col
))
11889 /* Don't redraw the cursor's spot in mouse face if it is at the
11890 end of a line (on a newline). The cursor appears there, but
11891 mouse highlighting does not. */
11892 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11893 mouse_face_here_p
= 1;
11895 /* Maybe clear the display under the cursor. */
11896 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11899 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11901 cursor_glyph
= get_phys_cursor_glyph (w
);
11902 if (cursor_glyph
== NULL
)
11903 goto mark_cursor_off
;
11905 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11907 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11909 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11911 cursor_glyph
->pixel_width
,
11912 cursor_row
->visible_height
,
11916 /* Erase the cursor by redrawing the character underneath it. */
11917 if (mouse_face_here_p
)
11918 hl
= DRAW_MOUSE_FACE
;
11920 hl
= DRAW_NORMAL_TEXT
;
11921 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11924 w
->phys_cursor_on_p
= 0;
11925 w
->phys_cursor_type
= NO_CURSOR
;
11929 /* Non-zero if physical cursor of window W is within mouse face. */
11932 cursor_in_mouse_face_p (w
)
11935 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
11936 int in_mouse_face
= 0;
11938 if (WINDOWP (dpyinfo
->mouse_face_window
)
11939 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
11941 int hpos
= w
->phys_cursor
.hpos
;
11942 int vpos
= w
->phys_cursor
.vpos
;
11944 if (vpos
>= dpyinfo
->mouse_face_beg_row
11945 && vpos
<= dpyinfo
->mouse_face_end_row
11946 && (vpos
> dpyinfo
->mouse_face_beg_row
11947 || hpos
>= dpyinfo
->mouse_face_beg_col
)
11948 && (vpos
< dpyinfo
->mouse_face_end_row
11949 || hpos
< dpyinfo
->mouse_face_end_col
11950 || dpyinfo
->mouse_face_past_end
))
11954 return in_mouse_face
;
11958 /* Display or clear cursor of window W. If ON is zero, clear the
11959 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11960 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11963 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11965 int on
, hpos
, vpos
, x
, y
;
11967 struct frame
*f
= XFRAME (w
->frame
);
11968 int new_cursor_type
;
11969 int new_cursor_width
;
11971 struct glyph_matrix
*current_glyphs
;
11972 struct glyph_row
*glyph_row
;
11973 struct glyph
*glyph
;
11975 /* This is pointless on invisible frames, and dangerous on garbaged
11976 windows and frames; in the latter case, the frame or window may
11977 be in the midst of changing its size, and x and y may be off the
11979 if (! FRAME_VISIBLE_P (f
)
11980 || FRAME_GARBAGED_P (f
)
11981 || vpos
>= w
->current_matrix
->nrows
11982 || hpos
>= w
->current_matrix
->matrix_w
)
11985 /* If cursor is off and we want it off, return quickly. */
11986 if (!on
&& !w
->phys_cursor_on_p
)
11989 current_glyphs
= w
->current_matrix
;
11990 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11991 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11993 /* If cursor row is not enabled, we don't really know where to
11994 display the cursor. */
11995 if (!glyph_row
->enabled_p
)
11997 w
->phys_cursor_on_p
= 0;
12001 xassert (interrupt_input_blocked
);
12003 /* Set new_cursor_type to the cursor we want to be displayed. */
12004 new_cursor_type
= get_window_cursor_type (w
, &new_cursor_width
, &active_cursor
);
12006 /* If cursor is currently being shown and we don't want it to be or
12007 it is in the wrong place, or the cursor type is not what we want,
12009 if (w
->phys_cursor_on_p
12011 || w
->phys_cursor
.x
!= x
12012 || w
->phys_cursor
.y
!= y
12013 || new_cursor_type
!= w
->phys_cursor_type
12014 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
12015 && new_cursor_width
!= w
->phys_cursor_width
)))
12016 x_erase_phys_cursor (w
);
12018 /* Don't check phys_cursor_on_p here because that flag is only set
12019 to zero in some cases where we know that the cursor has been
12020 completely erased, to avoid the extra work of erasing the cursor
12021 twice. In other words, phys_cursor_on_p can be 1 and the cursor
12022 still not be visible, or it has only been partly erased. */
12025 w
->phys_cursor_ascent
= glyph_row
->ascent
;
12026 w
->phys_cursor_height
= glyph_row
->height
;
12028 /* Set phys_cursor_.* before x_draw_.* is called because some
12029 of them may need the information. */
12030 w
->phys_cursor
.x
= x
;
12031 w
->phys_cursor
.y
= glyph_row
->y
;
12032 w
->phys_cursor
.hpos
= hpos
;
12033 w
->phys_cursor
.vpos
= vpos
;
12034 w
->phys_cursor_type
= new_cursor_type
;
12035 w
->phys_cursor_on_p
= 1;
12037 switch (new_cursor_type
)
12039 case HOLLOW_BOX_CURSOR
:
12040 x_draw_hollow_cursor (w
, glyph_row
);
12043 case FILLED_BOX_CURSOR
:
12044 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
12048 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
, BAR_CURSOR
);
12052 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
, HBAR_CURSOR
);
12056 w
->phys_cursor_width
= 0;
12064 if (w
== XWINDOW (f
->selected_window
))
12065 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
12066 xic_set_preeditarea (w
, x
, y
);
12071 if (updating_frame
!= f
)
12072 XFlush (FRAME_X_DISPLAY (f
));
12077 /* Display the cursor on window W, or clear it. X and Y are window
12078 relative pixel coordinates. HPOS and VPOS are glyph matrix
12079 positions. If W is not the selected window, display a hollow
12080 cursor. ON non-zero means display the cursor at X, Y which
12081 correspond to HPOS, VPOS, otherwise it is cleared. */
12084 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
12086 int on
, hpos
, vpos
, x
, y
;
12089 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
12094 /* Display the cursor on window W, or clear it, according to ON_P.
12095 Don't change the cursor's position. */
12098 x_update_cursor (f
, on_p
)
12102 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
12106 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
12107 in the window tree rooted at W. */
12110 x_update_cursor_in_window_tree (w
, on_p
)
12116 if (!NILP (w
->hchild
))
12117 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
12118 else if (!NILP (w
->vchild
))
12119 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
12121 x_update_window_cursor (w
, on_p
);
12123 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
12128 /* Switch the display of W's cursor on or off, according to the value
12132 x_update_window_cursor (w
, on
)
12136 /* Don't update cursor in windows whose frame is in the process
12137 of being deleted. */
12138 if (w
->current_matrix
)
12141 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
12142 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
12152 /* Make the x-window of frame F use the gnu icon bitmap. */
12155 x_bitmap_icon (f
, file
)
12161 if (FRAME_X_WINDOW (f
) == 0)
12164 /* Free up our existing icon bitmap if any. */
12165 if (f
->output_data
.x
->icon_bitmap
> 0)
12166 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
12167 f
->output_data
.x
->icon_bitmap
= 0;
12169 if (STRINGP (file
))
12170 bitmap_id
= x_create_bitmap_from_file (f
, file
);
12173 /* Create the GNU bitmap if necessary. */
12174 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
12175 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
12176 = x_create_bitmap_from_data (f
, gnu_bits
,
12177 gnu_width
, gnu_height
);
12179 /* The first time we create the GNU bitmap,
12180 this increments the ref-count one extra time.
12181 As a result, the GNU bitmap is never freed.
12182 That way, we don't have to worry about allocating it again. */
12183 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
12185 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
12188 x_wm_set_icon_pixmap (f
, bitmap_id
);
12189 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
12195 /* Make the x-window of frame F use a rectangle with text.
12196 Use ICON_NAME as the text. */
12199 x_text_icon (f
, icon_name
)
12203 if (FRAME_X_WINDOW (f
) == 0)
12208 XTextProperty text
;
12209 text
.value
= (unsigned char *) icon_name
;
12210 text
.encoding
= XA_STRING
;
12212 text
.nitems
= strlen (icon_name
);
12213 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
12215 #else /* not HAVE_X11R4 */
12216 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), icon_name
);
12217 #endif /* not HAVE_X11R4 */
12219 if (f
->output_data
.x
->icon_bitmap
> 0)
12220 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
12221 f
->output_data
.x
->icon_bitmap
= 0;
12222 x_wm_set_icon_pixmap (f
, 0);
12227 #define X_ERROR_MESSAGE_SIZE 200
12229 /* If non-nil, this should be a string.
12230 It means catch X errors and store the error message in this string. */
12232 static Lisp_Object x_error_message_string
;
12234 /* An X error handler which stores the error message in
12235 x_error_message_string. This is called from x_error_handler if
12236 x_catch_errors is in effect. */
12239 x_error_catcher (display
, error
)
12241 XErrorEvent
*error
;
12243 XGetErrorText (display
, error
->error_code
,
12244 SDATA (x_error_message_string
),
12245 X_ERROR_MESSAGE_SIZE
);
12248 /* Begin trapping X errors for display DPY. Actually we trap X errors
12249 for all displays, but DPY should be the display you are actually
12252 After calling this function, X protocol errors no longer cause
12253 Emacs to exit; instead, they are recorded in the string
12254 stored in x_error_message_string.
12256 Calling x_check_errors signals an Emacs error if an X error has
12257 occurred since the last call to x_catch_errors or x_check_errors.
12259 Calling x_uncatch_errors resumes the normal error handling. */
12261 void x_check_errors ();
12262 static Lisp_Object
x_catch_errors_unwind ();
12265 x_catch_errors (dpy
)
12268 int count
= SPECPDL_INDEX ();
12270 /* Make sure any errors from previous requests have been dealt with. */
12271 XSync (dpy
, False
);
12273 record_unwind_protect (x_catch_errors_unwind
,
12274 Fcons (make_save_value (dpy
, 0),
12275 x_error_message_string
));
12277 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
12278 SSET (x_error_message_string
, 0, 0);
12283 /* Unbind the binding that we made to check for X errors. */
12286 x_catch_errors_unwind (old_val
)
12287 Lisp_Object old_val
;
12291 first
= XCAR (old_val
);
12293 XSync (XSAVE_VALUE (first
)->pointer
, False
);
12295 x_error_message_string
= XCDR (old_val
);
12299 /* If any X protocol errors have arrived since the last call to
12300 x_catch_errors or x_check_errors, signal an Emacs error using
12301 sprintf (a buffer, FORMAT, the x error message text) as the text. */
12304 x_check_errors (dpy
, format
)
12308 /* Make sure to catch any errors incurred so far. */
12309 XSync (dpy
, False
);
12311 if (SREF (x_error_message_string
, 0))
12312 error (format
, SDATA (x_error_message_string
));
12315 /* Nonzero if we had any X protocol errors
12316 since we did x_catch_errors on DPY. */
12319 x_had_errors_p (dpy
)
12322 /* Make sure to catch any errors incurred so far. */
12323 XSync (dpy
, False
);
12325 return SREF (x_error_message_string
, 0) != 0;
12328 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
12331 x_clear_errors (dpy
)
12334 SSET (x_error_message_string
, 0, 0);
12337 /* Stop catching X protocol errors and let them make Emacs die.
12338 DPY should be the display that was passed to x_catch_errors.
12339 COUNT should be the value that was returned by
12340 the corresponding call to x_catch_errors. */
12343 x_uncatch_errors (dpy
, count
)
12347 unbind_to (count
, Qnil
);
12351 static unsigned int x_wire_count
;
12354 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
12359 /* Handle SIGPIPE, which can happen when the connection to a server
12360 simply goes away. SIGPIPE is handled by x_connection_signal.
12361 Don't need to do anything, because the write which caused the
12362 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
12363 which will do the appropriate cleanup for us. */
12366 x_connection_signal (signalnum
) /* If we don't have an argument, */
12367 int signalnum
; /* some compilers complain in signal calls. */
12370 /* USG systems forget handlers when they are used;
12371 must reestablish each time */
12372 signal (signalnum
, x_connection_signal
);
12377 /************************************************************************
12379 ************************************************************************/
12381 /* Error message passed to x_connection_closed. */
12383 static char *error_msg
;
12385 /* Function installed as fatal_error_signal_hook in
12386 x_connection_closed. Print the X error message, and exit normally,
12387 instead of dumping core when XtCloseDisplay fails. */
12390 x_fatal_error_signal ()
12392 fprintf (stderr
, "%s\n", error_msg
);
12396 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
12397 the text of an error message that lead to the connection loss. */
12400 x_connection_closed (dpy
, error_message
)
12402 char *error_message
;
12404 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
12405 Lisp_Object frame
, tail
;
12408 error_msg
= (char *) alloca (strlen (error_message
) + 1);
12409 strcpy (error_msg
, error_message
);
12410 handling_signal
= 0;
12412 /* Prevent being called recursively because of an error condition
12413 below. Otherwise, we might end up with printing ``can't find per
12414 display information'' in the recursive call instead of printing
12415 the original message here. */
12416 count
= x_catch_errors (dpy
);
12418 /* We have to close the display to inform Xt that it doesn't
12419 exist anymore. If we don't, Xt will continue to wait for
12420 events from the display. As a consequence, a sequence of
12422 M-x make-frame-on-display RET :1 RET
12423 ...kill the new frame, so that we get an IO error...
12424 M-x make-frame-on-display RET :1 RET
12426 will indefinitely wait in Xt for events for display `:1', opened
12427 in the first class to make-frame-on-display.
12429 Closing the display is reported to lead to a bus error on
12430 OpenWindows in certain situations. I suspect that is a bug
12431 in OpenWindows. I don't know how to cicumvent it here. */
12433 #ifdef USE_X_TOOLKIT
12434 /* If DPYINFO is null, this means we didn't open the display
12435 in the first place, so don't try to close it. */
12438 extern void (*fatal_error_signal_hook
) P_ ((void));
12439 fatal_error_signal_hook
= x_fatal_error_signal
;
12440 XtCloseDisplay (dpy
);
12441 fatal_error_signal_hook
= NULL
;
12445 /* Indicate that this display is dead. */
12447 dpyinfo
->display
= 0;
12449 /* First delete frames whose mini-buffers are on frames
12450 that are on the dead display. */
12451 FOR_EACH_FRAME (tail
, frame
)
12453 Lisp_Object minibuf_frame
;
12455 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
12456 if (FRAME_X_P (XFRAME (frame
))
12457 && FRAME_X_P (XFRAME (minibuf_frame
))
12458 && ! EQ (frame
, minibuf_frame
)
12459 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
12460 Fdelete_frame (frame
, Qt
);
12463 /* Now delete all remaining frames on the dead display.
12464 We are now sure none of these is used as the mini-buffer
12465 for another frame that we need to delete. */
12466 FOR_EACH_FRAME (tail
, frame
)
12467 if (FRAME_X_P (XFRAME (frame
))
12468 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
12470 /* Set this to t so that Fdelete_frame won't get confused
12471 trying to find a replacement. */
12472 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
12473 Fdelete_frame (frame
, Qt
);
12477 x_delete_display (dpyinfo
);
12479 x_uncatch_errors (dpy
, count
);
12481 if (x_display_list
== 0)
12483 fprintf (stderr
, "%s\n", error_msg
);
12484 shut_down_emacs (0, 0, Qnil
);
12488 /* Ordinary stack unwind doesn't deal with these. */
12490 sigunblock (sigmask (SIGIO
));
12492 sigunblock (sigmask (SIGALRM
));
12493 TOTALLY_UNBLOCK_INPUT
;
12495 clear_waiting_for_input ();
12496 error ("%s", error_msg
);
12500 /* This is the usual handler for X protocol errors.
12501 It kills all frames on the display that we got the error for.
12502 If that was the only one, it prints an error message and kills Emacs. */
12505 x_error_quitter (display
, error
)
12507 XErrorEvent
*error
;
12509 char buf
[256], buf1
[356];
12511 /* Note that there is no real way portable across R3/R4 to get the
12512 original error handler. */
12514 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
12515 sprintf (buf1
, "X protocol error: %s on protocol request %d",
12516 buf
, error
->request_code
);
12517 x_connection_closed (display
, buf1
);
12521 /* This is the first-level handler for X protocol errors.
12522 It calls x_error_quitter or x_error_catcher. */
12525 x_error_handler (display
, error
)
12527 XErrorEvent
*error
;
12529 if (! NILP (x_error_message_string
))
12530 x_error_catcher (display
, error
);
12532 x_error_quitter (display
, error
);
12536 /* This is the handler for X IO errors, always.
12537 It kills all frames on the display that we lost touch with.
12538 If that was the only one, it prints an error message and kills Emacs. */
12541 x_io_error_quitter (display
)
12546 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
12547 x_connection_closed (display
, buf
);
12551 /* Changing the font of the frame. */
12553 /* Give frame F the font named FONTNAME as its default font, and
12554 return the full name of that font. FONTNAME may be a wildcard
12555 pattern; in that case, we choose some font that fits the pattern.
12556 The return value shows which font we chose. */
12559 x_new_font (f
, fontname
)
12561 register char *fontname
;
12563 struct font_info
*fontp
12564 = FS_LOAD_FONT (f
, 0, fontname
, -1);
12569 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
12570 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
12571 f
->output_data
.x
->fontset
= -1;
12573 compute_fringe_widths (f
, 1);
12575 /* Compute the scroll bar width in character columns. */
12576 if (f
->scroll_bar_pixel_width
> 0)
12578 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12579 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
12583 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12584 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
12587 /* Now make the frame display the given font. */
12588 if (FRAME_X_WINDOW (f
) != 0)
12590 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
12591 f
->output_data
.x
->font
->fid
);
12592 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
12593 f
->output_data
.x
->font
->fid
);
12594 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
12595 f
->output_data
.x
->font
->fid
);
12597 frame_update_line_height (f
);
12599 /* Don't change the size of a tip frame; there's no point in
12600 doing it because it's done in Fx_show_tip, and it leads to
12601 problems because the tip frame has no widget. */
12602 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
12603 x_set_window_size (f
, 0, f
->width
, f
->height
);
12606 /* If we are setting a new frame's font for the first time,
12607 there are no faces yet, so this font's height is the line height. */
12608 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
12610 return build_string (fontp
->full_name
);
12613 /* Give frame F the fontset named FONTSETNAME as its default font, and
12614 return the full name of that fontset. FONTSETNAME may be a wildcard
12615 pattern; in that case, we choose some fontset that fits the pattern.
12616 The return value shows which fontset we chose. */
12619 x_new_fontset (f
, fontsetname
)
12623 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
12624 Lisp_Object result
;
12629 if (f
->output_data
.x
->fontset
== fontset
)
12630 /* This fontset is already set in frame F. There's nothing more
12632 return fontset_name (fontset
);
12634 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
12636 if (!STRINGP (result
))
12637 /* Can't load ASCII font. */
12640 /* Since x_new_font doesn't update any fontset information, do it now. */
12641 f
->output_data
.x
->fontset
= fontset
;
12645 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
12646 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
12649 return build_string (fontsetname
);
12653 /***********************************************************************
12655 ***********************************************************************/
12661 /* XIM destroy callback function, which is called whenever the
12662 connection to input method XIM dies. CLIENT_DATA contains a
12663 pointer to the x_display_info structure corresponding to XIM. */
12666 xim_destroy_callback (xim
, client_data
, call_data
)
12668 XPointer client_data
;
12669 XPointer call_data
;
12671 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
12672 Lisp_Object frame
, tail
;
12676 /* No need to call XDestroyIC.. */
12677 FOR_EACH_FRAME (tail
, frame
)
12679 struct frame
*f
= XFRAME (frame
);
12680 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
12682 FRAME_XIC (f
) = NULL
;
12683 if (FRAME_XIC_FONTSET (f
))
12685 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
12686 FRAME_XIC_FONTSET (f
) = NULL
;
12691 /* No need to call XCloseIM. */
12692 dpyinfo
->xim
= NULL
;
12693 XFree (dpyinfo
->xim_styles
);
12697 #endif /* HAVE_X11R6 */
12700 /* This isn't prototyped in OSF 5.0 or 5.1a. */
12701 extern char *XSetIMValues
P_ ((XIM
, ...));
12704 /* Open the connection to the XIM server on display DPYINFO.
12705 RESOURCE_NAME is the resource name Emacs uses. */
12708 xim_open_dpy (dpyinfo
, resource_name
)
12709 struct x_display_info
*dpyinfo
;
12710 char *resource_name
;
12715 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
12716 dpyinfo
->xim
= xim
;
12721 XIMCallback destroy
;
12724 /* Get supported styles and XIM values. */
12725 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
12728 destroy
.callback
= xim_destroy_callback
;
12729 destroy
.client_data
= (XPointer
)dpyinfo
;
12730 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
12734 #else /* not USE_XIM */
12735 dpyinfo
->xim
= NULL
;
12736 #endif /* not USE_XIM */
12740 #ifdef HAVE_X11R6_XIM
12744 struct x_display_info
*dpyinfo
;
12745 char *resource_name
;
12748 /* XIM instantiate callback function, which is called whenever an XIM
12749 server is available. DISPLAY is the display of the XIM.
12750 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12751 when the callback was registered. */
12754 xim_instantiate_callback (display
, client_data
, call_data
)
12756 XPointer client_data
;
12757 XPointer call_data
;
12759 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12760 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12762 /* We don't support multiple XIM connections. */
12766 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12768 /* Create XIC for the existing frames on the same display, as long
12769 as they have no XIC. */
12770 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12772 Lisp_Object tail
, frame
;
12775 FOR_EACH_FRAME (tail
, frame
)
12777 struct frame
*f
= XFRAME (frame
);
12779 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12780 if (FRAME_XIC (f
) == NULL
)
12782 create_frame_xic (f
);
12783 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12784 xic_set_statusarea (f
);
12785 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12787 struct window
*w
= XWINDOW (f
->selected_window
);
12788 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12797 #endif /* HAVE_X11R6_XIM */
12800 /* Open a connection to the XIM server on display DPYINFO.
12801 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12802 connection only at the first time. On X11R6, open the connection
12803 in the XIM instantiate callback function. */
12806 xim_initialize (dpyinfo
, resource_name
)
12807 struct x_display_info
*dpyinfo
;
12808 char *resource_name
;
12811 #ifdef HAVE_X11R6_XIM
12812 struct xim_inst_t
*xim_inst
;
12815 dpyinfo
->xim
= NULL
;
12816 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12817 xim_inst
->dpyinfo
= dpyinfo
;
12818 len
= strlen (resource_name
);
12819 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12820 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12821 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12822 resource_name
, EMACS_CLASS
,
12823 xim_instantiate_callback
,
12824 /* Fixme: This is XPointer in
12825 XFree86 but (XPointer *) on
12826 Tru64, at least. */
12827 (XPointer
) xim_inst
);
12828 #else /* not HAVE_X11R6_XIM */
12829 dpyinfo
->xim
= NULL
;
12830 xim_open_dpy (dpyinfo
, resource_name
);
12831 #endif /* not HAVE_X11R6_XIM */
12833 #else /* not USE_XIM */
12834 dpyinfo
->xim
= NULL
;
12835 #endif /* not USE_XIM */
12839 /* Close the connection to the XIM server on display DPYINFO. */
12842 xim_close_dpy (dpyinfo
)
12843 struct x_display_info
*dpyinfo
;
12846 #ifdef HAVE_X11R6_XIM
12847 if (dpyinfo
->display
)
12848 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12850 xim_instantiate_callback
, NULL
);
12851 #endif /* not HAVE_X11R6_XIM */
12852 if (dpyinfo
->display
)
12853 XCloseIM (dpyinfo
->xim
);
12854 dpyinfo
->xim
= NULL
;
12855 XFree (dpyinfo
->xim_styles
);
12856 #endif /* USE_XIM */
12859 #endif /* not HAVE_X11R6_XIM */
12863 /* Calculate the absolute position in frame F
12864 from its current recorded position values and gravity. */
12867 x_calc_absolute_position (f
)
12871 int win_x
= 0, win_y
= 0;
12872 int flags
= f
->output_data
.x
->size_hint_flags
;
12875 /* We have nothing to do if the current position
12876 is already for the top-left corner. */
12877 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12880 this_window
= FRAME_OUTER_WINDOW (f
);
12882 /* Find the position of the outside upper-left corner of
12883 the inner window, with respect to the outer window.
12884 But do this only if we will need the results. */
12885 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12890 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12893 x_clear_errors (FRAME_X_DISPLAY (f
));
12894 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12896 /* From-window, to-window. */
12898 f
->output_data
.x
->parent_desc
,
12900 /* From-position, to-position. */
12901 0, 0, &win_x
, &win_y
,
12903 /* Child of win. */
12905 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12907 Window newroot
, newparent
= 0xdeadbeef;
12908 Window
*newchildren
;
12909 unsigned int nchildren
;
12911 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12912 &newparent
, &newchildren
, &nchildren
))
12915 XFree ((char *) newchildren
);
12917 f
->output_data
.x
->parent_desc
= newparent
;
12923 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12927 /* Treat negative positions as relative to the leftmost bottommost
12928 position that fits on the screen. */
12929 if (flags
& XNegative
)
12930 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12931 - 2 * f
->output_data
.x
->border_width
- win_x
12933 + f
->output_data
.x
->left_pos
);
12936 int height
= PIXEL_HEIGHT (f
);
12938 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12939 /* Something is fishy here. When using Motif, starting Emacs with
12940 `-g -0-0', the frame appears too low by a few pixels.
12942 This seems to be so because initially, while Emacs is starting,
12943 the column widget's height and the frame's pixel height are
12944 different. The column widget's height is the right one. In
12945 later invocations, when Emacs is up, the frame's pixel height
12948 It's not obvious where the initial small difference comes from.
12949 2000-12-01, gerd. */
12951 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12954 if (flags
& YNegative
)
12955 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12956 - 2 * f
->output_data
.x
->border_width
12959 + f
->output_data
.x
->top_pos
);
12962 /* The left_pos and top_pos
12963 are now relative to the top and left screen edges,
12964 so the flags should correspond. */
12965 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12968 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12969 to really change the position, and 0 when calling from
12970 x_make_frame_visible (in that case, XOFF and YOFF are the current
12971 position values). It is -1 when calling from x_set_frame_parameters,
12972 which means, do adjust for borders but don't change the gravity. */
12975 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12977 register int xoff
, yoff
;
12978 int change_gravity
;
12980 int modified_top
, modified_left
;
12982 if (change_gravity
> 0)
12984 f
->output_data
.x
->top_pos
= yoff
;
12985 f
->output_data
.x
->left_pos
= xoff
;
12986 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12988 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12990 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12991 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12993 x_calc_absolute_position (f
);
12996 x_wm_set_size_hint (f
, (long) 0, 0);
12998 modified_left
= f
->output_data
.x
->left_pos
;
12999 modified_top
= f
->output_data
.x
->top_pos
;
13000 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
13001 this seems to be unnecessary and incorrect. rms, 4/17/97. */
13002 /* It is a mystery why we need to add the border_width here
13003 when the frame is already visible, but experiment says we do. */
13004 if (change_gravity
!= 0)
13006 modified_left
+= f
->output_data
.x
->border_width
;
13007 modified_top
+= f
->output_data
.x
->border_width
;
13011 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13012 modified_left
, modified_top
);
13016 /* Check if we need to resize the frame due to a fullscreen request.
13017 If so needed, resize the frame. */
13019 x_check_fullscreen (f
)
13022 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
13024 int width
, height
, ign
;
13026 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
13027 &f
->output_data
.x
->top_pos
);
13029 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
13031 /* We do not need to move the window, it shall be taken care of
13032 when setting WM manager hints.
13033 If the frame is visible already, the position is checked by
13034 x_check_fullscreen_move. */
13035 if (f
->width
!= width
|| f
->height
!= height
)
13037 change_frame_size (f
, height
, width
, 0, 1, 0);
13038 SET_FRAME_GARBAGED (f
);
13039 cancel_mouse_face (f
);
13041 /* Wait for the change of frame size to occur */
13042 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
13048 /* If frame parameters are set after the frame is mapped, we need to move
13049 the window. This is done in xfns.c.
13050 Some window managers moves the window to the right position, some
13051 moves the outer window manager window to the specified position.
13052 Here we check that we are in the right spot. If not, make a second
13053 move, assuming we are dealing with the second kind of window manager. */
13055 x_check_fullscreen_move (f
)
13058 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
13060 int expect_top
= f
->output_data
.x
->top_pos
;
13061 int expect_left
= f
->output_data
.x
->left_pos
;
13063 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
13065 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
13068 if (expect_top
!= f
->output_data
.x
->top_pos
13069 || expect_left
!= f
->output_data
.x
->left_pos
)
13070 x_set_offset (f
, expect_left
, expect_top
, 1);
13072 /* Just do this once */
13073 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
13078 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
13079 wanted positions of the WM window (not emacs window).
13080 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
13081 window (FRAME_X_WINDOW).
13084 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
13091 int newwidth
= f
->width
, newheight
= f
->height
;
13093 *top_pos
= f
->output_data
.x
->top_pos
;
13094 *left_pos
= f
->output_data
.x
->left_pos
;
13096 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
13100 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
13101 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
13102 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
13103 - f
->output_data
.x
->y_pixels_diff
;
13104 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
13108 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
13112 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
13113 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
13114 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
13115 - f
->output_data
.x
->x_pixels_diff
;
13116 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
13121 *height
= newheight
;
13125 /* Change the size of frame F's X window to COLS/ROWS in the case F
13126 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
13127 top-left-corner window gravity for this size change and subsequent
13128 size changes. Otherwise we leave the window gravity unchanged. */
13131 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
13133 int change_gravity
;
13136 int pixelwidth
, pixelheight
;
13138 check_frame_size (f
, &rows
, &cols
);
13139 f
->output_data
.x
->vertical_scroll_bar_extra
13140 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
13142 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
13143 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
13144 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
13146 compute_fringe_widths (f
, 0);
13148 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
13149 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
13151 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
13152 x_wm_set_size_hint (f
, (long) 0, 0);
13154 XSync (FRAME_X_DISPLAY (f
), False
);
13155 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13156 pixelwidth
, pixelheight
);
13158 /* Now, strictly speaking, we can't be sure that this is accurate,
13159 but the window manager will get around to dealing with the size
13160 change request eventually, and we'll hear how it went when the
13161 ConfigureNotify event gets here.
13163 We could just not bother storing any of this information here,
13164 and let the ConfigureNotify event set everything up, but that
13165 might be kind of confusing to the Lisp code, since size changes
13166 wouldn't be reported in the frame parameters until some random
13167 point in the future when the ConfigureNotify event arrives.
13169 We pass 1 for DELAY since we can't run Lisp code inside of
13171 change_frame_size (f
, rows
, cols
, 0, 1, 0);
13172 PIXEL_WIDTH (f
) = pixelwidth
;
13173 PIXEL_HEIGHT (f
) = pixelheight
;
13175 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
13176 receive in the ConfigureNotify event; if we get what we asked
13177 for, then the event won't cause the screen to become garbaged, so
13178 we have to make sure to do it here. */
13179 SET_FRAME_GARBAGED (f
);
13181 XFlush (FRAME_X_DISPLAY (f
));
13185 /* Call this to change the size of frame F's x-window.
13186 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
13187 for this size change and subsequent size changes.
13188 Otherwise we leave the window gravity unchanged. */
13191 x_set_window_size (f
, change_gravity
, cols
, rows
)
13193 int change_gravity
;
13199 if (FRAME_GTK_WIDGET (f
))
13200 xg_frame_set_char_size (f
, cols
, rows
);
13202 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13203 #elif USE_X_TOOLKIT
13205 if (f
->output_data
.x
->widget
!= NULL
)
13207 /* The x and y position of the widget is clobbered by the
13208 call to XtSetValues within EmacsFrameSetCharSize.
13209 This is a real kludge, but I don't understand Xt so I can't
13210 figure out a correct fix. Can anyone else tell me? -- rms. */
13211 int xpos
= f
->output_data
.x
->widget
->core
.x
;
13212 int ypos
= f
->output_data
.x
->widget
->core
.y
;
13213 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
13214 f
->output_data
.x
->widget
->core
.x
= xpos
;
13215 f
->output_data
.x
->widget
->core
.y
= ypos
;
13218 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13220 #else /* not USE_X_TOOLKIT */
13222 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13224 #endif /* not USE_X_TOOLKIT */
13226 /* If cursor was outside the new size, mark it as off. */
13227 mark_window_cursors_off (XWINDOW (f
->root_window
));
13229 /* Clear out any recollection of where the mouse highlighting was,
13230 since it might be in a place that's outside the new frame size.
13231 Actually checking whether it is outside is a pain in the neck,
13232 so don't try--just let the highlighting be done afresh with new size. */
13233 cancel_mouse_face (f
);
13238 /* Mouse warping. */
13241 x_set_mouse_position (f
, x
, y
)
13247 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
13248 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
13250 if (pix_x
< 0) pix_x
= 0;
13251 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
13253 if (pix_y
< 0) pix_y
= 0;
13254 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
13258 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13259 0, 0, 0, 0, pix_x
, pix_y
);
13263 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
13266 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
13272 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13273 0, 0, 0, 0, pix_x
, pix_y
);
13277 /* focus shifting, raising and lowering. */
13280 x_focus_on_frame (f
)
13283 #if 0 /* This proves to be unpleasant. */
13287 /* I don't think that the ICCCM allows programs to do things like this
13288 without the interaction of the window manager. Whatever you end up
13289 doing with this code, do it to x_unfocus_frame too. */
13290 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13291 RevertToPointerRoot
, CurrentTime
);
13296 x_unfocus_frame (f
)
13300 /* Look at the remarks in x_focus_on_frame. */
13301 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
13302 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
13303 RevertToPointerRoot
, CurrentTime
);
13307 /* Raise frame F. */
13313 if (f
->async_visible
)
13316 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
13317 XFlush (FRAME_X_DISPLAY (f
));
13322 /* Lower frame F. */
13328 if (f
->async_visible
)
13331 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
13332 XFlush (FRAME_X_DISPLAY (f
));
13338 XTframe_raise_lower (f
, raise_flag
)
13348 /* Change of visibility. */
13350 /* This tries to wait until the frame is really visible.
13351 However, if the window manager asks the user where to position
13352 the frame, this will return before the user finishes doing that.
13353 The frame will not actually be visible at that time,
13354 but it will become visible later when the window manager
13355 finishes with it. */
13358 x_make_frame_visible (f
)
13362 int original_top
, original_left
;
13363 int retry_count
= 2;
13369 type
= x_icon_type (f
);
13371 x_bitmap_icon (f
, type
);
13373 if (! FRAME_VISIBLE_P (f
))
13375 /* We test FRAME_GARBAGED_P here to make sure we don't
13376 call x_set_offset a second time
13377 if we get to x_make_frame_visible a second time
13378 before the window gets really visible. */
13379 if (! FRAME_ICONIFIED_P (f
)
13380 && ! f
->output_data
.x
->asked_for_visible
)
13381 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13383 f
->output_data
.x
->asked_for_visible
= 1;
13385 if (! EQ (Vx_no_window_manager
, Qt
))
13386 x_wm_set_window_state (f
, NormalState
);
13387 #ifdef USE_X_TOOLKIT
13388 /* This was XtPopup, but that did nothing for an iconified frame. */
13389 XtMapWidget (f
->output_data
.x
->widget
);
13390 #else /* not USE_X_TOOLKIT */
13392 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
13393 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
13395 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13396 #endif /* not USE_GTK */
13397 #endif /* not USE_X_TOOLKIT */
13398 #if 0 /* This seems to bring back scroll bars in the wrong places
13399 if the window configuration has changed. They seem
13400 to come back ok without this. */
13401 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
13402 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13406 XFlush (FRAME_X_DISPLAY (f
));
13408 /* Synchronize to ensure Emacs knows the frame is visible
13409 before we do anything else. We do this loop with input not blocked
13410 so that incoming events are handled. */
13414 /* This must be before UNBLOCK_INPUT
13415 since events that arrive in response to the actions above
13416 will set it when they are handled. */
13417 int previously_visible
= f
->output_data
.x
->has_been_visible
;
13419 original_left
= f
->output_data
.x
->left_pos
;
13420 original_top
= f
->output_data
.x
->top_pos
;
13422 /* This must come after we set COUNT. */
13425 /* We unblock here so that arriving X events are processed. */
13427 /* Now move the window back to where it was "supposed to be".
13428 But don't do it if the gravity is negative.
13429 When the gravity is negative, this uses a position
13430 that is 3 pixels too low. Perhaps that's really the border width.
13432 Don't do this if the window has never been visible before,
13433 because the window manager may choose the position
13434 and we don't want to override it. */
13436 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
13437 && f
->output_data
.x
->win_gravity
== NorthWestGravity
13438 && previously_visible
)
13442 unsigned int width
, height
, border
, depth
;
13446 /* On some window managers (such as FVWM) moving an existing
13447 window, even to the same place, causes the window manager
13448 to introduce an offset. This can cause the window to move
13449 to an unexpected location. Check the geometry (a little
13450 slow here) and then verify that the window is in the right
13451 place. If the window is not in the right place, move it
13452 there, and take the potential window manager hit. */
13453 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13454 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
13456 if (original_left
!= x
|| original_top
!= y
)
13457 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13458 original_left
, original_top
);
13463 XSETFRAME (frame
, f
);
13465 /* Wait until the frame is visible. Process X events until a
13466 MapNotify event has been seen, or until we think we won't get a
13467 MapNotify at all.. */
13468 for (count
= input_signal_count
+ 10;
13469 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
13471 /* Force processing of queued events. */
13474 /* Machines that do polling rather than SIGIO have been
13475 observed to go into a busy-wait here. So we'll fake an
13476 alarm signal to let the handler know that there's something
13477 to be read. We used to raise a real alarm, but it seems
13478 that the handler isn't always enabled here. This is
13480 if (input_polling_used ())
13482 /* It could be confusing if a real alarm arrives while
13483 processing the fake one. Turn it off and let the
13484 handler reset it. */
13485 extern void poll_for_input_1
P_ ((void));
13486 int old_poll_suppress_count
= poll_suppress_count
;
13487 poll_suppress_count
= 1;
13488 poll_for_input_1 ();
13489 poll_suppress_count
= old_poll_suppress_count
;
13492 /* See if a MapNotify event has been processed. */
13493 FRAME_SAMPLE_VISIBILITY (f
);
13498 (let ((f (selected-frame)))
13502 the frame is not raised with various window managers on
13503 FreeBSD, Linux and Solaris. It turns out that, for some
13504 unknown reason, the call to XtMapWidget is completely ignored.
13505 Mapping the widget a second time works. */
13507 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
13512 /* Change from mapped state to withdrawn state. */
13514 /* Make the frame visible (mapped and not iconified). */
13517 x_make_frame_invisible (f
)
13522 /* Use the frame's outermost window, not the one we normally draw on. */
13523 window
= FRAME_OUTER_WINDOW (f
);
13525 /* Don't keep the highlight on an invisible frame. */
13526 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13527 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13529 #if 0/* This might add unreliability; I don't trust it -- rms. */
13530 if (! f
->async_visible
&& ! f
->async_iconified
)
13536 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
13537 that the current position of the window is user-specified, rather than
13538 program-specified, so that when the window is mapped again, it will be
13539 placed at the same location, without forcing the user to position it
13540 by hand again (they have already done that once for this window.) */
13541 x_wm_set_size_hint (f
, (long) 0, 1);
13544 if (FRAME_GTK_OUTER_WIDGET (f
))
13546 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
13553 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
13554 DefaultScreen (FRAME_X_DISPLAY (f
))))
13556 UNBLOCK_INPUT_RESIGNAL
;
13557 error ("Can't notify window manager of window withdrawal");
13559 #else /* ! defined (HAVE_X11R4) */
13561 /* Tell the window manager what we're going to do. */
13562 if (! EQ (Vx_no_window_manager
, Qt
))
13566 unmap
.xunmap
.type
= UnmapNotify
;
13567 unmap
.xunmap
.window
= window
;
13568 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
13569 unmap
.xunmap
.from_configure
= False
;
13570 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13571 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13573 SubstructureRedirectMaskSubstructureNotifyMask
,
13576 UNBLOCK_INPUT_RESIGNAL
;
13577 error ("Can't notify window manager of withdrawal");
13581 /* Unmap the window ourselves. Cheeky! */
13582 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
13583 #endif /* ! defined (HAVE_X11R4) */
13586 /* We can't distinguish this from iconification
13587 just by the event that we get from the server.
13588 So we can't win using the usual strategy of letting
13589 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
13590 and synchronize with the server to make sure we agree. */
13592 FRAME_ICONIFIED_P (f
) = 0;
13593 f
->async_visible
= 0;
13594 f
->async_iconified
= 0;
13601 /* Change window state from mapped to iconified. */
13604 x_iconify_frame (f
)
13610 /* Don't keep the highlight on an invisible frame. */
13611 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13612 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13614 if (f
->async_iconified
)
13619 FRAME_SAMPLE_VISIBILITY (f
);
13621 type
= x_icon_type (f
);
13623 x_bitmap_icon (f
, type
);
13626 if (FRAME_GTK_OUTER_WIDGET (f
))
13628 if (! FRAME_VISIBLE_P (f
))
13629 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
13631 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
13634 f
->async_iconified
= 1;
13635 f
->async_visible
= 0;
13641 #ifdef USE_X_TOOLKIT
13643 if (! FRAME_VISIBLE_P (f
))
13645 if (! EQ (Vx_no_window_manager
, Qt
))
13646 x_wm_set_window_state (f
, IconicState
);
13647 /* This was XtPopup, but that did nothing for an iconified frame. */
13648 XtMapWidget (f
->output_data
.x
->widget
);
13649 /* The server won't give us any event to indicate
13650 that an invisible frame was changed to an icon,
13651 so we have to record it here. */
13654 f
->async_iconified
= 1;
13655 f
->async_visible
= 0;
13660 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
13661 XtWindow (f
->output_data
.x
->widget
),
13662 DefaultScreen (FRAME_X_DISPLAY (f
)));
13666 error ("Can't notify window manager of iconification");
13668 f
->async_iconified
= 1;
13669 f
->async_visible
= 0;
13673 XFlush (FRAME_X_DISPLAY (f
));
13675 #else /* not USE_X_TOOLKIT */
13677 /* Make sure the X server knows where the window should be positioned,
13678 in case the user deiconifies with the window manager. */
13679 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
13680 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13682 /* Since we don't know which revision of X we're running, we'll use both
13683 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
13685 /* X11R4: send a ClientMessage to the window manager using the
13686 WM_CHANGE_STATE type. */
13690 message
.xclient
.window
= FRAME_X_WINDOW (f
);
13691 message
.xclient
.type
= ClientMessage
;
13692 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
13693 message
.xclient
.format
= 32;
13694 message
.xclient
.data
.l
[0] = IconicState
;
13696 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13697 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13699 SubstructureRedirectMask
| SubstructureNotifyMask
,
13702 UNBLOCK_INPUT_RESIGNAL
;
13703 error ("Can't notify window manager of iconification");
13707 /* X11R3: set the initial_state field of the window manager hints to
13709 x_wm_set_window_state (f
, IconicState
);
13711 if (!FRAME_VISIBLE_P (f
))
13713 /* If the frame was withdrawn, before, we must map it. */
13714 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13717 f
->async_iconified
= 1;
13718 f
->async_visible
= 0;
13720 XFlush (FRAME_X_DISPLAY (f
));
13722 #endif /* not USE_X_TOOLKIT */
13726 /* Free X resources of frame F. */
13729 x_free_frame_resources (f
)
13732 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13734 struct scroll_bar
*b
;
13738 /* If a display connection is dead, don't try sending more
13739 commands to the X server. */
13740 if (dpyinfo
->display
)
13742 if (f
->output_data
.x
->icon_desc
)
13743 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
13745 #ifdef USE_X_TOOLKIT
13746 /* Explicitly destroy the scroll bars of the frame. Without
13747 this, we get "BadDrawable" errors from the toolkit later on,
13748 presumably from expose events generated for the disappearing
13749 toolkit scroll bars. */
13750 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
13752 b
= XSCROLL_BAR (bar
);
13753 x_scroll_bar_remove (b
);
13759 free_frame_xic (f
);
13762 #ifdef USE_X_TOOLKIT
13763 if (f
->output_data
.x
->widget
)
13765 XtDestroyWidget (f
->output_data
.x
->widget
);
13766 f
->output_data
.x
->widget
= NULL
;
13768 /* Tooltips don't have widgets, only a simple X window, even if
13769 we are using a toolkit. */
13770 else if (FRAME_X_WINDOW (f
))
13771 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13773 free_frame_menubar (f
);
13774 #else /* !USE_X_TOOLKIT */
13777 /* In the GTK version, tooltips are normal X
13778 frames. We must check and free both types. */
13779 if (FRAME_GTK_OUTER_WIDGET (f
))
13781 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
13782 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
13783 FRAME_GTK_OUTER_WIDGET (f
) = 0;
13785 #endif /* USE_GTK */
13787 if (FRAME_X_WINDOW (f
))
13788 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13789 #endif /* !USE_X_TOOLKIT */
13791 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
13792 unload_color (f
, f
->output_data
.x
->background_pixel
);
13793 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
13794 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
13795 unload_color (f
, f
->output_data
.x
->border_pixel
);
13796 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
13798 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
13799 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
13800 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
13801 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
13802 #ifdef USE_TOOLKIT_SCROLL_BARS
13803 /* Scrollbar shadow colors. */
13804 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
13805 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
13806 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
13807 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
13808 #endif /* USE_TOOLKIT_SCROLL_BARS */
13809 if (f
->output_data
.x
->white_relief
.allocated_p
)
13810 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
13811 if (f
->output_data
.x
->black_relief
.allocated_p
)
13812 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
13814 if (FRAME_FACE_CACHE (f
))
13815 free_frame_faces (f
);
13818 XFlush (FRAME_X_DISPLAY (f
));
13821 if (f
->output_data
.x
->saved_menu_event
)
13822 xfree (f
->output_data
.x
->saved_menu_event
);
13824 xfree (f
->output_data
.x
);
13825 f
->output_data
.x
= NULL
;
13827 if (f
== dpyinfo
->x_focus_frame
)
13828 dpyinfo
->x_focus_frame
= 0;
13829 if (f
== dpyinfo
->x_focus_event_frame
)
13830 dpyinfo
->x_focus_event_frame
= 0;
13831 if (f
== dpyinfo
->x_highlight_frame
)
13832 dpyinfo
->x_highlight_frame
= 0;
13834 if (f
== dpyinfo
->mouse_face_mouse_frame
)
13836 dpyinfo
->mouse_face_beg_row
13837 = dpyinfo
->mouse_face_beg_col
= -1;
13838 dpyinfo
->mouse_face_end_row
13839 = dpyinfo
->mouse_face_end_col
= -1;
13840 dpyinfo
->mouse_face_window
= Qnil
;
13841 dpyinfo
->mouse_face_deferred_gc
= 0;
13842 dpyinfo
->mouse_face_mouse_frame
= 0;
13849 /* Destroy the X window of frame F. */
13852 x_destroy_window (f
)
13855 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13857 /* If a display connection is dead, don't try sending more
13858 commands to the X server. */
13859 if (dpyinfo
->display
!= 0)
13860 x_free_frame_resources (f
);
13862 dpyinfo
->reference_count
--;
13866 /* Setting window manager hints. */
13868 /* Set the normal size hints for the window manager, for frame F.
13869 FLAGS is the flags word to use--or 0 meaning preserve the flags
13870 that the window now has.
13871 If USER_POSITION is nonzero, we set the USPosition
13872 flag (this is useful when FLAGS is 0).
13873 The GTK version is in gtkutils.c */
13877 x_wm_set_size_hint (f
, flags
, user_position
)
13882 XSizeHints size_hints
;
13884 #ifdef USE_X_TOOLKIT
13887 Dimension widget_width
, widget_height
;
13890 Window window
= FRAME_OUTER_WINDOW (f
);
13892 /* Setting PMaxSize caused various problems. */
13893 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
13895 size_hints
.x
= f
->output_data
.x
->left_pos
;
13896 size_hints
.y
= f
->output_data
.x
->top_pos
;
13898 #ifdef USE_X_TOOLKIT
13899 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
13900 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
13901 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
13902 size_hints
.height
= widget_height
;
13903 size_hints
.width
= widget_width
;
13904 #else /* not USE_X_TOOLKIT */
13905 size_hints
.height
= PIXEL_HEIGHT (f
);
13906 size_hints
.width
= PIXEL_WIDTH (f
);
13907 #endif /* not USE_X_TOOLKIT */
13909 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13910 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13911 size_hints
.max_width
13912 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13913 size_hints
.max_height
13914 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13916 /* Calculate the base and minimum sizes.
13918 (When we use the X toolkit, we don't do it here.
13919 Instead we copy the values that the widgets are using, below.) */
13920 #ifndef USE_X_TOOLKIT
13922 int base_width
, base_height
;
13923 int min_rows
= 0, min_cols
= 0;
13925 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13926 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13928 check_frame_size (f
, &min_rows
, &min_cols
);
13930 /* The window manager uses the base width hints to calculate the
13931 current number of rows and columns in the frame while
13932 resizing; min_width and min_height aren't useful for this
13933 purpose, since they might not give the dimensions for a
13934 zero-row, zero-column frame.
13936 We use the base_width and base_height members if we have
13937 them; otherwise, we set the min_width and min_height members
13938 to the size for a zero x zero frame. */
13941 size_hints
.flags
|= PBaseSize
;
13942 size_hints
.base_width
= base_width
;
13943 size_hints
.base_height
= base_height
;
13944 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13945 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13947 size_hints
.min_width
= base_width
;
13948 size_hints
.min_height
= base_height
;
13952 /* If we don't need the old flags, we don't need the old hint at all. */
13955 size_hints
.flags
|= flags
;
13958 #endif /* not USE_X_TOOLKIT */
13961 XSizeHints hints
; /* Sometimes I hate X Windows... */
13962 long supplied_return
;
13966 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13969 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13972 #ifdef USE_X_TOOLKIT
13973 size_hints
.base_height
= hints
.base_height
;
13974 size_hints
.base_width
= hints
.base_width
;
13975 size_hints
.min_height
= hints
.min_height
;
13976 size_hints
.min_width
= hints
.min_width
;
13980 size_hints
.flags
|= flags
;
13985 if (hints
.flags
& PSize
)
13986 size_hints
.flags
|= PSize
;
13987 if (hints
.flags
& PPosition
)
13988 size_hints
.flags
|= PPosition
;
13989 if (hints
.flags
& USPosition
)
13990 size_hints
.flags
|= USPosition
;
13991 if (hints
.flags
& USSize
)
13992 size_hints
.flags
|= USSize
;
13996 #ifndef USE_X_TOOLKIT
14001 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
14002 size_hints
.flags
|= PWinGravity
;
14006 size_hints
.flags
&= ~ PPosition
;
14007 size_hints
.flags
|= USPosition
;
14009 #endif /* PWinGravity */
14012 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
14014 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
14017 #endif /* not USE_GTK */
14019 /* Used for IconicState or NormalState */
14022 x_wm_set_window_state (f
, state
)
14026 #ifdef USE_X_TOOLKIT
14029 XtSetArg (al
[0], XtNinitialState
, state
);
14030 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
14031 #else /* not USE_X_TOOLKIT */
14032 Window window
= FRAME_X_WINDOW (f
);
14034 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
14035 f
->output_data
.x
->wm_hints
.initial_state
= state
;
14037 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
14038 #endif /* not USE_X_TOOLKIT */
14042 x_wm_set_icon_pixmap (f
, pixmap_id
)
14046 Pixmap icon_pixmap
;
14048 #ifndef USE_X_TOOLKIT
14049 Window window
= FRAME_OUTER_WINDOW (f
);
14054 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
14055 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
14059 /* It seems there is no way to turn off use of an icon pixmap.
14060 The following line does it, only if no icon has yet been created,
14061 for some window managers. But with mwm it crashes.
14062 Some people say it should clear the IconPixmapHint bit in this case,
14063 but that doesn't work, and the X consortium said it isn't the
14064 right thing at all. Since there is no way to win,
14065 best to explicitly give up. */
14067 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
14073 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
14077 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
14078 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
14081 #else /* not USE_X_TOOLKIT */
14083 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
14084 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
14086 #endif /* not USE_X_TOOLKIT */
14090 x_wm_set_icon_position (f
, icon_x
, icon_y
)
14092 int icon_x
, icon_y
;
14094 Window window
= FRAME_OUTER_WINDOW (f
);
14096 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
14097 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
14098 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
14100 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
14104 /***********************************************************************
14106 ***********************************************************************/
14108 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
14111 x_get_font_info (f
, font_idx
)
14115 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
14119 /* Return a list of names of available fonts matching PATTERN on frame F.
14121 If SIZE is > 0, it is the size (maximum bounds width) of fonts
14124 SIZE < 0 means include scalable fonts.
14126 Frame F null means we have not yet created any frame on X, and
14127 consult the first display in x_display_list. MAXNAMES sets a limit
14128 on how many fonts to match. */
14131 x_list_fonts (f
, pattern
, size
, maxnames
)
14133 Lisp_Object pattern
;
14137 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
14138 Lisp_Object tem
, second_best
;
14139 struct x_display_info
*dpyinfo
14140 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
14141 Display
*dpy
= dpyinfo
->display
;
14142 int try_XLoadQueryFont
= 0;
14144 int allow_scalable_fonts_p
= 0;
14148 allow_scalable_fonts_p
= 1;
14152 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
14153 if (NILP (patterns
))
14154 patterns
= Fcons (pattern
, Qnil
);
14156 if (maxnames
== 1 && !size
)
14157 /* We can return any single font matching PATTERN. */
14158 try_XLoadQueryFont
= 1;
14160 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
14163 char **names
= NULL
;
14165 pattern
= XCAR (patterns
);
14166 /* See if we cached the result for this particular query.
14167 The cache is an alist of the form:
14168 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
14169 tem
= XCDR (dpyinfo
->name_list_element
);
14170 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
14171 allow_scalable_fonts_p
? Qt
: Qnil
);
14172 list
= Fassoc (key
, tem
);
14175 list
= Fcdr_safe (list
);
14176 /* We have a cashed list. Don't have to get the list again. */
14180 /* At first, put PATTERN in the cache. */
14183 count
= x_catch_errors (dpy
);
14185 if (try_XLoadQueryFont
)
14188 unsigned long value
;
14190 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
14191 if (x_had_errors_p (dpy
))
14193 /* This error is perhaps due to insufficient memory on X
14194 server. Let's just ignore it. */
14196 x_clear_errors (dpy
);
14200 && XGetFontProperty (font
, XA_FONT
, &value
))
14202 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
14203 int len
= strlen (name
);
14206 /* If DXPC (a Differential X Protocol Compressor)
14207 Ver.3.7 is running, XGetAtomName will return null
14208 string. We must avoid such a name. */
14210 try_XLoadQueryFont
= 0;
14214 names
= (char **) alloca (sizeof (char *));
14215 /* Some systems only allow alloca assigned to a
14217 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
14218 bcopy (name
, names
[0], len
+ 1);
14223 try_XLoadQueryFont
= 0;
14226 XFreeFont (dpy
, font
);
14229 if (!try_XLoadQueryFont
)
14231 /* We try at least 10 fonts because XListFonts will return
14232 auto-scaled fonts at the head. */
14237 for (limit
= 500;;)
14239 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
14240 if (num_fonts
== limit
)
14243 XFreeFontNames (names
);
14252 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
14255 if (x_had_errors_p (dpy
))
14257 /* This error is perhaps due to insufficient memory on X
14258 server. Let's just ignore it. */
14260 x_clear_errors (dpy
);
14264 x_uncatch_errors (dpy
, count
);
14271 /* Make a list of all the fonts we got back.
14272 Store that in the font cache for the display. */
14273 for (i
= 0; i
< num_fonts
; i
++)
14276 char *p
= names
[i
];
14277 int average_width
= -1, dashes
= 0;
14279 /* Count the number of dashes in NAMES[I]. If there are
14280 14 dashes, and the field value following 12th dash
14281 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
14282 is usually too ugly to be used for editing. Let's
14288 if (dashes
== 7) /* PIXEL_SIZE field */
14290 else if (dashes
== 12) /* AVERAGE_WIDTH field */
14291 average_width
= atoi (p
);
14294 if (allow_scalable_fonts_p
14295 || dashes
< 14 || average_width
!= 0)
14297 tem
= build_string (names
[i
]);
14298 if (NILP (Fassoc (tem
, list
)))
14300 if (STRINGP (Vx_pixel_size_width_font_regexp
)
14301 && ((fast_c_string_match_ignore_case
14302 (Vx_pixel_size_width_font_regexp
, names
[i
]))
14304 /* We can set the value of PIXEL_SIZE to the
14305 width of this font. */
14306 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
14308 /* For the moment, width is not known. */
14309 list
= Fcons (Fcons (tem
, Qnil
), list
);
14314 if (!try_XLoadQueryFont
)
14317 XFreeFontNames (names
);
14322 /* Now store the result in the cache. */
14323 XSETCDR (dpyinfo
->name_list_element
,
14324 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
14327 if (NILP (list
)) continue; /* Try the remaining alternatives. */
14329 newlist
= second_best
= Qnil
;
14330 /* Make a list of the fonts that have the right width. */
14331 for (; CONSP (list
); list
= XCDR (list
))
14337 if (!CONSP (tem
) || NILP (XCAR (tem
)))
14341 newlist
= Fcons (XCAR (tem
), newlist
);
14345 if (!INTEGERP (XCDR (tem
)))
14347 /* Since we have not yet known the size of this font, we
14348 must try slow function call XLoadQueryFont. */
14349 XFontStruct
*thisinfo
;
14352 count
= x_catch_errors (dpy
);
14353 thisinfo
= XLoadQueryFont (dpy
,
14354 SDATA (XCAR (tem
)));
14355 if (x_had_errors_p (dpy
))
14357 /* This error is perhaps due to insufficient memory on X
14358 server. Let's just ignore it. */
14360 x_clear_errors (dpy
);
14362 x_uncatch_errors (dpy
, count
);
14368 (thisinfo
->min_bounds
.width
== 0
14370 : make_number (thisinfo
->max_bounds
.width
)));
14372 XFreeFont (dpy
, thisinfo
);
14376 /* For unknown reason, the previous call of XListFont had
14377 returned a font which can't be opened. Record the size
14378 as 0 not to try to open it again. */
14379 XSETCDR (tem
, make_number (0));
14382 found_size
= XINT (XCDR (tem
));
14383 if (found_size
== size
)
14384 newlist
= Fcons (XCAR (tem
), newlist
);
14385 else if (found_size
> 0)
14387 if (NILP (second_best
))
14389 else if (found_size
< size
)
14391 if (XINT (XCDR (second_best
)) > size
14392 || XINT (XCDR (second_best
)) < found_size
)
14397 if (XINT (XCDR (second_best
)) > size
14398 && XINT (XCDR (second_best
)) > found_size
)
14403 if (!NILP (newlist
))
14405 else if (!NILP (second_best
))
14407 newlist
= Fcons (XCAR (second_best
), Qnil
);
14418 /* Check that FONT is valid on frame F. It is if it can be found in F's
14422 x_check_font (f
, font
)
14427 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14429 xassert (font
!= NULL
);
14431 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14432 if (dpyinfo
->font_table
[i
].name
14433 && font
== dpyinfo
->font_table
[i
].font
)
14436 xassert (i
< dpyinfo
->n_fonts
);
14439 #endif /* GLYPH_DEBUG != 0 */
14441 /* Set *W to the minimum width, *H to the minimum font height of FONT.
14442 Note: There are (broken) X fonts out there with invalid XFontStruct
14443 min_bounds contents. For example, handa@etl.go.jp reports that
14444 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
14445 have font->min_bounds.width == 0. */
14448 x_font_min_bounds (font
, w
, h
)
14452 *h
= FONT_HEIGHT (font
);
14453 *w
= font
->min_bounds
.width
;
14455 /* Try to handle the case where FONT->min_bounds has invalid
14456 contents. Since the only font known to have invalid min_bounds
14457 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
14459 *w
= font
->max_bounds
.width
;
14463 /* Compute the smallest character width and smallest font height over
14464 all fonts available on frame F. Set the members smallest_char_width
14465 and smallest_font_height in F's x_display_info structure to
14466 the values computed. Value is non-zero if smallest_font_height or
14467 smallest_char_width become smaller than they were before. */
14470 x_compute_min_glyph_bounds (f
)
14474 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14476 int old_width
= dpyinfo
->smallest_char_width
;
14477 int old_height
= dpyinfo
->smallest_font_height
;
14479 dpyinfo
->smallest_font_height
= 100000;
14480 dpyinfo
->smallest_char_width
= 100000;
14482 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14483 if (dpyinfo
->font_table
[i
].name
)
14485 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
14488 font
= (XFontStruct
*) fontp
->font
;
14489 xassert (font
!= (XFontStruct
*) ~0);
14490 x_font_min_bounds (font
, &w
, &h
);
14492 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
14493 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
14496 xassert (dpyinfo
->smallest_char_width
> 0
14497 && dpyinfo
->smallest_font_height
> 0);
14499 return (dpyinfo
->n_fonts
== 1
14500 || dpyinfo
->smallest_char_width
< old_width
14501 || dpyinfo
->smallest_font_height
< old_height
);
14505 /* Load font named FONTNAME of the size SIZE for frame F, and return a
14506 pointer to the structure font_info while allocating it dynamically.
14507 If SIZE is 0, load any size of font.
14508 If loading is failed, return NULL. */
14511 x_load_font (f
, fontname
, size
)
14513 register char *fontname
;
14516 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14517 Lisp_Object font_names
;
14520 /* Get a list of all the fonts that match this name. Once we
14521 have a list of matching fonts, we compare them against the fonts
14522 we already have by comparing names. */
14523 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
14525 if (!NILP (font_names
))
14530 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14531 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
14532 if (dpyinfo
->font_table
[i
].name
14533 && (!strcmp (dpyinfo
->font_table
[i
].name
,
14534 SDATA (XCAR (tail
)))
14535 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
14536 SDATA (XCAR (tail
)))))
14537 return (dpyinfo
->font_table
+ i
);
14540 /* Load the font and add it to the table. */
14544 struct font_info
*fontp
;
14545 unsigned long value
;
14548 /* If we have found fonts by x_list_font, load one of them. If
14549 not, we still try to load a font by the name given as FONTNAME
14550 because XListFonts (called in x_list_font) of some X server has
14551 a bug of not finding a font even if the font surely exists and
14552 is loadable by XLoadQueryFont. */
14553 if (size
> 0 && !NILP (font_names
))
14554 fontname
= (char *) SDATA (XCAR (font_names
));
14557 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
14558 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
14559 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
14561 /* This error is perhaps due to insufficient memory on X
14562 server. Let's just ignore it. */
14564 x_clear_errors (FRAME_X_DISPLAY (f
));
14566 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
14571 /* Find a free slot in the font table. */
14572 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14573 if (dpyinfo
->font_table
[i
].name
== NULL
)
14576 /* If no free slot found, maybe enlarge the font table. */
14577 if (i
== dpyinfo
->n_fonts
14578 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
14581 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
14582 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
14583 dpyinfo
->font_table
14584 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
14587 fontp
= dpyinfo
->font_table
+ i
;
14588 if (i
== dpyinfo
->n_fonts
)
14589 ++dpyinfo
->n_fonts
;
14591 /* Now fill in the slots of *FONTP. */
14593 fontp
->font
= font
;
14594 fontp
->font_idx
= i
;
14595 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
14596 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
14598 /* Try to get the full name of FONT. Put it in FULL_NAME. */
14600 if (XGetFontProperty (font
, XA_FONT
, &value
))
14602 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
14606 /* Count the number of dashes in the "full name".
14607 If it is too few, this isn't really the font's full name,
14609 In X11R4, the fonts did not come with their canonical names
14620 full_name
= (char *) xmalloc (p
- name
+ 1);
14621 bcopy (name
, full_name
, p
- name
+ 1);
14627 if (full_name
!= 0)
14628 fontp
->full_name
= full_name
;
14630 fontp
->full_name
= fontp
->name
;
14632 fontp
->size
= font
->max_bounds
.width
;
14633 fontp
->height
= FONT_HEIGHT (font
);
14635 if (NILP (font_names
))
14637 /* We come here because of a bug of XListFonts mentioned at
14638 the head of this block. Let's store this information in
14639 the cache for x_list_fonts. */
14640 Lisp_Object lispy_name
= build_string (fontname
);
14641 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
14642 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
14645 XSETCDR (dpyinfo
->name_list_element
,
14647 Fcons (Fcons (lispy_full_name
,
14648 make_number (fontp
->size
)),
14650 XCDR (dpyinfo
->name_list_element
)));
14653 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
14655 XSETCDR (dpyinfo
->name_list_element
,
14657 Fcons (Fcons (lispy_full_name
,
14658 make_number (fontp
->size
)),
14660 XCDR (dpyinfo
->name_list_element
)));
14664 /* The slot `encoding' specifies how to map a character
14665 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
14666 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
14667 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
14668 2:0xA020..0xFF7F). For the moment, we don't know which charset
14669 uses this font. So, we set information in fontp->encoding[1]
14670 which is never used by any charset. If mapping can't be
14671 decided, set FONT_ENCODING_NOT_DECIDED. */
14673 = (font
->max_byte1
== 0
14675 ? (font
->min_char_or_byte2
< 0x80
14676 ? (font
->max_char_or_byte2
< 0x80
14677 ? 0 /* 0x20..0x7F */
14678 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
14679 : 1) /* 0xA0..0xFF */
14681 : (font
->min_byte1
< 0x80
14682 ? (font
->max_byte1
< 0x80
14683 ? (font
->min_char_or_byte2
< 0x80
14684 ? (font
->max_char_or_byte2
< 0x80
14685 ? 0 /* 0x2020..0x7F7F */
14686 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
14687 : 3) /* 0x20A0..0x7FFF */
14688 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
14689 : (font
->min_char_or_byte2
< 0x80
14690 ? (font
->max_char_or_byte2
< 0x80
14691 ? 2 /* 0xA020..0xFF7F */
14692 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
14693 : 1))); /* 0xA0A0..0xFFFF */
14695 fontp
->baseline_offset
14696 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
14697 ? (long) value
: 0);
14698 fontp
->relative_compose
14699 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
14700 ? (long) value
: 0);
14701 fontp
->default_ascent
14702 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
14703 ? (long) value
: 0);
14705 /* Set global flag fonts_changed_p to non-zero if the font loaded
14706 has a character with a smaller width than any other character
14707 before, or if the font loaded has a smaller height than any
14708 other font loaded before. If this happens, it will make a
14709 glyph matrix reallocation necessary. */
14710 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
14717 /* Return a pointer to struct font_info of a font named FONTNAME for
14718 frame F. If no such font is loaded, return NULL. */
14721 x_query_font (f
, fontname
)
14723 register char *fontname
;
14725 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14728 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14729 if (dpyinfo
->font_table
[i
].name
14730 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
14731 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
14732 return (dpyinfo
->font_table
+ i
);
14737 /* Find a CCL program for a font specified by FONTP, and set the member
14738 `encoder' of the structure. */
14741 x_find_ccl_program (fontp
)
14742 struct font_info
*fontp
;
14744 Lisp_Object list
, elt
;
14747 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
14751 && STRINGP (XCAR (elt
))
14752 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
14754 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
14761 struct ccl_program
*ccl
14762 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
14764 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
14767 fontp
->font_encoder
= ccl
;
14773 /***********************************************************************
14775 ***********************************************************************/
14777 #ifdef USE_X_TOOLKIT
14778 static XrmOptionDescRec emacs_options
[] = {
14779 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
14780 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
14782 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
14783 XrmoptionSepArg
, NULL
},
14784 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
14786 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14787 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14788 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14789 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14790 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14791 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
14792 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
14794 #endif /* USE_X_TOOLKIT */
14796 static int x_initialized
;
14798 #ifdef MULTI_KBOARD
14799 /* Test whether two display-name strings agree up to the dot that separates
14800 the screen number from the server number. */
14802 same_x_server (name1
, name2
)
14803 const char *name1
, *name2
;
14805 int seen_colon
= 0;
14806 const unsigned char *system_name
= SDATA (Vsystem_name
);
14807 int system_name_length
= strlen (system_name
);
14808 int length_until_period
= 0;
14810 while (system_name
[length_until_period
] != 0
14811 && system_name
[length_until_period
] != '.')
14812 length_until_period
++;
14814 /* Treat `unix' like an empty host name. */
14815 if (! strncmp (name1
, "unix:", 5))
14817 if (! strncmp (name2
, "unix:", 5))
14819 /* Treat this host's name like an empty host name. */
14820 if (! strncmp (name1
, system_name
, system_name_length
)
14821 && name1
[system_name_length
] == ':')
14822 name1
+= system_name_length
;
14823 if (! strncmp (name2
, system_name
, system_name_length
)
14824 && name2
[system_name_length
] == ':')
14825 name2
+= system_name_length
;
14826 /* Treat this host's domainless name like an empty host name. */
14827 if (! strncmp (name1
, system_name
, length_until_period
)
14828 && name1
[length_until_period
] == ':')
14829 name1
+= length_until_period
;
14830 if (! strncmp (name2
, system_name
, length_until_period
)
14831 && name2
[length_until_period
] == ':')
14832 name2
+= length_until_period
;
14834 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
14838 if (seen_colon
&& *name1
== '.')
14842 && (*name1
== '.' || *name1
== '\0')
14843 && (*name2
== '.' || *name2
== '\0'));
14847 struct x_display_info
*
14848 x_term_init (display_name
, xrm_option
, resource_name
)
14849 Lisp_Object display_name
;
14851 char *resource_name
;
14855 struct x_display_info
*dpyinfo
;
14860 if (!x_initialized
)
14868 #define NUM_ARGV 10
14870 char *argv
[NUM_ARGV
];
14871 char **argv2
= argv
;
14874 /* GTK 2.0 can only handle one display, GTK 2.2 can handle more
14875 than one, but this remains to be implemented. */
14876 if (x_initialized
> 1)
14881 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
14885 argv
[argc
++] = initial_argv
[0];
14887 if (! NILP (display_name
))
14889 argv
[argc
++] = "--display";
14890 argv
[argc
++] = SDATA (display_name
);
14893 argv
[argc
++] = "--name";
14894 argv
[argc
++] = resource_name
;
14897 XSetLocaleModifiers ("");
14900 gtk_init (&argc
, &argv2
);
14902 /* gtk_init does set_locale. We must fix locale after calling it. */
14906 dpy
= GDK_DISPLAY ();
14908 /* NULL window -> events for all windows go to our function */
14909 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
14911 /* Load our own gtkrc if it exists. */
14913 struct gcpro gcpro1
, gcpro2
;
14914 char *file
= "~/.emacs.d/gtkrc";
14915 Lisp_Object s
, abs_file
;
14917 GCPRO2 (s
, abs_file
);
14918 s
= make_string (file
, strlen (file
));
14919 abs_file
= Fexpand_file_name(s
, Qnil
);
14921 if (! NILP (abs_file
) && Ffile_readable_p (abs_file
))
14922 gtk_rc_parse (SDATA (abs_file
));
14927 XSetErrorHandler (x_error_handler
);
14928 XSetIOErrorHandler (x_io_error_quitter
);
14930 #else /* not USE_GTK */
14931 #ifdef USE_X_TOOLKIT
14932 /* weiner@footloose.sps.mot.com reports that this causes
14934 X protocol error: BadAtom (invalid Atom parameter)
14935 on protocol request 18skiloaf.
14936 So let's not use it until R6. */
14937 #ifdef HAVE_X11XTR6
14938 XtSetLanguageProc (NULL
, NULL
, NULL
);
14949 argv
[argc
++] = "-xrm";
14950 argv
[argc
++] = xrm_option
;
14952 turn_on_atimers (0);
14953 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
14954 resource_name
, EMACS_CLASS
,
14955 emacs_options
, XtNumber (emacs_options
),
14957 turn_on_atimers (1);
14959 #ifdef HAVE_X11XTR6
14960 /* I think this is to compensate for XtSetLanguageProc. */
14965 #else /* not USE_X_TOOLKIT */
14967 XSetLocaleModifiers ("");
14969 dpy
= XOpenDisplay (SDATA (display_name
));
14970 #endif /* not USE_X_TOOLKIT */
14971 #endif /* not USE_GTK*/
14973 /* Detect failure. */
14980 /* We have definitely succeeded. Record the new connection. */
14982 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
14983 bzero (dpyinfo
, sizeof *dpyinfo
);
14985 #ifdef MULTI_KBOARD
14987 struct x_display_info
*share
;
14990 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
14991 share
= share
->next
, tail
= XCDR (tail
))
14992 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
14993 SDATA (display_name
)))
14996 dpyinfo
->kboard
= share
->kboard
;
14999 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
15000 init_kboard (dpyinfo
->kboard
);
15001 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
15003 char *vendor
= ServerVendor (dpy
);
15005 dpyinfo
->kboard
->Vsystem_key_alist
15006 = call1 (Qvendor_specific_keysyms
,
15007 build_string (vendor
? vendor
: ""));
15011 dpyinfo
->kboard
->next_kboard
= all_kboards
;
15012 all_kboards
= dpyinfo
->kboard
;
15013 /* Don't let the initial kboard remain current longer than necessary.
15014 That would cause problems if a file loaded on startup tries to
15015 prompt in the mini-buffer. */
15016 if (current_kboard
== initial_kboard
)
15017 current_kboard
= dpyinfo
->kboard
;
15019 dpyinfo
->kboard
->reference_count
++;
15023 /* Put this display on the chain. */
15024 dpyinfo
->next
= x_display_list
;
15025 x_display_list
= dpyinfo
;
15027 /* Put it on x_display_name_list as well, to keep them parallel. */
15028 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
15029 x_display_name_list
);
15030 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
15032 dpyinfo
->display
= dpy
;
15035 XSetAfterFunction (x_current_display
, x_trace_wire
);
15039 = (char *) xmalloc (SBYTES (Vinvocation_name
)
15040 + SBYTES (Vsystem_name
)
15042 sprintf (dpyinfo
->x_id_name
, "%s@%s",
15043 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
15045 /* Figure out which modifier bits mean what. */
15046 x_find_modifier_meanings (dpyinfo
);
15048 /* Get the scroll bar cursor. */
15049 dpyinfo
->vertical_scroll_bar_cursor
15050 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
15052 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
15053 resource_name
, EMACS_CLASS
);
15054 #ifdef HAVE_XRMSETDATABASE
15055 XrmSetDatabase (dpyinfo
->display
, xrdb
);
15057 dpyinfo
->display
->db
= xrdb
;
15059 /* Put the rdb where we can find it in a way that works on
15061 dpyinfo
->xrdb
= xrdb
;
15063 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
15064 DefaultScreen (dpyinfo
->display
));
15065 select_visual (dpyinfo
);
15066 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
15067 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
15068 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
15069 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
15070 dpyinfo
->grabbed
= 0;
15071 dpyinfo
->reference_count
= 0;
15072 dpyinfo
->icon_bitmap_id
= -1;
15073 dpyinfo
->font_table
= NULL
;
15074 dpyinfo
->n_fonts
= 0;
15075 dpyinfo
->font_table_size
= 0;
15076 dpyinfo
->bitmaps
= 0;
15077 dpyinfo
->bitmaps_size
= 0;
15078 dpyinfo
->bitmaps_last
= 0;
15079 dpyinfo
->scratch_cursor_gc
= 0;
15080 dpyinfo
->mouse_face_mouse_frame
= 0;
15081 dpyinfo
->mouse_face_deferred_gc
= 0;
15082 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
15083 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
15084 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
15085 dpyinfo
->mouse_face_window
= Qnil
;
15086 dpyinfo
->mouse_face_overlay
= Qnil
;
15087 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
15088 dpyinfo
->mouse_face_defer
= 0;
15089 dpyinfo
->mouse_face_hidden
= 0;
15090 dpyinfo
->x_focus_frame
= 0;
15091 dpyinfo
->x_focus_event_frame
= 0;
15092 dpyinfo
->x_highlight_frame
= 0;
15093 dpyinfo
->image_cache
= make_image_cache ();
15095 /* See if a private colormap is requested. */
15096 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
15098 if (dpyinfo
->visual
->class == PseudoColor
)
15101 value
= display_x_get_resource (dpyinfo
,
15102 build_string ("privateColormap"),
15103 build_string ("PrivateColormap"),
15105 if (STRINGP (value
)
15106 && (!strcmp (SDATA (value
), "true")
15107 || !strcmp (SDATA (value
), "on")))
15108 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
15112 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
15113 dpyinfo
->visual
, AllocNone
);
15116 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
15117 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
15118 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
15119 dpyinfo
->resy
= pixels
* 25.4 / mm
;
15120 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
15121 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
15122 dpyinfo
->resx
= pixels
* 25.4 / mm
;
15125 dpyinfo
->Xatom_wm_protocols
15126 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
15127 dpyinfo
->Xatom_wm_take_focus
15128 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
15129 dpyinfo
->Xatom_wm_save_yourself
15130 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
15131 dpyinfo
->Xatom_wm_delete_window
15132 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
15133 dpyinfo
->Xatom_wm_change_state
15134 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
15135 dpyinfo
->Xatom_wm_configure_denied
15136 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
15137 dpyinfo
->Xatom_wm_window_moved
15138 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
15139 dpyinfo
->Xatom_editres
15140 = XInternAtom (dpyinfo
->display
, "Editres", False
);
15141 dpyinfo
->Xatom_CLIPBOARD
15142 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
15143 dpyinfo
->Xatom_TIMESTAMP
15144 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
15145 dpyinfo
->Xatom_TEXT
15146 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
15147 dpyinfo
->Xatom_COMPOUND_TEXT
15148 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
15149 dpyinfo
->Xatom_UTF8_STRING
15150 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
15151 dpyinfo
->Xatom_DELETE
15152 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
15153 dpyinfo
->Xatom_MULTIPLE
15154 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
15155 dpyinfo
->Xatom_INCR
15156 = XInternAtom (dpyinfo
->display
, "INCR", False
);
15157 dpyinfo
->Xatom_EMACS_TMP
15158 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
15159 dpyinfo
->Xatom_TARGETS
15160 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
15161 dpyinfo
->Xatom_NULL
15162 = XInternAtom (dpyinfo
->display
, "NULL", False
);
15163 dpyinfo
->Xatom_ATOM_PAIR
15164 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
15165 /* For properties of font. */
15166 dpyinfo
->Xatom_PIXEL_SIZE
15167 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
15168 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
15169 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
15170 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
15171 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
15172 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
15173 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
15175 /* Ghostscript support. */
15176 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
15177 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
15179 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
15182 dpyinfo
->cut_buffers_initialized
= 0;
15184 connection
= ConnectionNumber (dpyinfo
->display
);
15185 dpyinfo
->connection
= connection
;
15190 null_bits
[0] = 0x00;
15192 dpyinfo
->null_pixel
15193 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
15194 null_bits
, 1, 1, (long) 0, (long) 0,
15199 extern int gray_bitmap_width
, gray_bitmap_height
;
15200 extern char *gray_bitmap_bits
;
15202 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
15204 gray_bitmap_width
, gray_bitmap_height
,
15205 (unsigned long) 1, (unsigned long) 0, 1);
15209 xim_initialize (dpyinfo
, resource_name
);
15212 #ifdef subprocesses
15213 /* This is only needed for distinguishing keyboard and process input. */
15214 if (connection
!= 0)
15215 add_keyboard_wait_descriptor (connection
);
15218 #ifndef F_SETOWN_BUG
15220 #ifdef F_SETOWN_SOCK_NEG
15221 /* stdin is a socket here */
15222 fcntl (connection
, F_SETOWN
, -getpid ());
15223 #else /* ! defined (F_SETOWN_SOCK_NEG) */
15224 fcntl (connection
, F_SETOWN
, getpid ());
15225 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
15226 #endif /* ! defined (F_SETOWN) */
15227 #endif /* F_SETOWN_BUG */
15230 if (interrupt_input
)
15231 init_sigio (connection
);
15232 #endif /* ! defined (SIGIO) */
15235 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
15236 /* Make sure that we have a valid font for dialog boxes
15237 so that Xt does not crash. */
15239 Display
*dpy
= dpyinfo
->display
;
15240 XrmValue d
, fr
, to
;
15244 d
.addr
= (XPointer
)&dpy
;
15245 d
.size
= sizeof (Display
*);
15246 fr
.addr
= XtDefaultFont
;
15247 fr
.size
= sizeof (XtDefaultFont
);
15248 to
.size
= sizeof (Font
*);
15249 to
.addr
= (XPointer
)&font
;
15250 count
= x_catch_errors (dpy
);
15251 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
15253 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
15254 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
15255 x_uncatch_errors (dpy
, count
);
15260 /* See if we should run in synchronous mode. This is useful
15261 for debugging X code. */
15264 value
= display_x_get_resource (dpyinfo
,
15265 build_string ("synchronous"),
15266 build_string ("Synchronous"),
15268 if (STRINGP (value
)
15269 && (!strcmp (SDATA (value
), "true")
15270 || !strcmp (SDATA (value
), "on")))
15271 XSynchronize (dpyinfo
->display
, True
);
15279 /* Get rid of display DPYINFO, assuming all frames are already gone,
15280 and without sending any more commands to the X server. */
15283 x_delete_display (dpyinfo
)
15284 struct x_display_info
*dpyinfo
;
15286 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
15288 /* Discard this display from x_display_name_list and x_display_list.
15289 We can't use Fdelq because that can quit. */
15290 if (! NILP (x_display_name_list
)
15291 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
15292 x_display_name_list
= XCDR (x_display_name_list
);
15297 tail
= x_display_name_list
;
15298 while (CONSP (tail
) && CONSP (XCDR (tail
)))
15300 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
15302 XSETCDR (tail
, XCDR (XCDR (tail
)));
15305 tail
= XCDR (tail
);
15309 if (next_noop_dpyinfo
== dpyinfo
)
15310 next_noop_dpyinfo
= dpyinfo
->next
;
15312 if (x_display_list
== dpyinfo
)
15313 x_display_list
= dpyinfo
->next
;
15316 struct x_display_info
*tail
;
15318 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
15319 if (tail
->next
== dpyinfo
)
15320 tail
->next
= tail
->next
->next
;
15323 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
15324 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
15325 XrmDestroyDatabase (dpyinfo
->xrdb
);
15328 #ifdef MULTI_KBOARD
15329 if (--dpyinfo
->kboard
->reference_count
== 0)
15330 delete_kboard (dpyinfo
->kboard
);
15334 xim_close_dpy (dpyinfo
);
15337 xfree (dpyinfo
->font_table
);
15338 xfree (dpyinfo
->x_id_name
);
15339 xfree (dpyinfo
->color_cells
);
15344 /* Set up use of X before we make the first connection. */
15346 static struct redisplay_interface x_redisplay_interface
=
15351 x_clear_end_of_line
,
15353 x_after_update_window_line
,
15354 x_update_window_begin
,
15355 x_update_window_end
,
15358 x_clear_mouse_face
,
15359 x_get_glyph_overhangs
,
15360 x_fix_overlapping_area
,
15361 x_draw_fringe_bitmap
15367 rif
= &x_redisplay_interface
;
15369 clear_frame_hook
= x_clear_frame
;
15370 ins_del_lines_hook
= x_ins_del_lines
;
15371 delete_glyphs_hook
= x_delete_glyphs
;
15372 ring_bell_hook
= XTring_bell
;
15373 reset_terminal_modes_hook
= XTreset_terminal_modes
;
15374 set_terminal_modes_hook
= XTset_terminal_modes
;
15375 update_begin_hook
= x_update_begin
;
15376 update_end_hook
= x_update_end
;
15377 set_terminal_window_hook
= XTset_terminal_window
;
15378 read_socket_hook
= XTread_socket
;
15379 frame_up_to_date_hook
= XTframe_up_to_date
;
15380 mouse_position_hook
= XTmouse_position
;
15381 frame_rehighlight_hook
= XTframe_rehighlight
;
15382 frame_raise_lower_hook
= XTframe_raise_lower
;
15383 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
15384 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
15385 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
15386 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
15387 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
15389 scroll_region_ok
= 1; /* we'll scroll partial frames */
15390 char_ins_del_ok
= 1;
15391 line_ins_del_ok
= 1; /* we'll just blt 'em */
15392 fast_clear_end_of_line
= 1; /* X does this well */
15393 memory_below_frame
= 0; /* we don't remember what scrolls
15398 last_tool_bar_item
= -1;
15399 any_help_event_p
= 0;
15401 /* Try to use interrupt input; if we can't, then start polling. */
15402 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
15404 #ifdef USE_X_TOOLKIT
15405 XtToolkitInitialize ();
15407 Xt_app_con
= XtCreateApplicationContext ();
15409 /* Register a converter from strings to pixels, which uses
15410 Emacs' color allocation infrastructure. */
15411 XtAppSetTypeConverter (Xt_app_con
,
15412 XtRString
, XtRPixel
, cvt_string_to_pixel
,
15413 cvt_string_to_pixel_args
,
15414 XtNumber (cvt_string_to_pixel_args
),
15415 XtCacheByDisplay
, cvt_pixel_dtor
);
15417 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
15419 /* Install an asynchronous timer that processes Xt timeout events
15420 every 0.1s. This is necessary because some widget sets use
15421 timeouts internally, for example the LessTif menu bar, or the
15422 Xaw3d scroll bar. When Xt timouts aren't processed, these
15423 widgets don't behave normally. */
15425 EMACS_TIME interval
;
15426 EMACS_SET_SECS_USECS (interval
, 0, 100000);
15427 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
15431 #ifdef USE_TOOLKIT_SCROLL_BARS
15433 xaw3d_arrow_scroll
= False
;
15434 xaw3d_pick_top
= True
;
15438 /* Note that there is no real way portable across R3/R4 to get the
15439 original error handler. */
15440 XSetErrorHandler (x_error_handler
);
15441 XSetIOErrorHandler (x_io_error_quitter
);
15443 /* Disable Window Change signals; they are handled by X events. */
15445 signal (SIGWINCH
, SIG_DFL
);
15446 #endif /* SIGWINCH */
15448 signal (SIGPIPE
, x_connection_signal
);
15451 x_session_initialize ();
15459 staticpro (&x_error_message_string
);
15460 x_error_message_string
= Qnil
;
15462 staticpro (&x_display_name_list
);
15463 x_display_name_list
= Qnil
;
15465 staticpro (&last_mouse_scroll_bar
);
15466 last_mouse_scroll_bar
= Qnil
;
15468 staticpro (&Qvendor_specific_keysyms
);
15469 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
15471 staticpro (&Qutf_8
);
15472 Qutf_8
= intern ("utf-8");
15473 staticpro (&Qlatin_1
);
15474 Qlatin_1
= intern ("latin-1");
15476 staticpro (&last_mouse_press_frame
);
15477 last_mouse_press_frame
= Qnil
;
15480 staticpro (&help_echo
);
15481 help_echo_object
= Qnil
;
15482 staticpro (&help_echo_object
);
15483 help_echo_window
= Qnil
;
15484 staticpro (&help_echo_window
);
15485 previous_help_echo
= Qnil
;
15486 staticpro (&previous_help_echo
);
15487 help_echo_pos
= -1;
15489 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
15490 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
15491 mouse_autoselect_window
= 0;
15493 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
15494 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
15495 For example, if a block cursor is over a tab, it will be drawn as
15496 wide as that tab on the display. */);
15497 x_stretch_cursor_p
= 0;
15499 DEFVAR_BOOL ("x-use-underline-position-properties",
15500 &x_use_underline_position_properties
,
15501 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
15502 nil means ignore them. If you encounter fonts with bogus
15503 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
15504 to 4.1, set this to nil. */);
15505 x_use_underline_position_properties
= 1;
15507 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
15508 doc
: /* What X toolkit scroll bars Emacs uses.
15509 A value of nil means Emacs doesn't use X toolkit scroll bars.
15510 Otherwise, value is a symbol describing the X toolkit. */);
15511 #ifdef USE_TOOLKIT_SCROLL_BARS
15513 Vx_toolkit_scroll_bars
= intern ("motif");
15514 #elif defined HAVE_XAW3D
15515 Vx_toolkit_scroll_bars
= intern ("xaw3d");
15517 Vx_toolkit_scroll_bars
= intern ("gtk");
15519 Vx_toolkit_scroll_bars
= intern ("xaw");
15522 Vx_toolkit_scroll_bars
= Qnil
;
15525 staticpro (&last_mouse_motion_frame
);
15526 last_mouse_motion_frame
= Qnil
;
15528 Qmodifier_value
= intern ("modifier-value");
15529 Qalt
= intern ("alt");
15530 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
15531 Qhyper
= intern ("hyper");
15532 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
15533 Qmeta
= intern ("meta");
15534 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
15535 Qsuper
= intern ("super");
15536 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
15538 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
15539 doc
: /* Which keys Emacs uses for the alt modifier.
15540 This should be one of the symbols `alt', `hyper', `meta', `super'.
15541 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
15542 is nil, which is the same as `alt'. */);
15543 Vx_alt_keysym
= Qnil
;
15545 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
15546 doc
: /* Which keys Emacs uses for the hyper modifier.
15547 This should be one of the symbols `alt', `hyper', `meta', `super'.
15548 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
15549 default is nil, which is the same as `hyper'. */);
15550 Vx_hyper_keysym
= Qnil
;
15552 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
15553 doc
: /* Which keys Emacs uses for the meta modifier.
15554 This should be one of the symbols `alt', `hyper', `meta', `super'.
15555 For example, `meta' means use the Meta_L and Meta_R keysyms. The
15556 default is nil, which is the same as `meta'. */);
15557 Vx_meta_keysym
= Qnil
;
15559 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
15560 doc
: /* Which keys Emacs uses for the super modifier.
15561 This should be one of the symbols `alt', `hyper', `meta', `super'.
15562 For example, `super' means use the Super_L and Super_R keysyms. The
15563 default is nil, which is the same as `super'. */);
15564 Vx_super_keysym
= Qnil
;
15566 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
15567 doc
: /* Hash table of character codes indexed by X keysym codes. */);
15568 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
15569 make_float (DEFAULT_REHASH_SIZE
),
15570 make_float (DEFAULT_REHASH_THRESHOLD
),
15574 #endif /* HAVE_X_WINDOWS */