1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
74 #include "dispextern.h"
76 #include "termhooks.h"
88 #include "intervals.h"
93 #include <X11/Shell.h>
96 #ifdef HAVE_SYS_TIME_H
105 extern void free_frame_menubar
P_ ((struct frame
*));
106 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
109 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
111 extern void _XEditResCheckMessages ();
112 #endif /* not NO_EDITRES */
114 /* Include toolkit specific headers for the scroll bar widget. */
116 #ifdef USE_TOOLKIT_SCROLL_BARS
117 #if defined USE_MOTIF
118 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
119 #include <Xm/ScrollBar.h>
120 #else /* !USE_MOTIF i.e. use Xaw */
123 #include <X11/Xaw3d/Simple.h>
124 #include <X11/Xaw3d/Scrollbar.h>
125 #define ARROW_SCROLLBAR
126 #include <X11/Xaw3d/ScrollbarP.h>
127 #else /* !HAVE_XAW3D */
128 #include <X11/Xaw/Simple.h>
129 #include <X11/Xaw/Scrollbar.h>
130 #endif /* !HAVE_XAW3D */
132 #define XtNpickTop "pickTop"
133 #endif /* !XtNpickTop */
134 #endif /* !USE_MOTIF */
135 #endif /* USE_TOOLKIT_SCROLL_BARS */
137 #endif /* USE_X_TOOLKIT */
139 #ifndef USE_X_TOOLKIT
140 #define x_any_window_to_frame x_window_to_frame
141 #define x_top_window_to_frame x_window_to_frame
146 #ifndef XtNinitialState
147 #define XtNinitialState "initialState"
152 #define min(a,b) ((a) < (b) ? (a) : (b))
155 #define max(a,b) ((a) > (b) ? (a) : (b))
158 #define abs(x) ((x) < 0 ? -(x) : (x))
160 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
163 /* Bitmaps for truncated lines. */
168 LEFT_TRUNCATION_BITMAP
,
169 RIGHT_TRUNCATION_BITMAP
,
170 OVERLAY_ARROW_BITMAP
,
171 CONTINUED_LINE_BITMAP
,
172 CONTINUATION_LINE_BITMAP
,
176 /* Bitmap drawn to indicate lines not displaying text if
177 `indicate-empty-lines' is non-nil. */
181 static unsigned char zv_bits
[] = {
182 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
184 /* An arrow like this: `<-'. */
187 #define left_height 8
188 static unsigned char left_bits
[] = {
189 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
191 /* Right truncation arrow bitmap `->'. */
193 #define right_width 8
194 #define right_height 8
195 static unsigned char right_bits
[] = {
196 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
198 /* Marker for continued lines. */
200 #define continued_width 8
201 #define continued_height 8
202 static unsigned char continued_bits
[] = {
203 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
205 /* Marker for continuation lines. */
207 #define continuation_width 8
208 #define continuation_height 8
209 static unsigned char continuation_bits
[] = {
210 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
212 /* Overlay arrow bitmap. */
218 static unsigned char ov_bits
[] = {
219 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
221 /* A triangular arrow. */
224 static unsigned char ov_bits
[] = {
225 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
229 extern Lisp_Object Qhelp_echo
;
232 /* Non-nil means Emacs uses toolkit scroll bars. */
234 Lisp_Object Vx_toolkit_scroll_bars
;
236 /* If a string, XTread_socket generates an event to display that string.
237 (The display is done in read_char.) */
239 static Lisp_Object help_echo
;
240 static Lisp_Object help_echo_window
;
241 static Lisp_Object help_echo_object
;
242 static int help_echo_pos
;
244 /* Temporary variable for XTread_socket. */
246 static Lisp_Object previous_help_echo
;
248 /* Non-zero means that a HELP_EVENT has been generated since Emacs
251 static int any_help_event_p
;
253 /* Non-zero means draw block and hollow cursor as wide as the glyph
254 under it. For example, if a block cursor is over a tab, it will be
255 drawn as wide as that tab on the display. */
257 int x_stretch_cursor_p
;
259 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
261 int x_use_underline_position_properties
;
263 /* This is a chain of structures for all the X displays currently in
266 struct x_display_info
*x_display_list
;
268 /* This is a list of cons cells, each of the form (NAME
269 . FONT-LIST-CACHE), one for each element of x_display_list and in
270 the same order. NAME is the name of the frame. FONT-LIST-CACHE
271 records previous values returned by x-list-fonts. */
273 Lisp_Object x_display_name_list
;
275 /* Frame being updated by update_frame. This is declared in term.c.
276 This is set by update_begin and looked at by all the XT functions.
277 It is zero while not inside an update. In that case, the XT
278 functions assume that `selected_frame' is the frame to apply to. */
280 extern struct frame
*updating_frame
;
282 extern int waiting_for_input
;
284 /* This is a frame waiting to be auto-raised, within XTread_socket. */
286 struct frame
*pending_autoraise_frame
;
289 /* The application context for Xt use. */
290 XtAppContext Xt_app_con
;
291 static String Xt_default_resources
[] = {0};
292 #endif /* USE_X_TOOLKIT */
294 /* Nominal cursor position -- where to draw output.
295 HPOS and VPOS are window relative glyph matrix coordinates.
296 X and Y are window relative pixel coordinates. */
298 struct cursor_pos output_cursor
;
300 /* Non-zero means user is interacting with a toolkit scroll bar. */
302 static int toolkit_scroll_bar_interaction
;
306 Formerly, we used PointerMotionHintMask (in standard_event_mask)
307 so that we would have to call XQueryPointer after each MotionNotify
308 event to ask for another such event. However, this made mouse tracking
309 slow, and there was a bug that made it eventually stop.
311 Simply asking for MotionNotify all the time seems to work better.
313 In order to avoid asking for motion events and then throwing most
314 of them away or busy-polling the server for mouse positions, we ask
315 the server for pointer motion hints. This means that we get only
316 one event per group of mouse movements. "Groups" are delimited by
317 other kinds of events (focus changes and button clicks, for
318 example), or by XQueryPointer calls; when one of these happens, we
319 get another MotionNotify event the next time the mouse moves. This
320 is at least as efficient as getting motion events when mouse
321 tracking is on, and I suspect only negligibly worse when tracking
324 /* Where the mouse was last time we reported a mouse event. */
326 FRAME_PTR last_mouse_frame
;
327 static XRectangle last_mouse_glyph
;
328 static Lisp_Object last_mouse_press_frame
;
330 /* The scroll bar in which the last X motion event occurred.
332 If the last X motion event occurred in a scroll bar, we set this so
333 XTmouse_position can know whether to report a scroll bar motion or
336 If the last X motion event didn't occur in a scroll bar, we set
337 this to Qnil, to tell XTmouse_position to return an ordinary motion
340 static Lisp_Object last_mouse_scroll_bar
;
342 /* This is a hack. We would really prefer that XTmouse_position would
343 return the time associated with the position it returns, but there
344 doesn't seem to be any way to wrest the time-stamp from the server
345 along with the position query. So, we just keep track of the time
346 of the last movement we received, and return that in hopes that
347 it's somewhat accurate. */
349 static Time last_mouse_movement_time
;
351 /* Incremented by XTread_socket whenever it really tries to read
355 static int volatile input_signal_count
;
357 static int input_signal_count
;
360 /* Used locally within XTread_socket. */
362 static int x_noop_count
;
364 /* Initial values of argv and argc. */
366 extern char **initial_argv
;
367 extern int initial_argc
;
369 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
371 /* Tells if a window manager is present or not. */
373 extern Lisp_Object Vx_no_window_manager
;
375 extern Lisp_Object Qface
, Qmouse_face
;
379 /* A mask of extra modifier bits to put into every keyboard char. */
381 extern int extra_keyboard_modifiers
;
383 static Lisp_Object Qvendor_specific_keysyms
;
385 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
386 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
389 /* Enumeration for overriding/changing the face to use for drawing
390 glyphs in x_draw_glyphs. */
392 enum draw_glyphs_face
402 static int clear_mouse_face
P_ ((struct x_display_info
*));
403 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
404 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
405 static const XColor
*x_color_cells
P_ ((Display
*, int *));
406 static void x_update_window_end
P_ ((struct window
*, int, int));
407 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
408 void x_delete_display
P_ ((struct x_display_info
*));
409 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
411 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
413 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
414 int *, int *, int *, int *, int));
415 static void set_output_cursor
P_ ((struct cursor_pos
*));
416 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
417 int *, int *, int *, int));
418 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
419 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
420 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
421 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
422 static void show_mouse_face
P_ ((struct x_display_info
*,
423 enum draw_glyphs_face
));
424 static int x_io_error_quitter
P_ ((Display
*));
425 int x_catch_errors
P_ ((Display
*));
426 void x_uncatch_errors
P_ ((Display
*, int));
427 void x_lower_frame
P_ ((struct frame
*));
428 void x_scroll_bar_clear
P_ ((struct frame
*));
429 int x_had_errors_p
P_ ((Display
*));
430 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
431 void x_raise_frame
P_ ((struct frame
*));
432 void x_set_window_size
P_ ((struct frame
*, int, int, int));
433 void x_wm_set_window_state
P_ ((struct frame
*, int));
434 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
435 void x_initialize
P_ ((void));
436 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
437 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
438 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
440 enum draw_glyphs_face
));
441 static void x_update_end
P_ ((struct frame
*));
442 static void XTframe_up_to_date
P_ ((struct frame
*));
443 static void XTreassert_line_highlight
P_ ((int, int));
444 static void x_change_line_highlight
P_ ((int, int, int, int));
445 static void XTset_terminal_modes
P_ ((void));
446 static void XTreset_terminal_modes
P_ ((void));
447 static void XTcursor_to
P_ ((int, int, int, int));
448 static void x_write_glyphs
P_ ((struct glyph
*, int));
449 static void x_clear_end_of_line
P_ ((int));
450 static void x_clear_frame
P_ ((void));
451 static void x_clear_cursor
P_ ((struct window
*));
452 static void frame_highlight
P_ ((struct frame
*));
453 static void frame_unhighlight
P_ ((struct frame
*));
454 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
455 static void XTframe_rehighlight
P_ ((struct frame
*));
456 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
457 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
458 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
459 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
461 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
462 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
463 static int expose_window
P_ ((struct window
*, XRectangle
*));
464 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
465 XRectangle
*, enum glyph_row_area
));
466 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
468 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
469 static void x_update_window_cursor
P_ ((struct window
*, int));
470 static void x_erase_phys_cursor
P_ ((struct window
*));
471 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
472 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
475 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
477 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
478 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
479 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
480 static void x_flush
P_ ((struct frame
*f
));
481 static void x_update_begin
P_ ((struct frame
*));
482 static void x_update_window_begin
P_ ((struct window
*));
483 static void x_draw_vertical_border
P_ ((struct window
*));
484 static void x_after_update_window_line
P_ ((struct glyph_row
*));
485 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
486 static void x_produce_stretch_glyph
P_ ((struct it
*));
487 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
488 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
489 enum scroll_bar_part
*,
490 Lisp_Object
*, Lisp_Object
*,
493 /* Flush display of frame F, or of all frames if F is null. */
502 Lisp_Object rest
, frame
;
503 FOR_EACH_FRAME (rest
, frame
)
504 x_flush (XFRAME (frame
));
506 else if (FRAME_X_P (f
))
507 XFlush (FRAME_X_DISPLAY (f
));
512 /* Remove calls to XFlush by defining XFlush to an empty replacement.
513 Calls to XFlush should be unnecessary because the X output buffer
514 is flushed automatically as needed by calls to XPending,
515 XNextEvent, or XWindowEvent according to the XFlush man page.
516 XTread_socket calls XPending. Removing XFlush improves
519 #define XFlush(DISPLAY) (void) 0
522 /***********************************************************************
524 ***********************************************************************/
528 /* This is a function useful for recording debugging information about
529 the sequence of occurrences in this file. */
537 struct record event_record
[100];
539 int event_record_index
;
541 record_event (locus
, type
)
545 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
546 event_record_index
= 0;
548 event_record
[event_record_index
].locus
= locus
;
549 event_record
[event_record_index
].type
= type
;
550 event_record_index
++;
557 /* Return the struct x_display_info corresponding to DPY. */
559 struct x_display_info
*
560 x_display_info_for_display (dpy
)
563 struct x_display_info
*dpyinfo
;
565 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
566 if (dpyinfo
->display
== dpy
)
574 /***********************************************************************
575 Starting and ending an update
576 ***********************************************************************/
578 /* Start an update of frame F. This function is installed as a hook
579 for update_begin, i.e. it is called when update_begin is called.
580 This function is called prior to calls to x_update_window_begin for
581 each window being updated. Currently, there is nothing to do here
582 because all interesting stuff is done on a window basis. */
592 /* Start update of window W. Set the global variable updated_window
593 to the window being updated and set output_cursor to the cursor
597 x_update_window_begin (w
)
600 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
601 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
604 set_output_cursor (&w
->cursor
);
608 if (f
== display_info
->mouse_face_mouse_frame
)
610 /* Don't do highlighting for mouse motion during the update. */
611 display_info
->mouse_face_defer
= 1;
613 /* If F needs to be redrawn, simply forget about any prior mouse
615 if (FRAME_GARBAGED_P (f
))
616 display_info
->mouse_face_window
= Qnil
;
618 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
619 their mouse_face_p flag set, which means that they are always
620 unequal to rows in a desired matrix which never have that
621 flag set. So, rows containing mouse-face glyphs are never
622 scrolled, and we don't have to switch the mouse highlight off
623 here to prevent it from being scrolled. */
625 /* Can we tell that this update does not affect the window
626 where the mouse highlight is? If so, no need to turn off.
627 Likewise, don't do anything if the frame is garbaged;
628 in that case, the frame's current matrix that we would use
629 is all wrong, and we will redisplay that line anyway. */
630 if (!NILP (display_info
->mouse_face_window
)
631 && w
== XWINDOW (display_info
->mouse_face_window
))
635 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
636 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
639 if (i
< w
->desired_matrix
->nrows
)
640 clear_mouse_face (display_info
);
649 /* Draw a vertical window border to the right of window W if W doesn't
650 have vertical scroll bars. */
653 x_draw_vertical_border (w
)
656 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
658 /* Redraw borders between horizontally adjacent windows. Don't
659 do it for frames with vertical scroll bars because either the
660 right scroll bar of a window, or the left scroll bar of its
661 neighbor will suffice as a border. */
662 if (!WINDOW_RIGHTMOST_P (w
)
663 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
667 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
668 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
671 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
672 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
677 /* End update of window W (which is equal to updated_window).
679 Draw vertical borders between horizontally adjacent windows, and
680 display W's cursor if CURSOR_ON_P is non-zero.
682 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
683 glyphs in mouse-face were overwritten. In that case we have to
684 make sure that the mouse-highlight is properly redrawn.
686 W may be a menu bar pseudo-window in case we don't have X toolkit
687 support. Such windows don't have a cursor, so don't display it
691 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
693 int cursor_on_p
, mouse_face_overwritten_p
;
695 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
697 if (!w
->pseudo_window_p
)
702 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
704 output_cursor
.x
, output_cursor
.y
);
706 x_draw_vertical_border (w
);
710 /* If a row with mouse-face was overwritten, arrange for
711 XTframe_up_to_date to redisplay the mouse highlight. */
712 if (mouse_face_overwritten_p
)
714 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
715 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
716 dpyinfo
->mouse_face_window
= Qnil
;
719 updated_window
= NULL
;
723 /* End update of frame F. This function is installed as a hook in
730 /* Mouse highlight may be displayed again. */
731 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
734 XFlush (FRAME_X_DISPLAY (f
));
739 /* This function is called from various places in xdisp.c whenever a
740 complete update has been performed. The global variable
741 updated_window is not available here. */
744 XTframe_up_to_date (f
)
749 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
751 if (dpyinfo
->mouse_face_deferred_gc
752 || f
== dpyinfo
->mouse_face_mouse_frame
)
755 if (dpyinfo
->mouse_face_mouse_frame
)
756 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
757 dpyinfo
->mouse_face_mouse_x
,
758 dpyinfo
->mouse_face_mouse_y
);
759 dpyinfo
->mouse_face_deferred_gc
= 0;
766 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
767 arrow bitmaps, or clear the areas where they would be displayed
768 before DESIRED_ROW is made current. The window being updated is
769 found in updated_window. This function It is called from
770 update_window_line only if it is known that there are differences
771 between bitmaps to be drawn between current row and DESIRED_ROW. */
774 x_after_update_window_line (desired_row
)
775 struct glyph_row
*desired_row
;
777 struct window
*w
= updated_window
;
781 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
787 x_draw_row_bitmaps (w
, desired_row
);
789 /* When a window has disappeared, make sure that no rest of
790 full-width rows stays visible in the internal border. */
791 if (windows_or_buffers_changed
792 && (f
= XFRAME (w
->frame
),
793 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
796 int height
= desired_row
->visible_height
;
797 int x
= (window_box_right (w
, -1)
798 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
799 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
801 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
802 x
, y
, width
, height
, False
);
810 /* Draw the bitmap WHICH in one of the areas to the left or right of
811 window W. ROW is the glyph row for which to display the bitmap; it
812 determines the vertical position at which the bitmap has to be
816 x_draw_bitmap (w
, row
, which
)
818 struct glyph_row
*row
;
819 enum bitmap_type which
;
821 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
822 Display
*display
= FRAME_X_DISPLAY (f
);
823 Window window
= FRAME_X_WINDOW (f
);
827 GC gc
= f
->output_data
.x
->normal_gc
;
829 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
831 /* Must clip because of partially visible lines. */
832 x_clip_to_row (w
, row
, gc
, 1);
836 case LEFT_TRUNCATION_BITMAP
:
840 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
842 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
845 case OVERLAY_ARROW_BITMAP
:
849 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
851 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
854 case RIGHT_TRUNCATION_BITMAP
:
858 x
= window_box_right (w
, -1);
859 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
862 case CONTINUED_LINE_BITMAP
:
865 bits
= continued_bits
;
866 x
= window_box_right (w
, -1);
867 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
870 case CONTINUATION_LINE_BITMAP
:
871 wd
= continuation_width
;
872 h
= continuation_height
;
873 bits
= continuation_bits
;
874 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
876 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
883 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
885 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
892 /* Convert to frame coordinates. Set dy to the offset in the row to
893 start drawing the bitmap. */
894 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
895 dy
= (row
->height
- h
) / 2;
897 /* Draw the bitmap. I believe these small pixmaps can be cached
899 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
900 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
902 face
->background
, depth
);
903 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
904 XFreePixmap (display
, pixmap
);
905 XSetClipMask (display
, gc
, None
);
909 /* Draw flags bitmaps for glyph row ROW on window W. Call this
910 function with input blocked. */
913 x_draw_row_bitmaps (w
, row
)
915 struct glyph_row
*row
;
917 struct frame
*f
= XFRAME (w
->frame
);
918 enum bitmap_type bitmap
;
920 int header_line_height
= -1;
922 xassert (interrupt_input_blocked
);
924 /* If row is completely invisible, because of vscrolling, we
925 don't have to draw anything. */
926 if (row
->visible_height
<= 0)
929 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
930 PREPARE_FACE_FOR_DISPLAY (f
, face
);
932 /* Decide which bitmap to draw at the left side. */
933 if (row
->overlay_arrow_p
)
934 bitmap
= OVERLAY_ARROW_BITMAP
;
935 else if (row
->truncated_on_left_p
)
936 bitmap
= LEFT_TRUNCATION_BITMAP
;
937 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
938 bitmap
= CONTINUATION_LINE_BITMAP
;
939 else if (row
->indicate_empty_line_p
)
940 bitmap
= ZV_LINE_BITMAP
;
944 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
946 if (bitmap
== NO_BITMAP
947 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
948 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
950 /* If W has a vertical border to its left, don't draw over it. */
951 int border
= ((XFASTINT (w
->left
) > 0
952 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
954 int left
= window_box_left (w
, -1);
956 if (header_line_height
< 0)
957 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
959 /* In case the same realized face is used for bitmap areas and
960 for something displayed in the text (e.g. face `region' on
961 mono-displays, the fill style may have been changed to
962 FillSolid in x_draw_glyph_string_background. */
964 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
966 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
968 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
971 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
973 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
975 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
976 row
->visible_height
);
978 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
981 /* Draw the left bitmap. */
982 if (bitmap
!= NO_BITMAP
)
983 x_draw_bitmap (w
, row
, bitmap
);
985 /* Decide which bitmap to draw at the right side. */
986 if (row
->truncated_on_right_p
)
987 bitmap
= RIGHT_TRUNCATION_BITMAP
;
988 else if (row
->continued_p
)
989 bitmap
= CONTINUED_LINE_BITMAP
;
993 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
995 if (bitmap
== NO_BITMAP
996 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
997 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
999 int right
= window_box_right (w
, -1);
1001 if (header_line_height
< 0)
1002 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1004 /* In case the same realized face is used for bitmap areas and
1005 for something displayed in the text (e.g. face `region' on
1006 mono-displays, the fill style may have been changed to
1007 FillSolid in x_draw_glyph_string_background. */
1009 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1011 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1012 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1015 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1017 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
1018 row
->visible_height
);
1020 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1023 /* Draw the right bitmap. */
1024 if (bitmap
!= NO_BITMAP
)
1025 x_draw_bitmap (w
, row
, bitmap
);
1029 /***********************************************************************
1031 ***********************************************************************/
1033 /* External interface to control of standout mode. Not used for X
1034 frames. Aborts when called. */
1037 XTreassert_line_highlight (new, vpos
)
1044 /* Call this when about to modify line at position VPOS and change
1045 whether it is highlighted. Not used for X frames. Aborts when
1049 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1050 int new_highlight
, vpos
, y
, first_unused_hpos
;
1056 /* This is called when starting Emacs and when restarting after
1057 suspend. When starting Emacs, no X window is mapped. And nothing
1058 must be done to Emacs's own window if it is suspended (though that
1062 XTset_terminal_modes ()
1066 /* This is called when exiting or suspending Emacs. Exiting will make
1067 the X-windows go away, and suspending requires no action. */
1070 XTreset_terminal_modes ()
1076 /***********************************************************************
1078 ***********************************************************************/
1080 /* Set the global variable output_cursor to CURSOR. All cursor
1081 positions are relative to updated_window. */
1084 set_output_cursor (cursor
)
1085 struct cursor_pos
*cursor
;
1087 output_cursor
.hpos
= cursor
->hpos
;
1088 output_cursor
.vpos
= cursor
->vpos
;
1089 output_cursor
.x
= cursor
->x
;
1090 output_cursor
.y
= cursor
->y
;
1094 /* Set a nominal cursor position.
1096 HPOS and VPOS are column/row positions in a window glyph matrix. X
1097 and Y are window text area relative pixel positions.
1099 If this is done during an update, updated_window will contain the
1100 window that is being updated and the position is the future output
1101 cursor position for that window. If updated_window is null, use
1102 selected_window and display the cursor at the given position. */
1105 XTcursor_to (vpos
, hpos
, y
, x
)
1106 int vpos
, hpos
, y
, x
;
1110 /* If updated_window is not set, work on selected_window. */
1114 w
= XWINDOW (selected_window
);
1116 /* Set the output cursor. */
1117 output_cursor
.hpos
= hpos
;
1118 output_cursor
.vpos
= vpos
;
1119 output_cursor
.x
= x
;
1120 output_cursor
.y
= y
;
1122 /* If not called as part of an update, really display the cursor.
1123 This will also set the cursor position of W. */
1124 if (updated_window
== NULL
)
1127 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1128 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1135 /***********************************************************************
1137 ***********************************************************************/
1139 /* Function prototypes of this page. */
1141 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1145 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1146 int, XChar2b
*, int));
1147 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1148 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1149 static void x_append_glyph
P_ ((struct it
*));
1150 static void x_append_composite_glyph
P_ ((struct it
*));
1151 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1153 static void x_produce_glyphs
P_ ((struct it
*));
1154 static void x_produce_image_glyph
P_ ((struct it
*it
));
1157 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1158 is not contained in the font. */
1160 static INLINE XCharStruct
*
1161 x_per_char_metric (font
, char2b
)
1165 /* The result metric information. */
1166 XCharStruct
*pcm
= NULL
;
1168 xassert (font
&& char2b
);
1170 if (font
->per_char
!= NULL
)
1172 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1174 /* min_char_or_byte2 specifies the linear character index
1175 corresponding to the first element of the per_char array,
1176 max_char_or_byte2 is the index of the last character. A
1177 character with non-zero CHAR2B->byte1 is not in the font.
1178 A character with byte2 less than min_char_or_byte2 or
1179 greater max_char_or_byte2 is not in the font. */
1180 if (char2b
->byte1
== 0
1181 && char2b
->byte2
>= font
->min_char_or_byte2
1182 && char2b
->byte2
<= font
->max_char_or_byte2
)
1183 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1187 /* If either min_byte1 or max_byte1 are nonzero, both
1188 min_char_or_byte2 and max_char_or_byte2 are less than
1189 256, and the 2-byte character index values corresponding
1190 to the per_char array element N (counting from 0) are:
1192 byte1 = N/D + min_byte1
1193 byte2 = N\D + min_char_or_byte2
1197 D = max_char_or_byte2 - min_char_or_byte2 + 1
1198 / = integer division
1199 \ = integer modulus */
1200 if (char2b
->byte1
>= font
->min_byte1
1201 && char2b
->byte1
<= font
->max_byte1
1202 && char2b
->byte2
>= font
->min_char_or_byte2
1203 && char2b
->byte2
<= font
->max_char_or_byte2
)
1205 pcm
= (font
->per_char
1206 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1207 * (char2b
->byte1
- font
->min_byte1
))
1208 + (char2b
->byte2
- font
->min_char_or_byte2
));
1214 /* If the per_char pointer is null, all glyphs between the first
1215 and last character indexes inclusive have the same
1216 information, as given by both min_bounds and max_bounds. */
1217 if (char2b
->byte2
>= font
->min_char_or_byte2
1218 && char2b
->byte2
<= font
->max_char_or_byte2
)
1219 pcm
= &font
->max_bounds
;
1222 return ((pcm
== NULL
1223 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1228 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1229 the two-byte form of C. Encoding is returned in *CHAR2B. */
1232 x_encode_char (c
, char2b
, font_info
)
1235 struct font_info
*font_info
;
1237 int charset
= CHAR_CHARSET (c
);
1238 XFontStruct
*font
= font_info
->font
;
1240 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1241 This may be either a program in a special encoder language or a
1243 if (font_info
->font_encoder
)
1245 /* It's a program. */
1246 struct ccl_program
*ccl
= font_info
->font_encoder
;
1248 if (CHARSET_DIMENSION (charset
) == 1)
1250 ccl
->reg
[0] = charset
;
1251 ccl
->reg
[1] = char2b
->byte2
;
1255 ccl
->reg
[0] = charset
;
1256 ccl
->reg
[1] = char2b
->byte1
;
1257 ccl
->reg
[2] = char2b
->byte2
;
1260 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1262 /* We assume that MSBs are appropriately set/reset by CCL
1264 if (font
->max_byte1
== 0) /* 1-byte font */
1265 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1267 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1269 else if (font_info
->encoding
[charset
])
1271 /* Fixed encoding scheme. See fontset.h for the meaning of the
1272 encoding numbers. */
1273 int enc
= font_info
->encoding
[charset
];
1275 if ((enc
== 1 || enc
== 2)
1276 && CHARSET_DIMENSION (charset
) == 2)
1277 char2b
->byte1
|= 0x80;
1279 if (enc
== 1 || enc
== 3)
1280 char2b
->byte2
|= 0x80;
1285 /* Get face and two-byte form of character C in face FACE_ID on frame
1286 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1287 means we want to display multibyte text. Value is a pointer to a
1288 realized face that is ready for display. */
1290 static INLINE
struct face
*
1291 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1297 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1301 /* Unibyte case. We don't have to encode, but we have to make
1302 sure to use a face suitable for unibyte. */
1305 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1306 face
= FACE_FROM_ID (f
, face_id
);
1308 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1310 /* Case of ASCII in a face known to fit ASCII. */
1316 int c1
, c2
, charset
;
1318 /* Split characters into bytes. If c2 is -1 afterwards, C is
1319 really a one-byte character so that byte1 is zero. */
1320 SPLIT_CHAR (c
, charset
, c1
, c2
);
1322 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1324 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1326 /* Maybe encode the character in *CHAR2B. */
1327 if (face
->font
!= NULL
)
1329 struct font_info
*font_info
1330 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1332 x_encode_char (c
, char2b
, font_info
);
1336 /* Make sure X resources of the face are allocated. */
1337 xassert (face
!= NULL
);
1338 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1344 /* Get face and two-byte form of character glyph GLYPH on frame F.
1345 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1346 a pointer to a realized face that is ready for display. */
1348 static INLINE
struct face
*
1349 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1351 struct glyph
*glyph
;
1357 xassert (glyph
->type
== CHAR_GLYPH
);
1358 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1363 if (!glyph
->multibyte_p
)
1365 /* Unibyte case. We don't have to encode, but we have to make
1366 sure to use a face suitable for unibyte. */
1368 char2b
->byte2
= glyph
->u
.ch
;
1370 else if (glyph
->u
.ch
< 128
1371 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1373 /* Case of ASCII in a face known to fit ASCII. */
1375 char2b
->byte2
= glyph
->u
.ch
;
1379 int c1
, c2
, charset
;
1381 /* Split characters into bytes. If c2 is -1 afterwards, C is
1382 really a one-byte character so that byte1 is zero. */
1383 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1385 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1387 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1389 /* Maybe encode the character in *CHAR2B. */
1390 if (charset
!= CHARSET_ASCII
)
1392 struct font_info
*font_info
1393 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1396 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1399 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1404 /* Make sure X resources of the face are allocated. */
1405 xassert (face
!= NULL
);
1406 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1411 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1412 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1418 struct glyph
*glyph
;
1419 enum glyph_row_area area
= it
->area
;
1421 xassert (it
->glyph_row
);
1422 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1424 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1425 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1427 glyph
->charpos
= CHARPOS (it
->position
);
1428 glyph
->object
= it
->object
;
1429 glyph
->pixel_width
= it
->pixel_width
;
1430 glyph
->voffset
= it
->voffset
;
1431 glyph
->type
= CHAR_GLYPH
;
1432 glyph
->multibyte_p
= it
->multibyte_p
;
1433 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1434 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1435 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1436 || it
->phys_descent
> it
->descent
);
1437 glyph
->padding_p
= 0;
1438 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1439 glyph
->face_id
= it
->face_id
;
1440 glyph
->u
.ch
= it
->char_to_display
;
1441 ++it
->glyph_row
->used
[area
];
1445 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1446 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1449 x_append_composite_glyph (it
)
1452 struct glyph
*glyph
;
1453 enum glyph_row_area area
= it
->area
;
1455 xassert (it
->glyph_row
);
1457 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1458 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1460 glyph
->charpos
= CHARPOS (it
->position
);
1461 glyph
->object
= it
->object
;
1462 glyph
->pixel_width
= it
->pixel_width
;
1463 glyph
->voffset
= it
->voffset
;
1464 glyph
->type
= COMPOSITE_GLYPH
;
1465 glyph
->multibyte_p
= it
->multibyte_p
;
1466 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1467 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1468 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1469 || it
->phys_descent
> it
->descent
);
1470 glyph
->padding_p
= 0;
1471 glyph
->glyph_not_available_p
= 0;
1472 glyph
->face_id
= it
->face_id
;
1473 glyph
->u
.cmp_id
= it
->cmp_id
;
1474 ++it
->glyph_row
->used
[area
];
1479 /* Change IT->ascent and IT->height according to the setting of
1483 take_vertical_position_into_account (it
)
1488 if (it
->voffset
< 0)
1489 /* Increase the ascent so that we can display the text higher
1491 it
->ascent
+= abs (it
->voffset
);
1493 /* Increase the descent so that we can display the text lower
1495 it
->descent
+= it
->voffset
;
1500 /* Produce glyphs/get display metrics for the image IT is loaded with.
1501 See the description of struct display_iterator in dispextern.h for
1502 an overview of struct display_iterator. */
1505 x_produce_image_glyph (it
)
1511 xassert (it
->what
== IT_IMAGE
);
1513 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1514 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1517 /* Make sure X resources of the face and image are loaded. */
1518 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1519 prepare_image_for_display (it
->f
, img
);
1521 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1522 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1523 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1527 if (face
->box
!= FACE_NO_BOX
)
1529 if (face
->box_line_width
> 0)
1531 it
->ascent
+= face
->box_line_width
;
1532 it
->descent
+= face
->box_line_width
;
1535 if (it
->start_of_box_run_p
)
1536 it
->pixel_width
+= abs (face
->box_line_width
);
1537 if (it
->end_of_box_run_p
)
1538 it
->pixel_width
+= abs (face
->box_line_width
);
1541 take_vertical_position_into_account (it
);
1545 struct glyph
*glyph
;
1546 enum glyph_row_area area
= it
->area
;
1548 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1549 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1551 glyph
->charpos
= CHARPOS (it
->position
);
1552 glyph
->object
= it
->object
;
1553 glyph
->pixel_width
= it
->pixel_width
;
1554 glyph
->voffset
= it
->voffset
;
1555 glyph
->type
= IMAGE_GLYPH
;
1556 glyph
->multibyte_p
= it
->multibyte_p
;
1557 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1558 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1559 glyph
->overlaps_vertically_p
= 0;
1560 glyph
->padding_p
= 0;
1561 glyph
->glyph_not_available_p
= 0;
1562 glyph
->face_id
= it
->face_id
;
1563 glyph
->u
.img_id
= img
->id
;
1564 ++it
->glyph_row
->used
[area
];
1570 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1571 of the glyph, WIDTH and HEIGHT are the width and height of the
1572 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1573 ascent of the glyph (0 <= ASCENT <= 1). */
1576 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1582 struct glyph
*glyph
;
1583 enum glyph_row_area area
= it
->area
;
1585 xassert (ascent
>= 0 && ascent
<= 1);
1587 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1588 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1590 glyph
->charpos
= CHARPOS (it
->position
);
1591 glyph
->object
= object
;
1592 glyph
->pixel_width
= width
;
1593 glyph
->voffset
= it
->voffset
;
1594 glyph
->type
= STRETCH_GLYPH
;
1595 glyph
->multibyte_p
= it
->multibyte_p
;
1596 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1597 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1598 glyph
->overlaps_vertically_p
= 0;
1599 glyph
->padding_p
= 0;
1600 glyph
->glyph_not_available_p
= 0;
1601 glyph
->face_id
= it
->face_id
;
1602 glyph
->u
.stretch
.ascent
= height
* ascent
;
1603 glyph
->u
.stretch
.height
= height
;
1604 ++it
->glyph_row
->used
[area
];
1609 /* Produce a stretch glyph for iterator IT. IT->object is the value
1610 of the glyph property displayed. The value must be a list
1611 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1614 1. `:width WIDTH' specifies that the space should be WIDTH *
1615 canonical char width wide. WIDTH may be an integer or floating
1618 2. `:relative-width FACTOR' specifies that the width of the stretch
1619 should be computed from the width of the first character having the
1620 `glyph' property, and should be FACTOR times that width.
1622 3. `:align-to HPOS' specifies that the space should be wide enough
1623 to reach HPOS, a value in canonical character units.
1625 Exactly one of the above pairs must be present.
1627 4. `:height HEIGHT' specifies that the height of the stretch produced
1628 should be HEIGHT, measured in canonical character units.
1630 5. `:relative-height FACTOR' specifies that the height of the the
1631 stretch should be FACTOR times the height of the characters having
1634 Either none or exactly one of 4 or 5 must be present.
1636 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1637 of the stretch should be used for the ascent of the stretch.
1638 ASCENT must be in the range 0 <= ASCENT <= 100. */
1641 ((INTEGERP (X) || FLOATP (X)) \
1647 x_produce_stretch_glyph (it
)
1650 /* (space :width WIDTH :height HEIGHT. */
1652 extern Lisp_Object Qspace
;
1654 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1655 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1656 extern Lisp_Object QCalign_to
;
1657 Lisp_Object prop
, plist
;
1658 double width
= 0, height
= 0, ascent
= 0;
1659 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1660 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1662 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1664 /* List should start with `space'. */
1665 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1666 plist
= XCDR (it
->object
);
1668 /* Compute the width of the stretch. */
1669 if (prop
= Fplist_get (plist
, QCwidth
),
1671 /* Absolute width `:width WIDTH' specified and valid. */
1672 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1673 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1676 /* Relative width `:relative-width FACTOR' specified and valid.
1677 Compute the width of the characters having the `glyph'
1680 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1683 if (it
->multibyte_p
)
1685 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1686 - IT_BYTEPOS (*it
));
1687 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1690 it2
.c
= *p
, it2
.len
= 1;
1692 it2
.glyph_row
= NULL
;
1693 it2
.what
= IT_CHARACTER
;
1694 x_produce_glyphs (&it2
);
1695 width
= NUMVAL (prop
) * it2
.pixel_width
;
1697 else if (prop
= Fplist_get (plist
, QCalign_to
),
1699 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1701 /* Nothing specified -> width defaults to canonical char width. */
1702 width
= CANON_X_UNIT (it
->f
);
1704 /* Compute height. */
1705 if (prop
= Fplist_get (plist
, QCheight
),
1707 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1708 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1710 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1712 height
= FONT_HEIGHT (font
);
1714 /* Compute percentage of height used for ascent. If
1715 `:ascent ASCENT' is present and valid, use that. Otherwise,
1716 derive the ascent from the font in use. */
1717 if (prop
= Fplist_get (plist
, QCascent
),
1718 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1719 ascent
= NUMVAL (prop
) / 100.0;
1721 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1730 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1731 if (!STRINGP (object
))
1732 object
= it
->w
->buffer
;
1733 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1736 it
->pixel_width
= width
;
1737 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1738 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1741 if (face
->box
!= FACE_NO_BOX
)
1743 if (face
->box_line_width
> 0)
1745 it
->ascent
+= face
->box_line_width
;
1746 it
->descent
+= face
->box_line_width
;
1749 if (it
->start_of_box_run_p
)
1750 it
->pixel_width
+= abs (face
->box_line_width
);
1751 if (it
->end_of_box_run_p
)
1752 it
->pixel_width
+= abs (face
->box_line_width
);
1755 take_vertical_position_into_account (it
);
1758 /* Return proper value to be used as baseline offset of font that has
1759 ASCENT and DESCENT to draw characters by the font at the vertical
1760 center of the line of frame F.
1762 Here, out task is to find the value of BOFF in the following figure;
1764 -------------------------+-----------+-
1765 -+-+---------+-+ | |
1767 | | | | F_ASCENT F_HEIGHT
1770 | | |-|-+------+-----------|------- baseline
1772 | |---------|-+-+ | |
1774 -+-+---------+-+ F_DESCENT |
1775 -------------------------+-----------+-
1777 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1778 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1779 DESCENT = FONT->descent
1780 HEIGHT = FONT_HEIGHT (FONT)
1781 F_DESCENT = (F->output_data.x->font->descent
1782 - F->output_data.x->baseline_offset)
1783 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1786 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1788 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1789 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1790 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1792 /* Produce glyphs/get display metrics for the display element IT is
1793 loaded with. See the description of struct display_iterator in
1794 dispextern.h for an overview of struct display_iterator. */
1797 x_produce_glyphs (it
)
1800 it
->glyph_not_available_p
= 0;
1802 if (it
->what
== IT_CHARACTER
)
1806 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1808 int font_not_found_p
;
1809 struct font_info
*font_info
;
1810 int boff
; /* baseline offset */
1811 /* We may change it->multibyte_p upon unibyte<->multibyte
1812 conversion. So, save the current value now and restore it
1815 Note: It seems that we don't have to record multibyte_p in
1816 struct glyph because the character code itself tells if or
1817 not the character is multibyte. Thus, in the future, we must
1818 consider eliminating the field `multibyte_p' in the struct
1821 int saved_multibyte_p
= it
->multibyte_p
;
1823 /* Maybe translate single-byte characters to multibyte, or the
1825 it
->char_to_display
= it
->c
;
1826 if (!ASCII_BYTE_P (it
->c
))
1828 if (unibyte_display_via_language_environment
1829 && SINGLE_BYTE_CHAR_P (it
->c
)
1831 || !NILP (Vnonascii_translation_table
)))
1833 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1834 it
->multibyte_p
= 1;
1835 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1836 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1838 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1839 && !it
->multibyte_p
)
1841 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1842 it
->multibyte_p
= 0;
1843 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1844 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1848 /* Get font to use. Encode IT->char_to_display. */
1849 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1850 it
->face_id
, &char2b
,
1854 /* When no suitable font found, use the default font. */
1855 font_not_found_p
= font
== NULL
;
1856 if (font_not_found_p
)
1858 font
= FRAME_FONT (it
->f
);
1859 boff
= it
->f
->output_data
.x
->baseline_offset
;
1864 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1865 boff
= font_info
->baseline_offset
;
1866 if (font_info
->vertical_centering
)
1867 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1870 if (it
->char_to_display
>= ' '
1871 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1873 /* Either unibyte or ASCII. */
1878 pcm
= x_per_char_metric (font
, &char2b
);
1879 it
->ascent
= font
->ascent
+ boff
;
1880 it
->descent
= font
->descent
- boff
;
1884 it
->phys_ascent
= pcm
->ascent
+ boff
;
1885 it
->phys_descent
= pcm
->descent
- boff
;
1886 it
->pixel_width
= pcm
->width
;
1890 it
->glyph_not_available_p
= 1;
1891 it
->phys_ascent
= font
->ascent
+ boff
;
1892 it
->phys_descent
= font
->descent
- boff
;
1893 it
->pixel_width
= FONT_WIDTH (font
);
1896 /* If this is a space inside a region of text with
1897 `space-width' property, change its width. */
1898 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1900 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1902 /* If face has a box, add the box thickness to the character
1903 height. If character has a box line to the left and/or
1904 right, add the box line width to the character's width. */
1905 if (face
->box
!= FACE_NO_BOX
)
1907 int thick
= face
->box_line_width
;
1911 it
->ascent
+= thick
;
1912 it
->descent
+= thick
;
1917 if (it
->start_of_box_run_p
)
1918 it
->pixel_width
+= thick
;
1919 if (it
->end_of_box_run_p
)
1920 it
->pixel_width
+= thick
;
1923 /* If face has an overline, add the height of the overline
1924 (1 pixel) and a 1 pixel margin to the character height. */
1925 if (face
->overline_p
)
1928 take_vertical_position_into_account (it
);
1930 /* If we have to actually produce glyphs, do it. */
1935 /* Translate a space with a `space-width' property
1936 into a stretch glyph. */
1937 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1938 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1939 it
->ascent
+ it
->descent
, ascent
);
1942 x_append_glyph (it
);
1944 /* If characters with lbearing or rbearing are displayed
1945 in this line, record that fact in a flag of the
1946 glyph row. This is used to optimize X output code. */
1947 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1948 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1951 else if (it
->char_to_display
== '\n')
1953 /* A newline has no width but we need the height of the line. */
1954 it
->pixel_width
= 0;
1956 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1957 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1959 if (face
->box
!= FACE_NO_BOX
1960 && face
->box_line_width
> 0)
1962 it
->ascent
+= face
->box_line_width
;
1963 it
->descent
+= face
->box_line_width
;
1966 else if (it
->char_to_display
== '\t')
1968 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1969 int x
= it
->current_x
+ it
->continuation_lines_width
;
1970 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1972 /* If the distance from the current position to the next tab
1973 stop is less than a canonical character width, use the
1974 tab stop after that. */
1975 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1976 next_tab_x
+= tab_width
;
1978 it
->pixel_width
= next_tab_x
- x
;
1980 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1981 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1985 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1986 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1987 it
->ascent
+ it
->descent
, ascent
);
1992 /* A multi-byte character. Assume that the display width of the
1993 character is the width of the character multiplied by the
1994 width of the font. */
1996 /* If we found a font, this font should give us the right
1997 metrics. If we didn't find a font, use the frame's
1998 default font and calculate the width of the character
1999 from the charset width; this is what old redisplay code
2001 pcm
= x_per_char_metric (font
, &char2b
);
2002 if (font_not_found_p
|| !pcm
)
2004 int charset
= CHAR_CHARSET (it
->char_to_display
);
2006 it
->glyph_not_available_p
= 1;
2007 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2008 * CHARSET_WIDTH (charset
));
2009 it
->phys_ascent
= font
->ascent
+ boff
;
2010 it
->phys_descent
= font
->descent
- boff
;
2014 it
->pixel_width
= pcm
->width
;
2015 it
->phys_ascent
= pcm
->ascent
+ boff
;
2016 it
->phys_descent
= pcm
->descent
- boff
;
2018 && (pcm
->lbearing
< 0
2019 || pcm
->rbearing
> pcm
->width
))
2020 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2023 it
->ascent
= font
->ascent
+ boff
;
2024 it
->descent
= font
->descent
- boff
;
2025 if (face
->box
!= FACE_NO_BOX
)
2027 int thick
= face
->box_line_width
;
2031 it
->ascent
+= thick
;
2032 it
->descent
+= thick
;
2037 if (it
->start_of_box_run_p
)
2038 it
->pixel_width
+= thick
;
2039 if (it
->end_of_box_run_p
)
2040 it
->pixel_width
+= thick
;
2043 /* If face has an overline, add the height of the overline
2044 (1 pixel) and a 1 pixel margin to the character height. */
2045 if (face
->overline_p
)
2048 take_vertical_position_into_account (it
);
2051 x_append_glyph (it
);
2053 it
->multibyte_p
= saved_multibyte_p
;
2055 else if (it
->what
== IT_COMPOSITION
)
2057 /* Note: A composition is represented as one glyph in the
2058 glyph matrix. There are no padding glyphs. */
2061 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2063 int font_not_found_p
;
2064 struct font_info
*font_info
;
2065 int boff
; /* baseline offset */
2066 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2068 /* Maybe translate single-byte characters to multibyte. */
2069 it
->char_to_display
= it
->c
;
2070 if (unibyte_display_via_language_environment
2071 && SINGLE_BYTE_CHAR_P (it
->c
)
2074 && !NILP (Vnonascii_translation_table
))))
2076 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2079 /* Get face and font to use. Encode IT->char_to_display. */
2080 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2081 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2082 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2083 it
->face_id
, &char2b
, it
->multibyte_p
);
2086 /* When no suitable font found, use the default font. */
2087 font_not_found_p
= font
== NULL
;
2088 if (font_not_found_p
)
2090 font
= FRAME_FONT (it
->f
);
2091 boff
= it
->f
->output_data
.x
->baseline_offset
;
2096 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2097 boff
= font_info
->baseline_offset
;
2098 if (font_info
->vertical_centering
)
2099 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2102 /* There are no padding glyphs, so there is only one glyph to
2103 produce for the composition. Important is that pixel_width,
2104 ascent and descent are the values of what is drawn by
2105 draw_glyphs (i.e. the values of the overall glyphs composed). */
2108 /* If we have not yet calculated pixel size data of glyphs of
2109 the composition for the current face font, calculate them
2110 now. Theoretically, we have to check all fonts for the
2111 glyphs, but that requires much time and memory space. So,
2112 here we check only the font of the first glyph. This leads
2113 to incorrect display very rarely, and C-l (recenter) can
2114 correct the display anyway. */
2115 if (cmp
->font
!= (void *) font
)
2117 /* Ascent and descent of the font of the first character of
2118 this composition (adjusted by baseline offset). Ascent
2119 and descent of overall glyphs should not be less than
2120 them respectively. */
2121 int font_ascent
= font
->ascent
+ boff
;
2122 int font_descent
= font
->descent
- boff
;
2123 /* Bounding box of the overall glyphs. */
2124 int leftmost
, rightmost
, lowest
, highest
;
2125 int i
, width
, ascent
, descent
;
2127 cmp
->font
= (void *) font
;
2129 /* Initialize the bounding box. */
2131 && (pcm
= x_per_char_metric (font
, &char2b
)))
2134 ascent
= pcm
->ascent
;
2135 descent
= pcm
->descent
;
2139 width
= FONT_WIDTH (font
);
2140 ascent
= font
->ascent
;
2141 descent
= font
->descent
;
2145 lowest
= - descent
+ boff
;
2146 highest
= ascent
+ boff
;
2150 && font_info
->default_ascent
2151 && CHAR_TABLE_P (Vuse_default_ascent
)
2152 && !NILP (Faref (Vuse_default_ascent
,
2153 make_number (it
->char_to_display
))))
2154 highest
= font_info
->default_ascent
+ boff
;
2156 /* Draw the first glyph at the normal position. It may be
2157 shifted to right later if some other glyphs are drawn at
2159 cmp
->offsets
[0] = 0;
2160 cmp
->offsets
[1] = boff
;
2162 /* Set cmp->offsets for the remaining glyphs. */
2163 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2165 int left
, right
, btm
, top
;
2166 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2167 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2169 face
= FACE_FROM_ID (it
->f
, face_id
);
2170 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2175 font
= FRAME_FONT (it
->f
);
2176 boff
= it
->f
->output_data
.x
->baseline_offset
;
2182 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2183 boff
= font_info
->baseline_offset
;
2184 if (font_info
->vertical_centering
)
2185 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2189 && (pcm
= x_per_char_metric (font
, &char2b
)))
2192 ascent
= pcm
->ascent
;
2193 descent
= pcm
->descent
;
2197 width
= FONT_WIDTH (font
);
2202 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2204 /* Relative composition with or without
2206 left
= (leftmost
+ rightmost
- width
) / 2;
2207 btm
= - descent
+ boff
;
2208 if (font_info
&& font_info
->relative_compose
2209 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2210 || NILP (Faref (Vignore_relative_composition
,
2211 make_number (ch
)))))
2214 if (- descent
>= font_info
->relative_compose
)
2215 /* One extra pixel between two glyphs. */
2217 else if (ascent
<= 0)
2218 /* One extra pixel between two glyphs. */
2219 btm
= lowest
- 1 - ascent
- descent
;
2224 /* A composition rule is specified by an integer
2225 value that encodes global and new reference
2226 points (GREF and NREF). GREF and NREF are
2227 specified by numbers as below:
2235 ---3---4---5--- baseline
2237 6---7---8 -- descent
2239 int rule
= COMPOSITION_RULE (cmp
, i
);
2240 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2242 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2243 grefx
= gref
% 3, nrefx
= nref
% 3;
2244 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2247 + grefx
* (rightmost
- leftmost
) / 2
2248 - nrefx
* width
/ 2);
2249 btm
= ((grefy
== 0 ? highest
2251 : grefy
== 2 ? lowest
2252 : (highest
+ lowest
) / 2)
2253 - (nrefy
== 0 ? ascent
+ descent
2254 : nrefy
== 1 ? descent
- boff
2256 : (ascent
+ descent
) / 2));
2259 cmp
->offsets
[i
* 2] = left
;
2260 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2262 /* Update the bounding box of the overall glyphs. */
2263 right
= left
+ width
;
2264 top
= btm
+ descent
+ ascent
;
2265 if (left
< leftmost
)
2267 if (right
> rightmost
)
2275 /* If there are glyphs whose x-offsets are negative,
2276 shift all glyphs to the right and make all x-offsets
2280 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2281 cmp
->offsets
[i
* 2] -= leftmost
;
2282 rightmost
-= leftmost
;
2285 cmp
->pixel_width
= rightmost
;
2286 cmp
->ascent
= highest
;
2287 cmp
->descent
= - lowest
;
2288 if (cmp
->ascent
< font_ascent
)
2289 cmp
->ascent
= font_ascent
;
2290 if (cmp
->descent
< font_descent
)
2291 cmp
->descent
= font_descent
;
2294 it
->pixel_width
= cmp
->pixel_width
;
2295 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2296 it
->descent
= it
->phys_descent
= cmp
->descent
;
2298 if (face
->box
!= FACE_NO_BOX
)
2300 int thick
= face
->box_line_width
;
2304 it
->ascent
+= thick
;
2305 it
->descent
+= thick
;
2310 if (it
->start_of_box_run_p
)
2311 it
->pixel_width
+= thick
;
2312 if (it
->end_of_box_run_p
)
2313 it
->pixel_width
+= thick
;
2316 /* If face has an overline, add the height of the overline
2317 (1 pixel) and a 1 pixel margin to the character height. */
2318 if (face
->overline_p
)
2321 take_vertical_position_into_account (it
);
2324 x_append_composite_glyph (it
);
2326 else if (it
->what
== IT_IMAGE
)
2327 x_produce_image_glyph (it
);
2328 else if (it
->what
== IT_STRETCH
)
2329 x_produce_stretch_glyph (it
);
2331 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2332 because this isn't true for images with `:ascent 100'. */
2333 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2334 if (it
->area
== TEXT_AREA
)
2335 it
->current_x
+= it
->pixel_width
;
2337 it
->descent
+= it
->extra_line_spacing
;
2339 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2340 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2341 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2342 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2346 /* Estimate the pixel height of the mode or top line on frame F.
2347 FACE_ID specifies what line's height to estimate. */
2350 x_estimate_mode_line_height (f
, face_id
)
2352 enum face_id face_id
;
2354 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2356 /* This function is called so early when Emacs starts that the face
2357 cache and mode line face are not yet initialized. */
2358 if (FRAME_FACE_CACHE (f
))
2360 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2364 height
= FONT_HEIGHT (face
->font
);
2365 if (face
->box_line_width
> 0)
2366 height
+= 2 * face
->box_line_width
;
2374 /***********************************************************************
2376 ***********************************************************************/
2378 /* A sequence of glyphs to be drawn in the same face.
2380 This data structure is not really completely X specific, so it
2381 could possibly, at least partially, be useful for other systems. It
2382 is currently not part of the external redisplay interface because
2383 it's not clear what other systems will need. */
2387 /* X-origin of the string. */
2390 /* Y-origin and y-position of the base line of this string. */
2393 /* The width of the string, not including a face extension. */
2396 /* The width of the string, including a face extension. */
2397 int background_width
;
2399 /* The height of this string. This is the height of the line this
2400 string is drawn in, and can be different from the height of the
2401 font the string is drawn in. */
2404 /* Number of pixels this string overwrites in front of its x-origin.
2405 This number is zero if the string has an lbearing >= 0; it is
2406 -lbearing, if the string has an lbearing < 0. */
2409 /* Number of pixels this string overwrites past its right-most
2410 nominal x-position, i.e. x + width. Zero if the string's
2411 rbearing is <= its nominal width, rbearing - width otherwise. */
2414 /* The frame on which the glyph string is drawn. */
2417 /* The window on which the glyph string is drawn. */
2420 /* X display and window for convenience. */
2424 /* The glyph row for which this string was built. It determines the
2425 y-origin and height of the string. */
2426 struct glyph_row
*row
;
2428 /* The area within row. */
2429 enum glyph_row_area area
;
2431 /* Characters to be drawn, and number of characters. */
2435 /* A face-override for drawing cursors, mouse face and similar. */
2436 enum draw_glyphs_face hl
;
2438 /* Face in which this string is to be drawn. */
2441 /* Font in which this string is to be drawn. */
2444 /* Font info for this string. */
2445 struct font_info
*font_info
;
2447 /* Non-null means this string describes (part of) a composition.
2448 All characters from char2b are drawn composed. */
2449 struct composition
*cmp
;
2451 /* Index of this glyph string's first character in the glyph
2452 definition of CMP. If this is zero, this glyph string describes
2453 the first character of a composition. */
2456 /* 1 means this glyph strings face has to be drawn to the right end
2457 of the window's drawing area. */
2458 unsigned extends_to_end_of_line_p
: 1;
2460 /* 1 means the background of this string has been drawn. */
2461 unsigned background_filled_p
: 1;
2463 /* 1 means glyph string must be drawn with 16-bit functions. */
2464 unsigned two_byte_p
: 1;
2466 /* 1 means that the original font determined for drawing this glyph
2467 string could not be loaded. The member `font' has been set to
2468 the frame's default font in this case. */
2469 unsigned font_not_found_p
: 1;
2471 /* 1 means that the face in which this glyph string is drawn has a
2473 unsigned stippled_p
: 1;
2475 /* 1 means only the foreground of this glyph string must be drawn,
2476 and we should use the physical height of the line this glyph
2477 string appears in as clip rect. */
2478 unsigned for_overlaps_p
: 1;
2480 /* The GC to use for drawing this glyph string. */
2483 /* A pointer to the first glyph in the string. This glyph
2484 corresponds to char2b[0]. Needed to draw rectangles if
2485 font_not_found_p is 1. */
2486 struct glyph
*first_glyph
;
2488 /* Image, if any. */
2491 struct glyph_string
*next
, *prev
;
2498 x_dump_glyph_string (s
)
2499 struct glyph_string
*s
;
2501 fprintf (stderr
, "glyph string\n");
2502 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2503 s
->x
, s
->y
, s
->width
, s
->height
);
2504 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2505 fprintf (stderr
, " hl = %d\n", s
->hl
);
2506 fprintf (stderr
, " left overhang = %d, right = %d\n",
2507 s
->left_overhang
, s
->right_overhang
);
2508 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2509 fprintf (stderr
, " extends to end of line = %d\n",
2510 s
->extends_to_end_of_line_p
);
2511 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2512 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2515 #endif /* GLYPH_DEBUG */
2519 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2520 struct glyph_string
**,
2521 struct glyph_string
*,
2522 struct glyph_string
*));
2523 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2524 struct glyph_string
**,
2525 struct glyph_string
*,
2526 struct glyph_string
*));
2527 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2528 struct glyph_string
**,
2529 struct glyph_string
*));
2530 static int x_left_overwritten
P_ ((struct glyph_string
*));
2531 static int x_left_overwriting
P_ ((struct glyph_string
*));
2532 static int x_right_overwritten
P_ ((struct glyph_string
*));
2533 static int x_right_overwriting
P_ ((struct glyph_string
*));
2534 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2536 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2537 XChar2b
*, struct window
*,
2539 enum glyph_row_area
, int,
2540 enum draw_glyphs_face
));
2541 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2542 enum glyph_row_area
, int, int,
2543 enum draw_glyphs_face
, int *, int *, int));
2544 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2545 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2546 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2548 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2549 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2550 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2551 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2552 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2553 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2554 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2555 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2556 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2558 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2559 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2560 unsigned long *, double, int));
2561 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2562 double, int, unsigned long));
2563 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2564 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2565 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2566 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2567 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2568 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2569 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2571 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2572 int, int, int, int, XRectangle
*));
2573 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2574 int, int, int, XRectangle
*));
2575 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2576 enum glyph_row_area
));
2577 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2579 enum glyph_row_area
, int, int));
2582 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2586 /* Append the list of glyph strings with head H and tail T to the list
2587 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2590 x_append_glyph_string_lists (head
, tail
, h
, t
)
2591 struct glyph_string
**head
, **tail
;
2592 struct glyph_string
*h
, *t
;
2606 /* Prepend the list of glyph strings with head H and tail T to the
2607 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2611 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2612 struct glyph_string
**head
, **tail
;
2613 struct glyph_string
*h
, *t
;
2627 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2628 Set *HEAD and *TAIL to the resulting list. */
2631 x_append_glyph_string (head
, tail
, s
)
2632 struct glyph_string
**head
, **tail
;
2633 struct glyph_string
*s
;
2635 s
->next
= s
->prev
= NULL
;
2636 x_append_glyph_string_lists (head
, tail
, s
, s
);
2640 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2645 struct glyph_string
*s
;
2647 if (s
->font
== FRAME_FONT (s
->f
)
2648 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2649 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2651 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2654 /* Cursor on non-default face: must merge. */
2658 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2659 xgcv
.foreground
= s
->face
->background
;
2661 /* If the glyph would be invisible, try a different foreground. */
2662 if (xgcv
.foreground
== xgcv
.background
)
2663 xgcv
.foreground
= s
->face
->foreground
;
2664 if (xgcv
.foreground
== xgcv
.background
)
2665 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2666 if (xgcv
.foreground
== xgcv
.background
)
2667 xgcv
.foreground
= s
->face
->foreground
;
2669 /* Make sure the cursor is distinct from text in this face. */
2670 if (xgcv
.background
== s
->face
->background
2671 && xgcv
.foreground
== s
->face
->foreground
)
2673 xgcv
.background
= s
->face
->foreground
;
2674 xgcv
.foreground
= s
->face
->background
;
2677 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2678 xgcv
.font
= s
->font
->fid
;
2679 xgcv
.graphics_exposures
= False
;
2680 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2682 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2683 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2686 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2687 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2689 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2694 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2697 x_set_mouse_face_gc (s
)
2698 struct glyph_string
*s
;
2703 /* What face has to be used last for the mouse face? */
2704 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2705 face
= FACE_FROM_ID (s
->f
, face_id
);
2707 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2709 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2710 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2712 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2713 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2714 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2716 /* If font in this face is same as S->font, use it. */
2717 if (s
->font
== s
->face
->font
)
2718 s
->gc
= s
->face
->gc
;
2721 /* Otherwise construct scratch_cursor_gc with values from FACE
2726 xgcv
.background
= s
->face
->background
;
2727 xgcv
.foreground
= s
->face
->foreground
;
2728 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2729 xgcv
.font
= s
->font
->fid
;
2730 xgcv
.graphics_exposures
= False
;
2731 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2733 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2734 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2737 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2738 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2740 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2743 xassert (s
->gc
!= 0);
2747 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2748 Faces to use in the mode line have already been computed when the
2749 matrix was built, so there isn't much to do, here. */
2752 x_set_mode_line_face_gc (s
)
2753 struct glyph_string
*s
;
2755 s
->gc
= s
->face
->gc
;
2759 /* Set S->gc of glyph string S for drawing that glyph string. Set
2760 S->stippled_p to a non-zero value if the face of S has a stipple
2764 x_set_glyph_string_gc (s
)
2765 struct glyph_string
*s
;
2767 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2769 if (s
->hl
== DRAW_NORMAL_TEXT
)
2771 s
->gc
= s
->face
->gc
;
2772 s
->stippled_p
= s
->face
->stipple
!= 0;
2774 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2776 x_set_mode_line_face_gc (s
);
2777 s
->stippled_p
= s
->face
->stipple
!= 0;
2779 else if (s
->hl
== DRAW_CURSOR
)
2781 x_set_cursor_gc (s
);
2784 else if (s
->hl
== DRAW_MOUSE_FACE
)
2786 x_set_mouse_face_gc (s
);
2787 s
->stippled_p
= s
->face
->stipple
!= 0;
2789 else if (s
->hl
== DRAW_IMAGE_RAISED
2790 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2792 s
->gc
= s
->face
->gc
;
2793 s
->stippled_p
= s
->face
->stipple
!= 0;
2797 s
->gc
= s
->face
->gc
;
2798 s
->stippled_p
= s
->face
->stipple
!= 0;
2801 /* GC must have been set. */
2802 xassert (s
->gc
!= 0);
2806 /* Return in *R the clipping rectangle for glyph string S. */
2809 x_get_glyph_string_clip_rect (s
, r
)
2810 struct glyph_string
*s
;
2813 if (s
->row
->full_width_p
)
2815 /* Draw full-width. X coordinates are relative to S->w->left. */
2816 int canon_x
= CANON_X_UNIT (s
->f
);
2818 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2819 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2821 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2823 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2824 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2828 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2830 /* Unless displaying a mode or menu bar line, which are always
2831 fully visible, clip to the visible part of the row. */
2832 if (s
->w
->pseudo_window_p
)
2833 r
->height
= s
->row
->visible_height
;
2835 r
->height
= s
->height
;
2839 /* This is a text line that may be partially visible. */
2840 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2841 r
->width
= window_box_width (s
->w
, s
->area
);
2842 r
->height
= s
->row
->visible_height
;
2845 /* Don't use S->y for clipping because it doesn't take partially
2846 visible lines into account. For example, it can be negative for
2847 partially visible lines at the top of a window. */
2848 if (!s
->row
->full_width_p
2849 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2850 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2852 r
->y
= max (0, s
->row
->y
);
2854 /* If drawing a tool-bar window, draw it over the internal border
2855 at the top of the window. */
2856 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2857 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2859 /* If S draws overlapping rows, it's sufficient to use the top and
2860 bottom of the window for clipping because this glyph string
2861 intentionally draws over other lines. */
2862 if (s
->for_overlaps_p
)
2864 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2865 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2868 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2872 /* Set clipping for output of glyph string S. S may be part of a mode
2873 line or menu if we don't have X toolkit support. */
2876 x_set_glyph_string_clipping (s
)
2877 struct glyph_string
*s
;
2880 x_get_glyph_string_clip_rect (s
, &r
);
2881 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2885 /* Compute left and right overhang of glyph string S. If S is a glyph
2886 string for a composition, assume overhangs don't exist. */
2889 x_compute_glyph_string_overhangs (s
)
2890 struct glyph_string
*s
;
2893 && s
->first_glyph
->type
== CHAR_GLYPH
)
2896 int direction
, font_ascent
, font_descent
;
2897 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2898 &font_ascent
, &font_descent
, &cs
);
2899 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2900 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2905 /* Compute overhangs and x-positions for glyph string S and its
2906 predecessors, or successors. X is the starting x-position for S.
2907 BACKWARD_P non-zero means process predecessors. */
2910 x_compute_overhangs_and_x (s
, x
, backward_p
)
2911 struct glyph_string
*s
;
2919 x_compute_glyph_string_overhangs (s
);
2929 x_compute_glyph_string_overhangs (s
);
2938 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2939 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2940 assumed to be zero. */
2943 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2944 struct glyph
*glyph
;
2950 if (glyph
->type
== CHAR_GLYPH
)
2954 struct font_info
*font_info
;
2958 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2960 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2962 && (pcm
= x_per_char_metric (font
, &char2b
)))
2964 if (pcm
->rbearing
> pcm
->width
)
2965 *right
= pcm
->rbearing
- pcm
->width
;
2966 if (pcm
->lbearing
< 0)
2967 *left
= -pcm
->lbearing
;
2973 /* Return the index of the first glyph preceding glyph string S that
2974 is overwritten by S because of S's left overhang. Value is -1
2975 if no glyphs are overwritten. */
2978 x_left_overwritten (s
)
2979 struct glyph_string
*s
;
2983 if (s
->left_overhang
)
2986 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2987 int first
= s
->first_glyph
- glyphs
;
2989 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2990 x
-= glyphs
[i
].pixel_width
;
3001 /* Return the index of the first glyph preceding glyph string S that
3002 is overwriting S because of its right overhang. Value is -1 if no
3003 glyph in front of S overwrites S. */
3006 x_left_overwriting (s
)
3007 struct glyph_string
*s
;
3010 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3011 int first
= s
->first_glyph
- glyphs
;
3015 for (i
= first
- 1; i
>= 0; --i
)
3018 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3021 x
-= glyphs
[i
].pixel_width
;
3028 /* Return the index of the last glyph following glyph string S that is
3029 not overwritten by S because of S's right overhang. Value is -1 if
3030 no such glyph is found. */
3033 x_right_overwritten (s
)
3034 struct glyph_string
*s
;
3038 if (s
->right_overhang
)
3041 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3042 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3043 int end
= s
->row
->used
[s
->area
];
3045 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3046 x
+= glyphs
[i
].pixel_width
;
3055 /* Return the index of the last glyph following glyph string S that
3056 overwrites S because of its left overhang. Value is negative
3057 if no such glyph is found. */
3060 x_right_overwriting (s
)
3061 struct glyph_string
*s
;
3064 int end
= s
->row
->used
[s
->area
];
3065 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3066 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3070 for (i
= first
; i
< end
; ++i
)
3073 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3076 x
+= glyphs
[i
].pixel_width
;
3083 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3086 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3087 struct glyph_string
*s
;
3091 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3092 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3093 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3094 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3098 /* Draw the background of glyph_string S. If S->background_filled_p
3099 is non-zero don't draw it. FORCE_P non-zero means draw the
3100 background even if it wouldn't be drawn normally. This is used
3101 when a string preceding S draws into the background of S, or S
3102 contains the first component of a composition. */
3105 x_draw_glyph_string_background (s
, force_p
)
3106 struct glyph_string
*s
;
3109 /* Nothing to do if background has already been drawn or if it
3110 shouldn't be drawn in the first place. */
3111 if (!s
->background_filled_p
)
3113 int box_line_width
= max (s
->face
->box_line_width
, 0);
3117 /* Fill background with a stipple pattern. */
3118 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3119 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3120 s
->y
+ box_line_width
,
3121 s
->background_width
,
3122 s
->height
- 2 * box_line_width
);
3123 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3124 s
->background_filled_p
= 1;
3126 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3127 || s
->font_not_found_p
3128 || s
->extends_to_end_of_line_p
3131 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3132 s
->background_width
,
3133 s
->height
- 2 * box_line_width
);
3134 s
->background_filled_p
= 1;
3140 /* Draw the foreground of glyph string S. */
3143 x_draw_glyph_string_foreground (s
)
3144 struct glyph_string
*s
;
3148 /* If first glyph of S has a left box line, start drawing the text
3149 of S to the right of that box line. */
3150 if (s
->face
->box
!= FACE_NO_BOX
3151 && s
->first_glyph
->left_box_line_p
)
3152 x
= s
->x
+ abs (s
->face
->box_line_width
);
3156 /* Draw characters of S as rectangles if S's font could not be
3158 if (s
->font_not_found_p
)
3160 for (i
= 0; i
< s
->nchars
; ++i
)
3162 struct glyph
*g
= s
->first_glyph
+ i
;
3163 XDrawRectangle (s
->display
, s
->window
,
3164 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3166 x
+= g
->pixel_width
;
3171 char *char1b
= (char *) s
->char2b
;
3172 int boff
= s
->font_info
->baseline_offset
;
3174 if (s
->font_info
->vertical_centering
)
3175 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3177 /* If we can use 8-bit functions, condense S->char2b. */
3179 for (i
= 0; i
< s
->nchars
; ++i
)
3180 char1b
[i
] = s
->char2b
[i
].byte2
;
3182 /* Draw text with XDrawString if background has already been
3183 filled. Otherwise, use XDrawImageString. (Note that
3184 XDrawImageString is usually faster than XDrawString.) Always
3185 use XDrawImageString when drawing the cursor so that there is
3186 no chance that characters under a box cursor are invisible. */
3187 if (s
->for_overlaps_p
3188 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3190 /* Draw characters with 16-bit or 8-bit functions. */
3192 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3193 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3195 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3196 s
->ybase
- boff
, char1b
, s
->nchars
);
3201 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3202 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3204 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3205 s
->ybase
- boff
, char1b
, s
->nchars
);
3210 /* Draw the foreground of composite glyph string S. */
3213 x_draw_composite_glyph_string_foreground (s
)
3214 struct glyph_string
*s
;
3218 /* If first glyph of S has a left box line, start drawing the text
3219 of S to the right of that box line. */
3220 if (s
->face
->box
!= FACE_NO_BOX
3221 && s
->first_glyph
->left_box_line_p
)
3222 x
= s
->x
+ abs (s
->face
->box_line_width
);
3226 /* S is a glyph string for a composition. S->gidx is the index of
3227 the first character drawn for glyphs of this composition.
3228 S->gidx == 0 means we are drawing the very first character of
3229 this composition. */
3231 /* Draw a rectangle for the composition if the font for the very
3232 first character of the composition could not be loaded. */
3233 if (s
->font_not_found_p
)
3236 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3237 s
->width
- 1, s
->height
- 1);
3241 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3242 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3243 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3244 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3250 #ifdef USE_X_TOOLKIT
3252 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3253 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3254 XrmValue
*, XrmValue
*, XtPointer
*));
3255 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3256 XrmValue
*, Cardinal
*));
3259 /* Return the frame on which widget WIDGET is used.. Abort if frame
3260 cannot be determined. */
3262 static struct frame
*
3263 x_frame_of_widget (widget
)
3266 struct x_display_info
*dpyinfo
;
3270 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3272 /* Find the top-level shell of the widget. Note that this function
3273 can be called when the widget is not yet realized, so XtWindow
3274 (widget) == 0. That's the reason we can't simply use
3275 x_any_window_to_frame. */
3276 while (!XtIsTopLevelShell (widget
))
3277 widget
= XtParent (widget
);
3279 /* Look for a frame with that top-level widget. Allocate the color
3280 on that frame to get the right gamma correction value. */
3281 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3282 if (GC_FRAMEP (XCAR (tail
))
3283 && (f
= XFRAME (XCAR (tail
)),
3284 (f
->output_data
.nothing
!= 1
3285 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3286 && f
->output_data
.x
->widget
== widget
)
3293 /* Allocate the color COLOR->pixel on the screen and display of
3294 widget WIDGET in colormap CMAP. If an exact match cannot be
3295 allocated, try the nearest color available. Value is non-zero
3296 if successful. This is called from lwlib. */
3299 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3304 struct frame
*f
= x_frame_of_widget (widget
);
3305 return x_alloc_nearest_color (f
, cmap
, color
);
3309 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3310 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3311 If this produces the same color as PIXEL, try a color where all RGB
3312 values have DELTA added. Return the allocated color in *PIXEL.
3313 DISPLAY is the X display, CMAP is the colormap to operate on.
3314 Value is non-zero if successful. */
3317 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3321 unsigned long *pixel
;
3325 struct frame
*f
= x_frame_of_widget (widget
);
3326 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3330 /* Structure specifying which arguments should be passed by Xt to
3331 cvt_string_to_pixel. We want the widget's screen and colormap. */
3333 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3335 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3337 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3342 /* The address of this variable is returned by
3343 cvt_string_to_pixel. */
3345 static Pixel cvt_string_to_pixel_value
;
3348 /* Convert a color name to a pixel color.
3350 DPY is the display we are working on.
3352 ARGS is an array of *NARGS XrmValue structures holding additional
3353 information about the widget for which the conversion takes place.
3354 The contents of this array are determined by the specification
3355 in cvt_string_to_pixel_args.
3357 FROM is a pointer to an XrmValue which points to the color name to
3358 convert. TO is an XrmValue in which to return the pixel color.
3360 CLOSURE_RET is a pointer to user-data, in which we record if
3361 we allocated the color or not.
3363 Value is True if successful, False otherwise. */
3366 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3370 XrmValue
*from
, *to
;
3371 XtPointer
*closure_ret
;
3381 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3382 "wrongParameters", "cvt_string_to_pixel",
3384 "Screen and colormap args required", NULL
, NULL
);
3388 screen
= *(Screen
**) args
[0].addr
;
3389 cmap
= *(Colormap
*) args
[1].addr
;
3390 color_name
= (String
) from
->addr
;
3392 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3394 *closure_ret
= (XtPointer
) False
;
3395 pixel
= WhitePixelOfScreen (screen
);
3397 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3399 *closure_ret
= (XtPointer
) False
;
3400 pixel
= BlackPixelOfScreen (screen
);
3402 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3403 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3405 pixel
= color
.pixel
;
3406 *closure_ret
= (XtPointer
) True
;
3411 Cardinal nparams
= 1;
3413 params
[0] = color_name
;
3414 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3415 "badValue", "cvt_string_to_pixel",
3416 "XtToolkitError", "Invalid color `%s'",
3421 if (to
->addr
!= NULL
)
3423 if (to
->size
< sizeof (Pixel
))
3425 to
->size
= sizeof (Pixel
);
3429 *(Pixel
*) to
->addr
= pixel
;
3433 cvt_string_to_pixel_value
= pixel
;
3434 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3437 to
->size
= sizeof (Pixel
);
3442 /* Free a pixel color which was previously allocated via
3443 cvt_string_to_pixel. This is registered as the destructor
3444 for this type of resource via XtSetTypeConverter.
3446 APP is the application context in which we work.
3448 TO is a pointer to an XrmValue holding the color to free.
3449 CLOSURE is the value we stored in CLOSURE_RET for this color
3450 in cvt_string_to_pixel.
3452 ARGS and NARGS are like for cvt_string_to_pixel. */
3455 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3464 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3466 "Screen and colormap arguments required",
3469 else if (closure
!= NULL
)
3471 /* We did allocate the pixel, so free it. */
3472 Screen
*screen
= *(Screen
**) args
[0].addr
;
3473 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3474 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3475 (Pixel
*) to
->addr
, 1, 0);
3480 #endif /* USE_X_TOOLKIT */
3483 /* Value is an array of XColor structures for the contents of the
3484 color map of display DPY. Set *NCELLS to the size of the array.
3485 Note that this probably shouldn't be called for large color maps,
3486 say a 24-bit TrueColor map. */
3488 static const XColor
*
3489 x_color_cells (dpy
, ncells
)
3493 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3495 if (dpyinfo
->color_cells
== NULL
)
3497 Screen
*screen
= dpyinfo
->screen
;
3500 dpyinfo
->ncolor_cells
3501 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3502 dpyinfo
->color_cells
3503 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3504 * sizeof *dpyinfo
->color_cells
);
3506 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3507 dpyinfo
->color_cells
[i
].pixel
= i
;
3509 XQueryColors (dpy
, dpyinfo
->cmap
,
3510 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3513 *ncells
= dpyinfo
->ncolor_cells
;
3514 return dpyinfo
->color_cells
;
3518 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3519 colors in COLORS. Use cached information, if available. */
3522 x_query_colors (f
, colors
, ncolors
)
3527 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3529 if (dpyinfo
->color_cells
)
3532 for (i
= 0; i
< ncolors
; ++i
)
3534 unsigned long pixel
= colors
[i
].pixel
;
3535 xassert (pixel
< dpyinfo
->ncolor_cells
);
3536 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3537 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3541 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3545 /* On frame F, translate pixel color to RGB values for the color in
3546 COLOR. Use cached information, if available. */
3549 x_query_color (f
, color
)
3553 x_query_colors (f
, color
, 1);
3557 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3558 exact match can't be allocated, try the nearest color available.
3559 Value is non-zero if successful. Set *COLOR to the color
3563 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3570 rc
= XAllocColor (dpy
, cmap
, color
);
3573 /* If we got to this point, the colormap is full, so we're going
3574 to try to get the next closest color. The algorithm used is
3575 a least-squares matching, which is what X uses for closest
3576 color matching with StaticColor visuals. */
3578 unsigned long nearest_delta
= ~0;
3580 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3582 for (nearest
= i
= 0; i
< ncells
; ++i
)
3584 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3585 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3586 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3587 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3589 if (delta
< nearest_delta
)
3592 nearest_delta
= delta
;
3596 color
->red
= cells
[nearest
].red
;
3597 color
->green
= cells
[nearest
].green
;
3598 color
->blue
= cells
[nearest
].blue
;
3599 rc
= XAllocColor (dpy
, cmap
, color
);
3603 /* If allocation succeeded, and the allocated pixel color is not
3604 equal to a cached pixel color recorded earlier, there was a
3605 change in the colormap, so clear the color cache. */
3606 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3607 XColor
*cached_color
;
3609 if (dpyinfo
->color_cells
3610 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3611 (cached_color
->red
!= color
->red
3612 || cached_color
->blue
!= color
->blue
3613 || cached_color
->green
!= color
->green
)))
3615 xfree (dpyinfo
->color_cells
);
3616 dpyinfo
->color_cells
= NULL
;
3617 dpyinfo
->ncolor_cells
= 0;
3621 #ifdef DEBUG_X_COLORS
3623 register_color (color
->pixel
);
3624 #endif /* DEBUG_X_COLORS */
3630 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3631 exact match can't be allocated, try the nearest color available.
3632 Value is non-zero if successful. Set *COLOR to the color
3636 x_alloc_nearest_color (f
, cmap
, color
)
3641 gamma_correct (f
, color
);
3642 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3646 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3647 It's necessary to do this instead of just using PIXEL directly to
3648 get color reference counts right. */
3651 x_copy_color (f
, pixel
)
3653 unsigned long pixel
;
3657 color
.pixel
= pixel
;
3659 x_query_color (f
, &color
);
3660 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3662 #ifdef DEBUG_X_COLORS
3663 register_color (pixel
);
3669 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3670 It's necessary to do this instead of just using PIXEL directly to
3671 get color reference counts right. */
3674 x_copy_dpy_color (dpy
, cmap
, pixel
)
3677 unsigned long pixel
;
3681 color
.pixel
= pixel
;
3683 XQueryColor (dpy
, cmap
, &color
);
3684 XAllocColor (dpy
, cmap
, &color
);
3686 #ifdef DEBUG_X_COLORS
3687 register_color (pixel
);
3693 /* Brightness beyond which a color won't have its highlight brightness
3696 Nominally, highlight colors for `3d' faces are calculated by
3697 brightening an object's color by a constant scale factor, but this
3698 doesn't yield good results for dark colors, so for colors who's
3699 brightness is less than this value (on a scale of 0-65535) have an
3700 use an additional additive factor.
3702 The value here is set so that the default menu-bar/mode-line color
3703 (grey75) will not have its highlights changed at all. */
3704 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3707 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3708 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3709 If this produces the same color as PIXEL, try a color where all RGB
3710 values have DELTA added. Return the allocated color in *PIXEL.
3711 DISPLAY is the X display, CMAP is the colormap to operate on.
3712 Value is non-zero if successful. */
3715 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3719 unsigned long *pixel
;
3727 /* Get RGB color values. */
3728 color
.pixel
= *pixel
;
3729 x_query_color (f
, &color
);
3731 /* Change RGB values by specified FACTOR. Avoid overflow! */
3732 xassert (factor
>= 0);
3733 new.red
= min (0xffff, factor
* color
.red
);
3734 new.green
= min (0xffff, factor
* color
.green
);
3735 new.blue
= min (0xffff, factor
* color
.blue
);
3737 /* Calculate brightness of COLOR. */
3738 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3740 /* We only boost colors that are darker than
3741 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3742 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3743 /* Make an additive adjustment to NEW, because it's dark enough so
3744 that scaling by FACTOR alone isn't enough. */
3746 /* How far below the limit this color is (0 - 1, 1 being darker). */
3747 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3748 /* The additive adjustment. */
3749 int min_delta
= delta
* dimness
* factor
/ 2;
3753 new.red
= max (0, new.red
- min_delta
);
3754 new.green
= max (0, new.green
- min_delta
);
3755 new.blue
= max (0, new.blue
- min_delta
);
3759 new.red
= min (0xffff, min_delta
+ new.red
);
3760 new.green
= min (0xffff, min_delta
+ new.green
);
3761 new.blue
= min (0xffff, min_delta
+ new.blue
);
3765 /* Try to allocate the color. */
3766 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3769 if (new.pixel
== *pixel
)
3771 /* If we end up with the same color as before, try adding
3772 delta to the RGB values. */
3773 x_free_colors (f
, &new.pixel
, 1);
3775 new.red
= min (0xffff, delta
+ color
.red
);
3776 new.green
= min (0xffff, delta
+ color
.green
);
3777 new.blue
= min (0xffff, delta
+ color
.blue
);
3778 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3789 /* Set up the foreground color for drawing relief lines of glyph
3790 string S. RELIEF is a pointer to a struct relief containing the GC
3791 with which lines will be drawn. Use a color that is FACTOR or
3792 DELTA lighter or darker than the relief's background which is found
3793 in S->f->output_data.x->relief_background. If such a color cannot
3794 be allocated, use DEFAULT_PIXEL, instead. */
3797 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3799 struct relief
*relief
;
3802 unsigned long default_pixel
;
3805 struct x_output
*di
= f
->output_data
.x
;
3806 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3807 unsigned long pixel
;
3808 unsigned long background
= di
->relief_background
;
3809 Colormap cmap
= FRAME_X_COLORMAP (f
);
3810 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3811 Display
*dpy
= FRAME_X_DISPLAY (f
);
3813 xgcv
.graphics_exposures
= False
;
3814 xgcv
.line_width
= 1;
3816 /* Free previously allocated color. The color cell will be reused
3817 when it has been freed as many times as it was allocated, so this
3818 doesn't affect faces using the same colors. */
3820 && relief
->allocated_p
)
3822 x_free_colors (f
, &relief
->pixel
, 1);
3823 relief
->allocated_p
= 0;
3826 /* Allocate new color. */
3827 xgcv
.foreground
= default_pixel
;
3829 if (dpyinfo
->n_planes
!= 1
3830 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3832 relief
->allocated_p
= 1;
3833 xgcv
.foreground
= relief
->pixel
= pixel
;
3836 if (relief
->gc
== 0)
3838 xgcv
.stipple
= dpyinfo
->gray
;
3840 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3843 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3847 /* Set up colors for the relief lines around glyph string S. */
3850 x_setup_relief_colors (s
)
3851 struct glyph_string
*s
;
3853 struct x_output
*di
= s
->f
->output_data
.x
;
3854 unsigned long color
;
3856 if (s
->face
->use_box_color_for_shadows_p
)
3857 color
= s
->face
->box_color
;
3862 /* Get the background color of the face. */
3863 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3864 color
= xgcv
.background
;
3867 if (di
->white_relief
.gc
== 0
3868 || color
!= di
->relief_background
)
3870 di
->relief_background
= color
;
3871 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3872 WHITE_PIX_DEFAULT (s
->f
));
3873 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3874 BLACK_PIX_DEFAULT (s
->f
));
3879 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3880 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3881 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3882 relief. LEFT_P non-zero means draw a relief on the left side of
3883 the rectangle. RIGHT_P non-zero means draw a relief on the right
3884 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3888 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3889 raised_p
, left_p
, right_p
, clip_rect
)
3891 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3892 XRectangle
*clip_rect
;
3898 gc
= f
->output_data
.x
->white_relief
.gc
;
3900 gc
= f
->output_data
.x
->black_relief
.gc
;
3901 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3904 for (i
= 0; i
< width
; ++i
)
3905 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3906 left_x
+ i
* left_p
, top_y
+ i
,
3907 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3911 for (i
= 0; i
< width
; ++i
)
3912 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3913 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3915 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3917 gc
= f
->output_data
.x
->black_relief
.gc
;
3919 gc
= f
->output_data
.x
->white_relief
.gc
;
3920 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3923 for (i
= 0; i
< width
; ++i
)
3924 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3925 left_x
+ i
* left_p
+ 1, bottom_y
- i
,
3926 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3930 for (i
= 0; i
< width
; ++i
)
3931 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3932 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3934 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3938 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3939 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3940 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3941 left side of the rectangle. RIGHT_P non-zero means draw a line
3942 on the right side of the rectangle. CLIP_RECT is the clipping
3943 rectangle to use when drawing. */
3946 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3947 left_p
, right_p
, clip_rect
)
3948 struct glyph_string
*s
;
3949 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3950 XRectangle
*clip_rect
;
3954 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3955 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3956 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3959 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3960 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3964 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3965 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3968 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3969 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3973 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3974 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3976 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3977 XSetClipMask (s
->display
, s
->gc
, None
);
3981 /* Draw a box around glyph string S. */
3984 x_draw_glyph_string_box (s
)
3985 struct glyph_string
*s
;
3987 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3988 int left_p
, right_p
;
3989 struct glyph
*last_glyph
;
3990 XRectangle clip_rect
;
3992 last_x
= window_box_right (s
->w
, s
->area
);
3993 if (s
->row
->full_width_p
3994 && !s
->w
->pseudo_window_p
)
3996 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3997 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3998 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
4001 /* The glyph that may have a right box line. */
4002 last_glyph
= (s
->cmp
|| s
->img
4004 : s
->first_glyph
+ s
->nchars
- 1);
4006 width
= abs (s
->face
->box_line_width
);
4007 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
4009 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
4011 : min (last_x
, s
->x
+ s
->background_width
) - 1);
4013 bottom_y
= top_y
+ s
->height
- 1;
4015 left_p
= (s
->first_glyph
->left_box_line_p
4016 || (s
->hl
== DRAW_MOUSE_FACE
4018 || s
->prev
->hl
!= s
->hl
)));
4019 right_p
= (last_glyph
->right_box_line_p
4020 || (s
->hl
== DRAW_MOUSE_FACE
4022 || s
->next
->hl
!= s
->hl
)));
4024 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4026 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4027 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4028 left_p
, right_p
, &clip_rect
);
4031 x_setup_relief_colors (s
);
4032 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4033 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4038 /* Draw foreground of image glyph string S. */
4041 x_draw_image_foreground (s
)
4042 struct glyph_string
*s
;
4045 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4047 /* If first glyph of S has a left box line, start drawing it to the
4048 right of that line. */
4049 if (s
->face
->box
!= FACE_NO_BOX
4050 && s
->first_glyph
->left_box_line_p
)
4051 x
= s
->x
+ abs (s
->face
->box_line_width
);
4055 /* If there is a margin around the image, adjust x- and y-position
4057 x
+= s
->img
->hmargin
;
4058 y
+= s
->img
->vmargin
;
4064 /* We can't set both a clip mask and use XSetClipRectangles
4065 because the latter also sets a clip mask. We also can't
4066 trust on the shape extension to be available
4067 (XShapeCombineRegion). So, compute the rectangle to draw
4069 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4072 XRectangle clip_rect
, image_rect
, r
;
4074 xgcv
.clip_mask
= s
->img
->mask
;
4075 xgcv
.clip_x_origin
= x
;
4076 xgcv
.clip_y_origin
= y
;
4077 xgcv
.function
= GXcopy
;
4078 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4080 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4083 image_rect
.width
= s
->img
->width
;
4084 image_rect
.height
= s
->img
->height
;
4085 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4086 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4087 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4091 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
4093 XRectangle clip_rect
, image_rect
, r
;
4095 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4098 image_rect
.width
= s
->img
->width
;
4099 image_rect
.height
= s
->img
->height
;
4100 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4101 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4102 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4104 /* When the image has a mask, we can expect that at
4105 least part of a mouse highlight or a block cursor will
4106 be visible. If the image doesn't have a mask, make
4107 a block cursor visible by drawing a rectangle around
4108 the image. I believe it's looking better if we do
4109 nothing here for mouse-face. */
4110 if (s
->hl
== DRAW_CURSOR
)
4111 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4112 s
->img
->width
- 1, s
->img
->height
- 1);
4116 /* Draw a rectangle if image could not be loaded. */
4117 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4118 s
->img
->width
- 1, s
->img
->height
- 1);
4122 /* Draw a relief around the image glyph string S. */
4125 x_draw_image_relief (s
)
4126 struct glyph_string
*s
;
4128 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4131 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4133 /* If first glyph of S has a left box line, start drawing it to the
4134 right of that line. */
4135 if (s
->face
->box
!= FACE_NO_BOX
4136 && s
->first_glyph
->left_box_line_p
)
4137 x
= s
->x
+ abs (s
->face
->box_line_width
);
4141 /* If there is a margin around the image, adjust x- and y-position
4143 x
+= s
->img
->hmargin
;
4144 y
+= s
->img
->vmargin
;
4146 if (s
->hl
== DRAW_IMAGE_SUNKEN
4147 || s
->hl
== DRAW_IMAGE_RAISED
)
4149 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
4150 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4154 thick
= abs (s
->img
->relief
);
4155 raised_p
= s
->img
->relief
> 0;
4160 x1
= x
+ s
->img
->width
+ thick
- 1;
4161 y1
= y
+ s
->img
->height
+ thick
- 1;
4163 x_setup_relief_colors (s
);
4164 x_get_glyph_string_clip_rect (s
, &r
);
4165 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4169 /* Draw the foreground of image glyph string S to PIXMAP. */
4172 x_draw_image_foreground_1 (s
, pixmap
)
4173 struct glyph_string
*s
;
4177 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4179 /* If first glyph of S has a left box line, start drawing it to the
4180 right of that line. */
4181 if (s
->face
->box
!= FACE_NO_BOX
4182 && s
->first_glyph
->left_box_line_p
)
4183 x
= abs (s
->face
->box_line_width
);
4187 /* If there is a margin around the image, adjust x- and y-position
4189 x
+= s
->img
->hmargin
;
4190 y
+= s
->img
->vmargin
;
4196 /* We can't set both a clip mask and use XSetClipRectangles
4197 because the latter also sets a clip mask. We also can't
4198 trust on the shape extension to be available
4199 (XShapeCombineRegion). So, compute the rectangle to draw
4201 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4205 xgcv
.clip_mask
= s
->img
->mask
;
4206 xgcv
.clip_x_origin
= x
;
4207 xgcv
.clip_y_origin
= y
;
4208 xgcv
.function
= GXcopy
;
4209 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4211 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4212 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4213 XSetClipMask (s
->display
, s
->gc
, None
);
4217 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4218 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4220 /* When the image has a mask, we can expect that at
4221 least part of a mouse highlight or a block cursor will
4222 be visible. If the image doesn't have a mask, make
4223 a block cursor visible by drawing a rectangle around
4224 the image. I believe it's looking better if we do
4225 nothing here for mouse-face. */
4226 if (s
->hl
== DRAW_CURSOR
)
4227 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4228 s
->img
->width
- 1, s
->img
->height
- 1);
4232 /* Draw a rectangle if image could not be loaded. */
4233 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4234 s
->img
->width
- 1, s
->img
->height
- 1);
4238 /* Draw part of the background of glyph string S. X, Y, W, and H
4239 give the rectangle to draw. */
4242 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4243 struct glyph_string
*s
;
4248 /* Fill background with a stipple pattern. */
4249 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4250 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4251 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4254 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4258 /* Draw image glyph string S.
4261 s->x +-------------------------
4264 | +-------------------------
4267 | | +-------------------
4273 x_draw_image_glyph_string (s
)
4274 struct glyph_string
*s
;
4277 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4278 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4280 Pixmap pixmap
= None
;
4282 height
= s
->height
- 2 * box_line_vwidth
;
4284 /* Fill background with face under the image. Do it only if row is
4285 taller than image or if image has a clip mask to reduce
4287 s
->stippled_p
= s
->face
->stipple
!= 0;
4288 if (height
> s
->img
->height
4292 || s
->img
->pixmap
== 0
4293 || s
->width
!= s
->background_width
)
4295 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4296 x
= s
->x
+ box_line_hwidth
;
4300 y
= s
->y
+ box_line_vwidth
;
4304 /* Create a pixmap as large as the glyph string. Fill it
4305 with the background color. Copy the image to it, using
4306 its mask. Copy the temporary pixmap to the display. */
4307 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4308 int depth
= DefaultDepthOfScreen (screen
);
4310 /* Create a pixmap as large as the glyph string. */
4311 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4312 s
->background_width
,
4315 /* Don't clip in the following because we're working on the
4317 XSetClipMask (s
->display
, s
->gc
, None
);
4319 /* Fill the pixmap with the background color/stipple. */
4322 /* Fill background with a stipple pattern. */
4323 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4324 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4325 0, 0, s
->background_width
, s
->height
);
4326 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4331 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4333 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4334 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4335 0, 0, s
->background_width
, s
->height
);
4336 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4340 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4342 s
->background_filled_p
= 1;
4345 /* Draw the foreground. */
4348 x_draw_image_foreground_1 (s
, pixmap
);
4349 x_set_glyph_string_clipping (s
);
4350 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4351 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4352 XFreePixmap (s
->display
, pixmap
);
4355 x_draw_image_foreground (s
);
4357 /* If we must draw a relief around the image, do it. */
4359 || s
->hl
== DRAW_IMAGE_RAISED
4360 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4361 x_draw_image_relief (s
);
4365 /* Draw stretch glyph string S. */
4368 x_draw_stretch_glyph_string (s
)
4369 struct glyph_string
*s
;
4371 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4372 s
->stippled_p
= s
->face
->stipple
!= 0;
4374 if (s
->hl
== DRAW_CURSOR
4375 && !x_stretch_cursor_p
)
4377 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4378 as wide as the stretch glyph. */
4379 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4382 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4384 /* Clear rest using the GC of the original non-cursor face. */
4385 if (width
< s
->background_width
)
4387 GC gc
= s
->face
->gc
;
4388 int x
= s
->x
+ width
, y
= s
->y
;
4389 int w
= s
->background_width
- width
, h
= s
->height
;
4392 x_get_glyph_string_clip_rect (s
, &r
);
4393 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4395 if (s
->face
->stipple
)
4397 /* Fill background with a stipple pattern. */
4398 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4399 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4400 XSetFillStyle (s
->display
, gc
, FillSolid
);
4405 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4406 XSetForeground (s
->display
, gc
, xgcv
.background
);
4407 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4408 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4412 else if (!s
->background_filled_p
)
4413 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4416 s
->background_filled_p
= 1;
4420 /* Draw glyph string S. */
4423 x_draw_glyph_string (s
)
4424 struct glyph_string
*s
;
4426 int relief_drawn_p
= 0;
4428 /* If S draws into the background of its successor, draw the
4429 background of the successor first so that S can draw into it.
4430 This makes S->next use XDrawString instead of XDrawImageString. */
4431 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4433 xassert (s
->next
->img
== NULL
);
4434 x_set_glyph_string_gc (s
->next
);
4435 x_set_glyph_string_clipping (s
->next
);
4436 x_draw_glyph_string_background (s
->next
, 1);
4439 /* Set up S->gc, set clipping and draw S. */
4440 x_set_glyph_string_gc (s
);
4441 x_set_glyph_string_clipping (s
);
4443 /* Draw relief (if any) in advance for char/composition so that the
4444 glyph string can be drawn over it. */
4445 if (!s
->for_overlaps_p
4446 && s
->face
->box
!= FACE_NO_BOX
4447 && (s
->first_glyph
->type
== CHAR_GLYPH
4448 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4451 x_draw_glyph_string_background (s
, 1);
4452 x_draw_glyph_string_box (s
);
4456 switch (s
->first_glyph
->type
)
4459 x_draw_image_glyph_string (s
);
4463 x_draw_stretch_glyph_string (s
);
4467 if (s
->for_overlaps_p
)
4468 s
->background_filled_p
= 1;
4470 x_draw_glyph_string_background (s
, 0);
4471 x_draw_glyph_string_foreground (s
);
4474 case COMPOSITE_GLYPH
:
4475 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4476 s
->background_filled_p
= 1;
4478 x_draw_glyph_string_background (s
, 1);
4479 x_draw_composite_glyph_string_foreground (s
);
4486 if (!s
->for_overlaps_p
)
4488 /* Draw underline. */
4489 if (s
->face
->underline_p
)
4491 unsigned long tem
, h
;
4494 /* Get the underline thickness. Default is 1 pixel. */
4495 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4498 /* Get the underline position. This is the recommended
4499 vertical offset in pixels from the baseline to the top of
4500 the underline. This is a signed value according to the
4501 specs, and its default is
4503 ROUND ((maximum descent) / 2), with
4504 ROUND(x) = floor (x + 0.5) */
4506 if (x_use_underline_position_properties
4507 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4508 y
= s
->ybase
+ (long) tem
;
4509 else if (s
->face
->font
)
4510 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4512 y
= s
->y
+ s
->height
- h
;
4514 if (s
->face
->underline_defaulted_p
)
4515 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4516 s
->x
, y
, s
->width
, h
);
4520 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4521 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4522 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4523 s
->x
, y
, s
->width
, h
);
4524 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4528 /* Draw overline. */
4529 if (s
->face
->overline_p
)
4531 unsigned long dy
= 0, h
= 1;
4533 if (s
->face
->overline_color_defaulted_p
)
4534 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4539 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4540 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4541 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4543 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4547 /* Draw strike-through. */
4548 if (s
->face
->strike_through_p
)
4550 unsigned long h
= 1;
4551 unsigned long dy
= (s
->height
- h
) / 2;
4553 if (s
->face
->strike_through_color_defaulted_p
)
4554 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4559 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4560 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4561 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4563 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4567 /* Draw relief if not yet drawn. */
4568 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4569 x_draw_glyph_string_box (s
);
4572 /* Reset clipping. */
4573 XSetClipMask (s
->display
, s
->gc
, None
);
4577 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4578 struct face
**, int));
4581 /* Fill glyph string S with composition components specified by S->cmp.
4583 FACES is an array of faces for all components of this composition.
4584 S->gidx is the index of the first component for S.
4585 OVERLAPS_P non-zero means S should draw the foreground only, and
4586 use its physical height for clipping.
4588 Value is the index of a component not in S. */
4591 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4592 struct glyph_string
*s
;
4593 struct face
**faces
;
4600 s
->for_overlaps_p
= overlaps_p
;
4602 s
->face
= faces
[s
->gidx
];
4603 s
->font
= s
->face
->font
;
4604 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4606 /* For all glyphs of this composition, starting at the offset
4607 S->gidx, until we reach the end of the definition or encounter a
4608 glyph that requires the different face, add it to S. */
4610 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4613 /* All glyph strings for the same composition has the same width,
4614 i.e. the width set for the first component of the composition. */
4616 s
->width
= s
->first_glyph
->pixel_width
;
4618 /* If the specified font could not be loaded, use the frame's
4619 default font, but record the fact that we couldn't load it in
4620 the glyph string so that we can draw rectangles for the
4621 characters of the glyph string. */
4622 if (s
->font
== NULL
)
4624 s
->font_not_found_p
= 1;
4625 s
->font
= FRAME_FONT (s
->f
);
4628 /* Adjust base line for subscript/superscript text. */
4629 s
->ybase
+= s
->first_glyph
->voffset
;
4631 xassert (s
->face
&& s
->face
->gc
);
4633 /* This glyph string must always be drawn with 16-bit functions. */
4636 return s
->gidx
+ s
->nchars
;
4640 /* Fill glyph string S from a sequence of character glyphs.
4642 FACE_ID is the face id of the string. START is the index of the
4643 first glyph to consider, END is the index of the last + 1.
4644 OVERLAPS_P non-zero means S should draw the foreground only, and
4645 use its physical height for clipping.
4647 Value is the index of the first glyph not in S. */
4650 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4651 struct glyph_string
*s
;
4653 int start
, end
, overlaps_p
;
4655 struct glyph
*glyph
, *last
;
4657 int glyph_not_available_p
;
4659 xassert (s
->f
== XFRAME (s
->w
->frame
));
4660 xassert (s
->nchars
== 0);
4661 xassert (start
>= 0 && end
> start
);
4663 s
->for_overlaps_p
= overlaps_p
,
4664 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4665 last
= s
->row
->glyphs
[s
->area
] + end
;
4666 voffset
= glyph
->voffset
;
4668 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4671 && glyph
->type
== CHAR_GLYPH
4672 && glyph
->voffset
== voffset
4673 /* Same face id implies same font, nowadays. */
4674 && glyph
->face_id
== face_id
4675 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4679 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4680 s
->char2b
+ s
->nchars
,
4682 s
->two_byte_p
= two_byte_p
;
4684 xassert (s
->nchars
<= end
- start
);
4685 s
->width
+= glyph
->pixel_width
;
4689 s
->font
= s
->face
->font
;
4690 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4692 /* If the specified font could not be loaded, use the frame's font,
4693 but record the fact that we couldn't load it in
4694 S->font_not_found_p so that we can draw rectangles for the
4695 characters of the glyph string. */
4696 if (s
->font
== NULL
|| glyph_not_available_p
)
4698 s
->font_not_found_p
= 1;
4699 s
->font
= FRAME_FONT (s
->f
);
4702 /* Adjust base line for subscript/superscript text. */
4703 s
->ybase
+= voffset
;
4705 xassert (s
->face
&& s
->face
->gc
);
4706 return glyph
- s
->row
->glyphs
[s
->area
];
4710 /* Fill glyph string S from image glyph S->first_glyph. */
4713 x_fill_image_glyph_string (s
)
4714 struct glyph_string
*s
;
4716 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4717 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4719 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4720 s
->font
= s
->face
->font
;
4721 s
->width
= s
->first_glyph
->pixel_width
;
4723 /* Adjust base line for subscript/superscript text. */
4724 s
->ybase
+= s
->first_glyph
->voffset
;
4728 /* Fill glyph string S from a sequence of stretch glyphs.
4730 ROW is the glyph row in which the glyphs are found, AREA is the
4731 area within the row. START is the index of the first glyph to
4732 consider, END is the index of the last + 1.
4734 Value is the index of the first glyph not in S. */
4737 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4738 struct glyph_string
*s
;
4739 struct glyph_row
*row
;
4740 enum glyph_row_area area
;
4743 struct glyph
*glyph
, *last
;
4744 int voffset
, face_id
;
4746 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4748 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4749 last
= s
->row
->glyphs
[s
->area
] + end
;
4750 face_id
= glyph
->face_id
;
4751 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4752 s
->font
= s
->face
->font
;
4753 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4754 s
->width
= glyph
->pixel_width
;
4755 voffset
= glyph
->voffset
;
4759 && glyph
->type
== STRETCH_GLYPH
4760 && glyph
->voffset
== voffset
4761 && glyph
->face_id
== face_id
);
4763 s
->width
+= glyph
->pixel_width
;
4765 /* Adjust base line for subscript/superscript text. */
4766 s
->ybase
+= voffset
;
4768 xassert (s
->face
&& s
->face
->gc
);
4769 return glyph
- s
->row
->glyphs
[s
->area
];
4773 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4774 of XChar2b structures for S; it can't be allocated in
4775 x_init_glyph_string because it must be allocated via `alloca'. W
4776 is the window on which S is drawn. ROW and AREA are the glyph row
4777 and area within the row from which S is constructed. START is the
4778 index of the first glyph structure covered by S. HL is a
4779 face-override for drawing S. */
4782 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4783 struct glyph_string
*s
;
4786 struct glyph_row
*row
;
4787 enum glyph_row_area area
;
4789 enum draw_glyphs_face hl
;
4791 bzero (s
, sizeof *s
);
4793 s
->f
= XFRAME (w
->frame
);
4794 s
->display
= FRAME_X_DISPLAY (s
->f
);
4795 s
->window
= FRAME_X_WINDOW (s
->f
);
4800 s
->first_glyph
= row
->glyphs
[area
] + start
;
4801 s
->height
= row
->height
;
4802 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4804 /* Display the internal border below the tool-bar window. */
4805 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4806 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4808 s
->ybase
= s
->y
+ row
->ascent
;
4812 /* Set background width of glyph string S. START is the index of the
4813 first glyph following S. LAST_X is the right-most x-position + 1
4814 in the drawing area. */
4817 x_set_glyph_string_background_width (s
, start
, last_x
)
4818 struct glyph_string
*s
;
4822 /* If the face of this glyph string has to be drawn to the end of
4823 the drawing area, set S->extends_to_end_of_line_p. */
4824 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4826 if (start
== s
->row
->used
[s
->area
]
4827 && s
->hl
== DRAW_NORMAL_TEXT
4828 && s
->area
== TEXT_AREA
4829 && (s
->row
->fill_line_p
4830 || s
->face
->background
!= default_face
->background
4831 || s
->face
->stipple
!= default_face
->stipple
))
4832 s
->extends_to_end_of_line_p
= 1;
4834 /* If S extends its face to the end of the line, set its
4835 background_width to the distance to the right edge of the drawing
4837 if (s
->extends_to_end_of_line_p
)
4838 s
->background_width
= last_x
- s
->x
+ 1;
4840 s
->background_width
= s
->width
;
4844 /* Add a glyph string for a stretch glyph to the list of strings
4845 between HEAD and TAIL. START is the index of the stretch glyph in
4846 row area AREA of glyph row ROW. END is the index of the last glyph
4847 in that glyph row area. X is the current output position assigned
4848 to the new glyph string constructed. HL overrides that face of the
4849 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4850 is the right-most x-position of the drawing area. */
4852 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4853 and below -- keep them on one line. */
4854 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4857 s = (struct glyph_string *) alloca (sizeof *s); \
4858 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4859 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4860 x_append_glyph_string (&HEAD, &TAIL, s); \
4866 /* Add a glyph string for an image glyph to the list of strings
4867 between HEAD and TAIL. START is the index of the image glyph in
4868 row area AREA of glyph row ROW. END is the index of the last glyph
4869 in that glyph row area. X is the current output position assigned
4870 to the new glyph string constructed. HL overrides that face of the
4871 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4872 is the right-most x-position of the drawing area. */
4874 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4877 s = (struct glyph_string *) alloca (sizeof *s); \
4878 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4879 x_fill_image_glyph_string (s); \
4880 x_append_glyph_string (&HEAD, &TAIL, s); \
4887 /* Add a glyph string for a sequence of character glyphs to the list
4888 of strings between HEAD and TAIL. START is the index of the first
4889 glyph in row area AREA of glyph row ROW that is part of the new
4890 glyph string. END is the index of the last glyph in that glyph row
4891 area. X is the current output position assigned to the new glyph
4892 string constructed. HL overrides that face of the glyph; e.g. it
4893 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4894 right-most x-position of the drawing area. */
4896 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4902 c = (ROW)->glyphs[AREA][START].u.ch; \
4903 face_id = (ROW)->glyphs[AREA][START].face_id; \
4905 s = (struct glyph_string *) alloca (sizeof *s); \
4906 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4907 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4908 x_append_glyph_string (&HEAD, &TAIL, s); \
4910 START = x_fill_glyph_string (s, face_id, START, END, \
4916 /* Add a glyph string for a composite sequence to the list of strings
4917 between HEAD and TAIL. START is the index of the first glyph in
4918 row area AREA of glyph row ROW that is part of the new glyph
4919 string. END is the index of the last glyph in that glyph row area.
4920 X is the current output position assigned to the new glyph string
4921 constructed. HL overrides that face of the glyph; e.g. it is
4922 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4923 x-position of the drawing area. */
4925 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4927 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4928 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4929 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4930 struct composition *cmp = composition_table[cmp_id]; \
4931 int glyph_len = cmp->glyph_len; \
4933 struct face **faces; \
4934 struct glyph_string *first_s = NULL; \
4937 base_face = base_face->ascii_face; \
4938 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4939 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4940 /* At first, fill in `char2b' and `faces'. */ \
4941 for (n = 0; n < glyph_len; n++) \
4943 int c = COMPOSITION_GLYPH (cmp, n); \
4944 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4945 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4946 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4947 this_face_id, char2b + n, 1); \
4950 /* Make glyph_strings for each glyph sequence that is drawable by \
4951 the same face, and append them to HEAD/TAIL. */ \
4952 for (n = 0; n < cmp->glyph_len;) \
4954 s = (struct glyph_string *) alloca (sizeof *s); \
4955 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4956 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4964 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4972 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4973 of AREA of glyph row ROW on window W between indices START and END.
4974 HL overrides the face for drawing glyph strings, e.g. it is
4975 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4976 x-positions of the drawing area.
4978 This is an ugly monster macro construct because we must use alloca
4979 to allocate glyph strings (because x_draw_glyphs can be called
4982 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4985 HEAD = TAIL = NULL; \
4986 while (START < END) \
4988 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4989 switch (first_glyph->type) \
4992 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4993 TAIL, HL, X, LAST_X, \
4997 case COMPOSITE_GLYPH: \
4998 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4999 HEAD, TAIL, HL, X, LAST_X,\
5003 case STRETCH_GLYPH: \
5004 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5005 HEAD, TAIL, HL, X, LAST_X); \
5009 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5010 TAIL, HL, X, LAST_X); \
5017 x_set_glyph_string_background_width (s, START, LAST_X); \
5024 /* Draw glyphs between START and END in AREA of ROW on window W,
5025 starting at x-position X. X is relative to AREA in W. HL is a
5026 face-override with the following meaning:
5028 DRAW_NORMAL_TEXT draw normally
5029 DRAW_CURSOR draw in cursor face
5030 DRAW_MOUSE_FACE draw in mouse face.
5031 DRAW_INVERSE_VIDEO draw in mode line face
5032 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5033 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5035 If REAL_START is non-null, return in *REAL_START the real starting
5036 position for display. This can be different from START in case
5037 overlapping glyphs must be displayed. If REAL_END is non-null,
5038 return in *REAL_END the real end position for display. This can be
5039 different from END in case overlapping glyphs must be displayed.
5041 If OVERLAPS_P is non-zero, draw only the foreground of characters
5042 and clip to the physical height of ROW.
5044 Value is the x-position reached, relative to AREA of W. */
5047 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
5051 struct glyph_row
*row
;
5052 enum glyph_row_area area
;
5054 enum draw_glyphs_face hl
;
5055 int *real_start
, *real_end
;
5058 struct glyph_string
*head
, *tail
;
5059 struct glyph_string
*s
;
5060 int last_x
, area_width
;
5064 /* Let's rather be paranoid than getting a SEGV. */
5065 end
= min (end
, row
->used
[area
]);
5066 start
= max (0, start
);
5067 start
= min (end
, start
);
5069 *real_start
= start
;
5073 /* Translate X to frame coordinates. Set last_x to the right
5074 end of the drawing area. */
5075 if (row
->full_width_p
)
5077 /* X is relative to the left edge of W, without scroll bars
5079 struct frame
*f
= XFRAME (w
->frame
);
5080 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
5081 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5084 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5085 last_x
= window_left_x
+ area_width
;
5087 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5089 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5090 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5096 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5097 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
5101 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5102 area_width
= window_box_width (w
, area
);
5103 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5106 /* Build a doubly-linked list of glyph_string structures between
5107 head and tail from what we have to draw. Note that the macro
5108 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5109 the reason we use a separate variable `i'. */
5111 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5114 x_reached
= tail
->x
+ tail
->background_width
;
5118 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5119 the row, redraw some glyphs in front or following the glyph
5120 strings built above. */
5121 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5124 struct glyph_string
*h
, *t
;
5126 /* Compute overhangs for all glyph strings. */
5127 for (s
= head
; s
; s
= s
->next
)
5128 x_compute_glyph_string_overhangs (s
);
5130 /* Prepend glyph strings for glyphs in front of the first glyph
5131 string that are overwritten because of the first glyph
5132 string's left overhang. The background of all strings
5133 prepended must be drawn because the first glyph string
5135 i
= x_left_overwritten (head
);
5139 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5140 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5144 *real_start
= start
;
5145 x_compute_overhangs_and_x (t
, head
->x
, 1);
5146 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5149 /* Prepend glyph strings for glyphs in front of the first glyph
5150 string that overwrite that glyph string because of their
5151 right overhang. For these strings, only the foreground must
5152 be drawn, because it draws over the glyph string at `head'.
5153 The background must not be drawn because this would overwrite
5154 right overhangs of preceding glyphs for which no glyph
5156 i
= x_left_overwriting (head
);
5159 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5160 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5162 for (s
= h
; s
; s
= s
->next
)
5163 s
->background_filled_p
= 1;
5166 x_compute_overhangs_and_x (t
, head
->x
, 1);
5167 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5170 /* Append glyphs strings for glyphs following the last glyph
5171 string tail that are overwritten by tail. The background of
5172 these strings has to be drawn because tail's foreground draws
5174 i
= x_right_overwritten (tail
);
5177 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5178 DRAW_NORMAL_TEXT
, x
, last_x
,
5180 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5181 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5186 /* Append glyph strings for glyphs following the last glyph
5187 string tail that overwrite tail. The foreground of such
5188 glyphs has to be drawn because it writes into the background
5189 of tail. The background must not be drawn because it could
5190 paint over the foreground of following glyphs. */
5191 i
= x_right_overwriting (tail
);
5194 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5195 DRAW_NORMAL_TEXT
, x
, last_x
,
5197 for (s
= h
; s
; s
= s
->next
)
5198 s
->background_filled_p
= 1;
5199 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5200 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5206 /* Draw all strings. */
5207 for (s
= head
; s
; s
= s
->next
)
5208 x_draw_glyph_string (s
);
5210 /* Value is the x-position up to which drawn, relative to AREA of W.
5211 This doesn't include parts drawn because of overhangs. */
5212 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5213 if (!row
->full_width_p
)
5215 if (area
> LEFT_MARGIN_AREA
)
5216 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5217 if (area
> TEXT_AREA
)
5218 x_reached
-= window_box_width (w
, TEXT_AREA
);
5225 /* Fix the display of area AREA of overlapping row ROW in window W. */
5228 x_fix_overlapping_area (w
, row
, area
)
5230 struct glyph_row
*row
;
5231 enum glyph_row_area area
;
5237 if (area
== LEFT_MARGIN_AREA
)
5239 else if (area
== TEXT_AREA
)
5240 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5242 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5243 + window_box_width (w
, TEXT_AREA
));
5245 for (i
= 0; i
< row
->used
[area
];)
5247 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5249 int start
= i
, start_x
= x
;
5253 x
+= row
->glyphs
[area
][i
].pixel_width
;
5256 while (i
< row
->used
[area
]
5257 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5259 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5261 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5266 x
+= row
->glyphs
[area
][i
].pixel_width
;
5275 /* Output LEN glyphs starting at START at the nominal cursor position.
5276 Advance the nominal cursor over the text. The global variable
5277 updated_window contains the window being updated, updated_row is
5278 the glyph row being updated, and updated_area is the area of that
5279 row being updated. */
5282 x_write_glyphs (start
, len
)
5283 struct glyph
*start
;
5286 int x
, hpos
, real_start
, real_end
;
5288 xassert (updated_window
&& updated_row
);
5293 hpos
= start
- updated_row
->glyphs
[updated_area
];
5294 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5295 updated_row
, updated_area
,
5297 (updated_row
->inverse_p
5298 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5299 &real_start
, &real_end
, 0);
5301 /* If we drew over the cursor, note that it is not visible any more. */
5302 note_overwritten_text_cursor (updated_window
, real_start
,
5303 real_end
- real_start
);
5307 /* Advance the output cursor. */
5308 output_cursor
.hpos
+= len
;
5309 output_cursor
.x
= x
;
5313 /* Insert LEN glyphs from START at the nominal cursor position. */
5316 x_insert_glyphs (start
, len
)
5317 struct glyph
*start
;
5322 int line_height
, shift_by_width
, shifted_region_width
;
5323 struct glyph_row
*row
;
5324 struct glyph
*glyph
;
5325 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
5327 xassert (updated_window
&& updated_row
);
5330 f
= XFRAME (WINDOW_FRAME (w
));
5332 /* Get the height of the line we are in. */
5334 line_height
= row
->height
;
5336 /* Get the width of the glyphs to insert. */
5338 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5339 shift_by_width
+= glyph
->pixel_width
;
5341 /* Get the width of the region to shift right. */
5342 shifted_region_width
= (window_box_width (w
, updated_area
)
5347 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5348 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5349 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5350 f
->output_data
.x
->normal_gc
,
5352 shifted_region_width
, line_height
,
5353 frame_x
+ shift_by_width
, frame_y
);
5355 /* Write the glyphs. */
5356 hpos
= start
- row
->glyphs
[updated_area
];
5357 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5358 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
5359 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5361 /* Advance the output cursor. */
5362 output_cursor
.hpos
+= len
;
5363 output_cursor
.x
+= shift_by_width
;
5368 /* Delete N glyphs at the nominal cursor position. Not implemented
5379 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5380 If they are <= 0, this is probably an error. */
5383 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5390 xassert (width
> 0 && height
> 0);
5391 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5395 /* Erase the current text line from the nominal cursor position
5396 (inclusive) to pixel column TO_X (exclusive). The idea is that
5397 everything from TO_X onward is already erased.
5399 TO_X is a pixel position relative to updated_area of
5400 updated_window. TO_X == -1 means clear to the end of this area. */
5403 x_clear_end_of_line (to_x
)
5407 struct window
*w
= updated_window
;
5408 int max_x
, min_y
, max_y
;
5409 int from_x
, from_y
, to_y
;
5411 xassert (updated_window
&& updated_row
);
5412 f
= XFRAME (w
->frame
);
5414 if (updated_row
->full_width_p
)
5416 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5417 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5418 && !w
->pseudo_window_p
)
5419 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5422 max_x
= window_box_width (w
, updated_area
);
5423 max_y
= window_text_bottom_y (w
);
5425 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5426 of window. For TO_X > 0, truncate to end of drawing area. */
5432 to_x
= min (to_x
, max_x
);
5434 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5436 /* Notice if the cursor will be cleared by this operation. */
5437 if (!updated_row
->full_width_p
)
5438 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5440 from_x
= output_cursor
.x
;
5442 /* Translate to frame coordinates. */
5443 if (updated_row
->full_width_p
)
5445 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5446 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5450 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5451 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5454 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5455 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5456 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5458 /* Prevent inadvertently clearing to end of the X window. */
5459 if (to_x
> from_x
&& to_y
> from_y
)
5462 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5463 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5470 /* Clear entire frame. If updating_frame is non-null, clear that
5471 frame. Otherwise clear the selected frame. */
5481 f
= SELECTED_FRAME ();
5483 /* Clearing the frame will erase any cursor, so mark them all as no
5485 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5486 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5487 output_cursor
.x
= -1;
5489 /* We don't set the output cursor here because there will always
5490 follow an explicit cursor_to. */
5492 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5494 /* We have to clear the scroll bars, too. If we have changed
5495 colors or something like that, then they should be notified. */
5496 x_scroll_bar_clear (f
);
5498 XFlush (FRAME_X_DISPLAY (f
));
5504 /* Invert the middle quarter of the frame for .15 sec. */
5506 /* We use the select system call to do the waiting, so we have to make
5507 sure it's available. If it isn't, we just won't do visual bells. */
5509 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5512 /* Subtract the `struct timeval' values X and Y, storing the result in
5513 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5516 timeval_subtract (result
, x
, y
)
5517 struct timeval
*result
, x
, y
;
5519 /* Perform the carry for the later subtraction by updating y. This
5520 is safer because on some systems the tv_sec member is unsigned. */
5521 if (x
.tv_usec
< y
.tv_usec
)
5523 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5524 y
.tv_usec
-= 1000000 * nsec
;
5528 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5530 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5531 y
.tv_usec
+= 1000000 * nsec
;
5535 /* Compute the time remaining to wait. tv_usec is certainly
5537 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5538 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5540 /* Return indication of whether the result should be considered
5542 return x
.tv_sec
< y
.tv_sec
;
5554 /* Create a GC that will use the GXxor function to flip foreground
5555 pixels into background pixels. */
5559 values
.function
= GXxor
;
5560 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5561 ^ f
->output_data
.x
->background_pixel
);
5563 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5564 GCFunction
| GCForeground
, &values
);
5568 /* Get the height not including a menu bar widget. */
5569 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5570 /* Height of each line to flash. */
5571 int flash_height
= FRAME_LINE_HEIGHT (f
);
5572 /* These will be the left and right margins of the rectangles. */
5573 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5574 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5578 /* Don't flash the area between a scroll bar and the frame
5579 edge it is next to. */
5580 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5582 case vertical_scroll_bar_left
:
5583 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5586 case vertical_scroll_bar_right
:
5587 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5594 width
= flash_right
- flash_left
;
5596 /* If window is tall, flash top and bottom line. */
5597 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5599 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5601 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5602 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5603 width
, flash_height
);
5604 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5606 (height
- flash_height
5607 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5608 width
, flash_height
);
5611 /* If it is short, flash it all. */
5612 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5613 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5614 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5619 struct timeval wakeup
;
5621 EMACS_GET_TIME (wakeup
);
5623 /* Compute time to wait until, propagating carry from usecs. */
5624 wakeup
.tv_usec
+= 150000;
5625 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5626 wakeup
.tv_usec
%= 1000000;
5628 /* Keep waiting until past the time wakeup or any input gets
5630 while (! detect_input_pending ())
5632 struct timeval current
;
5633 struct timeval timeout
;
5635 EMACS_GET_TIME (current
);
5637 /* Break if result would be negative. */
5638 if (timeval_subtract (¤t
, wakeup
, current
))
5641 /* How long `select' should wait. */
5643 timeout
.tv_usec
= 10000;
5645 /* Try to wait that long--but we might wake up sooner. */
5646 select (0, NULL
, NULL
, NULL
, &timeout
);
5650 /* If window is tall, flash top and bottom line. */
5651 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5653 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5655 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5656 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5657 width
, flash_height
);
5658 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5660 (height
- flash_height
5661 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5662 width
, flash_height
);
5665 /* If it is short, flash it all. */
5666 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5667 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5668 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5670 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5678 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5681 /* Make audible bell. */
5686 struct frame
*f
= SELECTED_FRAME ();
5688 if (FRAME_X_DISPLAY (f
))
5690 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5697 XBell (FRAME_X_DISPLAY (f
), 0);
5698 XFlush (FRAME_X_DISPLAY (f
));
5705 /* Specify how many text lines, from the top of the window,
5706 should be affected by insert-lines and delete-lines operations.
5707 This, and those operations, are used only within an update
5708 that is bounded by calls to x_update_begin and x_update_end. */
5711 XTset_terminal_window (n
)
5714 /* This function intentionally left blank. */
5719 /***********************************************************************
5721 ***********************************************************************/
5723 /* Perform an insert-lines or delete-lines operation, inserting N
5724 lines or deleting -N lines at vertical position VPOS. */
5727 x_ins_del_lines (vpos
, n
)
5734 /* Scroll part of the display as described by RUN. */
5737 x_scroll_run (w
, run
)
5741 struct frame
*f
= XFRAME (w
->frame
);
5742 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5744 /* Get frame-relative bounding box of the text display area of W,
5745 without mode lines. Include in this box the flags areas to the
5746 left and right of W. */
5747 window_box (w
, -1, &x
, &y
, &width
, &height
);
5748 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5749 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5751 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5752 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5753 bottom_y
= y
+ height
;
5757 /* Scrolling up. Make sure we don't copy part of the mode
5758 line at the bottom. */
5759 if (from_y
+ run
->height
> bottom_y
)
5760 height
= bottom_y
- from_y
;
5762 height
= run
->height
;
5766 /* Scolling down. Make sure we don't copy over the mode line.
5768 if (to_y
+ run
->height
> bottom_y
)
5769 height
= bottom_y
- to_y
;
5771 height
= run
->height
;
5776 /* Cursor off. Will be switched on again in x_update_window_end. */
5780 XCopyArea (FRAME_X_DISPLAY (f
),
5781 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5782 f
->output_data
.x
->normal_gc
,
5792 /***********************************************************************
5794 ***********************************************************************/
5796 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5797 corner of the exposed rectangle. W and H are width and height of
5798 the exposed area. All are pixel values. W or H zero means redraw
5799 the entire frame. */
5802 expose_frame (f
, x
, y
, w
, h
)
5808 TRACE ((stderr
, "expose_frame "));
5810 /* No need to redraw if frame will be redrawn soon. */
5811 if (FRAME_GARBAGED_P (f
))
5813 TRACE ((stderr
, " garbaged\n"));
5817 /* If basic faces haven't been realized yet, there is no point in
5818 trying to redraw anything. This can happen when we get an expose
5819 event while Emacs is starting, e.g. by moving another window. */
5820 if (FRAME_FACE_CACHE (f
) == NULL
5821 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5823 TRACE ((stderr
, " no faces\n"));
5827 if (w
== 0 || h
== 0)
5830 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5831 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5841 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5842 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5844 if (WINDOWP (f
->tool_bar_window
))
5845 expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5847 #ifndef USE_X_TOOLKIT
5848 if (WINDOWP (f
->menu_bar_window
))
5849 expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5850 #endif /* not USE_X_TOOLKIT */
5854 /* Redraw (parts) of all windows in the window tree rooted at W that
5855 intersect R. R contains frame pixel coordinates. */
5858 expose_window_tree (w
, r
)
5864 if (!NILP (w
->hchild
))
5865 expose_window_tree (XWINDOW (w
->hchild
), r
);
5866 else if (!NILP (w
->vchild
))
5867 expose_window_tree (XWINDOW (w
->vchild
), r
);
5868 else if (expose_window (w
, r
) == 0)
5870 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5875 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5876 which intersects rectangle R. R is in window-relative coordinates. */
5879 expose_area (w
, row
, r
, area
)
5881 struct glyph_row
*row
;
5883 enum glyph_row_area area
;
5885 struct glyph
*first
= row
->glyphs
[area
];
5886 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5888 int first_x
, start_x
, x
;
5890 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5891 /* If row extends face to end of line write the whole line. */
5892 x_draw_glyphs (w
, 0, row
, area
,
5894 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5898 /* Set START_X to the window-relative start position for drawing glyphs of
5899 AREA. The first glyph of the text area can be partially visible.
5900 The first glyphs of other areas cannot. */
5901 if (area
== LEFT_MARGIN_AREA
)
5903 else if (area
== TEXT_AREA
)
5904 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5906 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5907 + window_box_width (w
, TEXT_AREA
));
5910 /* Find the first glyph that must be redrawn. */
5912 && x
+ first
->pixel_width
< r
->x
)
5914 x
+= first
->pixel_width
;
5918 /* Find the last one. */
5922 && x
< r
->x
+ r
->width
)
5924 x
+= last
->pixel_width
;
5930 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5931 first
- row
->glyphs
[area
],
5932 last
- row
->glyphs
[area
],
5933 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5939 /* Redraw the parts of the glyph row ROW on window W intersecting
5940 rectangle R. R is in window-relative coordinates. */
5943 expose_line (w
, row
, r
)
5945 struct glyph_row
*row
;
5948 xassert (row
->enabled_p
);
5950 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5951 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5952 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5956 if (row
->used
[LEFT_MARGIN_AREA
])
5957 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5958 if (row
->used
[TEXT_AREA
])
5959 expose_area (w
, row
, r
, TEXT_AREA
);
5960 if (row
->used
[RIGHT_MARGIN_AREA
])
5961 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5962 x_draw_row_bitmaps (w
, row
);
5967 /* Return non-zero if W's cursor intersects rectangle R. */
5970 x_phys_cursor_in_rect_p (w
, r
)
5974 XRectangle cr
, result
;
5975 struct glyph
*cursor_glyph
;
5977 cursor_glyph
= get_phys_cursor_glyph (w
);
5980 cr
.x
= w
->phys_cursor
.x
;
5981 cr
.y
= w
->phys_cursor
.y
;
5982 cr
.width
= cursor_glyph
->pixel_width
;
5983 cr
.height
= w
->phys_cursor_height
;
5984 return x_intersect_rectangles (&cr
, r
, &result
);
5991 /* Redraw the part of window W intersection rectangle FR. Pixel
5992 coordinates in FR are frame-relative. Call this function with
5996 expose_window (w
, fr
)
6000 struct frame
*f
= XFRAME (w
->frame
);
6003 /* If window is not yet fully initialized, do nothing. This can
6004 happen when toolkit scroll bars are used and a window is split.
6005 Reconfiguring the scroll bar will generate an expose for a newly
6007 if (w
->current_matrix
== NULL
)
6010 /* When we're currently updating the window, display and current
6011 matrix usually don't agree. Arrange for a thorough display
6013 if (w
== updated_window
)
6015 SET_FRAME_GARBAGED (f
);
6019 /* Frame-relative pixel rectangle of W. */
6020 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6021 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6022 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6023 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6025 if (x_intersect_rectangles (fr
, &wr
, &r
))
6027 int yb
= window_text_bottom_y (w
);
6028 struct glyph_row
*row
;
6029 int cursor_cleared_p
;
6031 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6032 r
.x
, r
.y
, r
.width
, r
.height
));
6034 /* Convert to window coordinates. */
6035 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
6036 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
6038 /* Turn off the cursor. */
6039 if (!w
->pseudo_window_p
6040 && x_phys_cursor_in_rect_p (w
, &r
))
6043 cursor_cleared_p
= 1;
6046 cursor_cleared_p
= 0;
6048 /* Find the first row intersecting the rectangle R. */
6049 for (row
= w
->current_matrix
->rows
;
6054 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6056 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
6057 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
6058 || (r
.y
>= y0
&& r
.y
< y1
)
6059 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
6060 expose_line (w
, row
, &r
);
6066 /* Display the mode line if there is one. */
6067 if (WINDOW_WANTS_MODELINE_P (w
)
6068 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6070 && row
->y
< r
.y
+ r
.height
)
6071 expose_line (w
, row
, &r
);
6073 if (!w
->pseudo_window_p
)
6075 /* Draw border between windows. */
6076 x_draw_vertical_border (w
);
6078 /* Turn the cursor on again. */
6079 if (cursor_cleared_p
)
6080 x_update_window_cursor (w
, 1);
6088 /* Determine the intersection of two rectangles R1 and R2. Return
6089 the intersection in *RESULT. Value is non-zero if RESULT is not
6093 x_intersect_rectangles (r1
, r2
, result
)
6094 XRectangle
*r1
, *r2
, *result
;
6096 XRectangle
*left
, *right
;
6097 XRectangle
*upper
, *lower
;
6098 int intersection_p
= 0;
6100 /* Rearrange so that R1 is the left-most rectangle. */
6102 left
= r1
, right
= r2
;
6104 left
= r2
, right
= r1
;
6106 /* X0 of the intersection is right.x0, if this is inside R1,
6107 otherwise there is no intersection. */
6108 if (right
->x
<= left
->x
+ left
->width
)
6110 result
->x
= right
->x
;
6112 /* The right end of the intersection is the minimum of the
6113 the right ends of left and right. */
6114 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6117 /* Same game for Y. */
6119 upper
= r1
, lower
= r2
;
6121 upper
= r2
, lower
= r1
;
6123 /* The upper end of the intersection is lower.y0, if this is inside
6124 of upper. Otherwise, there is no intersection. */
6125 if (lower
->y
<= upper
->y
+ upper
->height
)
6127 result
->y
= lower
->y
;
6129 /* The lower end of the intersection is the minimum of the lower
6130 ends of upper and lower. */
6131 result
->height
= (min (lower
->y
+ lower
->height
,
6132 upper
->y
+ upper
->height
)
6138 return intersection_p
;
6149 /* We used to only do this if Vx_no_window_manager was non-nil, but
6150 the ICCCM (section 4.1.6) says that the window's border pixmap
6151 and border pixel are window attributes which are "private to the
6152 client", so we can always change it to whatever we want. */
6154 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6155 f
->output_data
.x
->border_pixel
);
6157 x_update_cursor (f
, 1);
6161 frame_unhighlight (f
)
6164 /* We used to only do this if Vx_no_window_manager was non-nil, but
6165 the ICCCM (section 4.1.6) says that the window's border pixmap
6166 and border pixel are window attributes which are "private to the
6167 client", so we can always change it to whatever we want. */
6169 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6170 f
->output_data
.x
->border_tile
);
6172 x_update_cursor (f
, 1);
6175 /* The focus has changed. Update the frames as necessary to reflect
6176 the new situation. Note that we can't change the selected frame
6177 here, because the Lisp code we are interrupting might become confused.
6178 Each event gets marked with the frame in which it occurred, so the
6179 Lisp code can tell when the switch took place by examining the events. */
6182 x_new_focus_frame (dpyinfo
, frame
)
6183 struct x_display_info
*dpyinfo
;
6184 struct frame
*frame
;
6186 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6188 if (frame
!= dpyinfo
->x_focus_frame
)
6190 /* Set this before calling other routines, so that they see
6191 the correct value of x_focus_frame. */
6192 dpyinfo
->x_focus_frame
= frame
;
6194 if (old_focus
&& old_focus
->auto_lower
)
6195 x_lower_frame (old_focus
);
6198 selected_frame
= frame
;
6199 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6201 Fselect_window (selected_frame
->selected_window
);
6202 choose_minibuf_frame ();
6205 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6206 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6208 pending_autoraise_frame
= 0;
6211 x_frame_rehighlight (dpyinfo
);
6214 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6217 x_mouse_leave (dpyinfo
)
6218 struct x_display_info
*dpyinfo
;
6220 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6223 /* The focus has changed, or we have redirected a frame's focus to
6224 another frame (this happens when a frame uses a surrogate
6225 mini-buffer frame). Shift the highlight as appropriate.
6227 The FRAME argument doesn't necessarily have anything to do with which
6228 frame is being highlighted or un-highlighted; we only use it to find
6229 the appropriate X display info. */
6232 XTframe_rehighlight (frame
)
6233 struct frame
*frame
;
6235 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6239 x_frame_rehighlight (dpyinfo
)
6240 struct x_display_info
*dpyinfo
;
6242 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6244 if (dpyinfo
->x_focus_frame
)
6246 dpyinfo
->x_highlight_frame
6247 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6248 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6249 : dpyinfo
->x_focus_frame
);
6250 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6252 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6253 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6257 dpyinfo
->x_highlight_frame
= 0;
6259 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6262 frame_unhighlight (old_highlight
);
6263 if (dpyinfo
->x_highlight_frame
)
6264 frame_highlight (dpyinfo
->x_highlight_frame
);
6270 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6272 /* Initialize mode_switch_bit and modifier_meaning. */
6274 x_find_modifier_meanings (dpyinfo
)
6275 struct x_display_info
*dpyinfo
;
6277 int min_code
, max_code
;
6280 XModifierKeymap
*mods
;
6282 dpyinfo
->meta_mod_mask
= 0;
6283 dpyinfo
->shift_lock_mask
= 0;
6284 dpyinfo
->alt_mod_mask
= 0;
6285 dpyinfo
->super_mod_mask
= 0;
6286 dpyinfo
->hyper_mod_mask
= 0;
6289 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6291 min_code
= dpyinfo
->display
->min_keycode
;
6292 max_code
= dpyinfo
->display
->max_keycode
;
6295 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6296 min_code
, max_code
- min_code
+ 1,
6298 mods
= XGetModifierMapping (dpyinfo
->display
);
6300 /* Scan the modifier table to see which modifier bits the Meta and
6301 Alt keysyms are on. */
6303 int row
, col
; /* The row and column in the modifier table. */
6305 for (row
= 3; row
< 8; row
++)
6306 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6309 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6311 /* Zeroes are used for filler. Skip them. */
6315 /* Are any of this keycode's keysyms a meta key? */
6319 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6321 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6327 dpyinfo
->meta_mod_mask
|= (1 << row
);
6332 dpyinfo
->alt_mod_mask
|= (1 << row
);
6337 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6342 dpyinfo
->super_mod_mask
|= (1 << row
);
6346 /* Ignore this if it's not on the lock modifier. */
6347 if ((1 << row
) == LockMask
)
6348 dpyinfo
->shift_lock_mask
= LockMask
;
6356 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6357 if (! dpyinfo
->meta_mod_mask
)
6359 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6360 dpyinfo
->alt_mod_mask
= 0;
6363 /* If some keys are both alt and meta,
6364 make them just meta, not alt. */
6365 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6367 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6370 XFree ((char *) syms
);
6371 XFreeModifiermap (mods
);
6374 /* Convert between the modifier bits X uses and the modifier bits
6378 x_x_to_emacs_modifiers (dpyinfo
, state
)
6379 struct x_display_info
*dpyinfo
;
6382 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6383 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6384 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6385 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6386 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6387 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6391 x_emacs_to_x_modifiers (dpyinfo
, state
)
6392 struct x_display_info
*dpyinfo
;
6395 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6396 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6397 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6398 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6399 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6400 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6403 /* Convert a keysym to its name. */
6406 x_get_keysym_name (keysym
)
6412 value
= XKeysymToString (keysym
);
6420 /* Mouse clicks and mouse movement. Rah. */
6422 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6423 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6424 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6425 not force the value into range. */
6428 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6430 register int pix_x
, pix_y
;
6431 register int *x
, *y
;
6435 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6436 even for negative values. */
6438 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6440 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6442 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6443 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6447 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6448 bounds
->height
= f
->output_data
.x
->line_height
;
6449 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6450 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6457 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6458 pix_x
= FRAME_WINDOW_WIDTH (f
);
6462 else if (pix_y
> f
->height
)
6471 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6472 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6473 can't tell the positions because W's display is not up to date,
6477 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6480 int *frame_x
, *frame_y
;
6484 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6485 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6487 if (display_completed
)
6489 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6490 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6491 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6497 *frame_x
+= glyph
->pixel_width
;
6505 *frame_y
= *frame_x
= 0;
6509 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6510 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6515 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6517 If the event is a button press, then note that we have grabbed
6521 construct_mouse_click (result
, event
, f
)
6522 struct input_event
*result
;
6523 XButtonEvent
*event
;
6526 /* Make the event type no_event; we'll change that when we decide
6528 result
->kind
= mouse_click
;
6529 result
->code
= event
->button
- Button1
;
6530 result
->timestamp
= event
->time
;
6531 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6533 | (event
->type
== ButtonRelease
6537 XSETINT (result
->x
, event
->x
);
6538 XSETINT (result
->y
, event
->y
);
6539 XSETFRAME (result
->frame_or_window
, f
);
6545 /* Function to report a mouse movement to the mainstream Emacs code.
6546 The input handler calls this.
6548 We have received a mouse movement event, which is given in *event.
6549 If the mouse is over a different glyph than it was last time, tell
6550 the mainstream emacs code by setting mouse_moved. If not, ask for
6551 another motion event, so we can check again the next time it moves. */
6553 static XMotionEvent last_mouse_motion_event
;
6554 static Lisp_Object last_mouse_motion_frame
;
6557 note_mouse_movement (frame
, event
)
6559 XMotionEvent
*event
;
6561 last_mouse_movement_time
= event
->time
;
6562 last_mouse_motion_event
= *event
;
6563 XSETFRAME (last_mouse_motion_frame
, frame
);
6565 if (event
->window
!= FRAME_X_WINDOW (frame
))
6567 frame
->mouse_moved
= 1;
6568 last_mouse_scroll_bar
= Qnil
;
6569 note_mouse_highlight (frame
, -1, -1);
6572 /* Has the mouse moved off the glyph it was on at the last sighting? */
6573 else if (event
->x
< last_mouse_glyph
.x
6574 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6575 || event
->y
< last_mouse_glyph
.y
6576 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6578 frame
->mouse_moved
= 1;
6579 last_mouse_scroll_bar
= Qnil
;
6580 note_mouse_highlight (frame
, event
->x
, event
->y
);
6584 /* This is used for debugging, to turn off note_mouse_highlight. */
6586 int disable_mouse_highlight
;
6590 /************************************************************************
6592 ************************************************************************/
6594 /* Find the glyph under window-relative coordinates X/Y in window W.
6595 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6596 strings. Return in *HPOS and *VPOS the row and column number of
6597 the glyph found. Return in *AREA the glyph area containing X.
6598 Value is a pointer to the glyph found or null if X/Y is not on
6599 text, or we can't tell because W's current matrix is not up to
6602 static struct glyph
*
6603 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6606 int *hpos
, *vpos
, *area
;
6609 struct glyph
*glyph
, *end
;
6610 struct glyph_row
*row
= NULL
;
6611 int x0
, i
, left_area_width
;
6613 /* Find row containing Y. Give up if some row is not enabled. */
6614 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6616 row
= MATRIX_ROW (w
->current_matrix
, i
);
6617 if (!row
->enabled_p
)
6619 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6626 /* Give up if Y is not in the window. */
6627 if (i
== w
->current_matrix
->nrows
)
6630 /* Get the glyph area containing X. */
6631 if (w
->pseudo_window_p
)
6638 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6639 if (x
< left_area_width
)
6641 *area
= LEFT_MARGIN_AREA
;
6644 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6647 x0
= row
->x
+ left_area_width
;
6651 *area
= RIGHT_MARGIN_AREA
;
6652 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6656 /* Find glyph containing X. */
6657 glyph
= row
->glyphs
[*area
];
6658 end
= glyph
+ row
->used
[*area
];
6661 if (x
< x0
+ glyph
->pixel_width
)
6663 if (w
->pseudo_window_p
)
6665 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6669 x0
+= glyph
->pixel_width
;
6676 *hpos
= glyph
- row
->glyphs
[*area
];
6681 /* Convert frame-relative x/y to coordinates relative to window W.
6682 Takes pseudo-windows into account. */
6685 frame_to_window_pixel_xy (w
, x
, y
)
6689 if (w
->pseudo_window_p
)
6691 /* A pseudo-window is always full-width, and starts at the
6692 left edge of the frame, plus a frame border. */
6693 struct frame
*f
= XFRAME (w
->frame
);
6694 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6695 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6699 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6700 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6705 /* Take proper action when mouse has moved to the mode or header line of
6706 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6707 mode line. X is relative to the start of the text display area of
6708 W, so the width of bitmap areas and scroll bars must be subtracted
6709 to get a position relative to the start of the mode line. */
6712 note_mode_line_highlight (w
, x
, mode_line_p
)
6716 struct frame
*f
= XFRAME (w
->frame
);
6717 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6718 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6719 struct glyph_row
*row
;
6722 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6724 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6728 struct glyph
*glyph
, *end
;
6729 Lisp_Object help
, map
;
6732 /* Find the glyph under X. */
6733 glyph
= row
->glyphs
[TEXT_AREA
];
6734 end
= glyph
+ row
->used
[TEXT_AREA
];
6735 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6736 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6739 && x
>= x0
+ glyph
->pixel_width
)
6741 x0
+= glyph
->pixel_width
;
6746 && STRINGP (glyph
->object
)
6747 && XSTRING (glyph
->object
)->intervals
6748 && glyph
->charpos
>= 0
6749 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6751 /* If we're on a string with `help-echo' text property,
6752 arrange for the help to be displayed. This is done by
6753 setting the global variable help_echo to the help string. */
6754 help
= Fget_text_property (make_number (glyph
->charpos
),
6755 Qhelp_echo
, glyph
->object
);
6759 XSETWINDOW (help_echo_window
, w
);
6760 help_echo_object
= glyph
->object
;
6761 help_echo_pos
= glyph
->charpos
;
6764 /* Change the mouse pointer according to what is under X/Y. */
6765 map
= Fget_text_property (make_number (glyph
->charpos
),
6766 Qlocal_map
, glyph
->object
);
6768 cursor
= f
->output_data
.x
->nontext_cursor
;
6771 map
= Fget_text_property (make_number (glyph
->charpos
),
6772 Qkeymap
, glyph
->object
);
6774 cursor
= f
->output_data
.x
->nontext_cursor
;
6779 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6783 /* Take proper action when the mouse has moved to position X, Y on
6784 frame F as regards highlighting characters that have mouse-face
6785 properties. Also de-highlighting chars where the mouse was before.
6786 X and Y can be negative or out of range. */
6789 note_mouse_highlight (f
, x
, y
)
6793 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6797 Cursor cursor
= None
;
6800 /* When a menu is active, don't highlight because this looks odd. */
6801 #ifdef USE_X_TOOLKIT
6802 if (popup_activated ())
6806 if (disable_mouse_highlight
6807 || !f
->glyphs_initialized_p
)
6810 dpyinfo
->mouse_face_mouse_x
= x
;
6811 dpyinfo
->mouse_face_mouse_y
= y
;
6812 dpyinfo
->mouse_face_mouse_frame
= f
;
6814 if (dpyinfo
->mouse_face_defer
)
6819 dpyinfo
->mouse_face_deferred_gc
= 1;
6823 /* Which window is that in? */
6824 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6826 /* If we were displaying active text in another window, clear that. */
6827 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6828 clear_mouse_face (dpyinfo
);
6830 /* Not on a window -> return. */
6831 if (!WINDOWP (window
))
6834 /* Convert to window-relative pixel coordinates. */
6835 w
= XWINDOW (window
);
6836 frame_to_window_pixel_xy (w
, &x
, &y
);
6838 /* Handle tool-bar window differently since it doesn't display a
6840 if (EQ (window
, f
->tool_bar_window
))
6842 note_tool_bar_highlight (f
, x
, y
);
6846 /* Mouse is on the mode or header line? */
6847 if (portion
== 1 || portion
== 3)
6849 note_mode_line_highlight (w
, x
, portion
== 1);
6854 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6856 cursor
= f
->output_data
.x
->text_cursor
;
6858 /* Are we in a window whose display is up to date?
6859 And verify the buffer's text has not changed. */
6860 b
= XBUFFER (w
->buffer
);
6861 if (/* Within text portion of the window. */
6863 && EQ (w
->window_end_valid
, w
->buffer
)
6864 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6865 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6867 int hpos
, vpos
, pos
, i
, area
;
6868 struct glyph
*glyph
;
6870 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6871 Lisp_Object
*overlay_vec
= NULL
;
6873 struct buffer
*obuf
;
6874 int obegv
, ozv
, same_region
;
6876 /* Find the glyph under X/Y. */
6877 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6879 /* Clear mouse face if X/Y not over text. */
6881 || area
!= TEXT_AREA
6882 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6884 if (clear_mouse_face (dpyinfo
))
6889 pos
= glyph
->charpos
;
6890 object
= glyph
->object
;
6891 if (!STRINGP (object
) && !BUFFERP (object
))
6894 /* If we get an out-of-range value, return now; avoid an error. */
6895 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6898 /* Make the window's buffer temporarily current for
6899 overlays_at and compute_char_face. */
6900 obuf
= current_buffer
;
6907 /* Is this char mouse-active or does it have help-echo? */
6908 position
= make_number (pos
);
6910 if (BUFFERP (object
))
6912 /* Put all the overlays we want in a vector in overlay_vec.
6913 Store the length in len. If there are more than 10, make
6914 enough space for all, and try again. */
6916 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6917 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6918 if (noverlays
> len
)
6921 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6922 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6925 /* Sort overlays into increasing priority order. */
6926 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6931 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
6932 && vpos
>= dpyinfo
->mouse_face_beg_row
6933 && vpos
<= dpyinfo
->mouse_face_end_row
6934 && (vpos
> dpyinfo
->mouse_face_beg_row
6935 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6936 && (vpos
< dpyinfo
->mouse_face_end_row
6937 || hpos
< dpyinfo
->mouse_face_end_col
6938 || dpyinfo
->mouse_face_past_end
));
6943 /* Check mouse-face highlighting. */
6945 /* If there exists an overlay with mouse-face overlapping
6946 the one we are currently highlighting, we have to
6947 check if we enter the overlapping overlay, and then
6948 highlight only that. */
6949 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
6950 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
6952 /* Clear the display of the old active region, if any. */
6953 if (clear_mouse_face (dpyinfo
))
6956 /* Find the highest priority overlay that has a mouse-face
6959 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
6961 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6962 if (!NILP (mouse_face
))
6963 overlay
= overlay_vec
[i
];
6965 dpyinfo
->mouse_face_overlay
= overlay
;
6967 /* If no overlay applies, get a text property. */
6969 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
6971 /* Handle the overlay case. */
6972 if (!NILP (overlay
))
6974 /* Find the range of text around this char that
6975 should be active. */
6976 Lisp_Object before
, after
;
6979 before
= Foverlay_start (overlay
);
6980 after
= Foverlay_end (overlay
);
6981 /* Record this as the current active region. */
6982 fast_find_position (w
, XFASTINT (before
),
6983 &dpyinfo
->mouse_face_beg_col
,
6984 &dpyinfo
->mouse_face_beg_row
,
6985 &dpyinfo
->mouse_face_beg_x
,
6986 &dpyinfo
->mouse_face_beg_y
);
6987 dpyinfo
->mouse_face_past_end
6988 = !fast_find_position (w
, XFASTINT (after
),
6989 &dpyinfo
->mouse_face_end_col
,
6990 &dpyinfo
->mouse_face_end_row
,
6991 &dpyinfo
->mouse_face_end_x
,
6992 &dpyinfo
->mouse_face_end_y
);
6993 dpyinfo
->mouse_face_window
= window
;
6994 dpyinfo
->mouse_face_face_id
6995 = face_at_buffer_position (w
, pos
, 0, 0,
6996 &ignore
, pos
+ 1, 1);
6998 /* Display it as active. */
6999 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7001 /* Handle the text property case. */
7002 else if (!NILP (mouse_face
) && BUFFERP (object
))
7004 /* Find the range of text around this char that
7005 should be active. */
7006 Lisp_Object before
, after
, beginning
, end
;
7009 beginning
= Fmarker_position (w
->start
);
7010 end
= make_number (BUF_Z (XBUFFER (object
))
7011 - XFASTINT (w
->window_end_pos
));
7013 = Fprevious_single_property_change (make_number (pos
+ 1),
7017 = Fnext_single_property_change (position
, Qmouse_face
,
7020 /* Record this as the current active region. */
7021 fast_find_position (w
, XFASTINT (before
),
7022 &dpyinfo
->mouse_face_beg_col
,
7023 &dpyinfo
->mouse_face_beg_row
,
7024 &dpyinfo
->mouse_face_beg_x
,
7025 &dpyinfo
->mouse_face_beg_y
);
7026 dpyinfo
->mouse_face_past_end
7027 = !fast_find_position (w
, XFASTINT (after
),
7028 &dpyinfo
->mouse_face_end_col
,
7029 &dpyinfo
->mouse_face_end_row
,
7030 &dpyinfo
->mouse_face_end_x
,
7031 &dpyinfo
->mouse_face_end_y
);
7032 dpyinfo
->mouse_face_window
= window
;
7034 if (BUFFERP (object
))
7035 dpyinfo
->mouse_face_face_id
7036 = face_at_buffer_position (w
, pos
, 0, 0,
7037 &ignore
, pos
+ 1, 1);
7039 /* Display it as active. */
7040 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7042 else if (!NILP (mouse_face
) && STRINGP (object
))
7047 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7050 e
= Fnext_single_property_change (position
, Qmouse_face
,
7053 b
= make_number (0);
7055 e
= make_number (XSTRING (object
)->size
- 1);
7056 fast_find_string_pos (w
, XINT (b
), object
,
7057 &dpyinfo
->mouse_face_beg_col
,
7058 &dpyinfo
->mouse_face_beg_row
,
7059 &dpyinfo
->mouse_face_beg_x
,
7060 &dpyinfo
->mouse_face_beg_y
, 0);
7061 fast_find_string_pos (w
, XINT (e
), object
,
7062 &dpyinfo
->mouse_face_end_col
,
7063 &dpyinfo
->mouse_face_end_row
,
7064 &dpyinfo
->mouse_face_end_x
,
7065 &dpyinfo
->mouse_face_end_y
, 1);
7066 dpyinfo
->mouse_face_past_end
= 0;
7067 dpyinfo
->mouse_face_window
= window
;
7068 dpyinfo
->mouse_face_face_id
7069 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7071 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7075 /* Look for a `help-echo' property. */
7077 Lisp_Object help
, overlay
;
7079 /* Check overlays first. */
7080 help
= overlay
= Qnil
;
7081 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7083 overlay
= overlay_vec
[i
];
7084 help
= Foverlay_get (overlay
, Qhelp_echo
);
7090 help_echo_window
= window
;
7091 help_echo_object
= overlay
;
7092 help_echo_pos
= pos
;
7096 Lisp_Object object
= glyph
->object
;
7097 int charpos
= glyph
->charpos
;
7099 /* Try text properties. */
7100 if (STRINGP (object
)
7102 && charpos
< XSTRING (object
)->size
)
7104 help
= Fget_text_property (make_number (charpos
),
7105 Qhelp_echo
, object
);
7108 /* If the string itself doesn't specify a help-echo,
7109 see if the buffer text ``under'' it does. */
7111 = MATRIX_ROW (w
->current_matrix
, vpos
);
7112 int start
= MATRIX_ROW_START_CHARPOS (r
);
7113 int pos
= string_buffer_position (w
, object
, start
);
7116 help
= Fget_text_property (make_number (pos
),
7117 Qhelp_echo
, w
->buffer
);
7126 else if (BUFFERP (object
)
7129 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7135 help_echo_window
= window
;
7136 help_echo_object
= object
;
7137 help_echo_pos
= charpos
;
7144 current_buffer
= obuf
;
7150 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7154 redo_mouse_highlight ()
7156 if (!NILP (last_mouse_motion_frame
)
7157 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7158 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7159 last_mouse_motion_event
.x
,
7160 last_mouse_motion_event
.y
);
7165 /***********************************************************************
7167 ***********************************************************************/
7169 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7170 struct glyph
**, int *, int *, int *));
7172 /* Tool-bar item index of the item on which a mouse button was pressed
7175 static int last_tool_bar_item
;
7178 /* Get information about the tool-bar item at position X/Y on frame F.
7179 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7180 the current matrix of the tool-bar window of F, or NULL if not
7181 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7182 item in F->tool_bar_items. Value is
7184 -1 if X/Y is not on a tool-bar item
7185 0 if X/Y is on the same item that was highlighted before.
7189 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7192 struct glyph
**glyph
;
7193 int *hpos
, *vpos
, *prop_idx
;
7195 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7196 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7199 /* Find the glyph under X/Y. */
7200 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7204 /* Get the start of this tool-bar item's properties in
7205 f->tool_bar_items. */
7206 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7209 /* Is mouse on the highlighted item? */
7210 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7211 && *vpos
>= dpyinfo
->mouse_face_beg_row
7212 && *vpos
<= dpyinfo
->mouse_face_end_row
7213 && (*vpos
> dpyinfo
->mouse_face_beg_row
7214 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7215 && (*vpos
< dpyinfo
->mouse_face_end_row
7216 || *hpos
< dpyinfo
->mouse_face_end_col
7217 || dpyinfo
->mouse_face_past_end
))
7224 /* Handle mouse button event on the tool-bar of frame F, at
7225 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
7229 x_handle_tool_bar_click (f
, button_event
)
7231 XButtonEvent
*button_event
;
7233 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7234 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7235 int hpos
, vpos
, prop_idx
;
7236 struct glyph
*glyph
;
7237 Lisp_Object enabled_p
;
7238 int x
= button_event
->x
;
7239 int y
= button_event
->y
;
7241 /* If not on the highlighted tool-bar item, return. */
7242 frame_to_window_pixel_xy (w
, &x
, &y
);
7243 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7246 /* If item is disabled, do nothing. */
7247 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7248 if (NILP (enabled_p
))
7251 if (button_event
->type
== ButtonPress
)
7253 /* Show item in pressed state. */
7254 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7255 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7256 last_tool_bar_item
= prop_idx
;
7260 Lisp_Object key
, frame
;
7261 struct input_event event
;
7263 /* Show item in released state. */
7264 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7265 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7267 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7269 XSETFRAME (frame
, f
);
7270 event
.kind
= TOOL_BAR_EVENT
;
7271 event
.frame_or_window
= frame
;
7273 kbd_buffer_store_event (&event
);
7275 event
.kind
= TOOL_BAR_EVENT
;
7276 event
.frame_or_window
= frame
;
7278 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7279 button_event
->state
);
7280 kbd_buffer_store_event (&event
);
7281 last_tool_bar_item
= -1;
7286 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7287 tool-bar window-relative coordinates X/Y. Called from
7288 note_mouse_highlight. */
7291 note_tool_bar_highlight (f
, x
, y
)
7295 Lisp_Object window
= f
->tool_bar_window
;
7296 struct window
*w
= XWINDOW (window
);
7297 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7299 struct glyph
*glyph
;
7300 struct glyph_row
*row
;
7302 Lisp_Object enabled_p
;
7304 enum draw_glyphs_face draw
;
7305 int mouse_down_p
, rc
;
7307 /* Function note_mouse_highlight is called with negative x(y
7308 values when mouse moves outside of the frame. */
7309 if (x
<= 0 || y
<= 0)
7311 clear_mouse_face (dpyinfo
);
7315 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7318 /* Not on tool-bar item. */
7319 clear_mouse_face (dpyinfo
);
7325 clear_mouse_face (dpyinfo
);
7327 /* Mouse is down, but on different tool-bar item? */
7328 mouse_down_p
= (dpyinfo
->grabbed
7329 && f
== last_mouse_frame
7330 && FRAME_LIVE_P (f
));
7332 && last_tool_bar_item
!= prop_idx
)
7335 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7336 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7338 /* If tool-bar item is not enabled, don't highlight it. */
7339 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7340 if (!NILP (enabled_p
))
7342 /* Compute the x-position of the glyph. In front and past the
7343 image is a space. We include this is the highlighted area. */
7344 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7345 for (i
= x
= 0; i
< hpos
; ++i
)
7346 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7348 /* Record this as the current active region. */
7349 dpyinfo
->mouse_face_beg_col
= hpos
;
7350 dpyinfo
->mouse_face_beg_row
= vpos
;
7351 dpyinfo
->mouse_face_beg_x
= x
;
7352 dpyinfo
->mouse_face_beg_y
= row
->y
;
7353 dpyinfo
->mouse_face_past_end
= 0;
7355 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7356 dpyinfo
->mouse_face_end_row
= vpos
;
7357 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7358 dpyinfo
->mouse_face_end_y
= row
->y
;
7359 dpyinfo
->mouse_face_window
= window
;
7360 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7362 /* Display it as active. */
7363 show_mouse_face (dpyinfo
, draw
);
7364 dpyinfo
->mouse_face_image_state
= draw
;
7369 /* Set help_echo to a help string.to display for this tool-bar item.
7370 XTread_socket does the rest. */
7371 help_echo_object
= help_echo_window
= Qnil
;
7373 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7374 if (NILP (help_echo
))
7375 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7380 /* Find the glyph matrix position of buffer position POS in window W.
7381 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7382 current glyphs must be up to date. If POS is above window start
7383 return (0, 0, 0, 0). If POS is after end of W, return end of
7387 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
7390 int *hpos
, *vpos
, *x
, *y
;
7394 int maybe_next_line_p
= 0;
7395 int line_start_position
;
7396 int yb
= window_text_bottom_y (w
);
7397 struct glyph_row
*row
, *best_row
;
7398 int row_vpos
, best_row_vpos
;
7401 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7402 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7406 if (row
->used
[TEXT_AREA
])
7407 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7409 line_start_position
= 0;
7411 if (line_start_position
> pos
)
7413 /* If the position sought is the end of the buffer,
7414 don't include the blank lines at the bottom of the window. */
7415 else if (line_start_position
== pos
7416 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7418 maybe_next_line_p
= 1;
7421 else if (line_start_position
> 0)
7424 best_row_vpos
= row_vpos
;
7427 if (row
->y
+ row
->height
>= yb
)
7434 /* Find the right column within BEST_ROW. */
7436 current_x
= best_row
->x
;
7437 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7439 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7442 charpos
= glyph
->charpos
;
7446 *vpos
= best_row_vpos
;
7451 else if (charpos
> pos
)
7453 else if (charpos
> 0)
7456 current_x
+= glyph
->pixel_width
;
7459 /* If we're looking for the end of the buffer,
7460 and we didn't find it in the line we scanned,
7461 use the start of the following line. */
7462 if (maybe_next_line_p
)
7467 current_x
= best_row
->x
;
7470 *vpos
= best_row_vpos
;
7471 *hpos
= lastcol
+ 1;
7478 /* Find the position of the the glyph for position POS in OBJECT in
7479 window W's current matrix, and return in *X/*Y the pixel
7480 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7482 RIGHT_P non-zero means return the position of the right edge of the
7483 glyph, RIGHT_P zero means return the left edge position.
7485 If no glyph for POS exists in the matrix, return the position of
7486 the glyph with the next smaller position that is in the matrix, if
7487 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7488 exists in the matrix, return the position of the glyph with the
7489 next larger position in OBJECT.
7491 Value is non-zero if a glyph was found. */
7494 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7498 int *hpos
, *vpos
, *x
, *y
;
7501 int yb
= window_text_bottom_y (w
);
7502 struct glyph_row
*r
;
7503 struct glyph
*best_glyph
= NULL
;
7504 struct glyph_row
*best_row
= NULL
;
7507 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7508 r
->enabled_p
&& r
->y
< yb
;
7511 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7512 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7515 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7516 if (EQ (g
->object
, object
))
7518 if (g
->charpos
== pos
)
7525 else if (best_glyph
== NULL
7526 || ((abs (g
->charpos
- pos
)
7527 < abs (best_glyph
->charpos
- pos
))
7530 : g
->charpos
> pos
)))
7544 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7548 *x
+= best_glyph
->pixel_width
;
7553 *vpos
= best_row
- w
->current_matrix
->rows
;
7556 return best_glyph
!= NULL
;
7560 /* Display the active region described by mouse_face_*
7561 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7564 show_mouse_face (dpyinfo
, draw
)
7565 struct x_display_info
*dpyinfo
;
7566 enum draw_glyphs_face draw
;
7568 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7569 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7571 int cursor_off_p
= 0;
7572 struct cursor_pos saved_cursor
;
7574 saved_cursor
= output_cursor
;
7576 /* If window is in the process of being destroyed, don't bother
7578 if (w
->current_matrix
== NULL
)
7581 /* Recognize when we are called to operate on rows that don't exist
7582 anymore. This can happen when a window is split. */
7583 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7586 set_output_cursor (&w
->phys_cursor
);
7588 /* Note that mouse_face_beg_row etc. are window relative. */
7589 for (i
= dpyinfo
->mouse_face_beg_row
;
7590 i
<= dpyinfo
->mouse_face_end_row
;
7593 int start_hpos
, end_hpos
, start_x
;
7594 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7596 /* Don't do anything if row doesn't have valid contents. */
7597 if (!row
->enabled_p
)
7600 /* For all but the first row, the highlight starts at column 0. */
7601 if (i
== dpyinfo
->mouse_face_beg_row
)
7603 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7604 start_x
= dpyinfo
->mouse_face_beg_x
;
7612 if (i
== dpyinfo
->mouse_face_end_row
)
7613 end_hpos
= dpyinfo
->mouse_face_end_col
;
7615 end_hpos
= row
->used
[TEXT_AREA
];
7617 /* If the cursor's in the text we are about to rewrite, turn the
7619 if (!w
->pseudo_window_p
7620 && i
== output_cursor
.vpos
7621 && output_cursor
.hpos
>= start_hpos
- 1
7622 && output_cursor
.hpos
<= end_hpos
)
7624 x_update_window_cursor (w
, 0);
7628 if (end_hpos
> start_hpos
)
7630 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
|| DRAW_IMAGE_RAISED
;
7631 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7632 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7636 /* If we turned the cursor off, turn it back on. */
7638 x_display_cursor (w
, 1,
7639 output_cursor
.hpos
, output_cursor
.vpos
,
7640 output_cursor
.x
, output_cursor
.y
);
7642 output_cursor
= saved_cursor
;
7646 /* Change the mouse cursor. */
7647 if (draw
== DRAW_NORMAL_TEXT
)
7648 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7649 f
->output_data
.x
->text_cursor
);
7650 else if (draw
== DRAW_MOUSE_FACE
)
7651 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7652 f
->output_data
.x
->cross_cursor
);
7654 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7655 f
->output_data
.x
->nontext_cursor
);
7658 /* Clear out the mouse-highlighted active region.
7659 Redraw it un-highlighted first. Value is non-zero if mouse
7660 face was actually drawn unhighlighted. */
7663 clear_mouse_face (dpyinfo
)
7664 struct x_display_info
*dpyinfo
;
7668 if (!NILP (dpyinfo
->mouse_face_window
))
7670 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7674 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7675 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7676 dpyinfo
->mouse_face_window
= Qnil
;
7681 /* Clear any mouse-face on window W. This function is part of the
7682 redisplay interface, and is called from try_window_id and similar
7683 functions to ensure the mouse-highlight is off. */
7686 x_clear_mouse_face (w
)
7689 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7693 XSETWINDOW (window
, w
);
7694 if (EQ (window
, dpyinfo
->mouse_face_window
))
7695 clear_mouse_face (dpyinfo
);
7700 /* Just discard the mouse face information for frame F, if any.
7701 This is used when the size of F is changed. */
7704 cancel_mouse_face (f
)
7708 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7710 window
= dpyinfo
->mouse_face_window
;
7711 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7713 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7714 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7715 dpyinfo
->mouse_face_window
= Qnil
;
7720 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7723 /* Try to determine frame pixel position and size of the glyph under
7724 frame pixel coordinates X/Y on frame F . Return the position and
7725 size in *RECT. Value is non-zero if we could compute these
7729 glyph_rect (f
, x
, y
, rect
)
7735 int part
, found
= 0;
7737 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7740 struct window
*w
= XWINDOW (window
);
7741 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7742 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7745 frame_to_window_pixel_xy (w
, &x
, &y
);
7747 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7750 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7751 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7754 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7757 rect
->width
= g
->pixel_width
;
7758 rect
->height
= r
->height
;
7759 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7760 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7770 /* Return the current position of the mouse.
7771 *FP should be a frame which indicates which display to ask about.
7773 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7774 and *PART to the frame, window, and scroll bar part that the mouse
7775 is over. Set *X and *Y to the portion and whole of the mouse's
7776 position on the scroll bar.
7778 If the mouse movement started elsewhere, set *FP to the frame the
7779 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7782 Set *TIME to the server time-stamp for the time at which the mouse
7783 was at this position.
7785 Don't store anything if we don't have a valid set of values to report.
7787 This clears the mouse_moved flag, so we can wait for the next mouse
7791 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7794 Lisp_Object
*bar_window
;
7795 enum scroll_bar_part
*part
;
7797 unsigned long *time
;
7803 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7804 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7810 Window dummy_window
;
7813 Lisp_Object frame
, tail
;
7815 /* Clear the mouse-moved flag for every frame on this display. */
7816 FOR_EACH_FRAME (tail
, frame
)
7817 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7818 XFRAME (frame
)->mouse_moved
= 0;
7820 last_mouse_scroll_bar
= Qnil
;
7822 /* Figure out which root window we're on. */
7823 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7824 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7826 /* The root window which contains the pointer. */
7829 /* Trash which we can't trust if the pointer is on
7830 a different screen. */
7833 /* The position on that root window. */
7836 /* More trash we can't trust. */
7839 /* Modifier keys and pointer buttons, about which
7841 (unsigned int *) &dummy
);
7843 /* Now we have a position on the root; find the innermost window
7844 containing the pointer. */
7848 int parent_x
= 0, parent_y
= 0;
7853 /* XTranslateCoordinates can get errors if the window
7854 structure is changing at the same time this function
7855 is running. So at least we must not crash from them. */
7857 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7859 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7860 && FRAME_LIVE_P (last_mouse_frame
))
7862 /* If mouse was grabbed on a frame, give coords for that frame
7863 even if the mouse is now outside it. */
7864 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7866 /* From-window, to-window. */
7867 root
, FRAME_X_WINDOW (last_mouse_frame
),
7869 /* From-position, to-position. */
7870 root_x
, root_y
, &win_x
, &win_y
,
7874 f1
= last_mouse_frame
;
7880 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7882 /* From-window, to-window. */
7885 /* From-position, to-position. */
7886 root_x
, root_y
, &win_x
, &win_y
,
7891 if (child
== None
|| child
== win
)
7899 /* Now we know that:
7900 win is the innermost window containing the pointer
7901 (XTC says it has no child containing the pointer),
7902 win_x and win_y are the pointer's position in it
7903 (XTC did this the last time through), and
7904 parent_x and parent_y are the pointer's position in win's parent.
7905 (They are what win_x and win_y were when win was child.
7906 If win is the root window, it has no parent, and
7907 parent_{x,y} are invalid, but that's okay, because we'll
7908 never use them in that case.) */
7910 /* Is win one of our frames? */
7911 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7913 #ifdef USE_X_TOOLKIT
7914 /* If we end up with the menu bar window, say it's not
7917 && f1
->output_data
.x
->menubar_widget
7918 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
7920 #endif /* USE_X_TOOLKIT */
7923 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7926 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7928 /* If not, is it one of our scroll bars? */
7931 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7935 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7941 if (f1
== 0 && insist
> 0)
7942 f1
= SELECTED_FRAME ();
7946 /* Ok, we found a frame. Store all the values.
7947 last_mouse_glyph is a rectangle used to reduce the
7948 generation of mouse events. To not miss any motion
7949 events, we must divide the frame into rectangles of the
7950 size of the smallest character that could be displayed
7951 on it, i.e. into the same rectangles that matrices on
7952 the frame are divided into. */
7954 int width
, height
, gx
, gy
;
7957 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
7958 last_mouse_glyph
= rect
;
7961 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7962 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7966 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7967 round down even for negative values. */
7972 gx
= (gx
+ width
- 1) / width
* width
;
7973 gy
= (gy
+ height
- 1) / height
* height
;
7975 last_mouse_glyph
.width
= width
;
7976 last_mouse_glyph
.height
= height
;
7977 last_mouse_glyph
.x
= gx
;
7978 last_mouse_glyph
.y
= gy
;
7984 XSETINT (*x
, win_x
);
7985 XSETINT (*y
, win_y
);
7986 *time
= last_mouse_movement_time
;
7995 #ifdef USE_X_TOOLKIT
7997 /* Atimer callback function for TIMER. Called every 0.1s to process
7998 Xt timeouts, if needed. We must avoid calling XtAppPending as
7999 much as possible because that function does an implicit XFlush
8000 that slows us down. */
8003 x_process_timeouts (timer
)
8004 struct atimer
*timer
;
8006 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
8009 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8010 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8015 #endif /* USE_X_TOOLKIT */
8018 /* Scroll bar support. */
8020 /* Given an X window ID, find the struct scroll_bar which manages it.
8021 This can be called in GC, so we have to make sure to strip off mark
8024 static struct scroll_bar
*
8025 x_window_to_scroll_bar (window_id
)
8030 for (tail
= Vframe_list
;
8031 XGCTYPE (tail
) == Lisp_Cons
;
8034 Lisp_Object frame
, bar
, condemned
;
8036 frame
= XCAR (tail
);
8037 /* All elements of Vframe_list should be frames. */
8038 if (! GC_FRAMEP (frame
))
8041 /* Scan this frame's scroll bar list for a scroll bar with the
8043 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8044 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8045 /* This trick allows us to search both the ordinary and
8046 condemned scroll bar lists with one loop. */
8047 ! GC_NILP (bar
) || (bar
= condemned
,
8050 bar
= XSCROLL_BAR (bar
)->next
)
8051 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8052 return XSCROLL_BAR (bar
);
8059 #if defined USE_X_TOOLKIT && defined USE_LUCID
8061 /* Return the Lucid menu bar WINDOW is part of. Return null
8062 if WINDOW is not part of a menu bar. */
8065 x_window_to_menu_bar (window
)
8070 for (tail
= Vframe_list
;
8071 XGCTYPE (tail
) == Lisp_Cons
;
8074 Lisp_Object frame
= XCAR (tail
);
8075 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8077 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8084 #endif /* USE_X_TOOLKIT && USE_LUCID */
8087 /************************************************************************
8089 ************************************************************************/
8091 #ifdef USE_TOOLKIT_SCROLL_BARS
8093 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8094 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8095 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8096 struct scroll_bar
*));
8097 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8101 /* Id of action hook installed for scroll bars. */
8103 static XtActionHookId action_hook_id
;
8105 /* Lisp window being scrolled. Set when starting to interact with
8106 a toolkit scroll bar, reset to nil when ending the interaction. */
8108 static Lisp_Object window_being_scrolled
;
8110 /* Last scroll bar part sent in xm_scroll_callback. */
8112 static int last_scroll_bar_part
;
8114 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8115 that movements of 1/20 of the screen size are mapped to up/down. */
8117 static Boolean xaw3d_arrow_scroll
;
8119 /* Whether the drag scrolling maintains the mouse at the top of the
8120 thumb. If not, resizing the thumb needs to be done more carefully
8121 to avoid jerkyness. */
8123 static Boolean xaw3d_pick_top
;
8126 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8127 bars are used.. The hook is responsible for detecting when
8128 the user ends an interaction with the scroll bar, and generates
8129 a `end-scroll' scroll_bar_click' event if so. */
8132 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8135 XtPointer client_data
;
8139 Cardinal
*num_params
;
8145 scroll_bar_p
= XmIsScrollBar (widget
);
8146 end_action
= "Release";
8147 #else /* !USE_MOTIF i.e. use Xaw */
8148 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8149 end_action
= "EndScroll";
8150 #endif /* USE_MOTIF */
8153 && strcmp (action_name
, end_action
) == 0
8154 && WINDOWP (window_being_scrolled
))
8158 x_send_scroll_bar_event (window_being_scrolled
,
8159 scroll_bar_end_scroll
, 0, 0);
8160 w
= XWINDOW (window_being_scrolled
);
8161 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8162 window_being_scrolled
= Qnil
;
8163 last_scroll_bar_part
= -1;
8165 /* Xt timeouts no longer needed. */
8166 toolkit_scroll_bar_interaction
= 0;
8170 /* A vector of windows used for communication between
8171 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8173 static struct window
**scroll_bar_windows
;
8174 static int scroll_bar_windows_size
;
8177 /* Send a client message with message type Xatom_Scrollbar for a
8178 scroll action to the frame of WINDOW. PART is a value identifying
8179 the part of the scroll bar that was clicked on. PORTION is the
8180 amount to scroll of a whole of WHOLE. */
8183 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8185 int part
, portion
, whole
;
8188 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8189 struct window
*w
= XWINDOW (window
);
8190 struct frame
*f
= XFRAME (w
->frame
);
8195 /* Construct a ClientMessage event to send to the frame. */
8196 ev
->type
= ClientMessage
;
8197 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8198 ev
->display
= FRAME_X_DISPLAY (f
);
8199 ev
->window
= FRAME_X_WINDOW (f
);
8202 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8203 not enough to store a pointer or Lisp_Object on a 64 bit system.
8204 So, store the window in scroll_bar_windows and pass the index
8205 into that array in the event. */
8206 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8207 if (scroll_bar_windows
[i
] == NULL
)
8210 if (i
== scroll_bar_windows_size
)
8212 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8213 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8214 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8216 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8218 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8219 scroll_bar_windows_size
= new_size
;
8222 scroll_bar_windows
[i
] = w
;
8223 ev
->data
.l
[0] = (long) i
;
8224 ev
->data
.l
[1] = (long) part
;
8225 ev
->data
.l
[2] = (long) 0;
8226 ev
->data
.l
[3] = (long) portion
;
8227 ev
->data
.l
[4] = (long) whole
;
8229 /* Make Xt timeouts work while the scroll bar is active. */
8230 toolkit_scroll_bar_interaction
= 1;
8232 /* Setting the event mask to zero means that the message will
8233 be sent to the client that created the window, and if that
8234 window no longer exists, no event will be sent. */
8235 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8240 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8244 x_scroll_bar_to_input_event (event
, ievent
)
8246 struct input_event
*ievent
;
8248 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8253 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8254 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8256 XSETWINDOW (window
, w
);
8257 f
= XFRAME (w
->frame
);
8259 ievent
->kind
= scroll_bar_click
;
8260 ievent
->frame_or_window
= window
;
8262 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8263 ievent
->part
= ev
->data
.l
[1];
8264 ievent
->code
= ev
->data
.l
[2];
8265 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8266 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8267 ievent
->modifiers
= 0;
8273 /* Minimum and maximum values used for Motif scroll bars. */
8276 #define XM_SB_MAX 10000000
8277 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8280 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8281 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8282 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
8285 xm_scroll_callback (widget
, client_data
, call_data
)
8287 XtPointer client_data
, call_data
;
8289 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8290 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8292 int part
= -1, whole
= 0, portion
= 0;
8296 case XmCR_DECREMENT
:
8297 bar
->dragging
= Qnil
;
8298 part
= scroll_bar_up_arrow
;
8301 case XmCR_INCREMENT
:
8302 bar
->dragging
= Qnil
;
8303 part
= scroll_bar_down_arrow
;
8306 case XmCR_PAGE_DECREMENT
:
8307 bar
->dragging
= Qnil
;
8308 part
= scroll_bar_above_handle
;
8311 case XmCR_PAGE_INCREMENT
:
8312 bar
->dragging
= Qnil
;
8313 part
= scroll_bar_below_handle
;
8317 bar
->dragging
= Qnil
;
8318 part
= scroll_bar_to_top
;
8321 case XmCR_TO_BOTTOM
:
8322 bar
->dragging
= Qnil
;
8323 part
= scroll_bar_to_bottom
;
8329 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8330 && XINT (bar
->dragging
) <= cs
->value
);
8332 /* Get the slider size. */
8334 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8337 /* At the max position of the scroll bar, do a line-wise
8338 movement. Without doing anything, we would be called with
8339 the same cs->value again and again. If we want to make
8340 sure that we can reach the end of the buffer, we have to do
8343 Implementation note: setting bar->dragging always to
8344 cs->value gives a smoother movement at the max position.
8345 Setting it to nil when doing line-wise movement gives
8346 a better slider behavior. */
8348 if (cs
->value
+ slider_size
== XM_SB_MAX
8350 && last_scroll_bar_part
== scroll_bar_down_arrow
))
8352 part
= scroll_bar_down_arrow
;
8353 bar
->dragging
= Qnil
;
8357 whole
= XM_SB_RANGE
;
8358 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
8359 part
= scroll_bar_handle
;
8360 bar
->dragging
= make_number (cs
->value
);
8365 case XmCR_VALUE_CHANGED
:
8371 window_being_scrolled
= bar
->window
;
8372 last_scroll_bar_part
= part
;
8373 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8378 #else /* !USE_MOTIF, i.e. Xaw. */
8381 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8382 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8383 scroll bar struct. CALL_DATA is a pointer to a float saying where
8387 xaw_jump_callback (widget
, client_data
, call_data
)
8389 XtPointer client_data
, call_data
;
8391 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8392 float top
= *(float *) call_data
;
8394 int whole
, portion
, height
;
8397 /* Get the size of the thumb, a value between 0 and 1. */
8399 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8403 portion
= shown
< 1 ? top
* whole
: 0;
8405 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8406 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8407 the bottom, so we force the scrolling whenever we see that we're
8408 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8409 we try to ensure that we always stay two pixels away from the
8411 part
= scroll_bar_down_arrow
;
8413 part
= scroll_bar_handle
;
8415 window_being_scrolled
= bar
->window
;
8416 bar
->dragging
= make_number (portion
);
8417 last_scroll_bar_part
= part
;
8418 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8422 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8423 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8424 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8425 the scroll bar. CALL_DATA is an integer specifying the action that
8426 has taken place. It's magnitude is in the range 0..height of the
8427 scroll bar. Negative values mean scroll towards buffer start.
8428 Values < height of scroll bar mean line-wise movement. */
8431 xaw_scroll_callback (widget
, client_data
, call_data
)
8433 XtPointer client_data
, call_data
;
8435 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8436 int position
= (int) call_data
;
8440 /* Get the height of the scroll bar. */
8442 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8445 if (abs (position
) >= height
)
8446 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8448 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8449 it maps line-movement to call_data = max(5, height/20). */
8450 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8451 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8453 part
= scroll_bar_move_ratio
;
8455 window_being_scrolled
= bar
->window
;
8456 bar
->dragging
= Qnil
;
8457 last_scroll_bar_part
= part
;
8458 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8462 #endif /* not USE_MOTIF */
8465 /* Create the widget for scroll bar BAR on frame F. Record the widget
8466 and X window of the scroll bar in BAR. */
8469 x_create_toolkit_scroll_bar (f
, bar
)
8471 struct scroll_bar
*bar
;
8477 char *scroll_bar_name
= "verticalScrollBar";
8478 unsigned long pixel
;
8483 /* Set resources. Create the widget. */
8484 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8485 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8486 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8487 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8488 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8489 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8490 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8492 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8495 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8499 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8502 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8506 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8507 scroll_bar_name
, av
, ac
);
8509 /* Add one callback for everything that can happen. */
8510 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8512 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8514 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8516 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8518 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8520 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8522 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8525 /* Realize the widget. Only after that is the X window created. */
8526 XtRealizeWidget (widget
);
8528 /* Set the cursor to an arrow. I didn't find a resource to do that.
8529 And I'm wondering why it hasn't an arrow cursor by default. */
8530 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8531 f
->output_data
.x
->nontext_cursor
);
8533 #else /* !USE_MOTIF i.e. use Xaw */
8535 /* Set resources. Create the widget. The background of the
8536 Xaw3d scroll bar widget is a little bit light for my taste.
8537 We don't alter it here to let users change it according
8538 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8539 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8540 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8541 /* For smoother scrolling with Xaw3d -sm */
8542 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8543 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
8545 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8548 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8552 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8555 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8559 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8560 f
->output_data
.x
->edit_widget
, av
, ac
);
8564 char *val
= initial
;
8565 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8566 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8568 { /* ARROW_SCROLL */
8569 xaw3d_arrow_scroll
= True
;
8570 /* Isn't that just a personal preference ? -sm */
8571 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8575 /* Define callbacks. */
8576 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8577 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8580 /* Realize the widget. Only after that is the X window created. */
8581 XtRealizeWidget (widget
);
8583 #endif /* !USE_MOTIF */
8585 /* Install an action hook that let's us detect when the user
8586 finishes interacting with a scroll bar. */
8587 if (action_hook_id
== 0)
8588 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8590 /* Remember X window and widget in the scroll bar vector. */
8591 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8592 xwindow
= XtWindow (widget
);
8593 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8599 /* Set the thumb size and position of scroll bar BAR. We are currently
8600 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8603 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8604 struct scroll_bar
*bar
;
8605 int portion
, position
, whole
;
8607 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8608 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8615 top
= (float) position
/ whole
;
8616 shown
= (float) portion
/ whole
;
8624 XmScrollBarWidget sb
;
8626 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8627 is the scroll bar's maximum and MIN is the scroll bar's minimum
8629 size
= shown
* XM_SB_RANGE
;
8630 size
= min (size
, XM_SB_RANGE
);
8631 size
= max (size
, 1);
8633 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8634 value
= top
* XM_SB_RANGE
;
8635 value
= min (value
, XM_SB_MAX
- size
);
8636 value
= max (value
, XM_SB_MIN
);
8638 if (NILP (bar
->dragging
))
8639 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8640 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8641 /* This has the negative side effect that the slider value is
8642 not what it would be if we scrolled here using line-wise or
8643 page-wise movement. */
8644 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8647 /* If currently dragging, only update the slider size.
8648 This reduces flicker effects. */
8649 int old_value
, old_size
, increment
, page_increment
;
8651 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8652 &increment
, &page_increment
);
8653 XmScrollBarSetValues (widget
, old_value
,
8654 min (size
, XM_SB_RANGE
- old_value
),
8658 #else /* !USE_MOTIF i.e. use Xaw */
8660 float old_top
, old_shown
;
8662 XtVaGetValues (widget
,
8663 XtNtopOfThumb
, &old_top
,
8664 XtNshown
, &old_shown
,
8668 /* Massage the top+shown values. */
8669 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8670 top
= max (0, min (1, top
));
8673 /* Keep two pixels available for moving the thumb down. */
8674 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8676 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8677 check that your system's configuration file contains a define
8678 for `NARROWPROTO'. See s/freebsd.h for an example. */
8679 if (top
!= old_top
|| shown
!= old_shown
)
8681 if (NILP (bar
->dragging
))
8682 XawScrollbarSetThumb (widget
, top
, shown
);
8686 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8687 int scroll_mode
= 0;
8689 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8690 if (xaw3d_arrow_scroll
)
8692 /* Xaw3d stupidly ignores resize requests while dragging
8693 so we have to make it believe it's not in dragging mode. */
8694 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8695 if (scroll_mode
== 2)
8696 sb
->scrollbar
.scroll_mode
= 0;
8699 /* Try to make the scrolling a tad smoother. */
8700 if (!xaw3d_pick_top
)
8701 shown
= min (shown
, old_shown
);
8703 XawScrollbarSetThumb (widget
, top
, shown
);
8706 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8707 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8712 #endif /* !USE_MOTIF */
8717 #endif /* USE_TOOLKIT_SCROLL_BARS */
8721 /************************************************************************
8722 Scroll bars, general
8723 ************************************************************************/
8725 /* Create a scroll bar and return the scroll bar vector for it. W is
8726 the Emacs window on which to create the scroll bar. TOP, LEFT,
8727 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8730 static struct scroll_bar
*
8731 x_scroll_bar_create (w
, top
, left
, width
, height
)
8733 int top
, left
, width
, height
;
8735 struct frame
*f
= XFRAME (w
->frame
);
8736 struct scroll_bar
*bar
8737 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8741 #ifdef USE_TOOLKIT_SCROLL_BARS
8742 x_create_toolkit_scroll_bar (f
, bar
);
8743 #else /* not USE_TOOLKIT_SCROLL_BARS */
8745 XSetWindowAttributes a
;
8749 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8750 if (a
.background_pixel
== -1)
8751 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8753 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8754 | ButtonMotionMask
| PointerMotionHintMask
8756 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8758 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8760 /* Clear the area of W that will serve as a scroll bar. This is
8761 for the case that a window has been split horizontally. In
8762 this case, no clear_frame is generated to reduce flickering. */
8763 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8765 window_box_height (w
), False
);
8767 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8768 /* Position and size of scroll bar. */
8769 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8771 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8773 /* Border width, depth, class, and visual. */
8780 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8782 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8784 XSETWINDOW (bar
->window
, w
);
8785 XSETINT (bar
->top
, top
);
8786 XSETINT (bar
->left
, left
);
8787 XSETINT (bar
->width
, width
);
8788 XSETINT (bar
->height
, height
);
8789 XSETINT (bar
->start
, 0);
8790 XSETINT (bar
->end
, 0);
8791 bar
->dragging
= Qnil
;
8793 /* Add bar to its frame's list of scroll bars. */
8794 bar
->next
= FRAME_SCROLL_BARS (f
);
8796 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8797 if (!NILP (bar
->next
))
8798 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8800 /* Map the window/widget. */
8801 #ifdef USE_TOOLKIT_SCROLL_BARS
8803 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8804 XtConfigureWidget (scroll_bar
,
8805 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8807 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8808 max (height
, 1), 0);
8809 XtMapWidget (scroll_bar
);
8811 #else /* not USE_TOOLKIT_SCROLL_BARS */
8812 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8813 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8820 /* Draw BAR's handle in the proper position.
8822 If the handle is already drawn from START to END, don't bother
8823 redrawing it, unless REBUILD is non-zero; in that case, always
8824 redraw it. (REBUILD is handy for drawing the handle after expose
8827 Normally, we want to constrain the start and end of the handle to
8828 fit inside its rectangle, but if the user is dragging the scroll
8829 bar handle, we want to let them drag it down all the way, so that
8830 the bar's top is as far down as it goes; otherwise, there's no way
8831 to move to the very end of the buffer. */
8833 #ifndef USE_TOOLKIT_SCROLL_BARS
8836 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8837 struct scroll_bar
*bar
;
8841 int dragging
= ! NILP (bar
->dragging
);
8842 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8843 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8844 GC gc
= f
->output_data
.x
->normal_gc
;
8846 /* If the display is already accurate, do nothing. */
8848 && start
== XINT (bar
->start
)
8849 && end
== XINT (bar
->end
))
8855 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8856 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8857 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8859 /* Make sure the values are reasonable, and try to preserve
8860 the distance between start and end. */
8862 int length
= end
- start
;
8866 else if (start
> top_range
)
8868 end
= start
+ length
;
8872 else if (end
> top_range
&& ! dragging
)
8876 /* Store the adjusted setting in the scroll bar. */
8877 XSETINT (bar
->start
, start
);
8878 XSETINT (bar
->end
, end
);
8880 /* Clip the end position, just for display. */
8881 if (end
> top_range
)
8884 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8885 below top positions, to make sure the handle is always at least
8886 that many pixels tall. */
8887 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8889 /* Draw the empty space above the handle. Note that we can't clear
8890 zero-height areas; that means "clear to end of window." */
8892 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8893 /* x, y, width, height, and exposures. */
8894 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8895 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8896 inside_width
, start
,
8899 /* Change to proper foreground color if one is specified. */
8900 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8901 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8902 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8904 /* Draw the handle itself. */
8905 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8906 /* x, y, width, height */
8907 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8908 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8909 inside_width
, end
- start
);
8911 /* Restore the foreground color of the GC if we changed it above. */
8912 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8913 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8914 f
->output_data
.x
->foreground_pixel
);
8916 /* Draw the empty space below the handle. Note that we can't
8917 clear zero-height areas; that means "clear to end of window." */
8918 if (end
< inside_height
)
8919 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8920 /* x, y, width, height, and exposures. */
8921 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8922 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8923 inside_width
, inside_height
- end
,
8931 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8933 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8937 x_scroll_bar_remove (bar
)
8938 struct scroll_bar
*bar
;
8940 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8943 #ifdef USE_TOOLKIT_SCROLL_BARS
8944 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
8946 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8949 /* Disassociate this scroll bar from its window. */
8950 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8956 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8957 that we are displaying PORTION characters out of a total of WHOLE
8958 characters, starting at POSITION. If WINDOW has no scroll bar,
8962 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8964 int portion
, whole
, position
;
8966 struct frame
*f
= XFRAME (w
->frame
);
8967 struct scroll_bar
*bar
;
8968 int top
, height
, left
, sb_left
, width
, sb_width
;
8969 int window_x
, window_y
, window_width
, window_height
;
8971 /* Get window dimensions. */
8972 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8974 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8975 height
= window_height
;
8977 /* Compute the left edge of the scroll bar area. */
8978 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8979 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8981 left
= XFASTINT (w
->left
);
8982 left
*= CANON_X_UNIT (f
);
8983 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8985 /* Compute the width of the scroll bar which might be less than
8986 the width of the area reserved for the scroll bar. */
8987 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8988 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8992 /* Compute the left edge of the scroll bar. */
8993 #ifdef USE_TOOLKIT_SCROLL_BARS
8994 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8995 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8997 sb_left
= left
+ (width
- sb_width
) / 2;
8999 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9000 sb_left
= left
+ width
- sb_width
;
9005 /* Does the scroll bar exist yet? */
9006 if (NILP (w
->vertical_scroll_bar
))
9009 if (width
&& height
)
9010 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9011 left
, top
, width
, height
, False
);
9013 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9017 /* It may just need to be moved and resized. */
9018 unsigned int mask
= 0;
9020 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9024 if (sb_left
!= XINT (bar
->left
))
9026 if (top
!= XINT (bar
->top
))
9028 if (sb_width
!= XINT (bar
->width
))
9030 if (height
!= XINT (bar
->height
))
9033 #ifdef USE_TOOLKIT_SCROLL_BARS
9035 /* Since toolkit scroll bars are smaller than the space reserved
9036 for them on the frame, we have to clear "under" them. */
9037 if (width
&& height
)
9038 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9039 left
, top
, width
, height
, False
);
9041 /* Move/size the scroll bar widget. */
9043 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9044 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9046 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9047 max (height
, 1), 0);
9049 #else /* not USE_TOOLKIT_SCROLL_BARS */
9051 /* Clear areas not covered by the scroll bar because of
9052 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9053 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9055 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9056 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9058 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9059 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9060 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9064 /* Clear areas not covered by the scroll bar because it's not as
9065 wide as the area reserved for it . This makes sure a
9066 previous mode line display is cleared after C-x 2 C-x 1, for
9069 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9070 int rest
= area_width
- sb_width
;
9072 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9073 left
+ area_width
- rest
, 0,
9074 rest
, max (height
, 1), False
);
9077 /* Move/size the scroll bar window. */
9082 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9084 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9086 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9090 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9092 /* Remember new settings. */
9093 XSETINT (bar
->left
, sb_left
);
9094 XSETINT (bar
->top
, top
);
9095 XSETINT (bar
->width
, sb_width
);
9096 XSETINT (bar
->height
, height
);
9101 #ifdef USE_TOOLKIT_SCROLL_BARS
9102 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9103 #else /* not USE_TOOLKIT_SCROLL_BARS */
9104 /* Set the scroll bar's current state, unless we're currently being
9106 if (NILP (bar
->dragging
))
9108 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9111 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9114 int start
= ((double) position
* top_range
) / whole
;
9115 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9116 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9119 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9121 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9125 /* The following three hooks are used when we're doing a thorough
9126 redisplay of the frame. We don't explicitly know which scroll bars
9127 are going to be deleted, because keeping track of when windows go
9128 away is a real pain - "Can you say set-window-configuration, boys
9129 and girls?" Instead, we just assert at the beginning of redisplay
9130 that *all* scroll bars are to be removed, and then save a scroll bar
9131 from the fiery pit when we actually redisplay its window. */
9133 /* Arrange for all scroll bars on FRAME to be removed at the next call
9134 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9135 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9138 XTcondemn_scroll_bars (frame
)
9141 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9142 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9145 bar
= FRAME_SCROLL_BARS (frame
);
9146 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9147 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9148 XSCROLL_BAR (bar
)->prev
= Qnil
;
9149 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9150 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9151 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9156 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9157 Note that WINDOW isn't necessarily condemned at all. */
9160 XTredeem_scroll_bar (window
)
9161 struct window
*window
;
9163 struct scroll_bar
*bar
;
9166 /* We can't redeem this window's scroll bar if it doesn't have one. */
9167 if (NILP (window
->vertical_scroll_bar
))
9170 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9172 /* Unlink it from the condemned list. */
9173 f
= XFRAME (WINDOW_FRAME (window
));
9174 if (NILP (bar
->prev
))
9176 /* If the prev pointer is nil, it must be the first in one of
9178 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9179 /* It's not condemned. Everything's fine. */
9181 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9182 window
->vertical_scroll_bar
))
9183 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9185 /* If its prev pointer is nil, it must be at the front of
9186 one or the other! */
9190 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9192 if (! NILP (bar
->next
))
9193 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9195 bar
->next
= FRAME_SCROLL_BARS (f
);
9197 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9198 if (! NILP (bar
->next
))
9199 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9202 /* Remove all scroll bars on FRAME that haven't been saved since the
9203 last call to `*condemn_scroll_bars_hook'. */
9206 XTjudge_scroll_bars (f
)
9209 Lisp_Object bar
, next
;
9211 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9213 /* Clear out the condemned list now so we won't try to process any
9214 more events on the hapless scroll bars. */
9215 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9217 for (; ! NILP (bar
); bar
= next
)
9219 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9221 x_scroll_bar_remove (b
);
9224 b
->next
= b
->prev
= Qnil
;
9227 /* Now there should be no references to the condemned scroll bars,
9228 and they should get garbage-collected. */
9232 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9233 is a no-op when using toolkit scroll bars.
9235 This may be called from a signal handler, so we have to ignore GC
9239 x_scroll_bar_expose (bar
, event
)
9240 struct scroll_bar
*bar
;
9243 #ifndef USE_TOOLKIT_SCROLL_BARS
9245 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9246 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9247 GC gc
= f
->output_data
.x
->normal_gc
;
9248 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9252 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9254 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9255 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9257 /* x, y, width, height */
9259 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9260 XINT (bar
->height
) - 1);
9264 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9267 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9268 is set to something other than no_event, it is enqueued.
9270 This may be called from a signal handler, so we have to ignore GC
9273 #ifndef USE_TOOLKIT_SCROLL_BARS
9276 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9277 struct scroll_bar
*bar
;
9279 struct input_event
*emacs_event
;
9281 if (! GC_WINDOWP (bar
->window
))
9284 emacs_event
->kind
= scroll_bar_click
;
9285 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9286 emacs_event
->modifiers
9287 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9288 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9289 event
->xbutton
.state
)
9290 | (event
->type
== ButtonRelease
9293 emacs_event
->frame_or_window
= bar
->window
;
9294 emacs_event
->arg
= Qnil
;
9295 emacs_event
->timestamp
= event
->xbutton
.time
;
9298 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9300 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9303 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9304 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9307 if (y
> top_range
) y
= top_range
;
9309 if (y
< XINT (bar
->start
))
9310 emacs_event
->part
= scroll_bar_above_handle
;
9311 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9312 emacs_event
->part
= scroll_bar_handle
;
9314 emacs_event
->part
= scroll_bar_below_handle
;
9316 /* Just because the user has clicked on the handle doesn't mean
9317 they want to drag it. Lisp code needs to be able to decide
9318 whether or not we're dragging. */
9320 /* If the user has just clicked on the handle, record where they're
9322 if (event
->type
== ButtonPress
9323 && emacs_event
->part
== scroll_bar_handle
)
9324 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9327 /* If the user has released the handle, set it to its final position. */
9328 if (event
->type
== ButtonRelease
9329 && ! NILP (bar
->dragging
))
9331 int new_start
= y
- XINT (bar
->dragging
);
9332 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9334 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9335 bar
->dragging
= Qnil
;
9338 /* Same deal here as the other #if 0. */
9340 /* Clicks on the handle are always reported as occurring at the top of
9342 if (emacs_event
->part
== scroll_bar_handle
)
9343 emacs_event
->x
= bar
->start
;
9345 XSETINT (emacs_event
->x
, y
);
9347 XSETINT (emacs_event
->x
, y
);
9350 XSETINT (emacs_event
->y
, top_range
);
9354 /* Handle some mouse motion while someone is dragging the scroll bar.
9356 This may be called from a signal handler, so we have to ignore GC
9360 x_scroll_bar_note_movement (bar
, event
)
9361 struct scroll_bar
*bar
;
9364 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9366 last_mouse_movement_time
= event
->xmotion
.time
;
9369 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9371 /* If we're dragging the bar, display it. */
9372 if (! GC_NILP (bar
->dragging
))
9374 /* Where should the handle be now? */
9375 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9377 if (new_start
!= XINT (bar
->start
))
9379 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9381 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9386 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9388 /* Return information to the user about the current position of the mouse
9389 on the scroll bar. */
9392 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9394 Lisp_Object
*bar_window
;
9395 enum scroll_bar_part
*part
;
9397 unsigned long *time
;
9399 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9400 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9401 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9403 Window dummy_window
;
9405 unsigned int dummy_mask
;
9409 /* Get the mouse's position relative to the scroll bar window, and
9411 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9413 /* Root, child, root x and root y. */
9414 &dummy_window
, &dummy_window
,
9415 &dummy_coord
, &dummy_coord
,
9417 /* Position relative to scroll bar. */
9420 /* Mouse buttons and modifier keys. */
9427 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9430 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9432 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9434 if (! NILP (bar
->dragging
))
9435 win_y
-= XINT (bar
->dragging
);
9439 if (win_y
> top_range
)
9443 *bar_window
= bar
->window
;
9445 if (! NILP (bar
->dragging
))
9446 *part
= scroll_bar_handle
;
9447 else if (win_y
< XINT (bar
->start
))
9448 *part
= scroll_bar_above_handle
;
9449 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9450 *part
= scroll_bar_handle
;
9452 *part
= scroll_bar_below_handle
;
9454 XSETINT (*x
, win_y
);
9455 XSETINT (*y
, top_range
);
9458 last_mouse_scroll_bar
= Qnil
;
9461 *time
= last_mouse_movement_time
;
9467 /* The screen has been cleared so we may have changed foreground or
9468 background colors, and the scroll bars may need to be redrawn.
9469 Clear out the scroll bars, and ask for expose events, so we can
9473 x_scroll_bar_clear (f
)
9476 #ifndef USE_TOOLKIT_SCROLL_BARS
9479 /* We can have scroll bars even if this is 0,
9480 if we just turned off scroll bar mode.
9481 But in that case we should not clear them. */
9482 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9483 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9484 bar
= XSCROLL_BAR (bar
)->next
)
9485 XClearArea (FRAME_X_DISPLAY (f
),
9486 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9488 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9491 /* This processes Expose events from the menu-bar specific X event
9492 loop in xmenu.c. This allows to redisplay the frame if necessary
9493 when handling menu-bar or pop-up items. */
9496 process_expose_from_menu (event
)
9500 struct x_display_info
*dpyinfo
;
9501 int frame_exposed_p
= 0;
9505 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9506 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9509 if (f
->async_visible
== 0)
9511 f
->async_visible
= 1;
9512 f
->async_iconified
= 0;
9513 f
->output_data
.x
->has_been_visible
= 1;
9514 SET_FRAME_GARBAGED (f
);
9518 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9519 event
.xexpose
.x
, event
.xexpose
.y
,
9520 event
.xexpose
.width
, event
.xexpose
.height
);
9521 frame_exposed_p
= 1;
9526 struct scroll_bar
*bar
9527 = x_window_to_scroll_bar (event
.xexpose
.window
);
9530 x_scroll_bar_expose (bar
, &event
);
9534 return frame_exposed_p
;
9537 /* Define a queue to save up SelectionRequest events for later handling. */
9539 struct selection_event_queue
9542 struct selection_event_queue
*next
;
9545 static struct selection_event_queue
*queue
;
9547 /* Nonzero means queue up certain events--don't process them yet. */
9549 static int x_queue_selection_requests
;
9551 /* Queue up an X event *EVENT, to be processed later. */
9554 x_queue_event (f
, event
)
9558 struct selection_event_queue
*queue_tmp
9559 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9561 if (queue_tmp
!= NULL
)
9563 queue_tmp
->event
= *event
;
9564 queue_tmp
->next
= queue
;
9569 /* Take all the queued events and put them back
9570 so that they get processed afresh. */
9573 x_unqueue_events (display
)
9576 while (queue
!= NULL
)
9578 struct selection_event_queue
*queue_tmp
= queue
;
9579 XPutBackEvent (display
, &queue_tmp
->event
);
9580 queue
= queue_tmp
->next
;
9581 xfree ((char *)queue_tmp
);
9585 /* Start queuing SelectionRequest events. */
9588 x_start_queuing_selection_requests (display
)
9591 x_queue_selection_requests
++;
9594 /* Stop queuing SelectionRequest events. */
9597 x_stop_queuing_selection_requests (display
)
9600 x_queue_selection_requests
--;
9601 x_unqueue_events (display
);
9604 /* The main X event-reading loop - XTread_socket. */
9606 /* Time stamp of enter window event. This is only used by XTread_socket,
9607 but we have to put it out here, since static variables within functions
9608 sometimes don't work. */
9610 static Time enter_timestamp
;
9612 /* This holds the state XLookupString needs to implement dead keys
9613 and other tricks known as "compose processing". _X Window System_
9614 says that a portable program can't use this, but Stephen Gildea assures
9615 me that letting the compiler initialize it to zeros will work okay.
9617 This must be defined outside of XTread_socket, for the same reasons
9618 given for enter_time stamp, above. */
9620 static XComposeStatus compose_status
;
9622 /* Record the last 100 characters stored
9623 to help debug the loss-of-chars-during-GC problem. */
9625 static int temp_index
;
9626 static short temp_buffer
[100];
9628 /* Set this to nonzero to fake an "X I/O error"
9629 on a particular display. */
9631 struct x_display_info
*XTread_socket_fake_io_error
;
9633 /* When we find no input here, we occasionally do a no-op command
9634 to verify that the X server is still running and we can still talk with it.
9635 We try all the open displays, one by one.
9636 This variable is used for cycling thru the displays. */
9638 static struct x_display_info
*next_noop_dpyinfo
;
9640 #define SET_SAVED_MENU_EVENT(size) \
9643 if (f->output_data.x->saved_menu_event == 0) \
9644 f->output_data.x->saved_menu_event \
9645 = (XEvent *) xmalloc (sizeof (XEvent)); \
9646 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9647 if (numchars >= 1) \
9649 bufp->kind = menu_bar_activate_event; \
9650 XSETFRAME (bufp->frame_or_window, f); \
9659 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9660 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9662 /* Read events coming from the X server.
9663 This routine is called by the SIGIO handler.
9664 We return as soon as there are no more events to be read.
9666 Events representing keys are stored in buffer BUFP,
9667 which can hold up to NUMCHARS characters.
9668 We return the number of characters stored into the buffer,
9669 thus pretending to be `read'.
9671 EXPECTED is nonzero if the caller knows input is available. */
9674 XTread_socket (sd
, bufp
, numchars
, expected
)
9676 /* register */ struct input_event
*bufp
;
9677 /* register */ int numchars
;
9684 int event_found
= 0;
9685 struct x_display_info
*dpyinfo
;
9686 struct coding_system coding
;
9688 if (interrupt_input_blocked
)
9690 interrupt_input_pending
= 1;
9694 interrupt_input_pending
= 0;
9697 /* So people can tell when we have read the available input. */
9698 input_signal_count
++;
9701 abort (); /* Don't think this happens. */
9705 /* The input should be decoded if it is from XIM. Currently the
9706 locale of XIM is the same as that of the system. So, we can use
9707 Vlocale_coding_system which is initialized properly at Emacs
9709 setup_coding_system (Vlocale_coding_system
, &coding
);
9710 coding
.src_multibyte
= 0;
9711 coding
.dst_multibyte
= 1;
9712 /* The input is converted to events, thus we can't handle
9713 composition. Anyway, there's no XIM that gives us composition
9715 coding
.composing
= COMPOSITION_DISABLED
;
9717 /* Find the display we are supposed to read input for.
9718 It's the one communicating on descriptor SD. */
9719 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9721 #if 0 /* This ought to be unnecessary; let's verify it. */
9723 /* If available, Xlib uses FIOSNBIO to make the socket
9724 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9725 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9726 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9727 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9728 #endif /* ! defined (FIOSNBIO) */
9731 #if 0 /* This code can't be made to work, with multiple displays,
9732 and appears not to be used on any system any more.
9733 Also keyboard.c doesn't turn O_NDELAY on and off
9734 for X connections. */
9737 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9739 extern int read_alarm_should_throw
;
9740 read_alarm_should_throw
= 1;
9741 XPeekEvent (dpyinfo
->display
, &event
);
9742 read_alarm_should_throw
= 0;
9744 #endif /* HAVE_SELECT */
9748 /* For debugging, this gives a way to fake an I/O error. */
9749 if (dpyinfo
== XTread_socket_fake_io_error
)
9751 XTread_socket_fake_io_error
= 0;
9752 x_io_error_quitter (dpyinfo
->display
);
9755 while (XPending (dpyinfo
->display
))
9757 XNextEvent (dpyinfo
->display
, &event
);
9761 /* Filter events for the current X input method.
9762 XFilterEvent returns non-zero if the input method has
9763 consumed the event. We pass the frame's X window to
9764 XFilterEvent because that's the one for which the IC
9766 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9767 event
.xclient
.window
);
9768 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9778 if (event
.xclient
.message_type
9779 == dpyinfo
->Xatom_wm_protocols
9780 && event
.xclient
.format
== 32)
9782 if (event
.xclient
.data
.l
[0]
9783 == dpyinfo
->Xatom_wm_take_focus
)
9785 /* Use x_any_window_to_frame because this
9786 could be the shell widget window
9787 if the frame has no title bar. */
9788 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9790 /* Not quite sure this is needed -pd */
9791 if (f
&& FRAME_XIC (f
))
9792 XSetICFocus (FRAME_XIC (f
));
9794 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9795 instructs the WM to set the input focus automatically for
9796 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9797 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9798 it has set the focus. So, XSetInputFocus below is not
9801 The call to XSetInputFocus below has also caused trouble. In
9802 cases where the XSetInputFocus done by the WM and the one
9803 below are temporally close (on a fast machine), the call
9804 below can generate additional FocusIn events which confuse
9807 /* Since we set WM_TAKE_FOCUS, we must call
9808 XSetInputFocus explicitly. But not if f is null,
9809 since that might be an event for a deleted frame. */
9812 Display
*d
= event
.xclient
.display
;
9813 /* Catch and ignore errors, in case window has been
9814 iconified by a window manager such as GWM. */
9815 int count
= x_catch_errors (d
);
9816 XSetInputFocus (d
, event
.xclient
.window
,
9817 /* The ICCCM says this is
9818 the only valid choice. */
9820 event
.xclient
.data
.l
[1]);
9821 /* This is needed to detect the error
9822 if there is an error. */
9824 x_uncatch_errors (d
, count
);
9826 /* Not certain about handling scroll bars here */
9829 else if (event
.xclient
.data
.l
[0]
9830 == dpyinfo
->Xatom_wm_save_yourself
)
9832 /* Save state modify the WM_COMMAND property to
9833 something which can reinstate us. This notifies
9834 the session manager, who's looking for such a
9835 PropertyNotify. Can restart processing when
9836 a keyboard or mouse event arrives. */
9839 f
= x_top_window_to_frame (dpyinfo
,
9840 event
.xclient
.window
);
9842 /* This is just so we only give real data once
9843 for a single Emacs process. */
9844 if (f
== SELECTED_FRAME ())
9845 XSetCommand (FRAME_X_DISPLAY (f
),
9846 event
.xclient
.window
,
9847 initial_argv
, initial_argc
);
9849 XSetCommand (FRAME_X_DISPLAY (f
),
9850 event
.xclient
.window
,
9854 else if (event
.xclient
.data
.l
[0]
9855 == dpyinfo
->Xatom_wm_delete_window
)
9858 = x_any_window_to_frame (dpyinfo
,
9859 event
.xclient
.window
);
9866 bufp
->kind
= delete_window_event
;
9867 XSETFRAME (bufp
->frame_or_window
, f
);
9876 else if (event
.xclient
.message_type
9877 == dpyinfo
->Xatom_wm_configure_denied
)
9880 else if (event
.xclient
.message_type
9881 == dpyinfo
->Xatom_wm_window_moved
)
9885 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9887 new_x
= event
.xclient
.data
.s
[0];
9888 new_y
= event
.xclient
.data
.s
[1];
9892 f
->output_data
.x
->left_pos
= new_x
;
9893 f
->output_data
.x
->top_pos
= new_y
;
9897 else if (event
.xclient
.message_type
9898 == dpyinfo
->Xatom_editres
)
9901 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9902 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9905 #endif /* HACK_EDITRES */
9906 else if ((event
.xclient
.message_type
9907 == dpyinfo
->Xatom_DONE
)
9908 || (event
.xclient
.message_type
9909 == dpyinfo
->Xatom_PAGE
))
9911 /* Ghostview job completed. Kill it. We could
9912 reply with "Next" if we received "Page", but we
9913 currently never do because we are interested in
9914 images, only, which should have 1 page. */
9915 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9917 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9918 x_kill_gs_process (pixmap
, f
);
9919 expose_frame (f
, 0, 0, 0, 0);
9921 #ifdef USE_TOOLKIT_SCROLL_BARS
9922 /* Scroll bar callbacks send a ClientMessage from which
9923 we construct an input_event. */
9924 else if (event
.xclient
.message_type
9925 == dpyinfo
->Xatom_Scrollbar
)
9927 x_scroll_bar_to_input_event (&event
, bufp
);
9928 ++bufp
, ++count
, --numchars
;
9931 #endif /* USE_TOOLKIT_SCROLL_BARS */
9937 case SelectionNotify
:
9938 #ifdef USE_X_TOOLKIT
9939 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9941 #endif /* not USE_X_TOOLKIT */
9942 x_handle_selection_notify (&event
.xselection
);
9945 case SelectionClear
: /* Someone has grabbed ownership. */
9946 #ifdef USE_X_TOOLKIT
9947 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9949 #endif /* USE_X_TOOLKIT */
9951 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9956 bufp
->kind
= selection_clear_event
;
9957 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9958 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9959 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9960 bufp
->frame_or_window
= Qnil
;
9969 case SelectionRequest
: /* Someone wants our selection. */
9970 #ifdef USE_X_TOOLKIT
9971 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9973 #endif /* USE_X_TOOLKIT */
9974 if (x_queue_selection_requests
)
9975 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9979 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9984 bufp
->kind
= selection_request_event
;
9985 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9986 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9987 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9988 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9989 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9990 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9991 bufp
->frame_or_window
= Qnil
;
10000 case PropertyNotify
:
10001 #ifdef USE_X_TOOLKIT
10002 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10004 #endif /* not USE_X_TOOLKIT */
10005 x_handle_property_notify (&event
.xproperty
);
10008 case ReparentNotify
:
10009 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10013 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10014 x_real_positions (f
, &x
, &y
);
10015 f
->output_data
.x
->left_pos
= x
;
10016 f
->output_data
.x
->top_pos
= y
;
10021 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10024 if (f
->async_visible
== 0)
10026 f
->async_visible
= 1;
10027 f
->async_iconified
= 0;
10028 f
->output_data
.x
->has_been_visible
= 1;
10029 SET_FRAME_GARBAGED (f
);
10032 expose_frame (x_window_to_frame (dpyinfo
,
10033 event
.xexpose
.window
),
10034 event
.xexpose
.x
, event
.xexpose
.y
,
10035 event
.xexpose
.width
, event
.xexpose
.height
);
10039 #ifndef USE_TOOLKIT_SCROLL_BARS
10040 struct scroll_bar
*bar
;
10042 #if defined USE_X_TOOLKIT && defined USE_LUCID
10043 /* Submenus of the Lucid menu bar aren't widgets
10044 themselves, so there's no way to dispatch events
10045 to them. Recognize this case separately. */
10048 = x_window_to_menu_bar (event
.xexpose
.window
);
10050 xlwmenu_redisplay (widget
);
10052 #endif /* USE_X_TOOLKIT && USE_LUCID */
10054 #ifdef USE_TOOLKIT_SCROLL_BARS
10055 /* Dispatch event to the widget. */
10057 #else /* not USE_TOOLKIT_SCROLL_BARS */
10058 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10061 x_scroll_bar_expose (bar
, &event
);
10062 #ifdef USE_X_TOOLKIT
10065 #endif /* USE_X_TOOLKIT */
10066 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10070 case GraphicsExpose
: /* This occurs when an XCopyArea's
10071 source area was obscured or not
10073 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10077 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10078 event
.xgraphicsexpose
.width
,
10079 event
.xgraphicsexpose
.height
);
10081 #ifdef USE_X_TOOLKIT
10084 #endif /* USE_X_TOOLKIT */
10087 case NoExpose
: /* This occurs when an XCopyArea's
10088 source area was completely
10093 /* Redo the mouse-highlight after the tooltip has gone. */
10094 if (event
.xmap
.window
== tip_window
)
10097 redo_mouse_highlight ();
10100 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10101 if (f
) /* F may no longer exist if
10102 the frame was deleted. */
10104 /* While a frame is unmapped, display generation is
10105 disabled; you don't want to spend time updating a
10106 display that won't ever be seen. */
10107 f
->async_visible
= 0;
10108 /* We can't distinguish, from the event, whether the window
10109 has become iconified or invisible. So assume, if it
10110 was previously visible, than now it is iconified.
10111 But x_make_frame_invisible clears both
10112 the visible flag and the iconified flag;
10113 and that way, we know the window is not iconified now. */
10114 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10116 f
->async_iconified
= 1;
10118 bufp
->kind
= iconify_event
;
10119 XSETFRAME (bufp
->frame_or_window
, f
);
10129 if (event
.xmap
.window
== tip_window
)
10130 /* The tooltip has been drawn already. Avoid
10131 the SET_FRAME_GARBAGED below. */
10134 /* We use x_top_window_to_frame because map events can
10135 come for sub-windows and they don't mean that the
10136 frame is visible. */
10137 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10140 f
->async_visible
= 1;
10141 f
->async_iconified
= 0;
10142 f
->output_data
.x
->has_been_visible
= 1;
10144 /* wait_reading_process_input will notice this and update
10145 the frame's display structures. */
10146 SET_FRAME_GARBAGED (f
);
10150 bufp
->kind
= deiconify_event
;
10151 XSETFRAME (bufp
->frame_or_window
, f
);
10157 else if (! NILP (Vframe_list
)
10158 && ! NILP (XCDR (Vframe_list
)))
10159 /* Force a redisplay sooner or later
10160 to update the frame titles
10161 in case this is the second frame. */
10162 record_asynch_buffer_change ();
10167 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10169 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10172 /* Scroll bars consume key events, but we want
10173 the keys to go to the scroll bar's frame. */
10174 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10175 event
.xkey
.window
);
10176 if (widget
&& XmIsScrollBar (widget
))
10178 widget
= XtParent (widget
);
10179 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10182 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10186 KeySym keysym
, orig_keysym
;
10187 /* al%imercury@uunet.uu.net says that making this 81
10188 instead of 80 fixed a bug whereby meta chars made
10191 It seems that some version of XmbLookupString has
10192 a bug of not returning XBufferOverflow in
10193 status_return even if the input is too long to
10194 fit in 81 bytes. So, we must prepare sufficient
10195 bytes for copy_buffer. 513 bytes (256 chars for
10196 two-byte character set) seems to be a faily good
10197 approximation. -- 2000.8.10 handa@etl.go.jp */
10198 unsigned char copy_buffer
[513];
10199 unsigned char *copy_bufptr
= copy_buffer
;
10200 int copy_bufsiz
= sizeof (copy_buffer
);
10204 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10205 extra_keyboard_modifiers
);
10206 modifiers
= event
.xkey
.state
;
10208 /* This will have to go some day... */
10210 /* make_lispy_event turns chars into control chars.
10211 Don't do it here because XLookupString is too eager. */
10212 event
.xkey
.state
&= ~ControlMask
;
10213 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10214 | dpyinfo
->super_mod_mask
10215 | dpyinfo
->hyper_mod_mask
10216 | dpyinfo
->alt_mod_mask
);
10218 /* In case Meta is ComposeCharacter,
10219 clear its status. According to Markus Ehrnsperger
10220 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10221 this enables ComposeCharacter to work whether or
10222 not it is combined with Meta. */
10223 if (modifiers
& dpyinfo
->meta_mod_mask
)
10224 bzero (&compose_status
, sizeof (compose_status
));
10229 Status status_return
;
10231 nbytes
= XmbLookupString (FRAME_XIC (f
),
10232 &event
.xkey
, copy_bufptr
,
10233 copy_bufsiz
, &keysym
,
10235 if (status_return
== XBufferOverflow
)
10237 copy_bufsiz
= nbytes
+ 1;
10238 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10239 nbytes
= XmbLookupString (FRAME_XIC (f
),
10240 &event
.xkey
, copy_bufptr
,
10241 copy_bufsiz
, &keysym
,
10245 if (status_return
== XLookupNone
)
10247 else if (status_return
== XLookupChars
)
10252 else if (status_return
!= XLookupKeySym
10253 && status_return
!= XLookupBoth
)
10257 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10258 copy_bufsiz
, &keysym
,
10261 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10262 copy_bufsiz
, &keysym
,
10266 orig_keysym
= keysym
;
10270 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10271 || keysym
== XK_Delete
10272 #ifdef XK_ISO_Left_Tab
10273 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10275 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10276 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10277 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10279 /* This recognizes the "extended function keys".
10280 It seems there's no cleaner way.
10281 Test IsModifierKey to avoid handling mode_switch
10283 || ((unsigned) (keysym
) >= XK_Select
10284 && (unsigned)(keysym
) < XK_KP_Space
)
10286 #ifdef XK_dead_circumflex
10287 || orig_keysym
== XK_dead_circumflex
10289 #ifdef XK_dead_grave
10290 || orig_keysym
== XK_dead_grave
10292 #ifdef XK_dead_tilde
10293 || orig_keysym
== XK_dead_tilde
10295 #ifdef XK_dead_diaeresis
10296 || orig_keysym
== XK_dead_diaeresis
10298 #ifdef XK_dead_macron
10299 || orig_keysym
== XK_dead_macron
10301 #ifdef XK_dead_degree
10302 || orig_keysym
== XK_dead_degree
10304 #ifdef XK_dead_acute
10305 || orig_keysym
== XK_dead_acute
10307 #ifdef XK_dead_cedilla
10308 || orig_keysym
== XK_dead_cedilla
10310 #ifdef XK_dead_breve
10311 || orig_keysym
== XK_dead_breve
10313 #ifdef XK_dead_ogonek
10314 || orig_keysym
== XK_dead_ogonek
10316 #ifdef XK_dead_caron
10317 || orig_keysym
== XK_dead_caron
10319 #ifdef XK_dead_doubleacute
10320 || orig_keysym
== XK_dead_doubleacute
10322 #ifdef XK_dead_abovedot
10323 || orig_keysym
== XK_dead_abovedot
10325 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10326 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10327 /* Any "vendor-specific" key is ok. */
10328 || (orig_keysym
& (1 << 28)))
10329 && ! (IsModifierKey (orig_keysym
)
10331 #ifdef XK_Mode_switch
10332 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10335 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10337 #endif /* not HAVE_X11R5 */
10340 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10342 temp_buffer
[temp_index
++] = keysym
;
10343 bufp
->kind
= non_ascii_keystroke
;
10344 bufp
->code
= keysym
;
10345 XSETFRAME (bufp
->frame_or_window
, f
);
10348 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10350 bufp
->timestamp
= event
.xkey
.time
;
10355 else if (numchars
> nbytes
)
10361 for (i
= 0; i
< nbytes
; i
++)
10363 if (temp_index
== (sizeof temp_buffer
10366 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10369 if (/* If the event is not from XIM, */
10370 event
.xkey
.keycode
!= 0
10371 /* or the current locale doesn't request
10372 decoding of the intup data, ... */
10373 || coding
.type
== coding_type_raw_text
10374 || coding
.type
== coding_type_no_conversion
)
10376 /* ... we can use the input data as is. */
10381 /* We have to decode the input data. */
10385 require
= decoding_buffer_size (&coding
, nbytes
);
10386 p
= (unsigned char *) alloca (require
);
10387 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10388 decode_coding (&coding
, copy_bufptr
, p
,
10390 nbytes
= coding
.produced
;
10391 nchars
= coding
.produced_char
;
10395 /* Convert the input data to a sequence of
10396 character events. */
10397 for (i
= 0; i
< nbytes
; i
+= len
)
10399 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10401 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10403 : multibyte_char_keystroke
);
10405 XSETFRAME (bufp
->frame_or_window
, f
);
10408 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10410 bufp
->timestamp
= event
.xkey
.time
;
10415 numchars
-= nchars
;
10417 if (keysym
== NoSymbol
)
10427 /* Don't dispatch this event since XtDispatchEvent calls
10428 XFilterEvent, and two calls in a row may freeze the
10437 /* Don't dispatch this event since XtDispatchEvent calls
10438 XFilterEvent, and two calls in a row may freeze the
10445 /* Here's a possible interpretation of the whole
10446 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10447 you get a FocusIn event, you have to get a FocusOut
10448 event before you relinquish the focus. If you
10449 haven't received a FocusIn event, then a mere
10450 LeaveNotify is enough to free you. */
10454 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10456 if (event
.xcrossing
.focus
)
10458 /* Avoid nasty pop/raise loops. */
10459 if (f
&& (!(f
->auto_raise
)
10460 || !(f
->auto_lower
)
10461 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10463 x_new_focus_frame (dpyinfo
, f
);
10464 enter_timestamp
= event
.xcrossing
.time
;
10467 else if (f
== dpyinfo
->x_focus_frame
)
10468 x_new_focus_frame (dpyinfo
, 0);
10470 /* EnterNotify counts as mouse movement,
10471 so update things that depend on mouse position. */
10472 if (f
&& !f
->output_data
.x
->hourglass_p
)
10473 note_mouse_movement (f
, &event
.xmotion
);
10478 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10479 if (event
.xfocus
.detail
!= NotifyPointer
)
10480 dpyinfo
->x_focus_event_frame
= f
;
10483 x_new_focus_frame (dpyinfo
, f
);
10485 /* Don't stop displaying the initial startup message
10486 for a switch-frame event we don't need. */
10487 if (GC_NILP (Vterminal_frame
)
10488 && GC_CONSP (Vframe_list
)
10489 && !GC_NILP (XCDR (Vframe_list
)))
10491 bufp
->kind
= FOCUS_IN_EVENT
;
10492 XSETFRAME (bufp
->frame_or_window
, f
);
10494 ++bufp
, ++count
, --numchars
;
10499 if (f
&& FRAME_XIC (f
))
10500 XSetICFocus (FRAME_XIC (f
));
10506 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10509 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10511 /* If we move outside the frame, then we're
10512 certainly no longer on any text in the frame. */
10513 clear_mouse_face (dpyinfo
);
10514 dpyinfo
->mouse_face_mouse_frame
= 0;
10517 /* Generate a nil HELP_EVENT to cancel a help-echo.
10518 Do it only if there's something to cancel.
10519 Otherwise, the startup message is cleared when
10520 the mouse leaves the frame. */
10521 if (any_help_event_p
)
10526 XSETFRAME (frame
, f
);
10528 n
= gen_help_event (bufp
, numchars
,
10529 Qnil
, frame
, Qnil
, Qnil
, 0);
10530 bufp
+= n
, count
+= n
, numchars
-= n
;
10533 if (event
.xcrossing
.focus
)
10534 x_mouse_leave (dpyinfo
);
10537 if (f
== dpyinfo
->x_focus_event_frame
)
10538 dpyinfo
->x_focus_event_frame
= 0;
10539 if (f
== dpyinfo
->x_focus_frame
)
10540 x_new_focus_frame (dpyinfo
, 0);
10546 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10547 if (event
.xfocus
.detail
!= NotifyPointer
10548 && f
== dpyinfo
->x_focus_event_frame
)
10549 dpyinfo
->x_focus_event_frame
= 0;
10550 if (f
&& f
== dpyinfo
->x_focus_frame
)
10551 x_new_focus_frame (dpyinfo
, 0);
10554 if (f
&& FRAME_XIC (f
))
10555 XUnsetICFocus (FRAME_XIC (f
));
10562 previous_help_echo
= help_echo
;
10563 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10564 help_echo_pos
= -1;
10566 if (dpyinfo
->grabbed
&& last_mouse_frame
10567 && FRAME_LIVE_P (last_mouse_frame
))
10568 f
= last_mouse_frame
;
10570 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10573 note_mouse_movement (f
, &event
.xmotion
);
10576 #ifndef USE_TOOLKIT_SCROLL_BARS
10577 struct scroll_bar
*bar
10578 = x_window_to_scroll_bar (event
.xmotion
.window
);
10581 x_scroll_bar_note_movement (bar
, &event
);
10582 #endif /* USE_TOOLKIT_SCROLL_BARS */
10584 /* If we move outside the frame, then we're
10585 certainly no longer on any text in the frame. */
10586 clear_mouse_face (dpyinfo
);
10589 /* If the contents of the global variable help_echo
10590 has changed, generate a HELP_EVENT. */
10591 if (!NILP (help_echo
)
10592 || !NILP (previous_help_echo
))
10598 XSETFRAME (frame
, f
);
10602 any_help_event_p
= 1;
10603 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10604 help_echo_window
, help_echo_object
,
10606 bufp
+= n
, count
+= n
, numchars
-= n
;
10612 case ConfigureNotify
:
10613 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10616 #ifndef USE_X_TOOLKIT
10617 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10618 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10620 /* In the toolkit version, change_frame_size
10621 is called by the code that handles resizing
10622 of the EmacsFrame widget. */
10624 /* Even if the number of character rows and columns has
10625 not changed, the font size may have changed, so we need
10626 to check the pixel dimensions as well. */
10627 if (columns
!= f
->width
10628 || rows
!= f
->height
10629 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10630 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10632 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10633 SET_FRAME_GARBAGED (f
);
10634 cancel_mouse_face (f
);
10638 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10639 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10641 /* What we have now is the position of Emacs's own window.
10642 Convert that to the position of the window manager window. */
10643 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10644 &f
->output_data
.x
->top_pos
);
10647 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10648 xic_set_statusarea (f
);
10651 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10653 /* Since the WM decorations come below top_pos now,
10654 we must put them below top_pos in the future. */
10655 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10656 x_wm_set_size_hint (f
, (long) 0, 0);
10659 /* Some window managers pass (0,0) as the location of
10660 the window, and the Motif event handler stores it
10661 in the emacs widget, which messes up Motif menus. */
10662 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10664 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10665 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10667 #endif /* USE_MOTIF */
10672 case ButtonRelease
:
10674 /* If we decide we want to generate an event to be seen
10675 by the rest of Emacs, we put it here. */
10676 struct input_event emacs_event
;
10677 int tool_bar_p
= 0;
10679 emacs_event
.kind
= no_event
;
10680 bzero (&compose_status
, sizeof (compose_status
));
10682 if (dpyinfo
->grabbed
10683 && last_mouse_frame
10684 && FRAME_LIVE_P (last_mouse_frame
))
10685 f
= last_mouse_frame
;
10687 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10691 /* Is this in the tool-bar? */
10692 if (WINDOWP (f
->tool_bar_window
)
10693 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10695 Lisp_Object window
;
10698 x
= event
.xbutton
.x
;
10699 y
= event
.xbutton
.y
;
10702 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10703 if (EQ (window
, f
->tool_bar_window
))
10705 x_handle_tool_bar_click (f
, &event
.xbutton
);
10711 if (!dpyinfo
->x_focus_frame
10712 || f
== dpyinfo
->x_focus_frame
)
10713 construct_mouse_click (&emacs_event
, &event
, f
);
10717 #ifndef USE_TOOLKIT_SCROLL_BARS
10718 struct scroll_bar
*bar
10719 = x_window_to_scroll_bar (event
.xbutton
.window
);
10722 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10723 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10726 if (event
.type
== ButtonPress
)
10728 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10729 last_mouse_frame
= f
;
10730 /* Ignore any mouse motion that happened
10731 before this event; any subsequent mouse-movement
10732 Emacs events should reflect only motion after
10733 the ButtonPress. */
10735 f
->mouse_moved
= 0;
10738 last_tool_bar_item
= -1;
10742 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10745 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10747 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10753 #ifdef USE_X_TOOLKIT
10754 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10755 /* For a down-event in the menu bar,
10756 don't pass it to Xt right now.
10757 Instead, save it away
10758 and we will pass it to Xt from kbd_buffer_get_event.
10759 That way, we can run some Lisp code first. */
10760 if (f
&& event
.type
== ButtonPress
10761 /* Verify the event is really within the menu bar
10762 and not just sent to it due to grabbing. */
10763 && event
.xbutton
.x
>= 0
10764 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10765 && event
.xbutton
.y
>= 0
10766 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10767 && event
.xbutton
.same_screen
)
10769 SET_SAVED_BUTTON_EVENT
;
10770 XSETFRAME (last_mouse_press_frame
, f
);
10772 else if (event
.type
== ButtonPress
)
10774 last_mouse_press_frame
= Qnil
;
10778 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10779 but I am trying to be cautious. */
10780 else if (event
.type
== ButtonRelease
)
10782 if (!NILP (last_mouse_press_frame
))
10784 f
= XFRAME (last_mouse_press_frame
);
10785 if (f
->output_data
.x
)
10786 SET_SAVED_BUTTON_EVENT
;
10791 #endif /* USE_MOTIF */
10794 #endif /* USE_X_TOOLKIT */
10798 case CirculateNotify
:
10801 case CirculateRequest
:
10804 case VisibilityNotify
:
10807 case MappingNotify
:
10808 /* Someone has changed the keyboard mapping - update the
10810 switch (event
.xmapping
.request
)
10812 case MappingModifier
:
10813 x_find_modifier_meanings (dpyinfo
);
10814 /* This is meant to fall through. */
10815 case MappingKeyboard
:
10816 XRefreshKeyboardMapping (&event
.xmapping
);
10822 #ifdef USE_X_TOOLKIT
10824 XtDispatchEvent (&event
);
10826 #endif /* USE_X_TOOLKIT */
10834 /* On some systems, an X bug causes Emacs to get no more events
10835 when the window is destroyed. Detect that. (1994.) */
10838 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10839 One XNOOP in 100 loops will make Emacs terminate.
10840 B. Bretthauer, 1994 */
10842 if (x_noop_count
>= 100)
10846 if (next_noop_dpyinfo
== 0)
10847 next_noop_dpyinfo
= x_display_list
;
10849 XNoOp (next_noop_dpyinfo
->display
);
10851 /* Each time we get here, cycle through the displays now open. */
10852 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10856 /* If the focus was just given to an auto-raising frame,
10858 /* ??? This ought to be able to handle more than one such frame. */
10859 if (pending_autoraise_frame
)
10861 x_raise_frame (pending_autoraise_frame
);
10862 pending_autoraise_frame
= 0;
10873 /***********************************************************************
10875 ***********************************************************************/
10877 /* Note if the text cursor of window W has been overwritten by a
10878 drawing operation that outputs N glyphs starting at HPOS in the
10879 line given by output_cursor.vpos. N < 0 means all the rest of the
10880 line after HPOS has been written. */
10883 note_overwritten_text_cursor (w
, hpos
, n
)
10887 if (updated_area
== TEXT_AREA
10888 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10889 && hpos
<= w
->phys_cursor
.hpos
10891 || hpos
+ n
> w
->phys_cursor
.hpos
))
10892 w
->phys_cursor_on_p
= 0;
10896 /* Set clipping for output in glyph row ROW. W is the window in which
10897 we operate. GC is the graphics context to set clipping in.
10898 WHOLE_LINE_P non-zero means include the areas used for truncation
10899 mark display and alike in the clipping rectangle.
10901 ROW may be a text row or, e.g., a mode line. Text rows must be
10902 clipped to the interior of the window dedicated to text display,
10903 mode lines must be clipped to the whole window. */
10906 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10908 struct glyph_row
*row
;
10912 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10913 XRectangle clip_rect
;
10914 int window_x
, window_y
, window_width
, window_height
;
10916 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10918 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10919 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10920 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10921 clip_rect
.width
= window_width
;
10922 clip_rect
.height
= row
->visible_height
;
10924 /* If clipping to the whole line, including trunc marks, extend
10925 the rectangle to the left and increase its width. */
10928 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10929 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10932 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10936 /* Draw a hollow box cursor on window W in glyph row ROW. */
10939 x_draw_hollow_cursor (w
, row
)
10941 struct glyph_row
*row
;
10943 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10944 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10945 Display
*dpy
= FRAME_X_DISPLAY (f
);
10948 struct glyph
*cursor_glyph
;
10951 /* Compute frame-relative coordinates from window-relative
10953 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10954 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10955 + row
->ascent
- w
->phys_cursor_ascent
);
10956 h
= row
->height
- 1;
10958 /* Get the glyph the cursor is on. If we can't tell because
10959 the current matrix is invalid or such, give up. */
10960 cursor_glyph
= get_phys_cursor_glyph (w
);
10961 if (cursor_glyph
== NULL
)
10964 /* Compute the width of the rectangle to draw. If on a stretch
10965 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10966 rectangle as wide as the glyph, but use a canonical character
10968 wd
= cursor_glyph
->pixel_width
- 1;
10969 if (cursor_glyph
->type
== STRETCH_GLYPH
10970 && !x_stretch_cursor_p
)
10971 wd
= min (CANON_X_UNIT (f
), wd
);
10973 /* The foreground of cursor_gc is typically the same as the normal
10974 background color, which can cause the cursor box to be invisible. */
10975 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10976 if (dpyinfo
->scratch_cursor_gc
)
10977 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10979 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10980 GCForeground
, &xgcv
);
10981 gc
= dpyinfo
->scratch_cursor_gc
;
10983 /* Set clipping, draw the rectangle, and reset clipping again. */
10984 x_clip_to_row (w
, row
, gc
, 0);
10985 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10986 XSetClipMask (dpy
, gc
, None
);
10990 /* Draw a bar cursor on window W in glyph row ROW.
10992 Implementation note: One would like to draw a bar cursor with an
10993 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10994 Unfortunately, I didn't find a font yet that has this property set.
10998 x_draw_bar_cursor (w
, row
, width
)
11000 struct glyph_row
*row
;
11003 struct frame
*f
= XFRAME (w
->frame
);
11004 struct glyph
*cursor_glyph
;
11007 unsigned long mask
;
11012 /* If cursor is out of bounds, don't draw garbage. This can happen
11013 in mini-buffer windows when switching between echo area glyphs
11014 and mini-buffer. */
11015 cursor_glyph
= get_phys_cursor_glyph (w
);
11016 if (cursor_glyph
== NULL
)
11019 /* If on an image, draw like a normal cursor. That's usually better
11020 visible than drawing a bar, esp. if the image is large so that
11021 the bar might not be in the window. */
11022 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11024 struct glyph_row
*row
;
11025 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11026 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11030 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
11031 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11032 xgcv
.graphics_exposures
= 0;
11033 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11034 dpy
= FRAME_X_DISPLAY (f
);
11035 window
= FRAME_X_WINDOW (f
);
11036 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11039 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11042 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11043 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11047 width
= f
->output_data
.x
->cursor_width
;
11049 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11050 x_clip_to_row (w
, row
, gc
, 0);
11051 XFillRectangle (dpy
, window
, gc
,
11053 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11054 min (cursor_glyph
->pixel_width
, width
),
11056 XSetClipMask (dpy
, gc
, None
);
11061 /* Clear the cursor of window W to background color, and mark the
11062 cursor as not shown. This is used when the text where the cursor
11063 is is about to be rewritten. */
11069 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11070 x_update_window_cursor (w
, 0);
11074 /* Draw the cursor glyph of window W in glyph row ROW. See the
11075 comment of x_draw_glyphs for the meaning of HL. */
11078 x_draw_phys_cursor_glyph (w
, row
, hl
)
11080 struct glyph_row
*row
;
11081 enum draw_glyphs_face hl
;
11083 /* If cursor hpos is out of bounds, don't draw garbage. This can
11084 happen in mini-buffer windows when switching between echo area
11085 glyphs and mini-buffer. */
11086 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11088 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11089 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11092 /* When we erase the cursor, and ROW is overlapped by other
11093 rows, make sure that these overlapping parts of other rows
11095 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11097 if (row
> w
->current_matrix
->rows
11098 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11099 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11101 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11102 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11103 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11109 /* Erase the image of a cursor of window W from the screen. */
11112 x_erase_phys_cursor (w
)
11115 struct frame
*f
= XFRAME (w
->frame
);
11116 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11117 int hpos
= w
->phys_cursor
.hpos
;
11118 int vpos
= w
->phys_cursor
.vpos
;
11119 int mouse_face_here_p
= 0;
11120 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11121 struct glyph_row
*cursor_row
;
11122 struct glyph
*cursor_glyph
;
11123 enum draw_glyphs_face hl
;
11125 /* No cursor displayed or row invalidated => nothing to do on the
11127 if (w
->phys_cursor_type
== NO_CURSOR
)
11128 goto mark_cursor_off
;
11130 /* VPOS >= active_glyphs->nrows means that window has been resized.
11131 Don't bother to erase the cursor. */
11132 if (vpos
>= active_glyphs
->nrows
)
11133 goto mark_cursor_off
;
11135 /* If row containing cursor is marked invalid, there is nothing we
11137 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11138 if (!cursor_row
->enabled_p
)
11139 goto mark_cursor_off
;
11141 /* This can happen when the new row is shorter than the old one.
11142 In this case, either x_draw_glyphs or clear_end_of_line
11143 should have cleared the cursor. Note that we wouldn't be
11144 able to erase the cursor in this case because we don't have a
11145 cursor glyph at hand. */
11146 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11147 goto mark_cursor_off
;
11149 /* If the cursor is in the mouse face area, redisplay that when
11150 we clear the cursor. */
11151 if (! NILP (dpyinfo
->mouse_face_window
)
11152 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11153 && (vpos
> dpyinfo
->mouse_face_beg_row
11154 || (vpos
== dpyinfo
->mouse_face_beg_row
11155 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11156 && (vpos
< dpyinfo
->mouse_face_end_row
11157 || (vpos
== dpyinfo
->mouse_face_end_row
11158 && hpos
< dpyinfo
->mouse_face_end_col
))
11159 /* Don't redraw the cursor's spot in mouse face if it is at the
11160 end of a line (on a newline). The cursor appears there, but
11161 mouse highlighting does not. */
11162 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11163 mouse_face_here_p
= 1;
11165 /* Maybe clear the display under the cursor. */
11166 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11169 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11171 cursor_glyph
= get_phys_cursor_glyph (w
);
11172 if (cursor_glyph
== NULL
)
11173 goto mark_cursor_off
;
11175 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11177 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11179 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11181 cursor_glyph
->pixel_width
,
11182 cursor_row
->visible_height
,
11186 /* Erase the cursor by redrawing the character underneath it. */
11187 if (mouse_face_here_p
)
11188 hl
= DRAW_MOUSE_FACE
;
11189 else if (cursor_row
->inverse_p
)
11190 hl
= DRAW_INVERSE_VIDEO
;
11192 hl
= DRAW_NORMAL_TEXT
;
11193 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11196 w
->phys_cursor_on_p
= 0;
11197 w
->phys_cursor_type
= NO_CURSOR
;
11201 /* Display or clear cursor of window W. If ON is zero, clear the
11202 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11203 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11206 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11208 int on
, hpos
, vpos
, x
, y
;
11210 struct frame
*f
= XFRAME (w
->frame
);
11211 int new_cursor_type
;
11212 int new_cursor_width
;
11213 struct glyph_matrix
*current_glyphs
;
11214 struct glyph_row
*glyph_row
;
11215 struct glyph
*glyph
;
11217 /* This is pointless on invisible frames, and dangerous on garbaged
11218 windows and frames; in the latter case, the frame or window may
11219 be in the midst of changing its size, and x and y may be off the
11221 if (! FRAME_VISIBLE_P (f
)
11222 || FRAME_GARBAGED_P (f
)
11223 || vpos
>= w
->current_matrix
->nrows
11224 || hpos
>= w
->current_matrix
->matrix_w
)
11227 /* If cursor is off and we want it off, return quickly. */
11228 if (!on
&& !w
->phys_cursor_on_p
)
11231 current_glyphs
= w
->current_matrix
;
11232 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11233 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11235 /* If cursor row is not enabled, we don't really know where to
11236 display the cursor. */
11237 if (!glyph_row
->enabled_p
)
11239 w
->phys_cursor_on_p
= 0;
11243 xassert (interrupt_input_blocked
);
11245 /* Set new_cursor_type to the cursor we want to be displayed. In a
11246 mini-buffer window, we want the cursor only to appear if we are
11247 reading input from this window. For the selected window, we want
11248 the cursor type given by the frame parameter. If explicitly
11249 marked off, draw no cursor. In all other cases, we want a hollow
11251 new_cursor_width
= -1;
11252 if (cursor_in_echo_area
11253 && FRAME_HAS_MINIBUF_P (f
)
11254 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11256 if (w
== XWINDOW (echo_area_window
))
11257 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11259 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11263 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11264 || w
!= XWINDOW (f
->selected_window
))
11266 extern int cursor_in_non_selected_windows
;
11268 if (MINI_WINDOW_P (w
)
11269 || !cursor_in_non_selected_windows
11270 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11271 new_cursor_type
= NO_CURSOR
;
11273 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11275 else if (w
->cursor_off_p
)
11276 new_cursor_type
= NO_CURSOR
;
11279 struct buffer
*b
= XBUFFER (w
->buffer
);
11281 if (EQ (b
->cursor_type
, Qt
))
11282 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11284 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11285 &new_cursor_width
);
11289 /* If cursor is currently being shown and we don't want it to be or
11290 it is in the wrong place, or the cursor type is not what we want,
11292 if (w
->phys_cursor_on_p
11294 || w
->phys_cursor
.x
!= x
11295 || w
->phys_cursor
.y
!= y
11296 || new_cursor_type
!= w
->phys_cursor_type
))
11297 x_erase_phys_cursor (w
);
11299 /* If the cursor is now invisible and we want it to be visible,
11301 if (on
&& !w
->phys_cursor_on_p
)
11303 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11304 w
->phys_cursor_height
= glyph_row
->height
;
11306 /* Set phys_cursor_.* before x_draw_.* is called because some
11307 of them may need the information. */
11308 w
->phys_cursor
.x
= x
;
11309 w
->phys_cursor
.y
= glyph_row
->y
;
11310 w
->phys_cursor
.hpos
= hpos
;
11311 w
->phys_cursor
.vpos
= vpos
;
11312 w
->phys_cursor_type
= new_cursor_type
;
11313 w
->phys_cursor_on_p
= 1;
11315 switch (new_cursor_type
)
11317 case HOLLOW_BOX_CURSOR
:
11318 x_draw_hollow_cursor (w
, glyph_row
);
11321 case FILLED_BOX_CURSOR
:
11322 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11326 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11337 if (w
== XWINDOW (f
->selected_window
))
11338 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11339 xic_set_preeditarea (w
, x
, y
);
11344 if (updating_frame
!= f
)
11345 XFlush (FRAME_X_DISPLAY (f
));
11350 /* Display the cursor on window W, or clear it. X and Y are window
11351 relative pixel coordinates. HPOS and VPOS are glyph matrix
11352 positions. If W is not the selected window, display a hollow
11353 cursor. ON non-zero means display the cursor at X, Y which
11354 correspond to HPOS, VPOS, otherwise it is cleared. */
11357 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11359 int on
, hpos
, vpos
, x
, y
;
11362 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11367 /* Display the cursor on window W, or clear it, according to ON_P.
11368 Don't change the cursor's position. */
11371 x_update_cursor (f
, on_p
)
11374 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11378 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11379 in the window tree rooted at W. */
11382 x_update_cursor_in_window_tree (w
, on_p
)
11388 if (!NILP (w
->hchild
))
11389 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11390 else if (!NILP (w
->vchild
))
11391 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11393 x_update_window_cursor (w
, on_p
);
11395 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11400 /* Switch the display of W's cursor on or off, according to the value
11404 x_update_window_cursor (w
, on
)
11408 /* Don't update cursor in windows whose frame is in the process
11409 of being deleted. */
11410 if (w
->current_matrix
)
11413 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11414 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11424 /* Refresh bitmap kitchen sink icon for frame F
11425 when we get an expose event for it. */
11431 /* Normally, the window manager handles this function. */
11434 /* Make the x-window of frame F use the gnu icon bitmap. */
11437 x_bitmap_icon (f
, file
)
11443 if (FRAME_X_WINDOW (f
) == 0)
11446 /* Free up our existing icon bitmap if any. */
11447 if (f
->output_data
.x
->icon_bitmap
> 0)
11448 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11449 f
->output_data
.x
->icon_bitmap
= 0;
11451 if (STRINGP (file
))
11452 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11455 /* Create the GNU bitmap if necessary. */
11456 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11457 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11458 = x_create_bitmap_from_data (f
, gnu_bits
,
11459 gnu_width
, gnu_height
);
11461 /* The first time we create the GNU bitmap,
11462 this increments the ref-count one extra time.
11463 As a result, the GNU bitmap is never freed.
11464 That way, we don't have to worry about allocating it again. */
11465 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11467 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11470 x_wm_set_icon_pixmap (f
, bitmap_id
);
11471 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11477 /* Make the x-window of frame F use a rectangle with text.
11478 Use ICON_NAME as the text. */
11481 x_text_icon (f
, icon_name
)
11485 if (FRAME_X_WINDOW (f
) == 0)
11490 XTextProperty text
;
11491 text
.value
= (unsigned char *) icon_name
;
11492 text
.encoding
= XA_STRING
;
11494 text
.nitems
= strlen (icon_name
);
11495 #ifdef USE_X_TOOLKIT
11496 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11498 #else /* not USE_X_TOOLKIT */
11499 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11500 #endif /* not USE_X_TOOLKIT */
11502 #else /* not HAVE_X11R4 */
11503 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11504 #endif /* not HAVE_X11R4 */
11506 if (f
->output_data
.x
->icon_bitmap
> 0)
11507 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11508 f
->output_data
.x
->icon_bitmap
= 0;
11509 x_wm_set_icon_pixmap (f
, 0);
11514 #define X_ERROR_MESSAGE_SIZE 200
11516 /* If non-nil, this should be a string.
11517 It means catch X errors and store the error message in this string. */
11519 static Lisp_Object x_error_message_string
;
11521 /* An X error handler which stores the error message in
11522 x_error_message_string. This is called from x_error_handler if
11523 x_catch_errors is in effect. */
11526 x_error_catcher (display
, error
)
11528 XErrorEvent
*error
;
11530 XGetErrorText (display
, error
->error_code
,
11531 XSTRING (x_error_message_string
)->data
,
11532 X_ERROR_MESSAGE_SIZE
);
11535 /* Begin trapping X errors for display DPY. Actually we trap X errors
11536 for all displays, but DPY should be the display you are actually
11539 After calling this function, X protocol errors no longer cause
11540 Emacs to exit; instead, they are recorded in the string
11541 stored in x_error_message_string.
11543 Calling x_check_errors signals an Emacs error if an X error has
11544 occurred since the last call to x_catch_errors or x_check_errors.
11546 Calling x_uncatch_errors resumes the normal error handling. */
11548 void x_check_errors ();
11549 static Lisp_Object
x_catch_errors_unwind ();
11552 x_catch_errors (dpy
)
11555 int count
= specpdl_ptr
- specpdl
;
11557 /* Make sure any errors from previous requests have been dealt with. */
11558 XSync (dpy
, False
);
11560 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11562 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11563 XSTRING (x_error_message_string
)->data
[0] = 0;
11568 /* Unbind the binding that we made to check for X errors. */
11571 x_catch_errors_unwind (old_val
)
11572 Lisp_Object old_val
;
11574 x_error_message_string
= old_val
;
11578 /* If any X protocol errors have arrived since the last call to
11579 x_catch_errors or x_check_errors, signal an Emacs error using
11580 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11583 x_check_errors (dpy
, format
)
11587 /* Make sure to catch any errors incurred so far. */
11588 XSync (dpy
, False
);
11590 if (XSTRING (x_error_message_string
)->data
[0])
11591 error (format
, XSTRING (x_error_message_string
)->data
);
11594 /* Nonzero if we had any X protocol errors
11595 since we did x_catch_errors on DPY. */
11598 x_had_errors_p (dpy
)
11601 /* Make sure to catch any errors incurred so far. */
11602 XSync (dpy
, False
);
11604 return XSTRING (x_error_message_string
)->data
[0] != 0;
11607 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11610 x_clear_errors (dpy
)
11613 XSTRING (x_error_message_string
)->data
[0] = 0;
11616 /* Stop catching X protocol errors and let them make Emacs die.
11617 DPY should be the display that was passed to x_catch_errors.
11618 COUNT should be the value that was returned by
11619 the corresponding call to x_catch_errors. */
11622 x_uncatch_errors (dpy
, count
)
11626 unbind_to (count
, Qnil
);
11630 static unsigned int x_wire_count
;
11633 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11638 /* Handle SIGPIPE, which can happen when the connection to a server
11639 simply goes away. SIGPIPE is handled by x_connection_signal.
11640 Don't need to do anything, because the write which caused the
11641 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11642 which will do the appropriate cleanup for us. */
11645 x_connection_signal (signalnum
) /* If we don't have an argument, */
11646 int signalnum
; /* some compilers complain in signal calls. */
11649 /* USG systems forget handlers when they are used;
11650 must reestablish each time */
11651 signal (signalnum
, x_connection_signal
);
11656 /************************************************************************
11658 ************************************************************************/
11660 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
11661 the text of an error message that lead to the connection loss. */
11664 x_connection_closed (dpy
, error_message
)
11666 char *error_message
;
11668 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
11669 Lisp_Object frame
, tail
;
11673 msg
= (char *) alloca (strlen (error_message
) + 1);
11674 strcpy (msg
, error_message
);
11675 handling_signal
= 0;
11677 /* Prevent being called recursively because of an error condition
11678 below. Otherwise, we might end up with printing ``can't find per
11679 display information'' in the recursive call instead of printing
11680 the original message here. */
11681 count
= x_catch_errors (dpy
);
11683 /* We have to close the display to inform Xt that it doesn't
11684 exist anymore. If we don't, Xt will continue to wait for
11685 events from the display. As a consequence, a sequence of
11687 M-x make-frame-on-display RET :1 RET
11688 ...kill the new frame, so that we get an IO error...
11689 M-x make-frame-on-display RET :1 RET
11691 will indefinitely wait in Xt for events for display `:1', opened
11692 in the first class to make-frame-on-display.
11694 Closing the display is reported to lead to a bus error on
11695 OpenWindows in certain situations. I suspect that is a bug
11696 in OpenWindows. I don't know how to cicumvent it here. */
11698 #ifdef USE_X_TOOLKIT
11699 /* If DPYINFO is null, this means we didn't open the display
11700 in the first place, so don't try to close it. */
11702 XtCloseDisplay (dpy
);
11705 /* Indicate that this display is dead. */
11707 dpyinfo
->display
= 0;
11709 /* First delete frames whose mini-buffers are on frames
11710 that are on the dead display. */
11711 FOR_EACH_FRAME (tail
, frame
)
11713 Lisp_Object minibuf_frame
;
11715 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11716 if (FRAME_X_P (XFRAME (frame
))
11717 && FRAME_X_P (XFRAME (minibuf_frame
))
11718 && ! EQ (frame
, minibuf_frame
)
11719 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11720 Fdelete_frame (frame
, Qt
);
11723 /* Now delete all remaining frames on the dead display.
11724 We are now sure none of these is used as the mini-buffer
11725 for another frame that we need to delete. */
11726 FOR_EACH_FRAME (tail
, frame
)
11727 if (FRAME_X_P (XFRAME (frame
))
11728 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11730 /* Set this to t so that Fdelete_frame won't get confused
11731 trying to find a replacement. */
11732 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11733 Fdelete_frame (frame
, Qt
);
11737 x_delete_display (dpyinfo
);
11739 x_uncatch_errors (dpy
, count
);
11741 if (x_display_list
== 0)
11743 fprintf (stderr
, "%s\n", msg
);
11744 shut_down_emacs (0, 0, Qnil
);
11748 /* Ordinary stack unwind doesn't deal with these. */
11750 sigunblock (sigmask (SIGIO
));
11752 sigunblock (sigmask (SIGALRM
));
11753 TOTALLY_UNBLOCK_INPUT
;
11755 clear_waiting_for_input ();
11760 /* This is the usual handler for X protocol errors.
11761 It kills all frames on the display that we got the error for.
11762 If that was the only one, it prints an error message and kills Emacs. */
11765 x_error_quitter (display
, error
)
11767 XErrorEvent
*error
;
11769 char buf
[256], buf1
[356];
11771 /* Note that there is no real way portable across R3/R4 to get the
11772 original error handler. */
11774 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11775 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11776 buf
, error
->request_code
);
11777 x_connection_closed (display
, buf1
);
11781 /* This is the first-level handler for X protocol errors.
11782 It calls x_error_quitter or x_error_catcher. */
11785 x_error_handler (display
, error
)
11787 XErrorEvent
*error
;
11789 if (! NILP (x_error_message_string
))
11790 x_error_catcher (display
, error
);
11792 x_error_quitter (display
, error
);
11796 /* This is the handler for X IO errors, always.
11797 It kills all frames on the display that we lost touch with.
11798 If that was the only one, it prints an error message and kills Emacs. */
11801 x_io_error_quitter (display
)
11806 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11807 x_connection_closed (display
, buf
);
11811 /* Changing the font of the frame. */
11813 /* Give frame F the font named FONTNAME as its default font, and
11814 return the full name of that font. FONTNAME may be a wildcard
11815 pattern; in that case, we choose some font that fits the pattern.
11816 The return value shows which font we chose. */
11819 x_new_font (f
, fontname
)
11821 register char *fontname
;
11823 struct font_info
*fontp
11824 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11829 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11830 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11831 f
->output_data
.x
->fontset
= -1;
11833 /* Compute the scroll bar width in character columns. */
11834 if (f
->scroll_bar_pixel_width
> 0)
11836 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11837 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11841 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11842 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11845 /* Now make the frame display the given font. */
11846 if (FRAME_X_WINDOW (f
) != 0)
11848 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11849 f
->output_data
.x
->font
->fid
);
11850 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11851 f
->output_data
.x
->font
->fid
);
11852 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11853 f
->output_data
.x
->font
->fid
);
11855 frame_update_line_height (f
);
11857 /* Don't change the size of a tip frame; there's no point in
11858 doing it because it's done in Fx_show_tip, and it leads to
11859 problems because the tip frame has no widget. */
11860 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
11861 x_set_window_size (f
, 0, f
->width
, f
->height
);
11864 /* If we are setting a new frame's font for the first time,
11865 there are no faces yet, so this font's height is the line height. */
11866 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11868 return build_string (fontp
->full_name
);
11871 /* Give frame F the fontset named FONTSETNAME as its default font, and
11872 return the full name of that fontset. FONTSETNAME may be a wildcard
11873 pattern; in that case, we choose some fontset that fits the pattern.
11874 The return value shows which fontset we chose. */
11877 x_new_fontset (f
, fontsetname
)
11881 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11882 Lisp_Object result
;
11887 if (f
->output_data
.x
->fontset
== fontset
)
11888 /* This fontset is already set in frame F. There's nothing more
11890 return fontset_name (fontset
);
11892 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11894 if (!STRINGP (result
))
11895 /* Can't load ASCII font. */
11898 /* Since x_new_font doesn't update any fontset information, do it now. */
11899 f
->output_data
.x
->fontset
= fontset
;
11903 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11904 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11907 return build_string (fontsetname
);
11911 /***********************************************************************
11913 ***********************************************************************/
11919 /* XIM destroy callback function, which is called whenever the
11920 connection to input method XIM dies. CLIENT_DATA contains a
11921 pointer to the x_display_info structure corresponding to XIM. */
11924 xim_destroy_callback (xim
, client_data
, call_data
)
11926 XPointer client_data
;
11927 XPointer call_data
;
11929 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11930 Lisp_Object frame
, tail
;
11934 /* No need to call XDestroyIC.. */
11935 FOR_EACH_FRAME (tail
, frame
)
11937 struct frame
*f
= XFRAME (frame
);
11938 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11940 FRAME_XIC (f
) = NULL
;
11941 if (FRAME_XIC_FONTSET (f
))
11943 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11944 FRAME_XIC_FONTSET (f
) = NULL
;
11949 /* No need to call XCloseIM. */
11950 dpyinfo
->xim
= NULL
;
11951 XFree (dpyinfo
->xim_styles
);
11955 #endif /* HAVE_X11R6 */
11957 /* Open the connection to the XIM server on display DPYINFO.
11958 RESOURCE_NAME is the resource name Emacs uses. */
11961 xim_open_dpy (dpyinfo
, resource_name
)
11962 struct x_display_info
*dpyinfo
;
11963 char *resource_name
;
11968 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11969 dpyinfo
->xim
= xim
;
11974 XIMCallback destroy
;
11977 /* Get supported styles and XIM values. */
11978 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11981 destroy
.callback
= xim_destroy_callback
;
11982 destroy
.client_data
= (XPointer
)dpyinfo
;
11983 /* This isn't prptotyped in OSF 5.0. */
11984 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11988 #else /* not USE_XIM */
11989 dpyinfo
->xim
= NULL
;
11990 #endif /* not USE_XIM */
11994 #ifdef HAVE_X11R6_XIM
11998 struct x_display_info
*dpyinfo
;
11999 char *resource_name
;
12002 /* XIM instantiate callback function, which is called whenever an XIM
12003 server is available. DISPLAY is teh display of the XIM.
12004 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12005 when the callback was registered. */
12008 xim_instantiate_callback (display
, client_data
, call_data
)
12010 XPointer client_data
;
12011 XPointer call_data
;
12013 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12014 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12016 /* We don't support multiple XIM connections. */
12020 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12022 /* Create XIC for the existing frames on the same display, as long
12023 as they have no XIC. */
12024 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12026 Lisp_Object tail
, frame
;
12029 FOR_EACH_FRAME (tail
, frame
)
12031 struct frame
*f
= XFRAME (frame
);
12033 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12034 if (FRAME_XIC (f
) == NULL
)
12036 create_frame_xic (f
);
12037 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12038 xic_set_statusarea (f
);
12039 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12041 struct window
*w
= XWINDOW (f
->selected_window
);
12042 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12051 #endif /* HAVE_X11R6_XIM */
12054 /* Open a connection to the XIM server on display DPYINFO.
12055 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12056 connection only at the first time. On X11R6, open the connection
12057 in the XIM instantiate callback function. */
12060 xim_initialize (dpyinfo
, resource_name
)
12061 struct x_display_info
*dpyinfo
;
12062 char *resource_name
;
12065 #ifdef HAVE_X11R6_XIM
12066 struct xim_inst_t
*xim_inst
;
12069 dpyinfo
->xim
= NULL
;
12070 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12071 xim_inst
->dpyinfo
= dpyinfo
;
12072 len
= strlen (resource_name
);
12073 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12074 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12075 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12076 resource_name
, EMACS_CLASS
,
12077 xim_instantiate_callback
,
12078 /* Fixme: This is XPointer in
12079 XFree86 but (XPointer *) on
12080 Tru64, at least. */
12081 (XPointer
) xim_inst
);
12082 #else /* not HAVE_X11R6_XIM */
12083 dpyinfo
->xim
= NULL
;
12084 xim_open_dpy (dpyinfo
, resource_name
);
12085 #endif /* not HAVE_X11R6_XIM */
12087 #else /* not USE_XIM */
12088 dpyinfo
->xim
= NULL
;
12089 #endif /* not USE_XIM */
12093 /* Close the connection to the XIM server on display DPYINFO. */
12096 xim_close_dpy (dpyinfo
)
12097 struct x_display_info
*dpyinfo
;
12100 #ifdef HAVE_X11R6_XIM
12101 if (dpyinfo
->display
)
12102 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12104 xim_instantiate_callback
, NULL
);
12105 #endif /* not HAVE_X11R6_XIM */
12106 if (dpyinfo
->display
)
12107 XCloseIM (dpyinfo
->xim
);
12108 dpyinfo
->xim
= NULL
;
12109 XFree (dpyinfo
->xim_styles
);
12110 #endif /* USE_XIM */
12113 #endif /* not HAVE_X11R6_XIM */
12117 /* Calculate the absolute position in frame F
12118 from its current recorded position values and gravity. */
12121 x_calc_absolute_position (f
)
12125 int win_x
= 0, win_y
= 0;
12126 int flags
= f
->output_data
.x
->size_hint_flags
;
12129 /* We have nothing to do if the current position
12130 is already for the top-left corner. */
12131 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12134 #ifdef USE_X_TOOLKIT
12135 this_window
= XtWindow (f
->output_data
.x
->widget
);
12137 this_window
= FRAME_X_WINDOW (f
);
12140 /* Find the position of the outside upper-left corner of
12141 the inner window, with respect to the outer window.
12142 But do this only if we will need the results. */
12143 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12148 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12151 x_clear_errors (FRAME_X_DISPLAY (f
));
12152 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12154 /* From-window, to-window. */
12156 f
->output_data
.x
->parent_desc
,
12158 /* From-position, to-position. */
12159 0, 0, &win_x
, &win_y
,
12161 /* Child of win. */
12163 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12165 Window newroot
, newparent
= 0xdeadbeef;
12166 Window
*newchildren
;
12167 unsigned int nchildren
;
12169 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12170 &newparent
, &newchildren
, &nchildren
))
12173 XFree ((char *) newchildren
);
12175 f
->output_data
.x
->parent_desc
= newparent
;
12181 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12185 /* Treat negative positions as relative to the leftmost bottommost
12186 position that fits on the screen. */
12187 if (flags
& XNegative
)
12188 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12189 - 2 * f
->output_data
.x
->border_width
- win_x
12191 + f
->output_data
.x
->left_pos
);
12194 int height
= PIXEL_HEIGHT (f
);
12196 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12197 /* Something is fishy here. When using Motif, starting Emacs with
12198 `-g -0-0', the frame appears too low by a few pixels.
12200 This seems to be so because initially, while Emacs is starting,
12201 the column widget's height and the frame's pixel height are
12202 different. The column widget's height is the right one. In
12203 later invocations, when Emacs is up, the frame's pixel height
12206 It's not obvious where the initial small difference comes from.
12207 2000-12-01, gerd. */
12209 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12212 if (flags
& YNegative
)
12213 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12214 - 2 * f
->output_data
.x
->border_width
12217 + f
->output_data
.x
->top_pos
);
12220 /* The left_pos and top_pos
12221 are now relative to the top and left screen edges,
12222 so the flags should correspond. */
12223 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12226 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12227 to really change the position, and 0 when calling from
12228 x_make_frame_visible (in that case, XOFF and YOFF are the current
12229 position values). It is -1 when calling from x_set_frame_parameters,
12230 which means, do adjust for borders but don't change the gravity. */
12233 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12235 register int xoff
, yoff
;
12236 int change_gravity
;
12238 int modified_top
, modified_left
;
12240 if (change_gravity
> 0)
12242 f
->output_data
.x
->top_pos
= yoff
;
12243 f
->output_data
.x
->left_pos
= xoff
;
12244 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12246 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12248 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12249 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12251 x_calc_absolute_position (f
);
12254 x_wm_set_size_hint (f
, (long) 0, 0);
12256 modified_left
= f
->output_data
.x
->left_pos
;
12257 modified_top
= f
->output_data
.x
->top_pos
;
12258 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12259 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12260 /* It is a mystery why we need to add the border_width here
12261 when the frame is already visible, but experiment says we do. */
12262 if (change_gravity
!= 0)
12264 modified_left
+= f
->output_data
.x
->border_width
;
12265 modified_top
+= f
->output_data
.x
->border_width
;
12269 #ifdef USE_X_TOOLKIT
12270 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12271 modified_left
, modified_top
);
12272 #else /* not USE_X_TOOLKIT */
12273 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12274 modified_left
, modified_top
);
12275 #endif /* not USE_X_TOOLKIT */
12280 /* Change the size of frame F's X window to COLS/ROWS in the case F
12281 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12282 top-left-corner window gravity for this size change and subsequent
12283 size changes. Otherwise we leave the window gravity unchanged. */
12286 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12288 int change_gravity
;
12291 int pixelwidth
, pixelheight
;
12293 check_frame_size (f
, &rows
, &cols
);
12294 f
->output_data
.x
->vertical_scroll_bar_extra
12295 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12297 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12298 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12299 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12300 f
->output_data
.x
->flags_areas_extra
12301 = FRAME_FLAGS_AREA_WIDTH (f
);
12302 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12303 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12305 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12306 x_wm_set_size_hint (f
, (long) 0, 0);
12308 XSync (FRAME_X_DISPLAY (f
), False
);
12309 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12310 pixelwidth
, pixelheight
);
12312 /* Now, strictly speaking, we can't be sure that this is accurate,
12313 but the window manager will get around to dealing with the size
12314 change request eventually, and we'll hear how it went when the
12315 ConfigureNotify event gets here.
12317 We could just not bother storing any of this information here,
12318 and let the ConfigureNotify event set everything up, but that
12319 might be kind of confusing to the Lisp code, since size changes
12320 wouldn't be reported in the frame parameters until some random
12321 point in the future when the ConfigureNotify event arrives.
12323 We pass 1 for DELAY since we can't run Lisp code inside of
12325 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12326 PIXEL_WIDTH (f
) = pixelwidth
;
12327 PIXEL_HEIGHT (f
) = pixelheight
;
12329 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12330 receive in the ConfigureNotify event; if we get what we asked
12331 for, then the event won't cause the screen to become garbaged, so
12332 we have to make sure to do it here. */
12333 SET_FRAME_GARBAGED (f
);
12335 XFlush (FRAME_X_DISPLAY (f
));
12339 /* Call this to change the size of frame F's x-window.
12340 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12341 for this size change and subsequent size changes.
12342 Otherwise we leave the window gravity unchanged. */
12345 x_set_window_size (f
, change_gravity
, cols
, rows
)
12347 int change_gravity
;
12352 #ifdef USE_X_TOOLKIT
12354 if (f
->output_data
.x
->widget
!= NULL
)
12356 /* The x and y position of the widget is clobbered by the
12357 call to XtSetValues within EmacsFrameSetCharSize.
12358 This is a real kludge, but I don't understand Xt so I can't
12359 figure out a correct fix. Can anyone else tell me? -- rms. */
12360 int xpos
= f
->output_data
.x
->widget
->core
.x
;
12361 int ypos
= f
->output_data
.x
->widget
->core
.y
;
12362 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
12363 f
->output_data
.x
->widget
->core
.x
= xpos
;
12364 f
->output_data
.x
->widget
->core
.y
= ypos
;
12367 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12369 #else /* not USE_X_TOOLKIT */
12371 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12373 #endif /* not USE_X_TOOLKIT */
12375 /* If cursor was outside the new size, mark it as off. */
12376 mark_window_cursors_off (XWINDOW (f
->root_window
));
12378 /* Clear out any recollection of where the mouse highlighting was,
12379 since it might be in a place that's outside the new frame size.
12380 Actually checking whether it is outside is a pain in the neck,
12381 so don't try--just let the highlighting be done afresh with new size. */
12382 cancel_mouse_face (f
);
12387 /* Mouse warping. */
12390 x_set_mouse_position (f
, x
, y
)
12396 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
12397 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
12399 if (pix_x
< 0) pix_x
= 0;
12400 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
12402 if (pix_y
< 0) pix_y
= 0;
12403 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
12407 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12408 0, 0, 0, 0, pix_x
, pix_y
);
12412 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
12415 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
12421 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12422 0, 0, 0, 0, pix_x
, pix_y
);
12426 /* focus shifting, raising and lowering. */
12429 x_focus_on_frame (f
)
12432 #if 0 /* This proves to be unpleasant. */
12436 /* I don't think that the ICCCM allows programs to do things like this
12437 without the interaction of the window manager. Whatever you end up
12438 doing with this code, do it to x_unfocus_frame too. */
12439 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12440 RevertToPointerRoot
, CurrentTime
);
12445 x_unfocus_frame (f
)
12449 /* Look at the remarks in x_focus_on_frame. */
12450 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
12451 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
12452 RevertToPointerRoot
, CurrentTime
);
12456 /* Raise frame F. */
12462 if (f
->async_visible
)
12465 #ifdef USE_X_TOOLKIT
12466 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12467 #else /* not USE_X_TOOLKIT */
12468 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12469 #endif /* not USE_X_TOOLKIT */
12470 XFlush (FRAME_X_DISPLAY (f
));
12475 /* Lower frame F. */
12481 if (f
->async_visible
)
12484 #ifdef USE_X_TOOLKIT
12485 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12486 #else /* not USE_X_TOOLKIT */
12487 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12488 #endif /* not USE_X_TOOLKIT */
12489 XFlush (FRAME_X_DISPLAY (f
));
12495 XTframe_raise_lower (f
, raise_flag
)
12505 /* Change of visibility. */
12507 /* This tries to wait until the frame is really visible.
12508 However, if the window manager asks the user where to position
12509 the frame, this will return before the user finishes doing that.
12510 The frame will not actually be visible at that time,
12511 but it will become visible later when the window manager
12512 finishes with it. */
12515 x_make_frame_visible (f
)
12519 int original_top
, original_left
;
12520 int retry_count
= 2;
12526 type
= x_icon_type (f
);
12528 x_bitmap_icon (f
, type
);
12530 if (! FRAME_VISIBLE_P (f
))
12532 /* We test FRAME_GARBAGED_P here to make sure we don't
12533 call x_set_offset a second time
12534 if we get to x_make_frame_visible a second time
12535 before the window gets really visible. */
12536 if (! FRAME_ICONIFIED_P (f
)
12537 && ! f
->output_data
.x
->asked_for_visible
)
12538 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12540 f
->output_data
.x
->asked_for_visible
= 1;
12542 if (! EQ (Vx_no_window_manager
, Qt
))
12543 x_wm_set_window_state (f
, NormalState
);
12544 #ifdef USE_X_TOOLKIT
12545 /* This was XtPopup, but that did nothing for an iconified frame. */
12546 XtMapWidget (f
->output_data
.x
->widget
);
12547 #else /* not USE_X_TOOLKIT */
12548 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12549 #endif /* not USE_X_TOOLKIT */
12550 #if 0 /* This seems to bring back scroll bars in the wrong places
12551 if the window configuration has changed. They seem
12552 to come back ok without this. */
12553 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
12554 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12558 XFlush (FRAME_X_DISPLAY (f
));
12560 /* Synchronize to ensure Emacs knows the frame is visible
12561 before we do anything else. We do this loop with input not blocked
12562 so that incoming events are handled. */
12566 /* This must be before UNBLOCK_INPUT
12567 since events that arrive in response to the actions above
12568 will set it when they are handled. */
12569 int previously_visible
= f
->output_data
.x
->has_been_visible
;
12571 original_left
= f
->output_data
.x
->left_pos
;
12572 original_top
= f
->output_data
.x
->top_pos
;
12574 /* This must come after we set COUNT. */
12577 /* We unblock here so that arriving X events are processed. */
12579 /* Now move the window back to where it was "supposed to be".
12580 But don't do it if the gravity is negative.
12581 When the gravity is negative, this uses a position
12582 that is 3 pixels too low. Perhaps that's really the border width.
12584 Don't do this if the window has never been visible before,
12585 because the window manager may choose the position
12586 and we don't want to override it. */
12588 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
12589 && f
->output_data
.x
->win_gravity
== NorthWestGravity
12590 && previously_visible
)
12594 unsigned int width
, height
, border
, depth
;
12598 /* On some window managers (such as FVWM) moving an existing
12599 window, even to the same place, causes the window manager
12600 to introduce an offset. This can cause the window to move
12601 to an unexpected location. Check the geometry (a little
12602 slow here) and then verify that the window is in the right
12603 place. If the window is not in the right place, move it
12604 there, and take the potential window manager hit. */
12605 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12606 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
12608 if (original_left
!= x
|| original_top
!= y
)
12609 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12610 original_left
, original_top
);
12615 XSETFRAME (frame
, f
);
12617 /* Wait until the frame is visible. Process X events until a
12618 MapNotify event has been seen, or until we think we won't get a
12619 MapNotify at all.. */
12620 for (count
= input_signal_count
+ 10;
12621 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
12623 /* Force processing of queued events. */
12626 /* Machines that do polling rather than SIGIO have been
12627 observed to go into a busy-wait here. So we'll fake an
12628 alarm signal to let the handler know that there's something
12629 to be read. We used to raise a real alarm, but it seems
12630 that the handler isn't always enabled here. This is
12632 if (input_polling_used ())
12634 /* It could be confusing if a real alarm arrives while
12635 processing the fake one. Turn it off and let the
12636 handler reset it. */
12637 extern void poll_for_input_1
P_ ((void));
12638 int old_poll_suppress_count
= poll_suppress_count
;
12639 poll_suppress_count
= 1;
12640 poll_for_input_1 ();
12641 poll_suppress_count
= old_poll_suppress_count
;
12644 /* See if a MapNotify event has been processed. */
12645 FRAME_SAMPLE_VISIBILITY (f
);
12650 (let ((f (selected-frame)))
12654 the frame is not raised with various window managers on
12655 FreeBSD, Linux and Solaris. It turns out that, for some
12656 unknown reason, the call to XtMapWidget is completely ignored.
12657 Mapping the widget a second time works. */
12659 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
12664 /* Change from mapped state to withdrawn state. */
12666 /* Make the frame visible (mapped and not iconified). */
12669 x_make_frame_invisible (f
)
12674 #ifdef USE_X_TOOLKIT
12675 /* Use the frame's outermost window, not the one we normally draw on. */
12676 window
= XtWindow (f
->output_data
.x
->widget
);
12677 #else /* not USE_X_TOOLKIT */
12678 window
= FRAME_X_WINDOW (f
);
12679 #endif /* not USE_X_TOOLKIT */
12681 /* Don't keep the highlight on an invisible frame. */
12682 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12683 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12685 #if 0/* This might add unreliability; I don't trust it -- rms. */
12686 if (! f
->async_visible
&& ! f
->async_iconified
)
12692 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12693 that the current position of the window is user-specified, rather than
12694 program-specified, so that when the window is mapped again, it will be
12695 placed at the same location, without forcing the user to position it
12696 by hand again (they have already done that once for this window.) */
12697 x_wm_set_size_hint (f
, (long) 0, 1);
12701 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12702 DefaultScreen (FRAME_X_DISPLAY (f
))))
12704 UNBLOCK_INPUT_RESIGNAL
;
12705 error ("Can't notify window manager of window withdrawal");
12707 #else /* ! defined (HAVE_X11R4) */
12709 /* Tell the window manager what we're going to do. */
12710 if (! EQ (Vx_no_window_manager
, Qt
))
12714 unmap
.xunmap
.type
= UnmapNotify
;
12715 unmap
.xunmap
.window
= window
;
12716 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12717 unmap
.xunmap
.from_configure
= False
;
12718 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12719 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12721 SubstructureRedirectMaskSubstructureNotifyMask
,
12724 UNBLOCK_INPUT_RESIGNAL
;
12725 error ("Can't notify window manager of withdrawal");
12729 /* Unmap the window ourselves. Cheeky! */
12730 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12731 #endif /* ! defined (HAVE_X11R4) */
12733 /* We can't distinguish this from iconification
12734 just by the event that we get from the server.
12735 So we can't win using the usual strategy of letting
12736 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12737 and synchronize with the server to make sure we agree. */
12739 FRAME_ICONIFIED_P (f
) = 0;
12740 f
->async_visible
= 0;
12741 f
->async_iconified
= 0;
12748 /* Change window state from mapped to iconified. */
12751 x_iconify_frame (f
)
12757 /* Don't keep the highlight on an invisible frame. */
12758 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12759 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12761 if (f
->async_iconified
)
12766 FRAME_SAMPLE_VISIBILITY (f
);
12768 type
= x_icon_type (f
);
12770 x_bitmap_icon (f
, type
);
12772 #ifdef USE_X_TOOLKIT
12774 if (! FRAME_VISIBLE_P (f
))
12776 if (! EQ (Vx_no_window_manager
, Qt
))
12777 x_wm_set_window_state (f
, IconicState
);
12778 /* This was XtPopup, but that did nothing for an iconified frame. */
12779 XtMapWidget (f
->output_data
.x
->widget
);
12780 /* The server won't give us any event to indicate
12781 that an invisible frame was changed to an icon,
12782 so we have to record it here. */
12785 f
->async_iconified
= 1;
12786 f
->async_visible
= 0;
12791 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12792 XtWindow (f
->output_data
.x
->widget
),
12793 DefaultScreen (FRAME_X_DISPLAY (f
)));
12797 error ("Can't notify window manager of iconification");
12799 f
->async_iconified
= 1;
12800 f
->async_visible
= 0;
12804 XFlush (FRAME_X_DISPLAY (f
));
12806 #else /* not USE_X_TOOLKIT */
12808 /* Make sure the X server knows where the window should be positioned,
12809 in case the user deiconifies with the window manager. */
12810 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12811 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12813 /* Since we don't know which revision of X we're running, we'll use both
12814 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12816 /* X11R4: send a ClientMessage to the window manager using the
12817 WM_CHANGE_STATE type. */
12821 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12822 message
.xclient
.type
= ClientMessage
;
12823 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12824 message
.xclient
.format
= 32;
12825 message
.xclient
.data
.l
[0] = IconicState
;
12827 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12828 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12830 SubstructureRedirectMask
| SubstructureNotifyMask
,
12833 UNBLOCK_INPUT_RESIGNAL
;
12834 error ("Can't notify window manager of iconification");
12838 /* X11R3: set the initial_state field of the window manager hints to
12840 x_wm_set_window_state (f
, IconicState
);
12842 if (!FRAME_VISIBLE_P (f
))
12844 /* If the frame was withdrawn, before, we must map it. */
12845 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12848 f
->async_iconified
= 1;
12849 f
->async_visible
= 0;
12851 XFlush (FRAME_X_DISPLAY (f
));
12853 #endif /* not USE_X_TOOLKIT */
12857 /* Free X resources of frame F. */
12860 x_free_frame_resources (f
)
12863 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12867 /* If a display connection is dead, don't try sending more
12868 commands to the X server. */
12869 if (dpyinfo
->display
)
12871 if (f
->output_data
.x
->icon_desc
)
12872 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12876 free_frame_xic (f
);
12879 if (FRAME_X_WINDOW (f
))
12880 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12882 #ifdef USE_X_TOOLKIT
12883 if (f
->output_data
.x
->widget
)
12885 XtDestroyWidget (f
->output_data
.x
->widget
);
12886 f
->output_data
.x
->widget
= NULL
;
12888 free_frame_menubar (f
);
12889 #endif /* USE_X_TOOLKIT */
12891 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12892 unload_color (f
, f
->output_data
.x
->background_pixel
);
12893 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12894 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12895 unload_color (f
, f
->output_data
.x
->border_pixel
);
12896 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12898 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12899 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12900 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12901 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12902 if (f
->output_data
.x
->white_relief
.allocated_p
)
12903 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12904 if (f
->output_data
.x
->black_relief
.allocated_p
)
12905 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12907 if (FRAME_FACE_CACHE (f
))
12908 free_frame_faces (f
);
12911 XFlush (FRAME_X_DISPLAY (f
));
12914 if (f
->output_data
.x
->saved_menu_event
)
12915 xfree (f
->output_data
.x
->saved_menu_event
);
12917 xfree (f
->output_data
.x
);
12918 f
->output_data
.x
= NULL
;
12920 if (f
== dpyinfo
->x_focus_frame
)
12921 dpyinfo
->x_focus_frame
= 0;
12922 if (f
== dpyinfo
->x_focus_event_frame
)
12923 dpyinfo
->x_focus_event_frame
= 0;
12924 if (f
== dpyinfo
->x_highlight_frame
)
12925 dpyinfo
->x_highlight_frame
= 0;
12927 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12929 dpyinfo
->mouse_face_beg_row
12930 = dpyinfo
->mouse_face_beg_col
= -1;
12931 dpyinfo
->mouse_face_end_row
12932 = dpyinfo
->mouse_face_end_col
= -1;
12933 dpyinfo
->mouse_face_window
= Qnil
;
12934 dpyinfo
->mouse_face_deferred_gc
= 0;
12935 dpyinfo
->mouse_face_mouse_frame
= 0;
12942 /* Destroy the X window of frame F. */
12945 x_destroy_window (f
)
12948 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12950 /* If a display connection is dead, don't try sending more
12951 commands to the X server. */
12952 if (dpyinfo
->display
!= 0)
12953 x_free_frame_resources (f
);
12955 dpyinfo
->reference_count
--;
12959 /* Setting window manager hints. */
12961 /* Set the normal size hints for the window manager, for frame F.
12962 FLAGS is the flags word to use--or 0 meaning preserve the flags
12963 that the window now has.
12964 If USER_POSITION is nonzero, we set the USPosition
12965 flag (this is useful when FLAGS is 0). */
12968 x_wm_set_size_hint (f
, flags
, user_position
)
12973 XSizeHints size_hints
;
12975 #ifdef USE_X_TOOLKIT
12978 Dimension widget_width
, widget_height
;
12979 Window window
= XtWindow (f
->output_data
.x
->widget
);
12980 #else /* not USE_X_TOOLKIT */
12981 Window window
= FRAME_X_WINDOW (f
);
12982 #endif /* not USE_X_TOOLKIT */
12984 /* Setting PMaxSize caused various problems. */
12985 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12987 size_hints
.x
= f
->output_data
.x
->left_pos
;
12988 size_hints
.y
= f
->output_data
.x
->top_pos
;
12990 #ifdef USE_X_TOOLKIT
12991 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12992 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12993 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12994 size_hints
.height
= widget_height
;
12995 size_hints
.width
= widget_width
;
12996 #else /* not USE_X_TOOLKIT */
12997 size_hints
.height
= PIXEL_HEIGHT (f
);
12998 size_hints
.width
= PIXEL_WIDTH (f
);
12999 #endif /* not USE_X_TOOLKIT */
13001 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13002 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13003 size_hints
.max_width
13004 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13005 size_hints
.max_height
13006 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13008 /* Calculate the base and minimum sizes.
13010 (When we use the X toolkit, we don't do it here.
13011 Instead we copy the values that the widgets are using, below.) */
13012 #ifndef USE_X_TOOLKIT
13014 int base_width
, base_height
;
13015 int min_rows
= 0, min_cols
= 0;
13017 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13018 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13020 check_frame_size (f
, &min_rows
, &min_cols
);
13022 /* The window manager uses the base width hints to calculate the
13023 current number of rows and columns in the frame while
13024 resizing; min_width and min_height aren't useful for this
13025 purpose, since they might not give the dimensions for a
13026 zero-row, zero-column frame.
13028 We use the base_width and base_height members if we have
13029 them; otherwise, we set the min_width and min_height members
13030 to the size for a zero x zero frame. */
13033 size_hints
.flags
|= PBaseSize
;
13034 size_hints
.base_width
= base_width
;
13035 size_hints
.base_height
= base_height
;
13036 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13037 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13039 size_hints
.min_width
= base_width
;
13040 size_hints
.min_height
= base_height
;
13044 /* If we don't need the old flags, we don't need the old hint at all. */
13047 size_hints
.flags
|= flags
;
13050 #endif /* not USE_X_TOOLKIT */
13053 XSizeHints hints
; /* Sometimes I hate X Windows... */
13054 long supplied_return
;
13058 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13061 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13064 #ifdef USE_X_TOOLKIT
13065 size_hints
.base_height
= hints
.base_height
;
13066 size_hints
.base_width
= hints
.base_width
;
13067 size_hints
.min_height
= hints
.min_height
;
13068 size_hints
.min_width
= hints
.min_width
;
13072 size_hints
.flags
|= flags
;
13077 if (hints
.flags
& PSize
)
13078 size_hints
.flags
|= PSize
;
13079 if (hints
.flags
& PPosition
)
13080 size_hints
.flags
|= PPosition
;
13081 if (hints
.flags
& USPosition
)
13082 size_hints
.flags
|= USPosition
;
13083 if (hints
.flags
& USSize
)
13084 size_hints
.flags
|= USSize
;
13088 #ifndef USE_X_TOOLKIT
13093 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
13094 size_hints
.flags
|= PWinGravity
;
13098 size_hints
.flags
&= ~ PPosition
;
13099 size_hints
.flags
|= USPosition
;
13101 #endif /* PWinGravity */
13104 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13106 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13110 /* Used for IconicState or NormalState */
13113 x_wm_set_window_state (f
, state
)
13117 #ifdef USE_X_TOOLKIT
13120 XtSetArg (al
[0], XtNinitialState
, state
);
13121 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13122 #else /* not USE_X_TOOLKIT */
13123 Window window
= FRAME_X_WINDOW (f
);
13125 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
13126 f
->output_data
.x
->wm_hints
.initial_state
= state
;
13128 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13129 #endif /* not USE_X_TOOLKIT */
13133 x_wm_set_icon_pixmap (f
, pixmap_id
)
13137 Pixmap icon_pixmap
;
13139 #ifndef USE_X_TOOLKIT
13140 Window window
= FRAME_X_WINDOW (f
);
13145 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
13146 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
13150 /* It seems there is no way to turn off use of an icon pixmap.
13151 The following line does it, only if no icon has yet been created,
13152 for some window managers. But with mwm it crashes.
13153 Some people say it should clear the IconPixmapHint bit in this case,
13154 but that doesn't work, and the X consortium said it isn't the
13155 right thing at all. Since there is no way to win,
13156 best to explicitly give up. */
13158 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
13164 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
13168 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
13169 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13172 #else /* not USE_X_TOOLKIT */
13174 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
13175 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13177 #endif /* not USE_X_TOOLKIT */
13181 x_wm_set_icon_position (f
, icon_x
, icon_y
)
13183 int icon_x
, icon_y
;
13185 #ifdef USE_X_TOOLKIT
13186 Window window
= XtWindow (f
->output_data
.x
->widget
);
13188 Window window
= FRAME_X_WINDOW (f
);
13191 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
13192 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
13193 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
13195 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13199 /***********************************************************************
13201 ***********************************************************************/
13203 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
13206 x_get_font_info (f
, font_idx
)
13210 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
13214 /* Return a list of names of available fonts matching PATTERN on frame F.
13216 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13219 SIZE < 0 means include scalable fonts.
13221 Frame F null means we have not yet created any frame on X, and
13222 consult the first display in x_display_list. MAXNAMES sets a limit
13223 on how many fonts to match. */
13226 x_list_fonts (f
, pattern
, size
, maxnames
)
13228 Lisp_Object pattern
;
13232 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13233 Lisp_Object tem
, second_best
;
13234 struct x_display_info
*dpyinfo
13235 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13236 Display
*dpy
= dpyinfo
->display
;
13237 int try_XLoadQueryFont
= 0;
13239 int allow_scalable_fonts_p
= 0;
13243 allow_scalable_fonts_p
= 1;
13247 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13248 if (NILP (patterns
))
13249 patterns
= Fcons (pattern
, Qnil
);
13251 if (maxnames
== 1 && !size
)
13252 /* We can return any single font matching PATTERN. */
13253 try_XLoadQueryFont
= 1;
13255 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13258 char **names
= NULL
;
13260 pattern
= XCAR (patterns
);
13261 /* See if we cached the result for this particular query.
13262 The cache is an alist of the form:
13263 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13264 tem
= XCDR (dpyinfo
->name_list_element
);
13265 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13266 allow_scalable_fonts_p
? Qt
: Qnil
);
13267 list
= Fassoc (key
, tem
);
13270 list
= Fcdr_safe (list
);
13271 /* We have a cashed list. Don't have to get the list again. */
13275 /* At first, put PATTERN in the cache. */
13278 count
= x_catch_errors (dpy
);
13280 if (try_XLoadQueryFont
)
13283 unsigned long value
;
13285 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13286 if (x_had_errors_p (dpy
))
13288 /* This error is perhaps due to insufficient memory on X
13289 server. Let's just ignore it. */
13291 x_clear_errors (dpy
);
13295 && XGetFontProperty (font
, XA_FONT
, &value
))
13297 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13298 int len
= strlen (name
);
13301 /* If DXPC (a Differential X Protocol Compressor)
13302 Ver.3.7 is running, XGetAtomName will return null
13303 string. We must avoid such a name. */
13305 try_XLoadQueryFont
= 0;
13309 names
= (char **) alloca (sizeof (char *));
13310 /* Some systems only allow alloca assigned to a
13312 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13313 bcopy (name
, names
[0], len
+ 1);
13318 try_XLoadQueryFont
= 0;
13321 XFreeFont (dpy
, font
);
13324 if (!try_XLoadQueryFont
)
13326 /* We try at least 10 fonts because XListFonts will return
13327 auto-scaled fonts at the head. */
13328 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
13330 if (x_had_errors_p (dpy
))
13332 /* This error is perhaps due to insufficient memory on X
13333 server. Let's just ignore it. */
13335 x_clear_errors (dpy
);
13339 x_uncatch_errors (dpy
, count
);
13346 /* Make a list of all the fonts we got back.
13347 Store that in the font cache for the display. */
13348 for (i
= 0; i
< num_fonts
; i
++)
13351 char *p
= names
[i
];
13352 int average_width
= -1, dashes
= 0;
13354 /* Count the number of dashes in NAMES[I]. If there are
13355 14 dashes, and the field value following 12th dash
13356 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
13357 is usually too ugly to be used for editing. Let's
13363 if (dashes
== 7) /* PIXEL_SIZE field */
13365 else if (dashes
== 12) /* AVERAGE_WIDTH field */
13366 average_width
= atoi (p
);
13369 if (allow_scalable_fonts_p
13370 || dashes
< 14 || average_width
!= 0)
13372 tem
= build_string (names
[i
]);
13373 if (NILP (Fassoc (tem
, list
)))
13375 if (STRINGP (Vx_pixel_size_width_font_regexp
)
13376 && ((fast_c_string_match_ignore_case
13377 (Vx_pixel_size_width_font_regexp
, names
[i
]))
13379 /* We can set the value of PIXEL_SIZE to the
13380 width of this font. */
13381 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
13383 /* For the moment, width is not known. */
13384 list
= Fcons (Fcons (tem
, Qnil
), list
);
13388 if (!try_XLoadQueryFont
)
13389 XFreeFontNames (names
);
13392 /* Now store the result in the cache. */
13393 XCDR (dpyinfo
->name_list_element
)
13394 = Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
));
13397 if (NILP (list
)) continue; /* Try the remaining alternatives. */
13399 newlist
= second_best
= Qnil
;
13400 /* Make a list of the fonts that have the right width. */
13401 for (; CONSP (list
); list
= XCDR (list
))
13407 if (!CONSP (tem
) || NILP (XCAR (tem
)))
13411 newlist
= Fcons (XCAR (tem
), newlist
);
13415 if (!INTEGERP (XCDR (tem
)))
13417 /* Since we have not yet known the size of this font, we
13418 must try slow function call XLoadQueryFont. */
13419 XFontStruct
*thisinfo
;
13422 count
= x_catch_errors (dpy
);
13423 thisinfo
= XLoadQueryFont (dpy
,
13424 XSTRING (XCAR (tem
))->data
);
13425 if (x_had_errors_p (dpy
))
13427 /* This error is perhaps due to insufficient memory on X
13428 server. Let's just ignore it. */
13430 x_clear_errors (dpy
);
13432 x_uncatch_errors (dpy
, count
);
13438 = (thisinfo
->min_bounds
.width
== 0
13440 : make_number (thisinfo
->max_bounds
.width
));
13441 XFreeFont (dpy
, thisinfo
);
13444 /* For unknown reason, the previous call of XListFont had
13445 returned a font which can't be opened. Record the size
13446 as 0 not to try to open it again. */
13447 XCDR (tem
) = make_number (0);
13450 found_size
= XINT (XCDR (tem
));
13451 if (found_size
== size
)
13452 newlist
= Fcons (XCAR (tem
), newlist
);
13453 else if (found_size
> 0)
13455 if (NILP (second_best
))
13457 else if (found_size
< size
)
13459 if (XINT (XCDR (second_best
)) > size
13460 || XINT (XCDR (second_best
)) < found_size
)
13465 if (XINT (XCDR (second_best
)) > size
13466 && XINT (XCDR (second_best
)) > found_size
)
13471 if (!NILP (newlist
))
13473 else if (!NILP (second_best
))
13475 newlist
= Fcons (XCAR (second_best
), Qnil
);
13486 /* Check that FONT is valid on frame F. It is if it can be found in F's
13490 x_check_font (f
, font
)
13495 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13497 xassert (font
!= NULL
);
13499 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13500 if (dpyinfo
->font_table
[i
].name
13501 && font
== dpyinfo
->font_table
[i
].font
)
13504 xassert (i
< dpyinfo
->n_fonts
);
13507 #endif /* GLYPH_DEBUG != 0 */
13509 /* Set *W to the minimum width, *H to the minimum font height of FONT.
13510 Note: There are (broken) X fonts out there with invalid XFontStruct
13511 min_bounds contents. For example, handa@etl.go.jp reports that
13512 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
13513 have font->min_bounds.width == 0. */
13516 x_font_min_bounds (font
, w
, h
)
13520 *h
= FONT_HEIGHT (font
);
13521 *w
= font
->min_bounds
.width
;
13523 /* Try to handle the case where FONT->min_bounds has invalid
13524 contents. Since the only font known to have invalid min_bounds
13525 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
13527 *w
= font
->max_bounds
.width
;
13531 /* Compute the smallest character width and smallest font height over
13532 all fonts available on frame F. Set the members smallest_char_width
13533 and smallest_font_height in F's x_display_info structure to
13534 the values computed. Value is non-zero if smallest_font_height or
13535 smallest_char_width become smaller than they were before. */
13538 x_compute_min_glyph_bounds (f
)
13542 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13544 int old_width
= dpyinfo
->smallest_char_width
;
13545 int old_height
= dpyinfo
->smallest_font_height
;
13547 dpyinfo
->smallest_font_height
= 100000;
13548 dpyinfo
->smallest_char_width
= 100000;
13550 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13551 if (dpyinfo
->font_table
[i
].name
)
13553 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
13556 font
= (XFontStruct
*) fontp
->font
;
13557 xassert (font
!= (XFontStruct
*) ~0);
13558 x_font_min_bounds (font
, &w
, &h
);
13560 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
13561 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
13564 xassert (dpyinfo
->smallest_char_width
> 0
13565 && dpyinfo
->smallest_font_height
> 0);
13567 return (dpyinfo
->n_fonts
== 1
13568 || dpyinfo
->smallest_char_width
< old_width
13569 || dpyinfo
->smallest_font_height
< old_height
);
13573 /* Load font named FONTNAME of the size SIZE for frame F, and return a
13574 pointer to the structure font_info while allocating it dynamically.
13575 If SIZE is 0, load any size of font.
13576 If loading is failed, return NULL. */
13579 x_load_font (f
, fontname
, size
)
13581 register char *fontname
;
13584 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13585 Lisp_Object font_names
;
13588 /* Get a list of all the fonts that match this name. Once we
13589 have a list of matching fonts, we compare them against the fonts
13590 we already have by comparing names. */
13591 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
13593 if (!NILP (font_names
))
13598 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13599 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
13600 if (dpyinfo
->font_table
[i
].name
13601 && (!strcmp (dpyinfo
->font_table
[i
].name
,
13602 XSTRING (XCAR (tail
))->data
)
13603 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
13604 XSTRING (XCAR (tail
))->data
)))
13605 return (dpyinfo
->font_table
+ i
);
13608 /* Load the font and add it to the table. */
13612 struct font_info
*fontp
;
13613 unsigned long value
;
13616 /* If we have found fonts by x_list_font, load one of them. If
13617 not, we still try to load a font by the name given as FONTNAME
13618 because XListFonts (called in x_list_font) of some X server has
13619 a bug of not finding a font even if the font surely exists and
13620 is loadable by XLoadQueryFont. */
13621 if (size
> 0 && !NILP (font_names
))
13622 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
13625 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
13626 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
13627 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
13629 /* This error is perhaps due to insufficient memory on X
13630 server. Let's just ignore it. */
13632 x_clear_errors (FRAME_X_DISPLAY (f
));
13634 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
13639 /* Find a free slot in the font table. */
13640 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13641 if (dpyinfo
->font_table
[i
].name
== NULL
)
13644 /* If no free slot found, maybe enlarge the font table. */
13645 if (i
== dpyinfo
->n_fonts
13646 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
13649 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
13650 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
13651 dpyinfo
->font_table
13652 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
13655 fontp
= dpyinfo
->font_table
+ i
;
13656 if (i
== dpyinfo
->n_fonts
)
13657 ++dpyinfo
->n_fonts
;
13659 /* Now fill in the slots of *FONTP. */
13661 fontp
->font
= font
;
13662 fontp
->font_idx
= i
;
13663 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
13664 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
13666 /* Try to get the full name of FONT. Put it in FULL_NAME. */
13668 if (XGetFontProperty (font
, XA_FONT
, &value
))
13670 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
13674 /* Count the number of dashes in the "full name".
13675 If it is too few, this isn't really the font's full name,
13677 In X11R4, the fonts did not come with their canonical names
13688 full_name
= (char *) xmalloc (p
- name
+ 1);
13689 bcopy (name
, full_name
, p
- name
+ 1);
13695 if (full_name
!= 0)
13696 fontp
->full_name
= full_name
;
13698 fontp
->full_name
= fontp
->name
;
13700 fontp
->size
= font
->max_bounds
.width
;
13701 fontp
->height
= FONT_HEIGHT (font
);
13703 if (NILP (font_names
))
13705 /* We come here because of a bug of XListFonts mentioned at
13706 the head of this block. Let's store this information in
13707 the cache for x_list_fonts. */
13708 Lisp_Object lispy_name
= build_string (fontname
);
13709 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13710 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
13713 XCDR (dpyinfo
->name_list_element
)
13714 = Fcons (Fcons (key
,
13715 Fcons (Fcons (lispy_full_name
,
13716 make_number (fontp
->size
)),
13718 XCDR (dpyinfo
->name_list_element
));
13721 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
13723 XCDR (dpyinfo
->name_list_element
)
13724 = Fcons (Fcons (key
,
13725 Fcons (Fcons (lispy_full_name
,
13726 make_number (fontp
->size
)),
13728 XCDR (dpyinfo
->name_list_element
));
13732 /* The slot `encoding' specifies how to map a character
13733 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13734 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13735 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13736 2:0xA020..0xFF7F). For the moment, we don't know which charset
13737 uses this font. So, we set information in fontp->encoding[1]
13738 which is never used by any charset. If mapping can't be
13739 decided, set FONT_ENCODING_NOT_DECIDED. */
13741 = (font
->max_byte1
== 0
13743 ? (font
->min_char_or_byte2
< 0x80
13744 ? (font
->max_char_or_byte2
< 0x80
13745 ? 0 /* 0x20..0x7F */
13746 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13747 : 1) /* 0xA0..0xFF */
13749 : (font
->min_byte1
< 0x80
13750 ? (font
->max_byte1
< 0x80
13751 ? (font
->min_char_or_byte2
< 0x80
13752 ? (font
->max_char_or_byte2
< 0x80
13753 ? 0 /* 0x2020..0x7F7F */
13754 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13755 : 3) /* 0x20A0..0x7FFF */
13756 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13757 : (font
->min_char_or_byte2
< 0x80
13758 ? (font
->max_char_or_byte2
< 0x80
13759 ? 2 /* 0xA020..0xFF7F */
13760 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13761 : 1))); /* 0xA0A0..0xFFFF */
13763 fontp
->baseline_offset
13764 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13765 ? (long) value
: 0);
13766 fontp
->relative_compose
13767 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13768 ? (long) value
: 0);
13769 fontp
->default_ascent
13770 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13771 ? (long) value
: 0);
13773 /* Set global flag fonts_changed_p to non-zero if the font loaded
13774 has a character with a smaller width than any other character
13775 before, or if the font loaded has a smalle>r height than any
13776 other font loaded before. If this happens, it will make a
13777 glyph matrix reallocation necessary. */
13778 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13785 /* Return a pointer to struct font_info of a font named FONTNAME for
13786 frame F. If no such font is loaded, return NULL. */
13789 x_query_font (f
, fontname
)
13791 register char *fontname
;
13793 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13796 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13797 if (dpyinfo
->font_table
[i
].name
13798 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13799 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13800 return (dpyinfo
->font_table
+ i
);
13805 /* Find a CCL program for a font specified by FONTP, and set the member
13806 `encoder' of the structure. */
13809 x_find_ccl_program (fontp
)
13810 struct font_info
*fontp
;
13812 Lisp_Object list
, elt
;
13815 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13819 && STRINGP (XCAR (elt
))
13820 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13822 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
13829 struct ccl_program
*ccl
13830 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13832 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13835 fontp
->font_encoder
= ccl
;
13841 /***********************************************************************
13843 ***********************************************************************/
13845 #ifdef USE_X_TOOLKIT
13846 static XrmOptionDescRec emacs_options
[] = {
13847 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13848 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13850 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13851 XrmoptionSepArg
, NULL
},
13852 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13854 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13855 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13856 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13857 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13858 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13859 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13860 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13862 #endif /* USE_X_TOOLKIT */
13864 static int x_initialized
;
13866 #ifdef MULTI_KBOARD
13867 /* Test whether two display-name strings agree up to the dot that separates
13868 the screen number from the server number. */
13870 same_x_server (name1
, name2
)
13871 char *name1
, *name2
;
13873 int seen_colon
= 0;
13874 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13875 int system_name_length
= strlen (system_name
);
13876 int length_until_period
= 0;
13878 while (system_name
[length_until_period
] != 0
13879 && system_name
[length_until_period
] != '.')
13880 length_until_period
++;
13882 /* Treat `unix' like an empty host name. */
13883 if (! strncmp (name1
, "unix:", 5))
13885 if (! strncmp (name2
, "unix:", 5))
13887 /* Treat this host's name like an empty host name. */
13888 if (! strncmp (name1
, system_name
, system_name_length
)
13889 && name1
[system_name_length
] == ':')
13890 name1
+= system_name_length
;
13891 if (! strncmp (name2
, system_name
, system_name_length
)
13892 && name2
[system_name_length
] == ':')
13893 name2
+= system_name_length
;
13894 /* Treat this host's domainless name like an empty host name. */
13895 if (! strncmp (name1
, system_name
, length_until_period
)
13896 && name1
[length_until_period
] == ':')
13897 name1
+= length_until_period
;
13898 if (! strncmp (name2
, system_name
, length_until_period
)
13899 && name2
[length_until_period
] == ':')
13900 name2
+= length_until_period
;
13902 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13906 if (seen_colon
&& *name1
== '.')
13910 && (*name1
== '.' || *name1
== '\0')
13911 && (*name2
== '.' || *name2
== '\0'));
13915 struct x_display_info
*
13916 x_term_init (display_name
, xrm_option
, resource_name
)
13917 Lisp_Object display_name
;
13919 char *resource_name
;
13923 struct x_display_info
*dpyinfo
;
13928 if (!x_initialized
)
13934 #ifdef USE_X_TOOLKIT
13935 /* weiner@footloose.sps.mot.com reports that this causes
13937 X protocol error: BadAtom (invalid Atom parameter)
13938 on protocol request 18skiloaf.
13939 So let's not use it until R6. */
13940 #ifdef HAVE_X11XTR6
13941 XtSetLanguageProc (NULL
, NULL
, NULL
);
13952 argv
[argc
++] = "-xrm";
13953 argv
[argc
++] = xrm_option
;
13955 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13956 resource_name
, EMACS_CLASS
,
13957 emacs_options
, XtNumber (emacs_options
),
13960 #ifdef HAVE_X11XTR6
13961 /* I think this is to compensate for XtSetLanguageProc. */
13966 #else /* not USE_X_TOOLKIT */
13968 XSetLocaleModifiers ("");
13970 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13971 #endif /* not USE_X_TOOLKIT */
13973 /* Detect failure. */
13980 /* We have definitely succeeded. Record the new connection. */
13982 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13983 bzero (dpyinfo
, sizeof *dpyinfo
);
13985 #ifdef MULTI_KBOARD
13987 struct x_display_info
*share
;
13990 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13991 share
= share
->next
, tail
= XCDR (tail
))
13992 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13993 XSTRING (display_name
)->data
))
13996 dpyinfo
->kboard
= share
->kboard
;
13999 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
14000 init_kboard (dpyinfo
->kboard
);
14001 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
14003 char *vendor
= ServerVendor (dpy
);
14005 dpyinfo
->kboard
->Vsystem_key_alist
14006 = call1 (Qvendor_specific_keysyms
,
14007 build_string (vendor
? vendor
: ""));
14011 dpyinfo
->kboard
->next_kboard
= all_kboards
;
14012 all_kboards
= dpyinfo
->kboard
;
14013 /* Don't let the initial kboard remain current longer than necessary.
14014 That would cause problems if a file loaded on startup tries to
14015 prompt in the mini-buffer. */
14016 if (current_kboard
== initial_kboard
)
14017 current_kboard
= dpyinfo
->kboard
;
14019 dpyinfo
->kboard
->reference_count
++;
14023 /* Put this display on the chain. */
14024 dpyinfo
->next
= x_display_list
;
14025 x_display_list
= dpyinfo
;
14027 /* Put it on x_display_name_list as well, to keep them parallel. */
14028 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
14029 x_display_name_list
);
14030 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
14032 dpyinfo
->display
= dpy
;
14035 XSetAfterFunction (x_current_display
, x_trace_wire
);
14039 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
14040 + STRING_BYTES (XSTRING (Vsystem_name
))
14042 sprintf (dpyinfo
->x_id_name
, "%s@%s",
14043 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
14045 /* Figure out which modifier bits mean what. */
14046 x_find_modifier_meanings (dpyinfo
);
14048 /* Get the scroll bar cursor. */
14049 dpyinfo
->vertical_scroll_bar_cursor
14050 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
14052 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
14053 resource_name
, EMACS_CLASS
);
14054 #ifdef HAVE_XRMSETDATABASE
14055 XrmSetDatabase (dpyinfo
->display
, xrdb
);
14057 dpyinfo
->display
->db
= xrdb
;
14059 /* Put the rdb where we can find it in a way that works on
14061 dpyinfo
->xrdb
= xrdb
;
14063 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
14064 DefaultScreen (dpyinfo
->display
));
14065 select_visual (dpyinfo
);
14066 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
14067 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
14068 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
14069 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
14070 dpyinfo
->grabbed
= 0;
14071 dpyinfo
->reference_count
= 0;
14072 dpyinfo
->icon_bitmap_id
= -1;
14073 dpyinfo
->font_table
= NULL
;
14074 dpyinfo
->n_fonts
= 0;
14075 dpyinfo
->font_table_size
= 0;
14076 dpyinfo
->bitmaps
= 0;
14077 dpyinfo
->bitmaps_size
= 0;
14078 dpyinfo
->bitmaps_last
= 0;
14079 dpyinfo
->scratch_cursor_gc
= 0;
14080 dpyinfo
->mouse_face_mouse_frame
= 0;
14081 dpyinfo
->mouse_face_deferred_gc
= 0;
14082 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
14083 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
14084 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
14085 dpyinfo
->mouse_face_window
= Qnil
;
14086 dpyinfo
->mouse_face_overlay
= Qnil
;
14087 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
14088 dpyinfo
->mouse_face_defer
= 0;
14089 dpyinfo
->x_focus_frame
= 0;
14090 dpyinfo
->x_focus_event_frame
= 0;
14091 dpyinfo
->x_highlight_frame
= 0;
14092 dpyinfo
->image_cache
= make_image_cache ();
14094 /* See if a private colormap is requested. */
14095 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
14097 if (dpyinfo
->visual
->class == PseudoColor
)
14100 value
= display_x_get_resource (dpyinfo
,
14101 build_string ("privateColormap"),
14102 build_string ("PrivateColormap"),
14104 if (STRINGP (value
)
14105 && (!strcmp (XSTRING (value
)->data
, "true")
14106 || !strcmp (XSTRING (value
)->data
, "on")))
14107 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
14111 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
14112 dpyinfo
->visual
, AllocNone
);
14115 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
14116 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
14117 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
14118 dpyinfo
->resy
= pixels
* 25.4 / mm
;
14119 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
14120 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
14121 dpyinfo
->resx
= pixels
* 25.4 / mm
;
14124 dpyinfo
->Xatom_wm_protocols
14125 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
14126 dpyinfo
->Xatom_wm_take_focus
14127 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
14128 dpyinfo
->Xatom_wm_save_yourself
14129 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
14130 dpyinfo
->Xatom_wm_delete_window
14131 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
14132 dpyinfo
->Xatom_wm_change_state
14133 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
14134 dpyinfo
->Xatom_wm_configure_denied
14135 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
14136 dpyinfo
->Xatom_wm_window_moved
14137 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
14138 dpyinfo
->Xatom_editres
14139 = XInternAtom (dpyinfo
->display
, "Editres", False
);
14140 dpyinfo
->Xatom_CLIPBOARD
14141 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
14142 dpyinfo
->Xatom_TIMESTAMP
14143 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
14144 dpyinfo
->Xatom_TEXT
14145 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
14146 dpyinfo
->Xatom_COMPOUND_TEXT
14147 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
14148 dpyinfo
->Xatom_DELETE
14149 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
14150 dpyinfo
->Xatom_MULTIPLE
14151 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
14152 dpyinfo
->Xatom_INCR
14153 = XInternAtom (dpyinfo
->display
, "INCR", False
);
14154 dpyinfo
->Xatom_EMACS_TMP
14155 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
14156 dpyinfo
->Xatom_TARGETS
14157 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
14158 dpyinfo
->Xatom_NULL
14159 = XInternAtom (dpyinfo
->display
, "NULL", False
);
14160 dpyinfo
->Xatom_ATOM_PAIR
14161 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
14162 /* For properties of font. */
14163 dpyinfo
->Xatom_PIXEL_SIZE
14164 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
14165 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
14166 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
14167 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
14168 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
14169 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
14170 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
14172 /* Ghostscript support. */
14173 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
14174 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
14176 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
14179 dpyinfo
->cut_buffers_initialized
= 0;
14181 connection
= ConnectionNumber (dpyinfo
->display
);
14182 dpyinfo
->connection
= connection
;
14187 null_bits
[0] = 0x00;
14189 dpyinfo
->null_pixel
14190 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14191 null_bits
, 1, 1, (long) 0, (long) 0,
14196 extern int gray_bitmap_width
, gray_bitmap_height
;
14197 extern char *gray_bitmap_bits
;
14199 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14201 gray_bitmap_width
, gray_bitmap_height
,
14202 (unsigned long) 1, (unsigned long) 0, 1);
14206 xim_initialize (dpyinfo
, resource_name
);
14209 #ifdef subprocesses
14210 /* This is only needed for distinguishing keyboard and process input. */
14211 if (connection
!= 0)
14212 add_keyboard_wait_descriptor (connection
);
14215 #ifndef F_SETOWN_BUG
14217 #ifdef F_SETOWN_SOCK_NEG
14218 /* stdin is a socket here */
14219 fcntl (connection
, F_SETOWN
, -getpid ());
14220 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14221 fcntl (connection
, F_SETOWN
, getpid ());
14222 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14223 #endif /* ! defined (F_SETOWN) */
14224 #endif /* F_SETOWN_BUG */
14227 if (interrupt_input
)
14228 init_sigio (connection
);
14229 #endif /* ! defined (SIGIO) */
14232 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
14233 /* Make sure that we have a valid font for dialog boxes
14234 so that Xt does not crash. */
14236 Display
*dpy
= dpyinfo
->display
;
14237 XrmValue d
, fr
, to
;
14241 d
.addr
= (XPointer
)&dpy
;
14242 d
.size
= sizeof (Display
*);
14243 fr
.addr
= XtDefaultFont
;
14244 fr
.size
= sizeof (XtDefaultFont
);
14245 to
.size
= sizeof (Font
*);
14246 to
.addr
= (XPointer
)&font
;
14247 count
= x_catch_errors (dpy
);
14248 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
14250 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
14251 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
14252 x_uncatch_errors (dpy
, count
);
14257 /* See if we should run in synchronous mode. This is useful
14258 for debugging X code. */
14261 value
= display_x_get_resource (dpyinfo
,
14262 build_string ("synchronous"),
14263 build_string ("Synchronous"),
14265 if (STRINGP (value
)
14266 && (!strcmp (XSTRING (value
)->data
, "true")
14267 || !strcmp (XSTRING (value
)->data
, "on")))
14268 XSynchronize (dpyinfo
->display
, True
);
14276 /* Get rid of display DPYINFO, assuming all frames are already gone,
14277 and without sending any more commands to the X server. */
14280 x_delete_display (dpyinfo
)
14281 struct x_display_info
*dpyinfo
;
14283 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
14285 /* Discard this display from x_display_name_list and x_display_list.
14286 We can't use Fdelq because that can quit. */
14287 if (! NILP (x_display_name_list
)
14288 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
14289 x_display_name_list
= XCDR (x_display_name_list
);
14294 tail
= x_display_name_list
;
14295 while (CONSP (tail
) && CONSP (XCDR (tail
)))
14297 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
14299 XCDR (tail
) = XCDR (XCDR (tail
));
14302 tail
= XCDR (tail
);
14306 if (next_noop_dpyinfo
== dpyinfo
)
14307 next_noop_dpyinfo
= dpyinfo
->next
;
14309 if (x_display_list
== dpyinfo
)
14310 x_display_list
= dpyinfo
->next
;
14313 struct x_display_info
*tail
;
14315 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
14316 if (tail
->next
== dpyinfo
)
14317 tail
->next
= tail
->next
->next
;
14320 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
14321 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
14322 XrmDestroyDatabase (dpyinfo
->xrdb
);
14325 #ifdef MULTI_KBOARD
14326 if (--dpyinfo
->kboard
->reference_count
== 0)
14327 delete_kboard (dpyinfo
->kboard
);
14331 xim_close_dpy (dpyinfo
);
14334 xfree (dpyinfo
->font_table
);
14335 xfree (dpyinfo
->x_id_name
);
14336 xfree (dpyinfo
->color_cells
);
14341 /* Set up use of X before we make the first connection. */
14343 static struct redisplay_interface x_redisplay_interface
=
14348 x_clear_end_of_line
,
14350 x_after_update_window_line
,
14351 x_update_window_begin
,
14352 x_update_window_end
,
14355 x_clear_mouse_face
,
14356 x_get_glyph_overhangs
,
14357 x_fix_overlapping_area
14363 rif
= &x_redisplay_interface
;
14365 clear_frame_hook
= x_clear_frame
;
14366 ins_del_lines_hook
= x_ins_del_lines
;
14367 change_line_highlight_hook
= x_change_line_highlight
;
14368 delete_glyphs_hook
= x_delete_glyphs
;
14369 ring_bell_hook
= XTring_bell
;
14370 reset_terminal_modes_hook
= XTreset_terminal_modes
;
14371 set_terminal_modes_hook
= XTset_terminal_modes
;
14372 update_begin_hook
= x_update_begin
;
14373 update_end_hook
= x_update_end
;
14374 set_terminal_window_hook
= XTset_terminal_window
;
14375 read_socket_hook
= XTread_socket
;
14376 frame_up_to_date_hook
= XTframe_up_to_date
;
14377 reassert_line_highlight_hook
= XTreassert_line_highlight
;
14378 mouse_position_hook
= XTmouse_position
;
14379 frame_rehighlight_hook
= XTframe_rehighlight
;
14380 frame_raise_lower_hook
= XTframe_raise_lower
;
14381 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
14382 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
14383 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
14384 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
14385 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
14387 scroll_region_ok
= 1; /* we'll scroll partial frames */
14388 char_ins_del_ok
= 1;
14389 line_ins_del_ok
= 1; /* we'll just blt 'em */
14390 fast_clear_end_of_line
= 1; /* X does this well */
14391 memory_below_frame
= 0; /* we don't remember what scrolls
14396 last_tool_bar_item
= -1;
14397 any_help_event_p
= 0;
14399 /* Try to use interrupt input; if we can't, then start polling. */
14400 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
14402 #ifdef USE_X_TOOLKIT
14403 XtToolkitInitialize ();
14405 Xt_app_con
= XtCreateApplicationContext ();
14407 /* Register a converter from strings to pixels, which uses
14408 Emacs' color allocation infrastructure. */
14409 XtAppSetTypeConverter (Xt_app_con
,
14410 XtRString
, XtRPixel
, cvt_string_to_pixel
,
14411 cvt_string_to_pixel_args
,
14412 XtNumber (cvt_string_to_pixel_args
),
14413 XtCacheByDisplay
, cvt_pixel_dtor
);
14415 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
14417 /* Install an asynchronous timer that processes Xt timeout events
14418 every 0.1s. This is necessary because some widget sets use
14419 timeouts internally, for example the LessTif menu bar, or the
14420 Xaw3d scroll bar. When Xt timouts aren't processed, these
14421 widgets don't behave normally. */
14423 EMACS_TIME interval
;
14424 EMACS_SET_SECS_USECS (interval
, 0, 100000);
14425 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
14429 #ifdef USE_TOOLKIT_SCROLL_BARS
14430 xaw3d_arrow_scroll
= False
;
14431 xaw3d_pick_top
= True
;
14434 /* Note that there is no real way portable across R3/R4 to get the
14435 original error handler. */
14436 XSetErrorHandler (x_error_handler
);
14437 XSetIOErrorHandler (x_io_error_quitter
);
14439 /* Disable Window Change signals; they are handled by X events. */
14441 signal (SIGWINCH
, SIG_DFL
);
14442 #endif /* ! defined (SIGWINCH) */
14444 signal (SIGPIPE
, x_connection_signal
);
14451 staticpro (&x_error_message_string
);
14452 x_error_message_string
= Qnil
;
14454 staticpro (&x_display_name_list
);
14455 x_display_name_list
= Qnil
;
14457 staticpro (&last_mouse_scroll_bar
);
14458 last_mouse_scroll_bar
= Qnil
;
14460 staticpro (&Qvendor_specific_keysyms
);
14461 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
14463 staticpro (&last_mouse_press_frame
);
14464 last_mouse_press_frame
= Qnil
;
14467 staticpro (&help_echo
);
14468 help_echo_object
= Qnil
;
14469 staticpro (&help_echo_object
);
14470 help_echo_window
= Qnil
;
14471 staticpro (&help_echo_window
);
14472 previous_help_echo
= Qnil
;
14473 staticpro (&previous_help_echo
);
14474 help_echo_pos
= -1;
14476 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
14477 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
14478 For example, if a block cursor is over a tab, it will be drawn as\n\
14479 wide as that tab on the display.");
14480 x_stretch_cursor_p
= 0;
14482 DEFVAR_BOOL ("x-use-underline-position-properties",
14483 &x_use_underline_position_properties
,
14484 "*Non-nil means make use of UNDERLINE_POSITION font properties.\n\
14485 Nil means ignore them. If you encounter fonts with bogus\n\
14486 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior\n\
14487 to 4.1, set this to nil.");
14488 x_use_underline_position_properties
= 1;
14490 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
14491 "What X toolkit scroll bars Emacs uses.\n\
14492 A value of nil means Emacs doesn't use X toolkit scroll bars.\n\
14493 Otherwise, value is a symbol describing the X toolkit.");
14494 #ifdef USE_TOOLKIT_SCROLL_BARS
14496 Vx_toolkit_scroll_bars
= intern ("motif");
14497 #elif defined HAVE_XAW3D
14498 Vx_toolkit_scroll_bars
= intern ("xaw3d");
14500 Vx_toolkit_scroll_bars
= intern ("xaw");
14503 Vx_toolkit_scroll_bars
= Qnil
;
14506 staticpro (&last_mouse_motion_frame
);
14507 last_mouse_motion_frame
= Qnil
;
14510 #endif /* not HAVE_X_WINDOWS */