1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999
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. */
25 /* On 4.3 these lose if they come after xterm.h. */
26 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
27 /* Putting these at the beginning seems to be standard for other .c files. */
40 #include "blockinput.h"
42 /* Need syssignal.h for various externs and definitions that may be required
43 by some configurations for calls to signal later in this source file. */
44 #include "syssignal.h"
46 /* This may include sys/types.h, and that somehow loses
47 if this is not done before the other system files. */
49 #include <X11/cursorfont.h>
52 /* Load sys/types.h if not already loaded.
53 In some systems loading it twice is suicidal. */
55 #include <sys/types.h>
60 #include <sys/ioctl.h>
61 #endif /* ! defined (BSD_SYSTEM) */
66 #ifndef INCLUDED_FCNTL
73 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
74 /* #include <sys/param.h> */
80 #include "dispextern.h"
81 #include "termhooks.h"
93 #include "intervals.h"
97 #include <X11/Shell.h>
100 #include <sys/types.h>
101 #ifdef HAVE_SYS_TIME_H
102 #include <sys/time.h>
110 extern void free_frame_menubar ();
111 extern FRAME_PTR
x_menubar_window_to_frame ();
113 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
115 extern void _XEditResCheckMessages ();
116 #endif /* not NO_EDITRES */
118 /* Include toolkit specific headers for the scroll bar widget. */
120 #ifdef USE_TOOLKIT_SCROLL_BARS
121 #if defined USE_MOTIF
122 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
123 #include <Xm/ScrollBar.h>
124 #include <Xm/ScrollBarP.h>
125 #elif defined HAVE_XAW3D
126 #include <X11/Xaw3d/Simple.h>
127 #include <X11/Xaw3d/ThreeD.h>
128 #include <X11/Xaw3d/Scrollbar.h>
129 #define ARROW_SCROLLBAR
130 #include <X11/Xaw3d/ScrollbarP.h>
131 #endif /* HAVE_XAW3D */
132 #endif /* USE_TOOLKIT_SCROLL_BARS */
134 #endif /* USE_X_TOOLKIT */
136 #ifndef USE_X_TOOLKIT
137 #define x_any_window_to_frame x_window_to_frame
138 #define x_top_window_to_frame x_window_to_frame
143 #ifndef XtNinitialState
144 #define XtNinitialState "initialState"
148 #ifdef HAVE_SETLOCALE
149 /* So we can do setlocale. */
154 /* memmove will be defined as a macro in Xfuncs.h unless
155 <string.h> is included beforehand. The declaration for memmove in
156 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
161 #define min(a,b) ((a) < (b) ? (a) : (b))
164 #define max(a,b) ((a) > (b) ? (a) : (b))
167 #define abs(x) ((x) < 0 ? -(x) : (x))
169 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
172 /* Bitmaps for truncated lines. */
177 LEFT_TRUNCATION_BITMAP
,
178 RIGHT_TRUNCATION_BITMAP
,
179 OVERLAY_ARROW_BITMAP
,
180 CONTINUED_LINE_BITMAP
,
181 CONTINUATION_LINE_BITMAP
,
185 /* Bitmap drawn to indicate lines not displaying text if
186 `indicate-empty-lines' is non-nil. */
190 static unsigned char zv_bits
[] = {
191 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
193 /* An arrow like this: `<-'. */
196 #define left_height 8
197 static unsigned char left_bits
[] = {
198 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
200 /* Marker for continued lines. */
202 #define continued_width 8
203 #define continued_height 8
204 static unsigned char continued_bits
[] = {
205 0x30, 0x30, 0x30, 0x30, 0xb4, 0xfc, 0x78, 0x30};
207 #define continuation_width 8
208 #define continuation_height 8
209 static unsigned char continuation_bits
[] = {
210 0x0c, 0x1e, 0x3f, 0x2d, 0x0c, 0x0c, 0x0c, 0x0c};
212 /* Right truncation arrow bitmap `->'. */
214 #define right_width 8
215 #define right_height 8
216 static unsigned char right_bits
[] = {
217 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
219 /* Overlay arrow bitmap; a filled `<>'. */
224 static unsigned char ov_bits
[] = {
225 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
230 static unsigned char ov_bits
[] = {
231 0x18, 0x04, 0x08, 0x1c, 0x3e, 0x3a, 0x32, 0x1c};
235 static unsigned char ov_bits
[] = {
236 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x3c, 0x18};
239 extern Lisp_Object Qhelp_echo
;
242 /* Non-zero means Emacs uses toolkit scroll bars. */
244 int x_toolkit_scroll_bars_p
;
246 /* If a string, XTread_socket generates an event to display that string.
247 (The display is done in read_char.) */
249 static Lisp_Object help_echo
;
251 /* Temporary variable for XTread_socket. */
253 static Lisp_Object previous_help_echo
;
255 /* Non-zero means that a HELP_EVENT has been generated since Emacs
258 static int any_help_event_p
;
260 /* Non-zero means draw block and hollow cursor as wide as the glyph
261 under it. For example, if a block cursor is over a tab, it will be
262 drawn as wide as that tab on the display. */
264 int x_stretch_cursor_p
;
266 /* This is a chain of structures for all the X displays currently in
269 struct x_display_info
*x_display_list
;
271 /* This is a list of cons cells, each of the form (NAME
272 . FONT-LIST-CACHE), one for each element of x_display_list and in
273 the same order. NAME is the name of the frame. FONT-LIST-CACHE
274 records previous values returned by x-list-fonts. */
276 Lisp_Object x_display_name_list
;
278 /* Frame being updated by update_frame. This is declared in term.c.
279 This is set by update_begin and looked at by all the XT functions.
280 It is zero while not inside an update. In that case, the XT
281 functions assume that `selected_frame' is the frame to apply to. */
283 extern struct frame
*updating_frame
;
285 extern int waiting_for_input
;
287 /* This is a frame waiting to be auto-raised, within XTread_socket. */
289 struct frame
*pending_autoraise_frame
;
292 /* The application context for Xt use. */
293 XtAppContext Xt_app_con
;
294 static String Xt_default_resources
[] = {0};
295 #endif /* USE_X_TOOLKIT */
297 /* Nominal cursor position -- where to draw output.
298 HPOS and VPOS are window relative glyph matrix coordinates.
299 X and Y are window relative pixel coordinates. */
301 struct cursor_pos output_cursor
;
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 ();
386 extern Lisp_Object
x_icon_type ();
389 /* Enumeration for overriding/changing the face to use for drawing
390 glyphs in x_draw_glyphs. */
392 enum draw_glyphs_face
402 static void x_update_window_end
P_ ((struct window
*, int));
403 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
404 void x_delete_display
P_ ((struct x_display_info
*));
405 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
407 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
409 static void set_output_cursor
P_ ((struct cursor_pos
*));
410 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
411 int *, int *, int *));
412 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
413 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
414 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
415 static void note_toolbar_highlight
P_ ((struct frame
*f
, int, int));
416 static void x_handle_toolbar_click
P_ ((struct frame
*, XButtonEvent
*));
417 static void show_mouse_face
P_ ((struct x_display_info
*,
418 enum draw_glyphs_face
));
419 static int x_io_error_quitter
P_ ((Display
*));
420 int x_catch_errors
P_ ((Display
*));
421 void x_uncatch_errors
P_ ((Display
*, int));
422 void x_lower_frame
P_ ((struct frame
*));
423 void x_scroll_bar_clear
P_ ((struct frame
*));
424 int x_had_errors_p
P_ ((Display
*));
425 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
426 void x_raise_frame
P_ ((struct frame
*));
427 void x_set_window_size
P_ ((struct frame
*, int, int, int));
428 void x_wm_set_window_state
P_ ((struct frame
*, int));
429 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
430 void x_initialize
P_ ((void));
431 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
432 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
433 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
435 enum draw_glyphs_face
));
436 static void x_update_end
P_ ((struct frame
*));
437 static void XTframe_up_to_date
P_ ((struct frame
*));
438 static void XTreassert_line_highlight
P_ ((int, int));
439 static void x_change_line_highlight
P_ ((int, int, int, int));
440 static void XTset_terminal_modes
P_ ((void));
441 static void XTreset_terminal_modes
P_ ((void));
442 static void XTcursor_to
P_ ((int, int, int, int));
443 static void x_write_glyphs
P_ ((struct glyph
*, int));
444 static void x_clear_end_of_line
P_ ((int));
445 static void x_clear_frame
P_ ((void));
446 static void x_clear_cursor
P_ ((struct window
*));
447 static void frame_highlight
P_ ((struct frame
*));
448 static void frame_unhighlight
P_ ((struct frame
*));
449 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
450 static void XTframe_rehighlight
P_ ((struct frame
*));
451 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
452 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
453 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*));
454 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
456 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
457 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
458 static void expose_window
P_ ((struct window
*, XRectangle
*));
459 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
460 XRectangle
*, enum glyph_row_area
));
461 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
463 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
464 static void x_update_window_cursor
P_ ((struct window
*, int));
465 static void x_erase_phys_cursor
P_ ((struct window
*));
466 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
467 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
470 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
472 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
473 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
474 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
475 static void x_flush
P_ ((struct frame
*f
));
478 /* Flush display of frame F, or of all frames if F is null. */
487 Lisp_Object rest
, frame
;
488 FOR_EACH_FRAME (rest
, frame
)
489 x_flush (XFRAME (frame
));
491 else if (FRAME_X_P (f
))
492 XFlush (FRAME_X_DISPLAY (f
));
497 /* Remove calls to XFlush by defining XFlush to an empty replacement.
498 Calls to XFlush should be unnecessary because the X output buffer
499 is flushed automatically as needed by calls to XPending,
500 XNextEvent, or XWindowEvent according to the XFlush man page.
501 XTread_socket calls XPending. Removing XFlush improves
504 #define XFlush(DISPLAY) (void) 0
507 /***********************************************************************
509 ***********************************************************************/
513 /* This is a function useful for recording debugging information about
514 the sequence of occurrences in this file. */
522 struct record event_record
[100];
524 int event_record_index
;
526 record_event (locus
, type
)
530 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
531 event_record_index
= 0;
533 event_record
[event_record_index
].locus
= locus
;
534 event_record
[event_record_index
].type
= type
;
535 event_record_index
++;
542 /* Return the struct x_display_info corresponding to DPY. */
544 struct x_display_info
*
545 x_display_info_for_display (dpy
)
548 struct x_display_info
*dpyinfo
;
550 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
551 if (dpyinfo
->display
== dpy
)
559 /***********************************************************************
560 Starting and ending an update
561 ***********************************************************************/
563 /* Start an update of frame F. This function is installed as a hook
564 for update_begin, i.e. it is called when update_begin is called.
565 This function is called prior to calls to x_update_window_begin for
566 each window being updated. Currently, there is nothing to do here
567 because all interesting stuff is done on a window basis. */
577 /* Start update of window W. Set the global variable updated_window
578 to the window being updated and set output_cursor to the cursor
582 x_update_window_begin (w
)
585 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
586 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
589 set_output_cursor (&w
->cursor
);
593 if (f
== display_info
->mouse_face_mouse_frame
)
595 /* Don't do highlighting for mouse motion during the update. */
596 display_info
->mouse_face_defer
= 1;
598 /* If F needs to be redrawn, simply forget about any prior mouse
600 if (FRAME_GARBAGED_P (f
))
601 display_info
->mouse_face_window
= Qnil
;
603 /* Can we tell that this update does not affect the window
604 where the mouse highlight is? If so, no need to turn off.
605 Likewise, don't do anything if the frame is garbaged;
606 in that case, the frame's current matrix that we would use
607 is all wrong, and we will redisplay that line anyway. */
608 if (!NILP (display_info
->mouse_face_window
)
609 && w
== XWINDOW (display_info
->mouse_face_window
))
613 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
614 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
617 if (i
< w
->desired_matrix
->nrows
)
618 clear_mouse_face (display_info
);
626 /* Draw a vertical window border to the right of window W if W doesn't
627 have vertical scroll bars. */
630 x_draw_vertical_border (w
)
633 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
635 /* Redraw borders between horizontally adjacent windows. Don't
636 do it for frames with vertical scroll bars because either the
637 right scroll bar of a window, or the left scroll bar of its
638 neighbor will suffice as a border. */
639 if (!WINDOW_RIGHTMOST_P (w
)
640 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
644 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
645 x1
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
648 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
649 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
654 /* End update of window W (which is equal to updated_window). Draw
655 vertical borders between horizontally adjacent windows, and display
656 W's cursor if CURSOR_ON_P is non-zero. W may be a menu bar
657 pseudo-window in case we don't have X toolkit support. Such
658 windows don't have a cursor, so don't display it here. */
661 x_update_window_end (w
, cursor_on_p
)
665 if (!w
->pseudo_window_p
)
669 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
671 output_cursor
.x
, output_cursor
.y
);
672 x_draw_vertical_border (w
);
676 updated_window
= NULL
;
680 /* End update of frame F. This function is installed as a hook in
687 /* Mouse highlight may be displayed again. */
688 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
691 XFlush (FRAME_X_DISPLAY (f
));
696 /* This function is called from various places in xdisp.c whenever a
697 complete update has been performed. The global variable
698 updated_window is not available here. */
701 XTframe_up_to_date (f
)
706 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
707 if (dpyinfo
->mouse_face_deferred_gc
708 || f
== dpyinfo
->mouse_face_mouse_frame
)
711 if (dpyinfo
->mouse_face_mouse_frame
)
712 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
713 dpyinfo
->mouse_face_mouse_x
,
714 dpyinfo
->mouse_face_mouse_y
);
715 dpyinfo
->mouse_face_deferred_gc
= 0;
722 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
723 arrow bitmaps, or clear the areas where they would be displayed
724 before DESIRED_ROW is made current. The window being updated is
725 found in updated_window. This function It is called from
726 update_window_line only if it is known that there are differences
727 between bitmaps to be drawn between current row and DESIRED_ROW. */
730 x_after_update_window_line (desired_row
)
731 struct glyph_row
*desired_row
;
733 struct window
*w
= updated_window
;
737 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
740 x_draw_row_bitmaps (w
, desired_row
);
742 /* When a window has disappeared, make sure that no rest of
743 full-width rows stays visible in the internal border. */
744 if (windows_or_buffers_changed
)
746 struct frame
*f
= XFRAME (w
->frame
);
747 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
748 int height
= desired_row
->visible_height
;
749 int x
= window_box_right (w
, -1) + FRAME_X_FLAGS_AREA_WIDTH (f
);
750 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
752 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
753 x
, y
, width
, height
, False
);
761 /* Draw the bitmap WHICH in one of the areas to the left or right of
762 window W. ROW is the glyph row for which to display the bitmap; it
763 determines the vertical position at which the bitmap has to be
767 x_draw_bitmap (w
, row
, which
)
769 struct glyph_row
*row
;
770 enum bitmap_type which
;
772 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
773 Display
*display
= FRAME_X_DISPLAY (f
);
774 Window window
= FRAME_X_WINDOW (f
);
778 GC gc
= f
->output_data
.x
->normal_gc
;
780 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
782 /* Must clip because of partially visible lines. */
783 x_clip_to_row (w
, row
, gc
, 1);
787 case LEFT_TRUNCATION_BITMAP
:
791 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
793 - (FRAME_X_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
796 case OVERLAY_ARROW_BITMAP
:
800 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
802 - (FRAME_X_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
805 case RIGHT_TRUNCATION_BITMAP
:
809 x
= window_box_right (w
, -1);
810 x
+= (FRAME_X_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
813 case CONTINUED_LINE_BITMAP
:
816 bits
= continued_bits
;
817 x
= window_box_right (w
, -1);
818 x
+= (FRAME_X_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
821 case CONTINUATION_LINE_BITMAP
:
822 wd
= continuation_width
;
823 h
= continuation_height
;
824 bits
= continuation_bits
;
825 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
827 - (FRAME_X_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
834 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
836 - (FRAME_X_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
843 /* Convert to frame coordinates. Set dy to the offset in the row to
844 start drawing the bitmap. */
845 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
846 dy
= (row
->height
- h
) / 2;
848 /* Draw the bitmap. I believe these small pixmaps can be cached
850 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
851 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
853 face
->background
, depth
);
854 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
855 XFreePixmap (display
, pixmap
);
856 XSetClipMask (display
, gc
, None
);
860 /* Draw flags bitmaps for glyph row ROW on window W. Call this
861 function with input blocked. */
864 x_draw_row_bitmaps (w
, row
)
866 struct glyph_row
*row
;
868 struct frame
*f
= XFRAME (w
->frame
);
869 enum bitmap_type bitmap
;
871 int top_line_height
= -1;
873 xassert (interrupt_input_blocked
);
875 /* If row is completely invisible, because of vscrolling, we
876 don't have to draw anything. */
877 if (row
->visible_height
<= 0)
880 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
881 PREPARE_FACE_FOR_DISPLAY (f
, face
);
883 /* Decide which bitmap to draw at the left side. */
884 if (row
->overlay_arrow_p
)
885 bitmap
= OVERLAY_ARROW_BITMAP
;
886 else if (row
->truncated_on_left_p
)
887 bitmap
= LEFT_TRUNCATION_BITMAP
;
888 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
889 bitmap
= CONTINUATION_LINE_BITMAP
;
890 else if (row
->indicate_empty_line_p
)
891 bitmap
= ZV_LINE_BITMAP
;
895 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
897 if (bitmap
== NO_BITMAP
898 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_FLAGS_AREA_WIDTH (f
)
899 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
901 /* If W has a vertical border to its left, don't draw over it. */
902 int border
= ((XFASTINT (w
->left
) > 0
903 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
905 int left
= window_box_left (w
, -1);
907 if (top_line_height
< 0)
908 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
910 /* In case the same realized face is used for bitmap areas and
911 for something displayed in the text (e.g. face `region' on
912 mono-displays, the fill style may have been changed to
913 FillSolid in x_draw_glyph_string_background. */
915 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
917 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
919 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
922 - FRAME_X_FLAGS_AREA_WIDTH (f
)
924 WINDOW_TO_FRAME_PIXEL_Y (w
, max (top_line_height
,
926 FRAME_X_FLAGS_AREA_WIDTH (f
) - border
,
927 row
->visible_height
);
929 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
932 /* Draw the left bitmap. */
933 if (bitmap
!= NO_BITMAP
)
934 x_draw_bitmap (w
, row
, bitmap
);
936 /* Decide which bitmap to draw at the right side. */
937 if (row
->truncated_on_right_p
)
938 bitmap
= RIGHT_TRUNCATION_BITMAP
;
939 else if (row
->continued_p
)
940 bitmap
= CONTINUED_LINE_BITMAP
;
944 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
946 if (bitmap
== NO_BITMAP
947 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_FLAGS_AREA_WIDTH (f
)
948 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
950 int right
= window_box_right (w
, -1);
952 if (top_line_height
< 0)
953 top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
955 /* In case the same realized face is used for bitmap areas and
956 for something displayed in the text (e.g. face `region' on
957 mono-displays, the fill style may have been changed to
958 FillSolid in x_draw_glyph_string_background. */
960 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
962 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
963 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
966 WINDOW_TO_FRAME_PIXEL_Y (w
, max (top_line_height
,
968 FRAME_X_FLAGS_AREA_WIDTH (f
),
969 row
->visible_height
);
971 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
974 /* Draw the right bitmap. */
975 if (bitmap
!= NO_BITMAP
)
976 x_draw_bitmap (w
, row
, bitmap
);
980 /***********************************************************************
982 ***********************************************************************/
984 /* External interface to control of standout mode. Not used for X
985 frames. Aborts when called. */
988 XTreassert_line_highlight (new, vpos
)
995 /* Call this when about to modify line at position VPOS and change
996 whether it is highlighted. Not used for X frames. Aborts when
1000 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1001 int new_highlight
, vpos
, y
, first_unused_hpos
;
1007 /* This is called when starting Emacs and when restarting after
1008 suspend. When starting Emacs, no X window is mapped. And nothing
1009 must be done to Emacs's own window if it is suspended (though that
1013 XTset_terminal_modes ()
1017 /* This is called when exiting or suspending Emacs. Exiting will make
1018 the X-windows go away, and suspending requires no action. */
1021 XTreset_terminal_modes ()
1027 /***********************************************************************
1029 ***********************************************************************/
1031 /* Set the global variable output_cursor to CURSOR. All cursor
1032 positions are relative to updated_window. */
1035 set_output_cursor (cursor
)
1036 struct cursor_pos
*cursor
;
1038 output_cursor
.hpos
= cursor
->hpos
;
1039 output_cursor
.vpos
= cursor
->vpos
;
1040 output_cursor
.x
= cursor
->x
;
1041 output_cursor
.y
= cursor
->y
;
1045 /* Set a nominal cursor position.
1047 HPOS and VPOS are column/row positions in a window glyph matrix. X
1048 and Y are window text area relative pixel positions.
1050 If this is done during an update, updated_window will contain the
1051 window that is being updated and the position is the future output
1052 cursor position for that window. If updated_window is null, use
1053 selected_window and display the cursor at the given position. */
1056 XTcursor_to (vpos
, hpos
, y
, x
)
1057 int vpos
, hpos
, y
, x
;
1061 /* If updated_window is not set, work on selected_window. */
1065 w
= XWINDOW (selected_window
);
1067 /* Set the output cursor. */
1068 output_cursor
.hpos
= hpos
;
1069 output_cursor
.vpos
= vpos
;
1070 output_cursor
.x
= x
;
1071 output_cursor
.y
= y
;
1073 /* If not called as part of an update, really display the cursor.
1074 This will also set the cursor position of W. */
1075 if (updated_window
== NULL
)
1078 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1079 XFlush (FRAME_X_DISPLAY (selected_frame
));
1086 /***********************************************************************
1088 ***********************************************************************/
1090 /* Function prototypes of this page. */
1092 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1095 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1096 int, XChar2b
*, int));
1097 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1098 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1099 static void x_append_glyph
P_ ((struct it
*));
1100 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1102 static void x_produce_glyphs
P_ ((struct it
*));
1103 static void x_produce_special_glyphs
P_ ((struct it
*, enum display_element_type
));
1104 static void x_produce_image_glyph
P_ ((struct it
*it
));
1107 /* Return a pointer to per-char metric information in FONT of a
1108 character pointed by B which is a pointer to an XChar2b. */
1110 #define PER_CHAR_METRIC(font, b) \
1112 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1113 + (((font)->min_byte1 || (font)->max_byte1) \
1114 ? (((b)->byte1 - (font)->min_byte1) \
1115 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1117 : &((font)->max_bounds))
1120 /* Get metrics of character CHAR2B in FONT. Value is always non-null.
1121 If CHAR2B is not contained in FONT, the font's default character
1122 metric is returned. */
1124 static INLINE XCharStruct
*
1125 x_per_char_metric (font
, char2b
)
1129 /* The result metric information. */
1130 XCharStruct
*pcm
= NULL
;
1132 xassert (font
&& char2b
);
1134 if (font
->per_char
!= NULL
)
1136 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1138 /* min_char_or_byte2 specifies the linear character index
1139 corresponding to the first element of the per_char array,
1140 max_char_or_byte2 is the index of the last character. A
1141 character with non-zero CHAR2B->byte1 is not in the font.
1142 A character with byte2 less than min_char_or_byte2 or
1143 greater max_char_or_byte2 is not in the font. */
1144 if (char2b
->byte1
== 0
1145 && char2b
->byte2
>= font
->min_char_or_byte2
1146 && char2b
->byte2
<= font
->max_char_or_byte2
)
1147 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1151 /* If either min_byte1 or max_byte1 are nonzero, both
1152 min_char_or_byte2 and max_char_or_byte2 are less than
1153 256, and the 2-byte character index values corresponding
1154 to the per_char array element N (counting from 0) are:
1156 byte1 = N/D + min_byte1
1157 byte2 = N\D + min_char_or_byte2
1161 D = max_char_or_byte2 - min_char_or_byte2 + 1
1162 / = integer division
1163 \ = integer modulus */
1164 if (char2b
->byte1
>= font
->min_byte1
1165 && char2b
->byte1
<= font
->max_byte1
1166 && char2b
->byte2
>= font
->min_char_or_byte2
1167 && char2b
->byte2
<= font
->max_char_or_byte2
)
1169 pcm
= (font
->per_char
1170 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1171 * (char2b
->byte1
- font
->min_byte1
))
1172 + (char2b
->byte2
- font
->min_char_or_byte2
));
1178 /* If the per_char pointer is null, all glyphs between the first
1179 and last character indexes inclusive have the same
1180 information, as given by both min_bounds and max_bounds. */
1181 if (char2b
->byte2
>= font
->min_char_or_byte2
1182 && char2b
->byte2
<= font
->max_char_or_byte2
)
1183 pcm
= &font
->max_bounds
;
1187 if (pcm
== NULL
|| pcm
->width
== 0)
1189 /* Character not contained in the font. FONT->default_char
1190 gives the character that will be printed. FONT->default_char
1191 is a 16-bit character code with byte1 in the most significant
1192 byte and byte2 in the least significant byte. */
1193 XChar2b default_char
;
1194 default_char
.byte1
= (font
->default_char
>> BITS_PER_CHAR
) & 0xff;
1195 default_char
.byte2
= font
->default_char
& 0xff;
1197 /* Avoid an endless recursion if FONT->default_char itself
1198 hasn't per char metrics. handa@etl.go.jp reports that some
1199 fonts have this problem. */
1200 if (default_char
.byte1
!= char2b
->byte1
1201 || default_char
.byte2
!= char2b
->byte2
)
1202 pcm
= x_per_char_metric (font
, &default_char
);
1204 pcm
= &font
->max_bounds
;
1211 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1212 the two-byte form of C. Encoding is returned in *CHAR2B. */
1215 x_encode_char (c
, char2b
, font_info
)
1218 struct font_info
*font_info
;
1220 int charset
= CHAR_CHARSET (c
);
1221 XFontStruct
*font
= font_info
->font
;
1223 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1224 This may be either a program in a special encoder language or a
1226 if (font_info
->font_encoder
)
1228 /* It's a program. */
1229 struct ccl_program
*ccl
= font_info
->font_encoder
;
1231 if (CHARSET_DIMENSION (charset
) == 1)
1233 ccl
->reg
[0] = charset
;
1234 ccl
->reg
[1] = char2b
->byte2
;
1238 ccl
->reg
[0] = charset
;
1239 ccl
->reg
[1] = char2b
->byte1
;
1240 ccl
->reg
[2] = char2b
->byte2
;
1243 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1245 /* We assume that MSBs are appropriately set/reset by CCL
1247 if (font
->max_byte1
== 0) /* 1-byte font */
1248 char2b
->byte2
= ccl
->reg
[1];
1250 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1252 else if (font_info
->encoding
[charset
])
1254 /* Fixed encoding scheme. See fontset.h for the meaning of the
1255 encoding numbers. */
1256 int enc
= font_info
->encoding
[charset
];
1258 if ((enc
== 1 || enc
== 2)
1259 && CHARSET_DIMENSION (charset
) == 2)
1260 char2b
->byte1
|= 0x80;
1262 if (enc
== 1 || enc
== 3)
1263 char2b
->byte2
|= 0x80;
1268 /* Get face and two-byte form of character C in face FACE_ID on frame
1269 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1270 means we want to display multibyte text. Value is a pointer to a
1271 realized face that is ready for display. */
1273 static INLINE
struct face
*
1274 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1280 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1284 /* Unibyte case. We don't have to encode, but we have to make
1285 sure to use a face suitable for unibyte. */
1289 if (!FACE_SUITABLE_FOR_CHARSET_P (face
, -1))
1291 face_id
= FACE_FOR_CHARSET (f
, face_id
, -1);
1292 face
= FACE_FROM_ID (f
, face_id
);
1295 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1297 /* Case of ASCII in a face known to fit ASCII. */
1303 int c1
, c2
, charset
;
1305 /* Split characters into bytes. If c2 is -1 afterwards, C is
1306 really a one-byte character so that byte1 is zero. */
1307 SPLIT_CHAR (c
, charset
, c1
, c2
);
1309 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1311 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1313 /* Get the face for displaying C. If `face' is not suitable for
1314 charset, get the one that fits. (This can happen for the
1315 translations of composite characters where the glyph
1316 specifies a face for ASCII, but translations have a different
1318 if (!FACE_SUITABLE_FOR_CHARSET_P (face
, charset
))
1320 face_id
= FACE_FOR_CHARSET (f
, face_id
, charset
);
1321 face
= FACE_FROM_ID (f
, face_id
);
1324 /* Maybe encode the character in *CHAR2B. */
1325 if (charset
!= CHARSET_ASCII
)
1327 struct font_info
*font_info
1328 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1331 x_encode_char (c
, char2b
, font_info
);
1332 if (charset
== charset_latin_iso8859_1
)
1334 xassert (((XFontStruct
*) font_info
->font
)->max_char_or_byte2
1336 char2b
->byte2
|= 0x80;
1342 /* Make sure X resources of the face are allocated. */
1343 xassert (face
!= NULL
);
1344 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1350 /* Get face and two-byte form of character glyph GLYPH on frame F.
1351 The encoding of GLYPH->u.ch.code is returned in *CHAR2B. Value is
1352 a pointer to a realized face that is ready for display. */
1354 static INLINE
struct face
*
1355 x_get_glyph_face_and_encoding (f
, glyph
, char2b
)
1357 struct glyph
*glyph
;
1362 xassert (glyph
->type
== CHAR_GLYPH
);
1363 face
= FACE_FROM_ID (f
, glyph
->u
.ch
.face_id
);
1365 if (!glyph
->multibyte_p
)
1367 /* Unibyte case. We don't have to encode, but we have to make
1368 sure to use a face suitable for unibyte. */
1370 char2b
->byte2
= glyph
->u
.ch
.code
;
1372 else if (glyph
->u
.ch
.code
< 128
1373 && glyph
->u
.ch
.face_id
< BASIC_FACE_ID_SENTINEL
)
1375 /* Case of ASCII in a face known to fit ASCII. */
1377 char2b
->byte2
= glyph
->u
.ch
.code
;
1381 int c1
, c2
, charset
;
1383 /* Split characters into bytes. If c2 is -1 afterwards, C is
1384 really a one-byte character so that byte1 is zero. */
1385 SPLIT_CHAR (glyph
->u
.ch
.code
, charset
, c1
, c2
);
1387 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1389 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1391 /* Maybe encode the character in *CHAR2B. */
1392 if (charset
!= CHARSET_ASCII
)
1394 struct font_info
*font_info
1395 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1398 x_encode_char (glyph
->u
.ch
.code
, char2b
, font_info
);
1399 if (charset
== charset_latin_iso8859_1
)
1400 char2b
->byte2
|= 0x80;
1405 /* Make sure X resources of the face are allocated. */
1406 xassert (face
!= NULL
);
1407 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1412 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1413 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1419 struct glyph
*glyph
;
1420 enum glyph_row_area area
= it
->area
;
1422 xassert (it
->glyph_row
);
1423 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1425 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1426 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1428 /* Play it safe. If sub-structures of the glyph are not all the
1429 same size, it otherwise be that some bits stay set. This
1430 would prevent a comparison with GLYPH_EQUAL_P. */
1433 glyph
->type
= CHAR_GLYPH
;
1434 glyph
->pixel_width
= it
->pixel_width
;
1435 glyph
->u
.ch
.code
= it
->char_to_display
;
1436 glyph
->u
.ch
.face_id
= it
->face_id
;
1437 glyph
->charpos
= CHARPOS (it
->position
);
1438 glyph
->object
= it
->object
;
1439 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1440 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1441 glyph
->voffset
= it
->voffset
;
1442 glyph
->multibyte_p
= it
->multibyte_p
;
1443 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1444 || it
->phys_descent
> it
->descent
);
1445 ++it
->glyph_row
->used
[area
];
1450 /* Change IT->ascent and IT->height according to the setting of
1454 take_vertical_position_into_account (it
)
1459 if (it
->voffset
< 0)
1460 /* Increase the ascent so that we can display the text higher
1462 it
->ascent
+= abs (it
->voffset
);
1464 /* Increase the descent so that we can display the text lower
1466 it
->descent
+= it
->voffset
;
1471 /* Produce glyphs/get display metrics for the image IT is loaded with.
1472 See the description of struct display_iterator in dispextern.h for
1473 an overview of struct display_iterator. */
1476 x_produce_image_glyph (it
)
1482 xassert (it
->what
== IT_IMAGE
);
1484 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1485 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1488 /* Make sure X resources of the face and image are loaded. */
1489 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1490 prepare_image_for_display (it
->f
, img
);
1492 it
->ascent
= it
->phys_ascent
= IMAGE_ASCENT (img
);
1493 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->margin
- it
->ascent
;
1494 it
->pixel_width
= img
->width
+ 2 * img
->margin
;
1498 if (face
->box
!= FACE_NO_BOX
)
1500 it
->ascent
+= face
->box_line_width
;
1501 it
->descent
+= face
->box_line_width
;
1503 if (it
->start_of_box_run_p
)
1504 it
->pixel_width
+= face
->box_line_width
;
1505 if (it
->end_of_box_run_p
)
1506 it
->pixel_width
+= face
->box_line_width
;
1509 take_vertical_position_into_account (it
);
1513 struct glyph
*glyph
;
1514 enum glyph_row_area area
= it
->area
;
1516 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1517 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1519 glyph
->type
= IMAGE_GLYPH
;
1520 glyph
->u
.img
.id
= img
->id
;
1521 glyph
->u
.img
.face_id
= it
->face_id
;
1522 glyph
->pixel_width
= it
->pixel_width
;
1523 glyph
->charpos
= CHARPOS (it
->position
);
1524 glyph
->object
= it
->object
;
1525 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1526 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1527 glyph
->voffset
= it
->voffset
;
1528 glyph
->multibyte_p
= it
->multibyte_p
;
1529 ++it
->glyph_row
->used
[area
];
1535 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1536 of the glyph, WIDTH and HEIGHT are the width and height of the
1537 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1538 ascent of the glyph (0 <= ASCENT <= 1). */
1541 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1547 struct glyph
*glyph
;
1548 enum glyph_row_area area
= it
->area
;
1550 xassert (ascent
>= 0 && ascent
<= 1);
1552 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1553 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1555 glyph
->type
= STRETCH_GLYPH
;
1556 glyph
->u
.stretch
.ascent
= height
* ascent
;
1557 glyph
->u
.stretch
.height
= height
;
1558 glyph
->u
.stretch
.face_id
= it
->face_id
;
1559 glyph
->pixel_width
= width
;
1560 glyph
->charpos
= CHARPOS (it
->position
);
1561 glyph
->object
= object
;
1562 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1563 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1564 glyph
->voffset
= it
->voffset
;
1565 glyph
->multibyte_p
= it
->multibyte_p
;
1566 ++it
->glyph_row
->used
[area
];
1571 /* Produce a stretch glyph for iterator IT. IT->object is the value
1572 of the glyph property displayed. The value must be a list
1573 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1576 1. `:width WIDTH' specifies that the space should be WIDTH *
1577 canonical char width wide. WIDTH may be an integer or floating
1580 2. `:relative-width FACTOR' specifies that the width of the stretch
1581 should be computed from the width of the first character having the
1582 `glyph' property, and should be FACTOR times that width.
1584 3. `:align-to HPOS' specifies that the space should be wide enough
1585 to reach HPOS, a value in canonical character units.
1587 Exactly one of the above pairs must be present.
1589 4. `:height HEIGHT' specifies that the height of the stretch produced
1590 should be HEIGHT, measured in canonical character units.
1592 5. `:relative-height FACTOR' specifies that the height of the the
1593 stretch should be FACTOR times the height of the characters having
1596 Either none or exactly one of 4 or 5 must be present.
1598 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1599 of the stretch should be used for the ascent of the stretch.
1600 ASCENT must be in the range 0 <= ASCENT <= 100. */
1603 ((INTEGERP (X) || FLOATP (X)) \
1609 x_produce_stretch_glyph (it
)
1612 /* (space :width WIDTH :height HEIGHT. */
1613 extern Lisp_Object QCwidth
, QCheight
, QCascent
, Qspace
;
1614 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1615 extern Lisp_Object QCalign_to
;
1616 Lisp_Object prop
, plist
;
1617 double width
= 0, height
= 0, ascent
= 0;
1618 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1619 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1621 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1623 /* List should start with `space'. */
1624 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1625 plist
= XCDR (it
->object
);
1627 /* Compute the width of the stretch. */
1628 if (prop
= Fplist_get (plist
, QCwidth
),
1630 /* Absolute width `:width WIDTH' specified and valid. */
1631 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1632 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1635 /* Relative width `:relative-width FACTOR' specified and valid.
1636 Compute the width of the characters having the `glyph'
1639 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1642 if (it
->multibyte_p
)
1644 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1645 - IT_BYTEPOS (*it
));
1646 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1649 it2
.c
= *p
, it2
.len
= 1;
1651 it2
.glyph_row
= NULL
;
1652 it2
.what
= IT_CHARACTER
;
1653 x_produce_glyphs (&it2
);
1654 width
= NUMVAL (prop
) * it2
.pixel_width
;
1656 else if (prop
= Fplist_get (plist
, QCalign_to
),
1658 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1660 /* Nothing specified -> width defaults to canonical char width. */
1661 width
= CANON_X_UNIT (it
->f
);
1663 /* Compute height. */
1664 if (prop
= Fplist_get (plist
, QCheight
),
1666 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1667 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1669 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1671 height
= FONT_HEIGHT (font
);
1673 /* Compute percentage of height used for ascent. If
1674 `:ascent ASCENT' is present and valid, use that. Otherwise,
1675 derive the ascent from the font in use. */
1676 if (prop
= Fplist_get (plist
, QCascent
),
1677 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1678 ascent
= NUMVAL (prop
) / 100.0;
1680 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1689 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1690 if (!STRINGP (object
))
1691 object
= it
->w
->buffer
;
1692 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1695 it
->pixel_width
= width
;
1696 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1697 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1700 if (face
->box
!= FACE_NO_BOX
)
1702 it
->ascent
+= face
->box_line_width
;
1703 it
->descent
+= face
->box_line_width
;
1705 if (it
->start_of_box_run_p
)
1706 it
->pixel_width
+= face
->box_line_width
;
1707 if (it
->end_of_box_run_p
)
1708 it
->pixel_width
+= face
->box_line_width
;
1711 take_vertical_position_into_account (it
);
1715 /* Produce glyphs/get display metrics for the display element IT is
1716 loaded with. See the description of struct display_iterator in
1717 dispextern.h for an overview of struct display_iterator. */
1720 x_produce_glyphs (it
)
1723 if (it
->what
== IT_CHARACTER
)
1730 int font_not_found_p
;
1733 /* Maybe translate single-byte characters to multibyte. */
1734 it
->char_to_display
= it
->c
;
1735 if (unibyte_display_via_language_environment
1736 && SINGLE_BYTE_CHAR_P (it
->c
)
1739 && !NILP (Vnonascii_translation_table
))))
1741 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1742 it
->charset
= CHAR_CHARSET (it
->char_to_display
);
1745 /* Get face and font to use. Encode IT->char_to_display. */
1746 face
= x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1747 it
->face_id
, &char2b
,
1751 /* When no suitable font found, use the default font. */
1752 font_not_found_p
= font
== NULL
;
1753 if (font_not_found_p
)
1754 font
= FRAME_FONT (it
->f
);
1756 if (it
->char_to_display
>= ' '
1757 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1759 /* Either unibyte or ASCII. */
1764 pcm
= x_per_char_metric (font
, &char2b
);
1765 it
->ascent
= font
->ascent
;
1766 it
->descent
= font
->descent
;
1767 it
->phys_ascent
= pcm
->ascent
;
1768 it
->phys_descent
= pcm
->descent
;
1769 it
->pixel_width
= pcm
->width
;
1771 /* If this is a space inside a region of text with
1772 `space-width' property, change its width. */
1773 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1775 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1777 /* If face has a box, add the box thickness to the character
1778 height. If character has a box line to the left and/or
1779 right, add the box line width to the character's width. */
1780 if (face
->box
!= FACE_NO_BOX
)
1782 int thick
= face
->box_line_width
;
1784 it
->ascent
+= thick
;
1785 it
->descent
+= thick
;
1787 if (it
->start_of_box_run_p
)
1788 it
->pixel_width
+= thick
;
1789 if (it
->end_of_box_run_p
)
1790 it
->pixel_width
+= thick
;
1793 /* If face has an overline, add the height of the overline
1794 (1 pixel) and a 1 pixel margin to the character height. */
1795 if (face
->overline_p
)
1798 take_vertical_position_into_account (it
);
1800 /* If we have to actually produce glyphs, do it. */
1805 /* Translate a space with a `space-width' property
1806 into a stretch glyph. */
1807 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1808 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1809 it
->ascent
+ it
->descent
, ascent
);
1812 x_append_glyph (it
);
1814 /* If characters with lbearing or rbearing are displayed
1815 in this line, record that fact in a flag of the
1816 glyph row. This is used to optimize X output code. */
1817 if (pcm
->lbearing
< 0
1818 || pcm
->rbearing
> pcm
->width
)
1819 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1822 else if (it
->char_to_display
== '\n')
1824 /* A newline has no width but we need the height of the line. */
1825 it
->pixel_width
= 0;
1827 it
->ascent
= it
->phys_ascent
= font
->ascent
;
1828 it
->descent
= it
->phys_descent
= font
->descent
;
1830 if (face
->box
!= FACE_NO_BOX
)
1832 int thick
= face
->box_line_width
;
1833 it
->ascent
+= thick
;
1834 it
->descent
+= thick
;
1837 else if (it
->char_to_display
== '\t')
1839 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1840 int x
= (it
->current_x
1842 + it
->continuation_lines_width
);
1843 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1845 it
->pixel_width
= next_tab_x
- x
;
1847 it
->ascent
= it
->phys_ascent
= font
->ascent
;
1848 it
->descent
= it
->phys_descent
= font
->descent
;
1852 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1853 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1854 it
->ascent
+ it
->descent
, ascent
);
1859 /* A multi-byte character. Assume that the display width of the
1860 character is the width of the character multiplied by the
1861 width of the font. There has to be better support for
1862 variable sizes in cmpchar_info to do anything better than
1865 Note: composite characters are represented as one glyph in
1866 the glyph matrix. There are no padding glyphs. */
1867 if (it
->charset
== CHARSET_COMPOSITION
)
1869 struct cmpchar_info
*cmpcharp
;
1872 idx
= COMPOSITE_CHAR_ID (it
->char_to_display
);
1873 cmpcharp
= cmpchar_table
[idx
];
1874 it
->pixel_width
= font
->max_bounds
.width
* cmpcharp
->width
;
1876 /* There are no padding glyphs, so there is only one glyph
1877 to produce for the composite char. Important is that
1878 pixel_width, ascent and descent are the values of what is
1879 drawn by draw_glyphs. */
1882 /* These settings may not be correct. We must have more
1883 information in cmpcharp to do the correct setting. */
1884 it
->ascent
= font
->ascent
;
1885 it
->descent
= font
->descent
;
1886 it
->phys_ascent
= font
->max_bounds
.ascent
;
1887 it
->phys_descent
= font
->max_bounds
.descent
;
1891 /* If we found a font, this font should give us the right
1892 metrics. If we didn't find a font, use the frame's
1893 default font and calculate the width of the character
1894 from the charset width; this is what old redisplay code
1896 pcm
= x_per_char_metric (font
, &char2b
);
1897 it
->pixel_width
= pcm
->width
;
1898 if (font_not_found_p
)
1899 it
->pixel_width
*= CHARSET_WIDTH (it
->charset
);
1901 it
->ascent
= font
->ascent
;
1902 it
->descent
= font
->descent
;
1903 it
->phys_ascent
= pcm
->ascent
;
1904 it
->phys_descent
= pcm
->descent
;
1906 && (pcm
->lbearing
< 0
1907 || pcm
->rbearing
> pcm
->width
))
1908 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1911 if (face
->box
!= FACE_NO_BOX
)
1913 int thick
= face
->box_line_width
;
1914 it
->ascent
+= thick
;
1915 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
);
1931 x_append_glyph (it
);
1934 else if (it
->what
== IT_IMAGE
)
1935 x_produce_image_glyph (it
);
1936 else if (it
->what
== IT_STRETCH
)
1937 x_produce_stretch_glyph (it
);
1939 /* Accumulate dimensions. */
1940 xassert (it
->ascent
>= 0 && it
->descent
> 0);
1941 if (it
->area
== TEXT_AREA
)
1942 it
->current_x
+= it
->pixel_width
;
1944 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
1945 it
->max_descent
= max (it
->max_descent
, it
->descent
);
1946 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
1947 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
1951 /* Estimate the pixel height of the mode or top line on frame F.
1952 FACE_ID specifies what line's height to estimate. */
1955 x_estimate_mode_line_height (f
, face_id
)
1957 enum face_id face_id
;
1961 /* This function is called so early when Emacs starts that the face
1962 cache and mode line face are not yet initialized. */
1963 if (FRAME_FACE_CACHE (f
))
1965 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1967 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
1974 /***********************************************************************
1976 ***********************************************************************/
1978 /* A sequence of glyphs to be drawn in the same face.
1980 This data structure is not really completely X specific, so it
1981 could possibly, at least partially, be useful for other systems. It
1982 is currently not part of the external redisplay interface because
1983 it's not clear what other systems will need. */
1987 /* X-origin of the string. */
1990 /* Y-origin and y-position of the base line of this string. */
1993 /* The width of the string, not including a face extension. */
1996 /* The width of the string, including a face extension. */
1997 int background_width
;
1999 /* The height of this string. This is the height of the line this
2000 string is drawn in, and can be different from the height of the
2001 font the string is drawn in. */
2004 /* Number of pixels this string overwrites in front of its x-origin.
2005 This number is zero if the string has an lbearing >= 0; it is
2006 -lbearing, if the string has an lbearing < 0. */
2009 /* Number of pixels this string overwrites past its right-most
2010 nominal x-position, i.e. x + width. Zero if the string's
2011 rbearing is <= its nominal width, rbearing - width otherwise. */
2014 /* The frame on which the glyph string is drawn. */
2017 /* The window on which the glyph string is drawn. */
2020 /* X display and window for convenience. */
2024 /* The glyph row for which this string was built. It determines the
2025 y-origin and height of the string. */
2026 struct glyph_row
*row
;
2028 /* The area within row. */
2029 enum glyph_row_area area
;
2031 /* Characters to be drawn, and number of characters. */
2035 /* Character set of this glyph string. */
2038 /* A face-override for drawing cursors, mouse face and similar. */
2039 enum draw_glyphs_face hl
;
2041 /* Face in which this string is to be drawn. */
2044 /* Font in which this string is to be drawn. */
2047 /* Font info for this string. */
2048 struct font_info
*font_info
;
2050 /* Non-null means this string describes (part of) a composite
2051 character. All characters from char2b are drawn at the same
2052 x-origin in that case. */
2053 struct cmpchar_info
*cmpcharp
;
2055 /* Index of this glyph string's first character in the glyph
2056 definition of cmpcharp. If this is zero, this glyph string
2057 describes the first character of a composite character. */
2060 /* 1 means this glyph strings face has to be drawn to the right end
2061 of the window's drawing area. */
2062 unsigned extends_to_end_of_line_p
: 1;
2064 /* 1 means the background of this string has been drawn. */
2065 unsigned background_filled_p
: 1;
2067 /* 1 means glyph string must be drawn with 16-bit functions. */
2068 unsigned two_byte_p
: 1;
2070 /* 1 means that the original font determined for drawing this glyph
2071 string could not be loaded. The member `font' has been set to
2072 the frame's default font in this case. */
2073 unsigned font_not_found_p
: 1;
2075 /* 1 means that the face in which this glyph string is drawn has a
2077 unsigned stippled_p
: 1;
2079 /* 1 means only the foreground of this glyph string must be drawn,
2080 and we should use the physical height of the line this glyph
2081 string appears in as clip rect. */
2082 unsigned for_overlaps_p
: 1;
2084 /* The GC to use for drawing this glyph string. */
2087 /* A pointer to the first glyph in the string. This glyph
2088 corresponds to char2b[0]. Needed to draw rectangles if
2089 font_not_found_p is 1. */
2090 struct glyph
*first_glyph
;
2092 /* Image, if any. */
2095 struct glyph_string
*next
, *prev
;
2102 x_dump_glyph_string (s
)
2103 struct glyph_string
*s
;
2105 fprintf (stderr
, "glyph string\n");
2106 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2107 s
->x
, s
->y
, s
->width
, s
->height
);
2108 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2109 fprintf (stderr
, " hl = %d\n", s
->hl
);
2110 fprintf (stderr
, " left overhang = %d, right = %d\n",
2111 s
->left_overhang
, s
->right_overhang
);
2112 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2113 fprintf (stderr
, " extends to end of line = %d\n",
2114 s
->extends_to_end_of_line_p
);
2115 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2116 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2119 #endif /* GLYPH_DEBUG */
2123 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2124 struct glyph_string
**,
2125 struct glyph_string
*,
2126 struct glyph_string
*));
2127 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2128 struct glyph_string
**,
2129 struct glyph_string
*,
2130 struct glyph_string
*));
2131 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2132 struct glyph_string
**,
2133 struct glyph_string
*));
2134 static int x_left_overwritten
P_ ((struct glyph_string
*));
2135 static int x_left_overwriting
P_ ((struct glyph_string
*));
2136 static int x_right_overwritten
P_ ((struct glyph_string
*));
2137 static int x_right_overwriting
P_ ((struct glyph_string
*));
2138 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2140 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2141 XChar2b
*, struct window
*,
2143 enum glyph_row_area
, int,
2144 enum draw_glyphs_face
));
2145 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2146 enum glyph_row_area
, int, int,
2147 enum draw_glyphs_face
, int *, int *, int));
2148 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2149 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2150 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2152 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2153 static void x_draw_glyph_string_underline
P_ ((struct glyph_string
*));
2154 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2155 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2156 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2157 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2158 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2159 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2160 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2162 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2163 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2164 unsigned long *, float, int));
2165 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2166 float, int, unsigned long));
2167 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2168 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2169 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2170 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2171 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2172 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2173 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2175 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2176 int, int, int, int, XRectangle
*));
2177 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2178 int, int, int, XRectangle
*));
2179 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2180 enum glyph_row_area
));
2183 /* Append the list of glyph strings with head H and tail T to the list
2184 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2187 x_append_glyph_string_lists (head
, tail
, h
, t
)
2188 struct glyph_string
**head
, **tail
;
2189 struct glyph_string
*h
, *t
;
2203 /* Prepend the list of glyph strings with head H and tail T to the
2204 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2208 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2209 struct glyph_string
**head
, **tail
;
2210 struct glyph_string
*h
, *t
;
2224 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2225 Set *HEAD and *TAIL to the resulting list. */
2228 x_append_glyph_string (head
, tail
, s
)
2229 struct glyph_string
**head
, **tail
;
2230 struct glyph_string
*s
;
2232 s
->next
= s
->prev
= NULL
;
2233 x_append_glyph_string_lists (head
, tail
, s
, s
);
2237 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2242 struct glyph_string
*s
;
2244 if (s
->font
== FRAME_FONT (s
->f
)
2245 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2246 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2248 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2251 /* Cursor on non-default face: must merge. */
2255 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2256 xgcv
.foreground
= s
->face
->background
;
2258 /* If the glyph would be invisible, try a different foreground. */
2259 if (xgcv
.foreground
== xgcv
.background
)
2260 xgcv
.foreground
= s
->face
->foreground
;
2261 if (xgcv
.foreground
== xgcv
.background
)
2262 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2263 if (xgcv
.foreground
== xgcv
.background
)
2264 xgcv
.foreground
= s
->face
->foreground
;
2266 /* Make sure the cursor is distinct from text in this face. */
2267 if (xgcv
.background
== s
->face
->background
2268 && xgcv
.foreground
== s
->face
->foreground
)
2270 xgcv
.background
= s
->face
->foreground
;
2271 xgcv
.foreground
= s
->face
->background
;
2274 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2275 xgcv
.font
= s
->font
->fid
;
2276 xgcv
.graphics_exposures
= False
;
2277 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2279 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2280 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2283 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2284 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2286 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2291 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2294 x_set_mouse_face_gc (s
)
2295 struct glyph_string
*s
;
2299 /* What face has to be used for the mouse face? */
2300 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2301 face_id
= FACE_FOR_CHARSET (s
->f
, face_id
, s
->charset
);
2302 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2303 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2305 /* If font in this face is same as S->font, use it. */
2306 if (s
->font
== s
->face
->font
)
2307 s
->gc
= s
->face
->gc
;
2310 /* Otherwise construct scratch_cursor_gc with values from FACE
2315 xgcv
.background
= s
->face
->background
;
2316 xgcv
.foreground
= s
->face
->foreground
;
2317 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2318 xgcv
.font
= s
->font
->fid
;
2319 xgcv
.graphics_exposures
= False
;
2320 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2322 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2323 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2326 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2327 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2329 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2332 xassert (s
->gc
!= 0);
2336 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2337 Faces to use in the mode line have already been computed when the
2338 matrix was built, so there isn't much to do, here. */
2341 x_set_mode_line_face_gc (s
)
2342 struct glyph_string
*s
;
2344 s
->gc
= s
->face
->gc
;
2345 xassert (s
->gc
!= 0);
2349 /* Set S->gc of glyph string S for drawing that glyph string. Set
2350 S->stippled_p to a non-zero value if the face of S has a stipple
2354 x_set_glyph_string_gc (s
)
2355 struct glyph_string
*s
;
2357 if (s
->hl
== DRAW_NORMAL_TEXT
)
2359 s
->gc
= s
->face
->gc
;
2360 s
->stippled_p
= s
->face
->stipple
!= 0;
2362 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2364 x_set_mode_line_face_gc (s
);
2365 s
->stippled_p
= s
->face
->stipple
!= 0;
2367 else if (s
->hl
== DRAW_CURSOR
)
2369 x_set_cursor_gc (s
);
2372 else if (s
->hl
== DRAW_MOUSE_FACE
)
2374 x_set_mouse_face_gc (s
);
2375 s
->stippled_p
= s
->face
->stipple
!= 0;
2377 else if (s
->hl
== DRAW_IMAGE_RAISED
2378 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2380 s
->gc
= s
->face
->gc
;
2381 s
->stippled_p
= s
->face
->stipple
!= 0;
2385 s
->gc
= s
->face
->gc
;
2386 s
->stippled_p
= s
->face
->stipple
!= 0;
2389 /* GC must have been set. */
2390 xassert (s
->gc
!= 0);
2394 /* Return in *R the clipping rectangle for glyph string S. */
2397 x_get_glyph_string_clip_rect (s
, r
)
2398 struct glyph_string
*s
;
2401 if (s
->row
->full_width_p
)
2403 /* Draw full-width. X coordinates are relative to S->w->left. */
2404 int canon_x
= CANON_X_UNIT (s
->f
);
2406 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2407 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2409 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2411 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2412 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2416 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2418 /* Unless displaying a mode or menu bar line, which are always
2419 fully visible, clip to the visible part of the row. */
2420 if (s
->w
->pseudo_window_p
)
2421 r
->height
= s
->row
->visible_height
;
2423 r
->height
= s
->height
;
2427 /* This is a text line that may be partially visible. */
2428 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2429 r
->width
= window_box_width (s
->w
, s
->area
);
2430 r
->height
= s
->row
->visible_height
;
2433 /* Don't use S->y for clipping because it doesn't take partially
2434 visible lines into account. For example, it can be negative for
2435 partially visible lines at the top of a window. */
2436 if (!s
->row
->full_width_p
2437 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2438 r
->y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (s
->w
);
2440 r
->y
= max (0, s
->row
->y
);
2442 /* If drawing a toolbar window, draw it over the internal border
2443 at the top of the window. */
2444 if (s
->w
== XWINDOW (s
->f
->toolbar_window
))
2445 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2447 /* If S draws overlapping rows, it's sufficient to use the top and
2448 bottom of the window for clipping because this glyph string
2449 intentionally draws over other lines. */
2450 if (s
->for_overlaps_p
)
2452 r
->y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (s
->w
);
2453 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2456 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2460 /* Set clipping for output of glyph string S. S may be part of a mode
2461 line or menu if we don't have X toolkit support. */
2464 x_set_glyph_string_clipping (s
)
2465 struct glyph_string
*s
;
2468 x_get_glyph_string_clip_rect (s
, &r
);
2469 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2473 /* Compute left and right overhang of glyph string S. If S is a glyph
2474 string for a composite character, assume overhangs don't exist. */
2477 x_compute_glyph_string_overhangs (s
)
2478 struct glyph_string
*s
;
2480 if (s
->cmpcharp
== NULL
2481 && s
->first_glyph
->type
== CHAR_GLYPH
)
2484 int direction
, font_ascent
, font_descent
;
2485 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2486 &font_ascent
, &font_descent
, &cs
);
2487 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2488 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2493 /* Compute overhangs and x-positions for glyph string S and its
2494 predecessors, or successors. X is the starting x-position for S.
2495 BACKWARD_P non-zero means process predecessors. */
2498 x_compute_overhangs_and_x (s
, x
, backward_p
)
2499 struct glyph_string
*s
;
2507 x_compute_glyph_string_overhangs (s
);
2517 x_compute_glyph_string_overhangs (s
);
2526 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2527 frame F. Overhangs of glyphs other than type CHAR_GLYPH or of
2528 character glyphs for composite characters are assumed to be zero. */
2531 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2532 struct glyph
*glyph
;
2540 if (glyph
->type
== CHAR_GLYPH
2541 && (c
= glyph
->u
.ch
.code
,
2542 CHAR_CHARSET (c
) != CHARSET_COMPOSITION
))
2546 struct font_info
*font_info
;
2549 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
);
2551 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2554 XCharStruct
*pcm
= x_per_char_metric (font
, &char2b
);
2556 if (pcm
->rbearing
> pcm
->width
)
2557 *right
= pcm
->rbearing
- pcm
->width
;
2558 if (pcm
->lbearing
< 0)
2559 *left
= -pcm
->lbearing
;
2565 /* Return the index of the first glyph preceding glyph string S that
2566 is overwritten by S because of S's left overhang. Value is -1
2567 if no glyphs are overwritten. */
2570 x_left_overwritten (s
)
2571 struct glyph_string
*s
;
2575 if (s
->left_overhang
)
2578 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2579 int first
= s
->first_glyph
- glyphs
;
2581 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2582 x
-= glyphs
[i
].pixel_width
;
2593 /* Return the index of the first glyph preceding glyph string S that
2594 is overwriting S because of its right overhang. Value is -1 if no
2595 glyph in front of S overwrites S. */
2598 x_left_overwriting (s
)
2599 struct glyph_string
*s
;
2602 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2603 int first
= s
->first_glyph
- glyphs
;
2607 for (i
= first
- 1; i
>= 0; --i
)
2610 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2613 x
-= glyphs
[i
].pixel_width
;
2620 /* Return the index of the last glyph following glyph string S that is
2621 not overwritten by S because of S's right overhang. Value is -1 if
2622 no such glyph is found. */
2625 x_right_overwritten (s
)
2626 struct glyph_string
*s
;
2630 if (s
->right_overhang
)
2633 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2634 int first
= (s
->first_glyph
- glyphs
) + (s
->cmpcharp
? 1 : s
->nchars
);
2635 int end
= s
->row
->used
[s
->area
];
2637 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
2638 x
+= glyphs
[i
].pixel_width
;
2647 /* Return the index of the last glyph following glyph string S that
2648 overwrites S because of its left overhang. Value is negative
2649 if no such glyph is found. */
2652 x_right_overwriting (s
)
2653 struct glyph_string
*s
;
2656 int end
= s
->row
->used
[s
->area
];
2657 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2658 int first
= (s
->first_glyph
- glyphs
) + (s
->cmpcharp
? 1 : s
->nchars
);
2662 for (i
= first
; i
< end
; ++i
)
2665 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2668 x
+= glyphs
[i
].pixel_width
;
2675 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2678 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2679 struct glyph_string
*s
;
2683 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
2684 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2685 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2686 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2690 /* Draw the background of glyph_string S. If S->background_filled_p
2691 is non-zero don't draw it. FORCE_P non-zero means draw the
2692 background even if it wouldn't be drawn normally. This is used
2693 when a string preceding S draws into the background of S. */
2696 x_draw_glyph_string_background (s
, force_p
)
2697 struct glyph_string
*s
;
2700 /* Nothing to do if background has already been drawn or if it
2701 shouldn't be drawn in the first place. */
2702 if (!s
->background_filled_p
)
2706 && !s
->font_not_found_p
2707 && !s
->extends_to_end_of_line_p
)
2709 /* Don't draw background for glyphs of a composite
2710 characters, except for the first one. */
2711 s
->background_filled_p
= 1;
2713 else if (s
->stippled_p
)
2715 /* Fill background with a stipple pattern. */
2716 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2717 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2718 s
->y
+ s
->face
->box_line_width
,
2719 s
->background_width
,
2720 s
->height
- 2 * s
->face
->box_line_width
);
2721 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2722 s
->background_filled_p
= 1;
2724 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
2725 || s
->font_not_found_p
2726 || s
->extends_to_end_of_line_p
2730 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
2731 s
->background_width
,
2732 s
->height
- 2 * s
->face
->box_line_width
);
2733 s
->background_filled_p
= 1;
2739 /* Draw the foreground of glyph string S. */
2742 x_draw_glyph_string_foreground (s
)
2743 struct glyph_string
*s
;
2747 /* If first glyph of S has a left box line, start drawing the text
2748 of S to the right of that box line. */
2749 if (s
->face
->box
!= FACE_NO_BOX
2750 && s
->first_glyph
->left_box_line_p
)
2751 x
= s
->x
+ s
->face
->box_line_width
;
2755 if (s
->cmpcharp
== NULL
)
2757 /* Not a composite character. Draw characters of S as
2758 rectangles if S's font could not be loaded. */
2759 if (s
->font_not_found_p
)
2761 for (i
= 0; i
< s
->nchars
; ++i
)
2763 struct glyph
*g
= s
->first_glyph
+ i
;
2764 XDrawRectangle (s
->display
, s
->window
,
2765 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
2767 x
+= g
->pixel_width
;
2772 char *char1b
= (char *) s
->char2b
;
2774 /* If we can use 8-bit functions, condense S->char2b. */
2776 for (i
= 0; i
< s
->nchars
; ++i
)
2777 char1b
[i
] = s
->char2b
[i
].byte2
;
2779 /* Draw text with XDrawString if background has already been
2780 filled. Otherwise, use XDrawImageString. (Note that
2781 XDrawImageString is usually faster than XDrawString.)
2782 Always use XDrawImageString when drawing the cursor so
2783 that there is no chance that characters under a box
2784 cursor are invisible. */
2785 if (s
->for_overlaps_p
2786 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
2788 /* Draw characters with 16-bit or 8-bit functions. */
2790 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
, s
->ybase
,
2791 s
->char2b
, s
->nchars
);
2793 XDrawString (s
->display
, s
->window
, s
->gc
, x
, s
->ybase
,
2799 XDrawImageString16 (s
->display
, s
->window
, s
->gc
,
2800 x
, s
->ybase
, s
->char2b
, s
->nchars
);
2802 XDrawImageString (s
->display
, s
->window
, s
->gc
,
2803 x
, s
->ybase
, char1b
, s
->nchars
);
2809 /* S is a glyph string for a composite character. S->gidx is the
2810 index of the first character drawn in the vector
2811 S->cmpcharp->glyph. S->gidx == 0 means we are drawing the
2812 very first component character of a composite char. */
2814 /* Draw a single rectangle for the composite character if S's
2815 font could not be loaded. */
2816 if (s
->font_not_found_p
&& s
->gidx
== 0)
2817 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
2818 s
->width
- 1, s
->height
- 1);
2822 int relative_compose
, default_ascent
, i
;
2823 int highest
= 0, lowest
= 0;
2825 /* The value of font_info my be null if we couldn't find it
2826 in x_get_char_face_and_encoding. */
2827 if (s
->cmpcharp
->cmp_rule
== NULL
&& s
->font_info
)
2829 relative_compose
= s
->font_info
->relative_compose
;
2830 default_ascent
= s
->font_info
->default_ascent
;
2833 relative_compose
= default_ascent
= 0;
2835 if ((s
->cmpcharp
->cmp_rule
|| relative_compose
)
2838 /* This is the first character. Initialize variables.
2839 Highest is the highest position of glyphs ever
2840 written, lowest the lowest position. */
2842 int first_ch
= s
->first_glyph
->u
.ch
.code
;
2845 && CHAR_TABLE_P (Vuse_default_ascent
)
2846 && !NILP (Faref (Vuse_default_ascent
, first_ch
)))
2848 highest
= default_ascent
;
2853 pcm
= PER_CHAR_METRIC (s
->font
, s
->char2b
);
2854 highest
= pcm
->ascent
+ 1;
2855 lowest
= - pcm
->descent
;
2858 if (s
->cmpcharp
->cmp_rule
)
2859 x_offset
= (s
->cmpcharp
->col_offset
[0]
2860 * FONT_WIDTH (s
->f
->output_data
.x
->font
));
2862 /* Draw the first character at the normal position. */
2863 XDrawString16 (s
->display
, s
->window
, s
->gc
,
2865 s
->ybase
, s
->char2b
, 1);
2872 for (; i
< s
->nchars
; i
++, ++s
->gidx
)
2874 int x_offset
= 0, y_offset
= 0;
2876 if (relative_compose
)
2878 pcm
= PER_CHAR_METRIC (s
->font
, s
->char2b
+ i
);
2879 if (NILP (Vignore_relative_composition
)
2880 || NILP (Faref (Vignore_relative_composition
,
2881 make_number (s
->cmpcharp
->glyph
[s
->gidx
]))))
2883 if (- pcm
->descent
>= relative_compose
)
2885 /* Draw above the current glyphs. */
2886 y_offset
= highest
+ pcm
->descent
;
2887 highest
+= pcm
->ascent
+ pcm
->descent
;
2889 else if (pcm
->ascent
<= 0)
2891 /* Draw beneath the current glyphs. */
2892 y_offset
= lowest
- pcm
->ascent
;
2893 lowest
-= pcm
->ascent
+ pcm
->descent
;
2898 /* Draw the glyph at normal position. If
2899 it sticks out of HIGHEST or LOWEST,
2900 update them appropriately. */
2901 if (pcm
->ascent
> highest
)
2902 highest
= pcm
->ascent
;
2903 else if (- pcm
->descent
< lowest
)
2904 lowest
= - pcm
->descent
;
2907 else if (s
->cmpcharp
->cmp_rule
)
2909 int gref
= (s
->cmpcharp
->cmp_rule
[s
->gidx
] - 0xA0) / 9;
2910 int nref
= (s
->cmpcharp
->cmp_rule
[s
->gidx
] - 0xA0) % 9;
2913 /* Re-encode GREF and NREF so that they specify
2914 only Y-axis information:
2915 0:top, 1:base, 2:bottom, 3:center */
2916 gref
= gref
/ 3 + (gref
== 4) * 2;
2917 nref
= nref
/ 3 + (nref
== 4) * 2;
2919 pcm
= PER_CHAR_METRIC (s
->font
, s
->char2b
+ i
);
2920 bottom
= ((gref
== 0 ? highest
: gref
== 1 ? 0
2921 : gref
== 2 ? lowest
2922 : (highest
+ lowest
) / 2)
2923 - (nref
== 0 ? pcm
->ascent
+ pcm
->descent
2924 : nref
== 1 ? pcm
->descent
: nref
== 2 ? 0
2925 : (pcm
->ascent
+ pcm
->descent
) / 2));
2926 top
= bottom
+ (pcm
->ascent
+ pcm
->descent
);
2929 if (bottom
< lowest
)
2931 y_offset
= bottom
+ pcm
->descent
;
2932 x_offset
= (s
->cmpcharp
->col_offset
[s
->gidx
]
2933 * FONT_WIDTH (FRAME_FONT (s
->f
)));
2936 XDrawString16 (s
->display
, s
->window
, s
->gc
,
2937 x
+ x_offset
, s
->ybase
- y_offset
,
2945 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
2946 CMAP. If an exact match can't be allocated, try the nearest color
2947 available. Value is non-zero if successful. Set *COLOR to the
2951 x_alloc_nearest_color (display
, screen
, cmap
, color
)
2957 int rc
= XAllocColor (display
, cmap
, color
);
2960 /* If we got to this point, the colormap is full, so we're going
2961 to try to get the next closest color. The algorithm used is
2962 a least-squares matching, which is what X uses for closest
2963 color matching with StaticColor visuals. */
2965 unsigned long nearest_delta
= ~0;
2966 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
2967 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
2969 for (i
= 0; i
< ncells
; ++i
)
2971 XQueryColors (display
, cmap
, cells
, ncells
);
2973 for (nearest
= i
= 0; i
< ncells
; ++i
)
2975 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
2976 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
2977 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
2978 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
2980 if (delta
< nearest_delta
)
2983 nearest_delta
= delta
;
2987 color
->red
= cells
[nearest
].red
;
2988 color
->green
= cells
[nearest
].green
;
2989 color
->blue
= cells
[nearest
].blue
;
2990 rc
= XAllocColor (display
, cmap
, color
);
2997 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
2998 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2999 If this produces the same color as PIXEL, try a color where all RGB
3000 values have DELTA added. Return the allocated color in *PIXEL.
3001 DISPLAY is the X display, CMAP is the colormap to operate on.
3002 Value is non-zero if successful. */
3005 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3009 unsigned long *pixel
;
3016 /* Get RGB color values. */
3017 color
.pixel
= *pixel
;
3018 XQueryColor (display
, cmap
, &color
);
3020 /* Change RGB values by specified FACTOR. Avoid overflow! */
3021 xassert (factor
>= 0);
3022 new.red
= min (0xffff, factor
* color
.red
);
3023 new.green
= min (0xffff, factor
* color
.green
);
3024 new.blue
= min (0xffff, factor
* color
.blue
);
3026 /* Try to allocate the color. */
3027 success_p
= x_alloc_nearest_color (display
, FRAME_X_SCREEN (f
), cmap
, &new);
3030 if (new.pixel
== *pixel
)
3032 /* If we end up with the same color as before, try adding
3033 delta to the RGB values. */
3034 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
3036 /* If display has an immutable color map, freeing colors is
3037 not necessary and some servers don't allow it. So don't
3039 if (class != StaticColor
3040 && class != StaticGray
3041 && class != TrueColor
)
3042 XFreeColors (display
, cmap
, &new.pixel
, 1, 0);
3044 new.red
= min (0xffff, delta
+ color
.red
);
3045 new.green
= min (0xffff, delta
+ color
.green
);
3046 new.blue
= min (0xffff, delta
+ color
.blue
);
3047 success_p
= x_alloc_nearest_color (display
, FRAME_X_SCREEN (f
),
3059 /* Set up the foreground color for drawing relief lines of glyph
3060 string S. RELIEF is a pointer to a struct relief containing the GC
3061 with which lines will be drawn. Use a color that is FACTOR or
3062 DELTA lighter or darker than the relief's background which is found
3063 in S->f->output_data.x->relief_background. If such a color cannot
3064 be allocated, use DEFAULT_PIXEL, instead. */
3067 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3069 struct relief
*relief
;
3072 unsigned long default_pixel
;
3075 struct x_output
*di
= f
->output_data
.x
;
3076 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3077 unsigned long pixel
;
3078 unsigned long background
= di
->relief_background
;
3079 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
3080 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3081 Display
*dpy
= FRAME_X_DISPLAY (f
);
3083 xgcv
.graphics_exposures
= False
;
3084 xgcv
.line_width
= 1;
3086 /* Free previously allocated color. The color cell will be reused
3087 when it has been freed as many times as it was allocated, so this
3088 doesn't affect faces using the same colors. */
3090 && relief
->allocated_p
)
3092 /* If display has an immutable color map, freeing colors is not
3093 necessary and some servers don't allow it. So don't do it. */
3094 int class = dpyinfo
->visual
->class;
3095 if (class != StaticColor
3096 && class != StaticGray
3097 && class != TrueColor
)
3098 XFreeColors (dpy
, cmap
, &relief
->pixel
, 1, 0);
3099 relief
->allocated_p
= 0;
3102 /* Allocate new color. */
3103 xgcv
.foreground
= default_pixel
;
3105 if (dpyinfo
->n_planes
!= 1
3106 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3108 relief
->allocated_p
= 1;
3109 xgcv
.foreground
= relief
->pixel
= pixel
;
3112 if (relief
->gc
== 0)
3114 xgcv
.stipple
= dpyinfo
->gray
;
3116 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3119 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3123 /* Set up colors for the relief lines around glyph string S. */
3126 x_setup_relief_colors (s
)
3127 struct glyph_string
*s
;
3129 struct x_output
*di
= s
->f
->output_data
.x
;
3130 unsigned long color
;
3132 if (s
->face
->use_box_color_for_shadows_p
)
3133 color
= s
->face
->box_color
;
3138 /* Get the background color of the face. */
3139 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3140 color
= xgcv
.background
;
3143 if (di
->white_relief
.gc
== 0
3144 || color
!= di
->relief_background
)
3146 di
->relief_background
= color
;
3147 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3148 WHITE_PIX_DEFAULT (s
->f
));
3149 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3150 BLACK_PIX_DEFAULT (s
->f
));
3155 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3156 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3157 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3158 relief. LEFT_P non-zero means draw a relief on the left side of
3159 the rectangle. RIGHT_P non-zero means draw a relief on the right
3160 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3164 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3165 raised_p
, left_p
, right_p
, clip_rect
)
3167 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3168 XRectangle
*clip_rect
;
3174 gc
= f
->output_data
.x
->white_relief
.gc
;
3176 gc
= f
->output_data
.x
->black_relief
.gc
;
3177 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3180 for (i
= 0; i
< width
; ++i
)
3181 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3182 left_x
+ i
* left_p
, top_y
+ i
,
3183 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3187 for (i
= 0; i
< width
; ++i
)
3188 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3189 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3191 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3193 gc
= f
->output_data
.x
->black_relief
.gc
;
3195 gc
= f
->output_data
.x
->white_relief
.gc
;
3196 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3199 for (i
= 0; i
< width
; ++i
)
3200 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3201 left_x
+ i
* left_p
, bottom_y
- i
,
3202 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3206 for (i
= 0; i
< width
; ++i
)
3207 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3208 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3210 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3214 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3215 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3216 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3217 left side of the rectangle. RIGHT_P non-zero means draw a line
3218 on the right side of the rectangle. CLIP_RECT is the clipping
3219 rectangle to use when drawing. */
3222 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3223 left_p
, right_p
, clip_rect
)
3224 struct glyph_string
*s
;
3225 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3226 XRectangle
*clip_rect
;
3230 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3231 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3232 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3235 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3236 left_x
, top_y
, right_x
- left_x
, width
);
3240 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3241 left_x
, top_y
, width
, bottom_y
- top_y
);
3244 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3245 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3249 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3250 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3252 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3253 XSetClipMask (s
->display
, s
->gc
, None
);
3257 /* Draw a box around glyph string S. */
3260 x_draw_glyph_string_box (s
)
3261 struct glyph_string
*s
;
3263 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3264 int left_p
, right_p
;
3265 struct glyph
*last_glyph
;
3266 XRectangle clip_rect
;
3268 last_x
= window_box_right (s
->w
, s
->area
);
3269 if (s
->row
->full_width_p
3270 && !s
->w
->pseudo_window_p
)
3272 last_x
+= FRAME_X_FLAGS_AREA_WIDTH (s
->f
);
3273 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3274 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3277 /* The glyph that may have a right box line. */
3278 last_glyph
= (s
->cmpcharp
|| s
->img
3280 : s
->first_glyph
+ s
->nchars
- 1);
3282 width
= s
->face
->box_line_width
;
3283 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3285 right_x
= ((s
->row
->full_width_p
3287 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3289 bottom_y
= top_y
+ s
->height
- 1;
3291 left_p
= (s
->first_glyph
->left_box_line_p
3292 || (s
->hl
== DRAW_MOUSE_FACE
3294 || s
->prev
->hl
!= s
->hl
)));
3295 right_p
= (last_glyph
->right_box_line_p
3296 || (s
->hl
== DRAW_MOUSE_FACE
3298 || s
->next
->hl
!= s
->hl
)));
3300 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3302 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3303 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3304 left_p
, right_p
, &clip_rect
);
3307 x_setup_relief_colors (s
);
3308 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3309 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3314 /* Draw foreground of image glyph string S. */
3317 x_draw_image_foreground (s
)
3318 struct glyph_string
*s
;
3321 int y
= s
->ybase
- IMAGE_ASCENT (s
->img
);
3323 /* If first glyph of S has a left box line, start drawing it to the
3324 right of that line. */
3325 if (s
->face
->box
!= FACE_NO_BOX
3326 && s
->first_glyph
->left_box_line_p
)
3327 x
= s
->x
+ s
->face
->box_line_width
;
3331 /* If there is a margin around the image, adjust x- and y-position
3335 x
+= s
->img
->margin
;
3336 y
+= s
->img
->margin
;
3343 /* We can't set both a clip mask and use XSetClipRectangles
3344 because the latter also sets a clip mask. We also can't
3345 trust on the shape extension to be available
3346 (XShapeCombineRegion). So, compute the rectangle to draw
3348 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3351 XRectangle clip_rect
, image_rect
, r
;
3353 xgcv
.clip_mask
= s
->img
->mask
;
3354 xgcv
.clip_x_origin
= x
;
3355 xgcv
.clip_y_origin
= y
;
3356 xgcv
.function
= GXcopy
;
3357 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3359 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3362 image_rect
.width
= s
->img
->width
;
3363 image_rect
.height
= s
->img
->height
;
3364 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3365 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3366 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3370 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3371 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3373 /* When the image has a mask, we can expect that at
3374 least part of a mouse highlight or a block cursor will
3375 be visible. If the image doesn't have a mask, make
3376 a block cursor visible by drawing a rectangle around
3377 the image. I believe it's looking better if we do
3378 nothing here for mouse-face. */
3379 if (s
->hl
== DRAW_CURSOR
)
3380 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3381 s
->img
->width
- 1, s
->img
->height
- 1);
3385 /* Draw a rectangle if image could not be loaded. */
3386 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3387 s
->img
->width
- 1, s
->img
->height
- 1);
3391 /* Draw a relief around the image glyph string S. */
3394 x_draw_image_relief (s
)
3395 struct glyph_string
*s
;
3397 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3400 int y
= s
->ybase
- IMAGE_ASCENT (s
->img
);
3402 /* If first glyph of S has a left box line, start drawing it to the
3403 right of that line. */
3404 if (s
->face
->box
!= FACE_NO_BOX
3405 && s
->first_glyph
->left_box_line_p
)
3406 x
= s
->x
+ s
->face
->box_line_width
;
3410 /* If there is a margin around the image, adjust x- and y-position
3414 x
+= s
->img
->margin
;
3415 y
+= s
->img
->margin
;
3418 if (s
->hl
== DRAW_IMAGE_SUNKEN
3419 || s
->hl
== DRAW_IMAGE_RAISED
)
3421 thick
= toolbar_button_relief
> 0 ? toolbar_button_relief
: 3;
3422 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3426 thick
= abs (s
->img
->relief
);
3427 raised_p
= s
->img
->relief
> 0;
3432 x1
= x
+ s
->img
->width
+ thick
- 1;
3433 y1
= y
+ s
->img
->height
+ thick
- 1;
3435 x_setup_relief_colors (s
);
3436 x_get_glyph_string_clip_rect (s
, &r
);
3437 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3441 /* Draw the foreground of image glyph string S to PIXMAP. */
3444 x_draw_image_foreground_1 (s
, pixmap
)
3445 struct glyph_string
*s
;
3449 int y
= s
->ybase
- s
->y
- IMAGE_ASCENT (s
->img
);
3451 /* If first glyph of S has a left box line, start drawing it to the
3452 right of that line. */
3453 if (s
->face
->box
!= FACE_NO_BOX
3454 && s
->first_glyph
->left_box_line_p
)
3455 x
= s
->face
->box_line_width
;
3459 /* If there is a margin around the image, adjust x- and y-position
3463 x
+= s
->img
->margin
;
3464 y
+= s
->img
->margin
;
3471 /* We can't set both a clip mask and use XSetClipRectangles
3472 because the latter also sets a clip mask. We also can't
3473 trust on the shape extension to be available
3474 (XShapeCombineRegion). So, compute the rectangle to draw
3476 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3480 xgcv
.clip_mask
= s
->img
->mask
;
3481 xgcv
.clip_x_origin
= x
;
3482 xgcv
.clip_y_origin
= y
;
3483 xgcv
.function
= GXcopy
;
3484 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3486 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3487 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3488 XSetClipMask (s
->display
, s
->gc
, None
);
3492 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3493 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3495 /* When the image has a mask, we can expect that at
3496 least part of a mouse highlight or a block cursor will
3497 be visible. If the image doesn't have a mask, make
3498 a block cursor visible by drawing a rectangle around
3499 the image. I believe it's looking better if we do
3500 nothing here for mouse-face. */
3501 if (s
->hl
== DRAW_CURSOR
)
3502 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3503 s
->img
->width
- 1, s
->img
->height
- 1);
3507 /* Draw a rectangle if image could not be loaded. */
3508 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3509 s
->img
->width
- 1, s
->img
->height
- 1);
3513 /* Draw part of the background of glyph string S. X, Y, W, and H
3514 give the rectangle to draw. */
3517 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3518 struct glyph_string
*s
;
3523 /* Fill background with a stipple pattern. */
3524 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3525 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3526 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3529 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3533 /* Draw image glyph string S.
3536 s->x +-------------------------
3539 | +-------------------------
3542 | | +-------------------
3548 x_draw_image_glyph_string (s
)
3549 struct glyph_string
*s
;
3552 int box_line_width
= s
->face
->box_line_width
;
3553 int margin
= s
->img
->margin
;
3555 Pixmap pixmap
= None
;
3557 height
= s
->height
- 2 * box_line_width
;
3559 /* Fill background with face under the image. Do it only if row is
3560 taller than image or if image has a clip mask to reduce
3562 s
->stippled_p
= s
->face
->stipple
!= 0;
3563 if (height
> s
->img
->height
3566 || s
->img
->pixmap
== 0
3567 || s
->width
!= s
->background_width
)
3569 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3570 x
= s
->x
+ box_line_width
;
3574 y
= s
->y
+ box_line_width
;
3578 /* Create a pixmap as large as the glyph string Fill it with
3579 the background color. Copy the image to it, using its
3580 mask. Copy the temporary pixmap to the display. */
3581 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3582 int depth
= DefaultDepthOfScreen (screen
);
3584 /* Create a pixmap as large as the glyph string. */
3585 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3586 s
->background_width
,
3589 /* Don't clip in the following because we're working on the
3591 XSetClipMask (s
->display
, s
->gc
, None
);
3593 /* Fill the pixmap with the background color/stipple. */
3596 /* Fill background with a stipple pattern. */
3597 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3598 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3599 0, 0, s
->background_width
, s
->height
);
3600 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3605 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3607 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3608 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3609 0, 0, s
->background_width
, s
->height
);
3610 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3614 /* Implementation idea: Is it possible to construct a mask?
3615 We could look at the color at the margins of the image, and
3616 say that this color is probably the background color of the
3618 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3620 s
->background_filled_p
= 1;
3623 /* Draw the foreground. */
3626 x_draw_image_foreground_1 (s
, pixmap
);
3627 x_set_glyph_string_clipping (s
);
3628 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
3629 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3630 XFreePixmap (s
->display
, pixmap
);
3633 x_draw_image_foreground (s
);
3635 /* If we must draw a relief around the image, do it. */
3637 || s
->hl
== DRAW_IMAGE_RAISED
3638 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3639 x_draw_image_relief (s
);
3643 /* Draw stretch glyph string S. */
3646 x_draw_stretch_glyph_string (s
)
3647 struct glyph_string
*s
;
3649 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3650 s
->stippled_p
= s
->face
->stipple
!= 0;
3652 if (s
->hl
== DRAW_CURSOR
3653 && !x_stretch_cursor_p
)
3655 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3656 as wide as the stretch glyph. */
3657 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
3660 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3662 /* Clear rest using the GC of the original non-cursor face. */
3663 if (width
< s
->background_width
)
3665 GC gc
= s
->face
->gc
;
3666 int x
= s
->x
+ width
, y
= s
->y
;
3667 int w
= s
->background_width
- width
, h
= s
->height
;
3670 x_get_glyph_string_clip_rect (s
, &r
);
3671 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
3673 if (s
->face
->stipple
)
3675 /* Fill background with a stipple pattern. */
3676 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3677 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3678 XSetFillStyle (s
->display
, gc
, FillSolid
);
3683 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
3684 XSetForeground (s
->display
, gc
, xgcv
.background
);
3685 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3686 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
3691 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
3694 s
->background_filled_p
= 1;
3698 /* Draw glyph string S. */
3701 x_draw_glyph_string (s
)
3702 struct glyph_string
*s
;
3704 /* If S draws into the background of its successor, draw the
3705 background of the successor first so that S can draw into it.
3706 This makes S->next use XDrawString instead of XDrawImageString. */
3707 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
3709 xassert (s
->next
->img
== NULL
);
3710 x_set_glyph_string_gc (s
->next
);
3711 x_set_glyph_string_clipping (s
->next
);
3712 x_draw_glyph_string_background (s
->next
, 1);
3715 /* Set up S->gc, set clipping and draw S. */
3716 x_set_glyph_string_gc (s
);
3717 x_set_glyph_string_clipping (s
);
3719 switch (s
->first_glyph
->type
)
3722 x_draw_image_glyph_string (s
);
3726 x_draw_stretch_glyph_string (s
);
3730 if (s
->for_overlaps_p
)
3731 s
->background_filled_p
= 1;
3733 x_draw_glyph_string_background (s
, 0);
3734 x_draw_glyph_string_foreground (s
);
3741 if (!s
->for_overlaps_p
)
3743 /* Draw underline. */
3744 if (s
->face
->underline_p
)
3746 unsigned long dy
, h
;
3748 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
3750 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
3753 if (s
->face
->underline_defaulted_p
)
3754 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3759 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3760 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3761 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3763 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3767 /* Draw overline. */
3768 if (s
->face
->overline_p
)
3770 unsigned long dy
= 0, h
= 1;
3772 if (s
->face
->overline_color_defaulted_p
)
3773 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3778 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3779 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3780 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3782 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3786 /* Draw strike-through. */
3787 if (s
->face
->strike_through_p
)
3789 unsigned long h
= 1;
3790 unsigned long dy
= (s
->height
- h
) / 2;
3792 if (s
->face
->strike_through_color_defaulted_p
)
3793 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3798 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3799 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3800 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3802 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3807 if (s
->face
->box
!= FACE_NO_BOX
)
3808 x_draw_glyph_string_box (s
);
3811 /* Reset clipping. */
3812 XSetClipMask (s
->display
, s
->gc
, None
);
3816 /* A work-list entry used during the construction of glyph_string
3817 structures for a composite character. */
3821 /* Pointer to composite char info defining has the composite
3822 character is drawn. */
3823 struct cmpchar_info
*cmpcharp
;
3825 /* Start index in compcharp->glyph[]. */
3828 /* Next in stack. */
3833 static void x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
3834 int, struct work
**,
3835 struct work
**, int));
3838 /* Load glyph string S with information from the top of *STACK for a
3839 composite character. FACE_ID is the id of the face in which S is
3840 drawn. *NEW is a pointer to a struct work not on the stack, that
3841 can be used if this function needs to push a new structure on the
3842 stack. If it uses it, *NEW is set to null. OVERLAPS_P non-zero
3843 means S should draw the foreground only, and use its lines physical
3844 height for clipping. */
3847 x_fill_composite_glyph_string (s
, face_id
, stack
, new, overlaps_p
)
3848 struct glyph_string
*s
;
3850 struct work
**stack
, **new;
3856 xassert (s
&& *new && *stack
);
3858 s
->for_overlaps_p
= 1;
3860 /* Pop the work stack. */
3862 *stack
= work
->next
;
3864 /* For all glyphs of cmpcharp->glyph, starting at the offset
3865 work->offset, until we reach the end of the definition or
3866 encounter another composite char, get the font and face to use,
3868 for (i
= work
->gidx
; i
< work
->cmpcharp
->glyph_len
; ++i
)
3870 c
= FAST_GLYPH_CHAR (work
->cmpcharp
->glyph
[i
]);
3871 if (CHAR_CHARSET (c
) == CHARSET_COMPOSITION
)
3873 s
->face
= x_get_char_face_and_encoding (s
->f
, c
, face_id
,
3874 s
->char2b
+ s
->nchars
, 1);
3875 s
->font
= s
->face
->font
;
3876 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
3880 /* If we find another composite char in the glyph definition of
3881 work->cmpcharp, put back the rest of the glyphs on the work
3882 stack, and make a new entry for the composite char. */
3883 if (i
< work
->cmpcharp
->glyph_len
)
3885 /* Push back an unprocessed rest of this glyph spec. */
3886 if (i
< work
->cmpcharp
->glyph_len
- 1)
3889 work
->next
= *stack
;
3895 /* Make an entry for the composite char on the work stack. */
3896 work
->cmpcharp
= cmpchar_table
[COMPOSITE_CHAR_ID (c
)];
3898 work
->next
= *stack
;
3902 /* The width of this glyph string equals the width of the first
3903 glyph. All characters are drawn at the same x-position. */
3904 s
->width
= s
->first_glyph
->pixel_width
;
3906 /* If the specified font could not be loaded, use the frame's
3907 default font, but record the fact that we couldn't load it in
3908 the glyph string so that we can draw rectangles for the
3909 characters of the glyph string. */
3910 if (s
->font
== NULL
)
3912 s
->font_not_found_p
= 1;
3913 s
->font
= FRAME_FONT (s
->f
);
3916 /* Adjust base line for subscript/superscript text. */
3917 s
->ybase
+= s
->first_glyph
->voffset
;
3919 xassert (s
->face
&& s
->face
->gc
);
3921 /* This glyph string must always be drawn with 16-bit functions. */
3926 /* Load glyph string S with a sequence of non-composite characters.
3927 FACE_ID is the face id of the string. START is the index of the
3928 first glyph to consider, END is the index of the last + 1.
3929 OVERLAPS_P non-zero means S should draw the foreground only, and
3930 use its lines physical height for clipping.
3932 Value is the index of the first glyph not in S. */
3935 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
3936 struct glyph_string
*s
;
3938 int start
, end
, overlaps_p
;
3940 struct glyph
*glyph
, *last
;
3943 xassert (s
->charset
!= CHARSET_COMPOSITION
);
3944 xassert (s
->f
== XFRAME (s
->w
->frame
));
3945 xassert (s
->nchars
== 0);
3946 xassert (start
>= 0 && end
> start
);
3948 s
->for_overlaps_p
= overlaps_p
,
3949 glyph
= s
->row
->glyphs
[s
->area
] + start
;
3950 last
= s
->row
->glyphs
[s
->area
] + end
;
3951 voffset
= glyph
->voffset
;
3954 && glyph
->type
== CHAR_GLYPH
3955 && glyph
->voffset
== voffset
3956 /* Same face id implies same charset, nowadays. */
3957 && glyph
->u
.ch
.face_id
== face_id
)
3959 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
3960 s
->char2b
+ s
->nchars
);
3961 if (s
->char2b
[s
->nchars
].byte2
!= 0)
3965 xassert (s
->nchars
<= end
- start
);
3966 s
->width
+= glyph
->pixel_width
;
3970 s
->font
= s
->face
->font
;
3971 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
3973 /* If the specified font could not be loaded, use the frame's font,
3974 but record the fact that we couldn't load it in
3975 S->font_not_found_p so that we can draw rectangles for the
3976 characters of the glyph string. */
3977 if (s
->font
== NULL
)
3979 s
->font_not_found_p
= 1;
3980 s
->font
= FRAME_FONT (s
->f
);
3983 /* Adjust base line for subscript/superscript text. */
3984 s
->ybase
+= voffset
;
3986 xassert (s
->face
&& s
->face
->gc
);
3987 return glyph
- s
->row
->glyphs
[s
->area
];
3991 /* Fill glyph string S from image glyph S->first_glyph. */
3994 x_fill_image_glyph_string (s
)
3995 struct glyph_string
*s
;
3997 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
3998 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img
.id
);
4000 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->u
.img
.face_id
);
4001 s
->font
= s
->face
->font
;
4002 s
->width
= s
->first_glyph
->pixel_width
;
4004 /* Adjust base line for subscript/superscript text. */
4005 s
->ybase
+= s
->first_glyph
->voffset
;
4009 /* Fill glyph string S from stretch glyph S->first_glyph. */
4012 x_fill_stretch_glyph_string (s
)
4013 struct glyph_string
*s
;
4015 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4016 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->u
.stretch
.face_id
);
4017 s
->font
= s
->face
->font
;
4018 s
->width
= s
->first_glyph
->pixel_width
;
4020 /* Adjust base line for subscript/superscript text. */
4021 s
->ybase
+= s
->first_glyph
->voffset
;
4025 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4026 of XChar2b structures for S; it can't be allocated in
4027 x_init_glyph_string because it must be allocated via `alloca'. W
4028 is the window on which S is drawn. ROW and AREA are the glyph row
4029 and area within the row from which S is constructed. START is the
4030 index of the first glyph structure covered by S. HL is a
4031 face-override for drawing S. */
4034 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4035 struct glyph_string
*s
;
4038 struct glyph_row
*row
;
4039 enum glyph_row_area area
;
4041 enum draw_glyphs_face hl
;
4043 bzero (s
, sizeof *s
);
4045 s
->f
= XFRAME (w
->frame
);
4046 s
->display
= FRAME_X_DISPLAY (s
->f
);
4047 s
->window
= FRAME_X_WINDOW (s
->f
);
4052 s
->first_glyph
= row
->glyphs
[area
] + start
;
4053 s
->height
= row
->height
;
4054 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4056 /* Display the internal border below the toolbar window. */
4057 if (s
->w
== XWINDOW (s
->f
->toolbar_window
))
4058 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4060 s
->ybase
= s
->y
+ row
->ascent
;
4064 /* Set background width of glyph string S. START is the index of the
4065 first glyph following S. LAST_X is the right-most x-position + 1
4066 in the drawing area. */
4069 x_set_glyph_string_background_width (s
, start
, last_x
)
4070 struct glyph_string
*s
;
4074 /* If the face of this glyph string has to be drawn to the end of
4075 the drawing area, set S->extends_to_end_of_line_p. */
4076 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4078 if (start
== s
->row
->used
[s
->area
]
4079 && s
->hl
== DRAW_NORMAL_TEXT
4080 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4081 || s
->face
->background
!= default_face
->background
4082 || s
->face
->stipple
!= default_face
->stipple
))
4083 s
->extends_to_end_of_line_p
= 1;
4085 /* If S extends its face to the end of the line, set its
4086 background_width to the distance to the right edge of the drawing
4088 if (s
->extends_to_end_of_line_p
)
4089 s
->background_width
= last_x
- s
->x
+ 1;
4091 s
->background_width
= s
->width
;
4095 /* Add a glyph string for a stretch glyph to the list of strings
4096 between HEAD and TAIL. START is the index of the stretch glyph in
4097 row area AREA of glyph row ROW. END is the index of the last glyph
4098 in that glyph row area. X is the current output position assigned
4099 to the new glyph string constructed. HL overrides that face of the
4100 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4101 is the right-most x-position of the drawing area. */
4103 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, \
4107 s = (struct glyph_string *) alloca (sizeof *s); \
4108 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4109 x_fill_stretch_glyph_string (s); \
4110 x_append_glyph_string (&HEAD, &TAIL, s); \
4117 /* Add a glyph string for an image glyph to the list of strings
4118 between HEAD and TAIL. START is the index of the image glyph in
4119 row area AREA of glyph row ROW. END is the index of the last glyph
4120 in that glyph row area. X is the current output position assigned
4121 to the new glyph string constructed. HL overrides that face of the
4122 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4123 is the right-most x-position of the drawing area. */
4125 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, \
4129 s = (struct glyph_string *) alloca (sizeof *s); \
4130 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4131 x_fill_image_glyph_string (s); \
4132 x_append_glyph_string (&HEAD, &TAIL, s); \
4139 /* Add a glyph string for a sequence of character glyphs to the list
4140 of strings between HEAD and TAIL. START is the index of the first
4141 glyph in row area AREA of glyph row ROW that is part of the new
4142 glyph string. END is the index of the last glyph in that glyph row
4143 area. X is the current output position assigned to the new glyph
4144 string constructed. HL overrides that face of the glyph; e.g. it
4145 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4146 right-most x-position of the drawing area. */
4148 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, \
4149 X, LAST_X, OVERLAPS_P) \
4152 int c, charset, face_id; \
4155 c = (ROW)->glyphs[AREA][START].u.ch.code; \
4156 charset = CHAR_CHARSET (c); \
4157 face_id = (ROW)->glyphs[AREA][START].u.ch.face_id; \
4159 if (charset == CHARSET_COMPOSITION) \
4161 struct work *stack, *work, *new = NULL; \
4163 struct glyph_string *first_s = NULL; \
4165 /* Push an initial entry for character c on the stack. */ \
4167 work = (struct work *) alloca (sizeof *work); \
4168 work->cmpcharp = cmpchar_table[COMPOSITE_CHAR_ID (c)]; \
4170 work->next = stack; \
4173 /* While the stack is not empty, append glyph_strings \
4174 to head/tail for glyphs to draw. */ \
4177 s = (struct glyph_string *) alloca (sizeof *s); \
4178 char2b = (XChar2b *) alloca (stack->cmpcharp->glyph_len \
4179 * sizeof (XChar2b)); \
4180 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4181 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4182 s->cmpcharp = stack->cmpcharp; \
4183 s->gidx = stack->gidx; \
4184 s->charset = charset; \
4189 /* Don't draw the background except for the \
4190 first glyph string. */ \
4191 s->background_filled_p = n > 0; \
4197 new = (struct work *) alloca (sizeof *new); \
4198 x_fill_composite_glyph_string (s, face_id, &stack, \
4199 &new, OVERLAPS_P); \
4207 s = (struct glyph_string *) alloca (sizeof *s); \
4208 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4209 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4210 x_append_glyph_string (&HEAD, &TAIL, s); \
4211 s->charset = charset; \
4213 START = x_fill_glyph_string (s, face_id, START, END, \
4220 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4221 of AREA of glyph row ROW on window W between indices START and END.
4222 HL overrides the face for drawing glyph strings, e.g. it is
4223 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4224 x-positions of the drawing area.
4226 This is an ugly monster macro construct because we must use alloca
4227 to allocate glyph strings (because x_draw_glyphs can be called
4230 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, \
4231 X, LAST_X, OVERLAPS_P) \
4234 HEAD = TAIL = NULL; \
4235 while (START < END) \
4237 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4238 switch (first_glyph->type) \
4241 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4242 TAIL, HL, X, LAST_X, \
4246 case STRETCH_GLYPH: \
4247 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4248 HEAD, TAIL, HL, X, LAST_X); \
4252 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4253 TAIL, HL, X, LAST_X); \
4260 x_set_glyph_string_background_width (s, START, LAST_X); \
4267 /* Draw glyphs between START and END in AREA of ROW on window W,
4268 starting at x-position X. X is relative to AREA in W. HL is a
4269 face-override with the following meaning:
4271 DRAW_NORMAL_TEXT draw normally
4272 DRAW_CURSOR draw in cursor face
4273 DRAW_MOUSE_FACE draw in mouse face.
4274 DRAW_INVERSE_VIDEO draw in mode line face
4275 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4276 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4278 If REAL_START is non-null, return in *REAL_START the real starting
4279 position for display. This can be different from START in case
4280 overlapping glyphs must be displayed. If REAL_END is non-null,
4281 return in *REAL_END the real end position for display. This can be
4282 different from END in case overlapping glyphs must be displayed.
4284 If OVERLAPS_P is non-zero, draw only the foreground of characters
4285 and clip to the physical height of ROW.
4287 Value is the x-position reached, relative to AREA of W. */
4290 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4294 struct glyph_row
*row
;
4295 enum glyph_row_area area
;
4297 enum draw_glyphs_face hl
;
4298 int *real_start
, *real_end
;
4301 struct glyph_string
*head
, *tail
;
4302 struct glyph_string
*s
;
4303 int last_x
, area_width
;
4307 /* Let's rather be paranoid than getting a SEGV. */
4308 start
= max (0, start
);
4309 end
= min (end
, row
->used
[area
]);
4311 *real_start
= start
;
4315 /* Translate X to frame coordinates. Set last_x to the right
4316 end of the drawing area. */
4317 if (row
->full_width_p
)
4319 /* X is relative to the left edge of W, without scroll bars
4321 struct frame
*f
= XFRAME (w
->frame
);
4322 int width
= FRAME_FLAGS_AREA_WIDTH (f
);
4323 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4326 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4327 last_x
= window_left_x
+ area_width
;
4329 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4331 width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4332 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4338 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4339 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4343 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4344 area_width
= window_box_width (w
, area
);
4345 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4348 /* Build a doubly-linked list of glyph_string structures between
4349 head and tail from what we have to draw. Note that the macro
4350 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4351 the reason we use a separate variable `i'. */
4353 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4356 x_reached
= tail
->x
+ tail
->background_width
;
4360 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4361 the row, redraw some glyphs in front or following the glyph
4362 strings built above. */
4363 if (!overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4366 struct glyph_string
*h
, *t
;
4368 /* Compute overhangs for all glyph strings. */
4369 for (s
= head
; s
; s
= s
->next
)
4370 x_compute_glyph_string_overhangs (s
);
4372 /* Prepend glyph strings for glyphs in front of the first glyph
4373 string that are overwritten because of the first glyph
4374 string's left overhang. The background of all strings
4375 prepended must be drawn because the first glyph string
4377 i
= x_left_overwritten (head
);
4381 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4382 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4386 *real_start
= start
;
4387 x_compute_overhangs_and_x (t
, head
->x
, 1);
4388 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4391 /* Prepend glyph strings for glyphs in front of the first glyph
4392 string that overwrite that glyph string because of their
4393 right overhang. For these strings, only the foreground must
4394 be drawn, because it draws over the glyph string at `head'.
4395 The background must not be drawn because this would overwrite
4396 right overhangs of preceding glyphs for which no glyph
4398 i
= x_left_overwriting (head
);
4401 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4402 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4404 for (s
= h
; s
; s
= s
->next
)
4405 s
->background_filled_p
= 1;
4408 x_compute_overhangs_and_x (t
, head
->x
, 1);
4409 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4412 /* Append glyphs strings for glyphs following the last glyph
4413 string tail that are overwritten by tail. The background of
4414 these strings has to be drawn because tail's foreground draws
4416 i
= x_right_overwritten (tail
);
4419 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4420 DRAW_NORMAL_TEXT
, x
, last_x
,
4422 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4423 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4428 /* Append glyph strings for glyphs following the last glyph
4429 string tail that overwrite tail. The foreground of such
4430 glyphs has to be drawn because it writes into the background
4431 of tail. The background must not be drawn because it could
4432 paint over the foreground of following glyphs. */
4433 i
= x_right_overwriting (tail
);
4436 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4437 DRAW_NORMAL_TEXT
, x
, last_x
,
4439 for (s
= h
; s
; s
= s
->next
)
4440 s
->background_filled_p
= 1;
4441 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4442 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4448 /* Draw all strings. */
4449 for (s
= head
; s
; s
= s
->next
)
4450 x_draw_glyph_string (s
);
4452 /* Value is the x-position up to which drawn, relative to AREA of W.
4453 This doesn't include parts drawn because of overhangs. */
4454 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4455 if (!row
->full_width_p
)
4457 if (area
> LEFT_MARGIN_AREA
)
4458 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4459 if (area
> TEXT_AREA
)
4460 x_reached
-= window_box_width (w
, TEXT_AREA
);
4466 /* Fix the display of area AREA of overlapping row ROW in window W. */
4469 x_fix_overlapping_area (w
, row
, area
)
4471 struct glyph_row
*row
;
4472 enum glyph_row_area area
;
4478 if (area
== LEFT_MARGIN_AREA
)
4480 else if (area
== TEXT_AREA
)
4481 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4483 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4484 + window_box_width (w
, TEXT_AREA
));
4486 for (i
= 0; i
< row
->used
[area
];)
4488 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4490 int start
= i
, start_x
= x
;
4494 x
+= row
->glyphs
[area
][i
].pixel_width
;
4497 while (i
< row
->used
[area
]
4498 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4500 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4502 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4507 x
+= row
->glyphs
[area
][i
].pixel_width
;
4516 /* Output LEN glyphs starting at START at the nominal cursor position.
4517 Advance the nominal cursor over the text. The global variable
4518 updated_window contains the window being updated, updated_row is
4519 the glyph row being updated, and updated_area is the area of that
4520 row being updated. */
4523 x_write_glyphs (start
, len
)
4524 struct glyph
*start
;
4527 int x
, hpos
, real_start
, real_end
;
4529 xassert (updated_window
&& updated_row
);
4534 hpos
= start
- updated_row
->glyphs
[updated_area
];
4535 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4536 updated_row
, updated_area
,
4538 (updated_row
->inverse_p
4539 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4540 &real_start
, &real_end
, 0);
4542 /* If we drew over the cursor, note that it is not visible any more. */
4543 note_overwritten_text_cursor (updated_window
, real_start
,
4544 real_end
- real_start
);
4548 /* Advance the output cursor. */
4549 output_cursor
.hpos
+= len
;
4550 output_cursor
.x
= x
;
4554 /* Insert LEN glyphs from START at the nominal cursor position. */
4557 x_insert_glyphs (start
, len
)
4558 struct glyph
*start
;
4563 int line_height
, shift_by_width
, shifted_region_width
;
4564 struct glyph_row
*row
;
4565 struct glyph
*glyph
;
4566 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4568 xassert (updated_window
&& updated_row
);
4571 f
= XFRAME (WINDOW_FRAME (w
));
4573 /* Get the height of the line we are in. */
4575 line_height
= row
->height
;
4577 /* Get the width of the glyphs to insert. */
4579 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4580 shift_by_width
+= glyph
->pixel_width
;
4582 /* Get the width of the region to shift right. */
4583 shifted_region_width
= (window_box_width (w
, updated_area
)
4588 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4589 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4590 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4591 f
->output_data
.x
->normal_gc
,
4593 shifted_region_width
, line_height
,
4594 frame_x
+ shift_by_width
, frame_y
);
4596 /* Write the glyphs. */
4597 hpos
= start
- row
->glyphs
[updated_area
];
4598 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4599 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4600 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4602 /* Advance the output cursor. */
4603 output_cursor
.hpos
+= len
;
4604 output_cursor
.x
+= shift_by_width
;
4609 /* Delete N glyphs at the nominal cursor position. Not implemented
4620 /* Erase the current text line from the nominal cursor position
4621 (inclusive) to pixel column TO_X (exclusive). The idea is that
4622 everything from TO_X onward is already erased.
4624 TO_X is a pixel position relative to updated_area of
4625 updated_window. TO_X == -1 means clear to the end of this area. */
4628 x_clear_end_of_line (to_x
)
4632 struct window
*w
= updated_window
;
4633 int max_x
, min_y
, max_y
;
4634 int from_x
, from_y
, to_y
;
4636 xassert (updated_window
&& updated_row
);
4637 f
= XFRAME (w
->frame
);
4639 if (updated_row
->full_width_p
)
4641 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4642 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4643 && !w
->pseudo_window_p
)
4644 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4647 max_x
= window_box_width (w
, updated_area
);
4648 max_y
= window_text_bottom_y (w
);
4650 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
4651 of window. For TO_X > 0, truncate to end of drawing area. */
4657 to_x
= min (to_x
, max_x
);
4659 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
4661 /* Notice if the cursor will be cleared by this operation. */
4662 if (!updated_row
->full_width_p
)
4663 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
4665 from_x
= output_cursor
.x
;
4667 /* Translate to frame coordinates. */
4668 if (updated_row
->full_width_p
)
4670 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
4671 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
4675 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
4676 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
4679 min_y
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
4680 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
4681 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
4683 /* Prevent inadvertently clearing to end of the X window. */
4684 if (to_x
> from_x
&& to_y
> from_y
)
4687 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4688 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
4695 /* Clear entire frame. If updating_frame is non-null, clear that
4696 frame. Otherwise clear selected_frame. */
4708 /* Clearing the frame will erase any cursor, so mark them all as no
4710 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4711 output_cursor
.hpos
= output_cursor
.vpos
= 0;
4712 output_cursor
.x
= -1;
4714 /* We don't set the output cursor here because there will always
4715 follow an explicit cursor_to. */
4717 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
4719 /* We have to clear the scroll bars, too. If we have changed
4720 colors or something like that, then they should be notified. */
4721 x_scroll_bar_clear (f
);
4723 XFlush (FRAME_X_DISPLAY (f
));
4729 /* Invert the middle quarter of the frame for .15 sec. */
4731 /* We use the select system call to do the waiting, so we have to make
4732 sure it's available. If it isn't, we just won't do visual bells. */
4734 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4737 /* Subtract the `struct timeval' values X and Y, storing the result in
4738 *RESULT. Return 1 if the difference is negative, otherwise 0. */
4741 timeval_subtract (result
, x
, y
)
4742 struct timeval
*result
, x
, y
;
4744 /* Perform the carry for the later subtraction by updating y. This
4745 is safer because on some systems the tv_sec member is unsigned. */
4746 if (x
.tv_usec
< y
.tv_usec
)
4748 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
4749 y
.tv_usec
-= 1000000 * nsec
;
4753 if (x
.tv_usec
- y
.tv_usec
> 1000000)
4755 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
4756 y
.tv_usec
+= 1000000 * nsec
;
4760 /* Compute the time remaining to wait. tv_usec is certainly
4762 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
4763 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
4765 /* Return indication of whether the result should be considered
4767 return x
.tv_sec
< y
.tv_sec
;
4779 /* Create a GC that will use the GXxor function to flip foreground
4780 pixels into background pixels. */
4784 values
.function
= GXxor
;
4785 values
.foreground
= (f
->output_data
.x
->foreground_pixel
4786 ^ f
->output_data
.x
->background_pixel
);
4788 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4789 GCFunction
| GCForeground
, &values
);
4793 /* Get the height not including a menu bar widget. */
4794 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
4795 /* Height of each line to flash. */
4796 int flash_height
= FRAME_LINE_HEIGHT (f
);
4797 /* These will be the left and right margins of the rectangles. */
4798 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
4799 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
4803 /* Don't flash the area between a scroll bar and the frame
4804 edge it is next to. */
4805 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
4807 case vertical_scroll_bar_left
:
4808 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
4811 case vertical_scroll_bar_right
:
4812 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
4819 width
= flash_right
- flash_left
;
4821 /* If window is tall, flash top and bottom line. */
4822 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4824 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4826 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4827 + FRAME_TOOLBAR_LINES (f
) * CANON_Y_UNIT (f
)),
4828 width
, flash_height
);
4829 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4831 (height
- flash_height
4832 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4833 width
, flash_height
);
4836 /* If it is short, flash it all. */
4837 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4838 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4839 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4844 struct timeval wakeup
;
4846 EMACS_GET_TIME (wakeup
);
4848 /* Compute time to wait until, propagating carry from usecs. */
4849 wakeup
.tv_usec
+= 150000;
4850 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
4851 wakeup
.tv_usec
%= 1000000;
4853 /* Keep waiting until past the time wakeup. */
4856 struct timeval timeout
;
4858 EMACS_GET_TIME (timeout
);
4860 /* In effect, timeout = wakeup - timeout.
4861 Break if result would be negative. */
4862 if (timeval_subtract (&timeout
, wakeup
, timeout
))
4865 /* Try to wait that long--but we might wake up sooner. */
4866 select (0, NULL
, NULL
, NULL
, &timeout
);
4870 /* If window is tall, flash top and bottom line. */
4871 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4873 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4875 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4876 + FRAME_TOOLBAR_LINES (f
) * CANON_Y_UNIT (f
)),
4877 width
, flash_height
);
4878 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4880 (height
- flash_height
4881 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4882 width
, flash_height
);
4885 /* If it is short, flash it all. */
4886 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4887 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4888 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4890 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
4898 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
4901 /* Make audible bell. */
4903 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
4908 if (FRAME_X_DISPLAY (selected_frame
) == 0)
4911 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4913 XTflash (selected_frame
);
4919 XFlush (FRAME_X_DISPLAY (selected_frame
));
4925 /* Specify how many text lines, from the top of the window,
4926 should be affected by insert-lines and delete-lines operations.
4927 This, and those operations, are used only within an update
4928 that is bounded by calls to x_update_begin and x_update_end. */
4931 XTset_terminal_window (n
)
4934 /* This function intentionally left blank. */
4939 /***********************************************************************
4941 ***********************************************************************/
4943 /* Perform an insert-lines or delete-lines operation, inserting N
4944 lines or deleting -N lines at vertical position VPOS. */
4947 x_ins_del_lines (vpos
, n
)
4954 /* Scroll part of the display as described by RUN. */
4957 x_scroll_run (w
, run
)
4961 struct frame
*f
= XFRAME (w
->frame
);
4962 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
4964 /* Get frame-relative bounding box of the text display area of W,
4965 without mode lines. Include in this box the flags areas to the
4966 left and right of W. */
4967 window_box (w
, -1, &x
, &y
, &width
, &height
);
4968 width
+= 2 * FRAME_X_FLAGS_AREA_WIDTH (f
);
4969 x
-= FRAME_X_FLAGS_AREA_WIDTH (f
);
4971 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
4972 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
4973 bottom_y
= y
+ height
;
4977 /* Scrolling up. Make sure we don't copy part of the mode
4978 line at the bottom. */
4979 if (from_y
+ run
->height
> bottom_y
)
4980 height
= bottom_y
- from_y
;
4982 height
= run
->height
;
4986 /* Scolling down. Make sure we don't copy over the mode line.
4988 if (to_y
+ run
->height
> bottom_y
)
4989 height
= bottom_y
- to_y
;
4991 height
= run
->height
;
4996 /* Cursor off. Will be switched on again in x_update_window_end. */
5000 XCopyArea (FRAME_X_DISPLAY (f
),
5001 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5002 f
->output_data
.x
->normal_gc
,
5012 /***********************************************************************
5014 ***********************************************************************/
5016 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5017 corner of the exposed rectangle. W and H are width and height of
5018 the exposed area. All are pixel values. W or H zero means redraw
5019 the entire frame. */
5022 expose_frame (f
, x
, y
, w
, h
)
5028 TRACE ((stderr
, "expose_frame "));
5030 /* No need to redraw if frame will be redrawn soon. */
5031 if (FRAME_GARBAGED_P (f
))
5033 TRACE ((stderr
, " garbaged\n"));
5037 /* If basic faces haven't been realized yet, there is no point in
5038 trying to redraw anything. This can happen when we get an expose
5039 event while Emacs is starting, e.g. by moving another window. */
5040 if (FRAME_FACE_CACHE (f
) == NULL
5041 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5043 TRACE ((stderr
, " no faces\n"));
5047 if (w
== 0 || h
== 0)
5050 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5051 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5061 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5062 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5064 if (WINDOWP (f
->toolbar_window
))
5066 struct window
*w
= XWINDOW (f
->toolbar_window
);
5067 XRectangle window_rect
;
5068 XRectangle intersection_rect
;
5069 int window_x
, window_y
, window_width
, window_height
;
5072 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5073 window_rect
.x
= window_x
;
5074 window_rect
.y
= window_y
;
5075 window_rect
.width
= window_width
;
5076 window_rect
.height
= window_height
;
5078 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5079 expose_window (w
, &intersection_rect
);
5082 #ifndef USE_X_TOOLKIT
5083 if (WINDOWP (f
->menu_bar_window
))
5085 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5086 XRectangle window_rect
;
5087 XRectangle intersection_rect
;
5088 int window_x
, window_y
, window_width
, window_height
;
5091 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5092 window_rect
.x
= window_x
;
5093 window_rect
.y
= window_y
;
5094 window_rect
.width
= window_width
;
5095 window_rect
.height
= window_height
;
5097 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5098 expose_window (w
, &intersection_rect
);
5100 #endif /* not USE_X_TOOLKIT */
5104 /* Redraw (parts) of all windows in the window tree rooted at W that
5105 intersect R. R contains frame pixel coordinates. */
5108 expose_window_tree (w
, r
)
5114 if (!NILP (w
->hchild
))
5115 expose_window_tree (XWINDOW (w
->hchild
), r
);
5116 else if (!NILP (w
->vchild
))
5117 expose_window_tree (XWINDOW (w
->vchild
), r
);
5120 XRectangle window_rect
;
5121 XRectangle intersection_rect
;
5122 struct frame
*f
= XFRAME (w
->frame
);
5123 int window_x
, window_y
, window_width
, window_height
;
5125 /* Frame-relative pixel rectangle of W. */
5126 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5130 - FRAME_X_FLAGS_AREA_WIDTH (f
)
5131 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_Y_UNIT (f
));
5132 window_rect
.y
= window_y
;
5135 + 2 * FRAME_X_FLAGS_AREA_WIDTH (f
)
5136 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5138 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5140 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5141 expose_window (w
, &intersection_rect
);
5144 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5149 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5150 which intersects rectangle R. R is in window-relative coordinates. */
5153 expose_area (w
, row
, r
, area
)
5155 struct glyph_row
*row
;
5157 enum glyph_row_area area
;
5160 struct glyph
*first
= row
->glyphs
[area
];
5161 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5165 /* Set x to the window-relative start position for drawing glyphs of
5166 AREA. The first glyph of the text area can be partially visible.
5167 The first glyphs of other areas cannot. */
5168 if (area
== LEFT_MARGIN_AREA
)
5170 else if (area
== TEXT_AREA
)
5171 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5173 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5174 + window_box_width (w
, TEXT_AREA
));
5176 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5177 /* If row extends face to end of line write the whole line. */
5178 x_draw_glyphs (w
, x
, row
, area
,
5180 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5184 /* Find the first glyph that must be redrawn. */
5186 && x
+ first
->pixel_width
< r
->x
)
5188 x
+= first
->pixel_width
;
5192 /* Find the last one. */
5196 && x
< r
->x
+ r
->width
)
5198 x
+= last
->pixel_width
;
5204 x_draw_glyphs (w
, first_x
, row
, area
,
5205 first
- row
->glyphs
[area
],
5206 last
- row
->glyphs
[area
],
5207 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5213 /* Redraw the parts of the glyph row ROW on window W intersecting
5214 rectangle R. R is in window-relative coordinates. */
5217 expose_line (w
, row
, r
)
5219 struct glyph_row
*row
;
5222 xassert (row
->enabled_p
);
5224 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5225 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5226 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5230 if (row
->used
[LEFT_MARGIN_AREA
])
5231 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5232 if (row
->used
[TEXT_AREA
])
5233 expose_area (w
, row
, r
, TEXT_AREA
);
5234 if (row
->used
[RIGHT_MARGIN_AREA
])
5235 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5236 x_draw_row_bitmaps (w
, row
);
5241 /* Return non-zero if W's cursor intersects rectangle R. */
5244 x_phys_cursor_in_rect_p (w
, r
)
5248 XRectangle cr
, result
;
5249 struct glyph
*cursor_glyph
;
5251 cursor_glyph
= get_phys_cursor_glyph (w
);
5254 cr
.x
= w
->phys_cursor
.x
;
5255 cr
.y
= w
->phys_cursor
.y
;
5256 cr
.width
= cursor_glyph
->pixel_width
;
5257 cr
.height
= w
->phys_cursor_height
;
5258 return x_intersect_rectangles (&cr
, r
, &result
);
5265 /* Redraw a rectangle of window W. R is a rectangle in window
5266 relative coordinates. Call this function with input blocked. */
5269 expose_window (w
, r
)
5273 struct glyph_row
*row
;
5275 int yb
= window_text_bottom_y (w
);
5276 int cursor_cleared_p
;
5278 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5279 r
->x
, r
->y
, r
->width
, r
->height
));
5281 /* Convert to window coordinates. */
5282 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5283 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5285 /* Turn off the cursor. */
5286 if (!w
->pseudo_window_p
5287 && x_phys_cursor_in_rect_p (w
, r
))
5290 cursor_cleared_p
= 1;
5293 cursor_cleared_p
= 0;
5295 /* Find the first row intersecting the rectangle R. */
5296 row
= w
->current_matrix
->rows
;
5298 while (row
->enabled_p
5300 && y
+ row
->height
< r
->y
)
5306 /* Display the text in the rectangle, one text line at a time. */
5307 while (row
->enabled_p
5309 && y
< r
->y
+ r
->height
)
5311 expose_line (w
, row
, r
);
5316 /* Display the mode line if there is one. */
5317 if (WINDOW_WANTS_MODELINE_P (w
)
5318 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5320 && row
->y
< r
->y
+ r
->height
)
5321 expose_line (w
, row
, r
);
5323 if (!w
->pseudo_window_p
)
5325 /* Draw border between windows. */
5326 x_draw_vertical_border (w
);
5328 /* Turn the cursor on again. */
5329 if (cursor_cleared_p
)
5330 x_update_window_cursor (w
, 1);
5335 /* Determine the intersection of two rectangles R1 and R2. Return
5336 the intersection in *RESULT. Value is non-zero if RESULT is not
5340 x_intersect_rectangles (r1
, r2
, result
)
5341 XRectangle
*r1
, *r2
, *result
;
5343 XRectangle
*left
, *right
;
5344 XRectangle
*upper
, *lower
;
5345 int intersection_p
= 0;
5347 /* Rearrange so that R1 is the left-most rectangle. */
5349 left
= r1
, right
= r2
;
5351 left
= r2
, right
= r1
;
5353 /* X0 of the intersection is right.x0, if this is inside R1,
5354 otherwise there is no intersection. */
5355 if (right
->x
<= left
->x
+ left
->width
)
5357 result
->x
= right
->x
;
5359 /* The right end of the intersection is the minimum of the
5360 the right ends of left and right. */
5361 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5364 /* Same game for Y. */
5366 upper
= r1
, lower
= r2
;
5368 upper
= r2
, lower
= r1
;
5370 /* The upper end of the intersection is lower.y0, if this is inside
5371 of upper. Otherwise, there is no intersection. */
5372 if (lower
->y
<= upper
->y
+ upper
->height
)
5374 result
->y
= lower
->y
;
5376 /* The lower end of the intersection is the minimum of the lower
5377 ends of upper and lower. */
5378 result
->height
= (min (lower
->y
+ lower
->height
,
5379 upper
->y
+ upper
->height
)
5385 return intersection_p
;
5396 /* We used to only do this if Vx_no_window_manager was non-nil, but
5397 the ICCCM (section 4.1.6) says that the window's border pixmap
5398 and border pixel are window attributes which are "private to the
5399 client", so we can always change it to whatever we want. */
5401 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5402 f
->output_data
.x
->border_pixel
);
5404 x_update_cursor (f
, 1);
5408 frame_unhighlight (f
)
5411 /* We used to only do this if Vx_no_window_manager was non-nil, but
5412 the ICCCM (section 4.1.6) says that the window's border pixmap
5413 and border pixel are window attributes which are "private to the
5414 client", so we can always change it to whatever we want. */
5416 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5417 f
->output_data
.x
->border_tile
);
5419 x_update_cursor (f
, 1);
5422 /* The focus has changed. Update the frames as necessary to reflect
5423 the new situation. Note that we can't change the selected frame
5424 here, because the Lisp code we are interrupting might become confused.
5425 Each event gets marked with the frame in which it occurred, so the
5426 Lisp code can tell when the switch took place by examining the events. */
5429 x_new_focus_frame (dpyinfo
, frame
)
5430 struct x_display_info
*dpyinfo
;
5431 struct frame
*frame
;
5433 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5435 if (frame
!= dpyinfo
->x_focus_frame
)
5437 /* Set this before calling other routines, so that they see
5438 the correct value of x_focus_frame. */
5439 dpyinfo
->x_focus_frame
= frame
;
5441 if (old_focus
&& old_focus
->auto_lower
)
5442 x_lower_frame (old_focus
);
5445 selected_frame
= frame
;
5446 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5448 Fselect_window (selected_frame
->selected_window
);
5449 choose_minibuf_frame ();
5452 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5453 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5455 pending_autoraise_frame
= 0;
5458 x_frame_rehighlight (dpyinfo
);
5461 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5464 x_mouse_leave (dpyinfo
)
5465 struct x_display_info
*dpyinfo
;
5467 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5470 /* The focus has changed, or we have redirected a frame's focus to
5471 another frame (this happens when a frame uses a surrogate
5472 mini-buffer frame). Shift the highlight as appropriate.
5474 The FRAME argument doesn't necessarily have anything to do with which
5475 frame is being highlighted or un-highlighted; we only use it to find
5476 the appropriate X display info. */
5479 XTframe_rehighlight (frame
)
5480 struct frame
*frame
;
5482 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5486 x_frame_rehighlight (dpyinfo
)
5487 struct x_display_info
*dpyinfo
;
5489 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5491 if (dpyinfo
->x_focus_frame
)
5493 dpyinfo
->x_highlight_frame
5494 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5495 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5496 : dpyinfo
->x_focus_frame
);
5497 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5499 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5500 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5504 dpyinfo
->x_highlight_frame
= 0;
5506 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5509 frame_unhighlight (old_highlight
);
5510 if (dpyinfo
->x_highlight_frame
)
5511 frame_highlight (dpyinfo
->x_highlight_frame
);
5517 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5519 /* Initialize mode_switch_bit and modifier_meaning. */
5521 x_find_modifier_meanings (dpyinfo
)
5522 struct x_display_info
*dpyinfo
;
5524 int min_code
, max_code
;
5527 XModifierKeymap
*mods
;
5529 dpyinfo
->meta_mod_mask
= 0;
5530 dpyinfo
->shift_lock_mask
= 0;
5531 dpyinfo
->alt_mod_mask
= 0;
5532 dpyinfo
->super_mod_mask
= 0;
5533 dpyinfo
->hyper_mod_mask
= 0;
5536 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5538 min_code
= dpyinfo
->display
->min_keycode
;
5539 max_code
= dpyinfo
->display
->max_keycode
;
5542 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5543 min_code
, max_code
- min_code
+ 1,
5545 mods
= XGetModifierMapping (dpyinfo
->display
);
5547 /* Scan the modifier table to see which modifier bits the Meta and
5548 Alt keysyms are on. */
5550 int row
, col
; /* The row and column in the modifier table. */
5552 for (row
= 3; row
< 8; row
++)
5553 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5556 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5558 /* Zeroes are used for filler. Skip them. */
5562 /* Are any of this keycode's keysyms a meta key? */
5566 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5568 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5574 dpyinfo
->meta_mod_mask
|= (1 << row
);
5579 dpyinfo
->alt_mod_mask
|= (1 << row
);
5584 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5589 dpyinfo
->super_mod_mask
|= (1 << row
);
5593 /* Ignore this if it's not on the lock modifier. */
5594 if ((1 << row
) == LockMask
)
5595 dpyinfo
->shift_lock_mask
= LockMask
;
5603 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5604 if (! dpyinfo
->meta_mod_mask
)
5606 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
5607 dpyinfo
->alt_mod_mask
= 0;
5610 /* If some keys are both alt and meta,
5611 make them just meta, not alt. */
5612 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
5614 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
5617 XFree ((char *) syms
);
5618 XFreeModifiermap (mods
);
5621 /* Convert between the modifier bits X uses and the modifier bits
5625 x_x_to_emacs_modifiers (dpyinfo
, state
)
5626 struct x_display_info
*dpyinfo
;
5629 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
5630 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
5631 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
5632 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
5633 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
5634 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
5638 x_emacs_to_x_modifiers (dpyinfo
, state
)
5639 struct x_display_info
*dpyinfo
;
5642 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
5643 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
5644 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
5645 | ((state
& shift_modifier
) ? ShiftMask
: 0)
5646 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
5647 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
5650 /* Convert a keysym to its name. */
5653 x_get_keysym_name (keysym
)
5659 value
= XKeysymToString (keysym
);
5667 /* Mouse clicks and mouse movement. Rah. */
5669 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5670 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5671 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5672 not force the value into range. */
5675 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5677 register int pix_x
, pix_y
;
5678 register int *x
, *y
;
5682 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5683 even for negative values. */
5685 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
5687 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
5689 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5690 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5694 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
5695 bounds
->height
= f
->output_data
.x
->line_height
;
5696 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5697 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5704 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5705 pix_x
= FRAME_WINDOW_WIDTH (f
);
5709 else if (pix_y
> f
->height
)
5718 /* Given HPOS/VPOS in the current matrix of W, return corresponding
5719 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
5720 can't tell the positions because W's display is not up to date,
5724 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
5727 int *frame_x
, *frame_y
;
5731 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
5732 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
5734 if (display_completed
)
5736 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
5737 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
5738 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
5744 *frame_x
+= glyph
->pixel_width
;
5752 *frame_y
= *frame_x
= 0;
5756 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
5757 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
5762 /* Prepare a mouse-event in *RESULT for placement in the input queue.
5764 If the event is a button press, then note that we have grabbed
5768 construct_mouse_click (result
, event
, f
)
5769 struct input_event
*result
;
5770 XButtonEvent
*event
;
5773 /* Make the event type no_event; we'll change that when we decide
5775 result
->kind
= mouse_click
;
5776 result
->code
= event
->button
- Button1
;
5777 result
->timestamp
= event
->time
;
5778 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
5780 | (event
->type
== ButtonRelease
5784 XSETINT (result
->x
, event
->x
);
5785 XSETINT (result
->y
, event
->y
);
5786 XSETFRAME (result
->frame_or_window
, f
);
5790 #if 0 /* This function isn't called. --gerd */
5792 /* Prepare a menu-event in *RESULT for placement in the input queue. */
5795 construct_menu_click (result
, event
, f
)
5796 struct input_event
*result
;
5797 XButtonEvent
*event
;
5800 /* Make the event type no_event; we'll change that when we decide
5802 result
->kind
= mouse_click
;
5803 result
->code
= event
->button
- Button1
;
5804 result
->timestamp
= event
->time
;
5805 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
5807 | (event
->type
== ButtonRelease
5811 XSETINT (result
->x
, event
->x
);
5812 XSETINT (result
->y
, -1);
5813 XSETFRAME (result
->frame_or_window
, f
);
5819 /* Function to report a mouse movement to the mainstream Emacs code.
5820 The input handler calls this.
5822 We have received a mouse movement event, which is given in *event.
5823 If the mouse is over a different glyph than it was last time, tell
5824 the mainstream emacs code by setting mouse_moved. If not, ask for
5825 another motion event, so we can check again the next time it moves. */
5827 static XMotionEvent last_mouse_motion_event
;
5828 static Lisp_Object last_mouse_motion_frame
;
5831 note_mouse_movement (frame
, event
)
5833 XMotionEvent
*event
;
5835 last_mouse_movement_time
= event
->time
;
5836 last_mouse_motion_event
= *event
;
5837 XSETFRAME (last_mouse_motion_frame
, frame
);
5839 if (event
->window
!= FRAME_X_WINDOW (frame
))
5841 frame
->mouse_moved
= 1;
5842 last_mouse_scroll_bar
= Qnil
;
5843 note_mouse_highlight (frame
, -1, -1);
5846 /* Has the mouse moved off the glyph it was on at the last sighting? */
5847 else if (event
->x
< last_mouse_glyph
.x
5848 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
5849 || event
->y
< last_mouse_glyph
.y
5850 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
5852 frame
->mouse_moved
= 1;
5853 last_mouse_scroll_bar
= Qnil
;
5854 note_mouse_highlight (frame
, event
->x
, event
->y
);
5858 /* This is used for debugging, to turn off note_mouse_highlight. */
5860 int disable_mouse_highlight
;
5864 /************************************************************************
5866 ************************************************************************/
5868 /* Find the glyph under window-relative coordinates X/Y in window W.
5869 Consider only glyphs from buffer text, i.e. no glyphs from overlay
5870 strings. Return in *HPOS and *VPOS the row and column number of
5871 the glyph found. Return in *AREA the glyph area containing X.
5872 Value is a pointer to the glyph found or null if X/Y is not on
5873 text, or we can't tell because W's current matrix is not up to
5876 static struct glyph
*
5877 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
5880 int *hpos
, *vpos
, *area
;
5882 struct glyph
*glyph
, *end
;
5883 struct glyph_row
*row
;
5884 int x0
, i
, left_area_width
;
5886 /* Find row containing Y. Give up if some row is not enabled. */
5887 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
5889 row
= MATRIX_ROW (w
->current_matrix
, i
);
5890 if (!row
->enabled_p
)
5892 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
5899 /* Give up if Y is not in the window. */
5900 if (i
== w
->current_matrix
->nrows
)
5903 /* Get the glyph area containing X. */
5904 if (w
->pseudo_window_p
)
5911 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5912 if (x
< left_area_width
)
5914 *area
= LEFT_MARGIN_AREA
;
5917 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
5920 x0
= row
->x
+ left_area_width
;
5924 *area
= RIGHT_MARGIN_AREA
;
5925 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
5929 /* Find glyph containing X. */
5930 glyph
= row
->glyphs
[*area
];
5931 end
= glyph
+ row
->used
[*area
];
5934 if (x
< x0
+ glyph
->pixel_width
)
5936 if (w
->pseudo_window_p
)
5938 else if (BUFFERP (glyph
->object
))
5942 x0
+= glyph
->pixel_width
;
5949 *hpos
= glyph
- row
->glyphs
[*area
];
5954 /* Convert frame-relative x/y to coordinates relative to window W.
5955 Takes pseudo-windows into account. */
5958 frame_to_window_pixel_xy (w
, x
, y
)
5962 if (w
->pseudo_window_p
)
5964 /* A pseudo-window is always full-width, and starts at the
5965 left edge of the frame, plus a frame border. */
5966 struct frame
*f
= XFRAME (w
->frame
);
5967 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
5968 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
5972 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
5973 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
5978 /* Take proper action when mouse has moved to the mode or top line of
5979 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
5980 mode line. X is relative to the start of the text display area of
5981 W, so the width of bitmap areas and scroll bars must be subtracted
5982 to get a position relative to the start of the mode line. */
5985 note_mode_line_highlight (w
, x
, mode_line_p
)
5989 struct frame
*f
= XFRAME (w
->frame
);
5990 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5991 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
5992 struct glyph_row
*row
;
5995 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
5997 row
= MATRIX_TOP_LINE_ROW (w
->current_matrix
);
6001 struct glyph
*glyph
, *end
;
6002 Lisp_Object help
, map
;
6005 /* Find the glyph under X. */
6006 glyph
= row
->glyphs
[TEXT_AREA
];
6007 end
= glyph
+ row
->used
[TEXT_AREA
];
6008 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6009 + FRAME_X_FLAGS_AREA_WIDTH (f
));
6011 && x
>= x0
+ glyph
->pixel_width
)
6013 x0
+= glyph
->pixel_width
;
6018 && STRINGP (glyph
->object
)
6019 && XSTRING (glyph
->object
)->intervals
6020 && glyph
->charpos
>= 0
6021 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6023 /* If we're on a string with `help-echo' text property,
6024 arrange for the help to be displayed. This is done by
6025 setting the global variable help_echo to the help string. */
6026 help
= Fget_text_property (make_number (glyph
->charpos
),
6027 Qhelp_echo
, glyph
->object
);
6031 /* Change the mouse pointer according to what is under X/Y. */
6032 map
= Fget_text_property (make_number (glyph
->charpos
),
6033 Qlocal_map
, glyph
->object
);
6034 if (!NILP (Fkeymapp (map
)))
6035 cursor
= f
->output_data
.x
->nontext_cursor
;
6039 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6043 /* Take proper action when the mouse has moved to position X, Y on
6044 frame F as regards highlighting characters that have mouse-face
6045 properties. Also de-highlighting chars where the mouse was before.
6046 X and Y can be negative or out of range. */
6049 note_mouse_highlight (f
, x
, y
)
6053 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6058 /* When a menu is active, don't highlight because this looks odd. */
6059 #ifdef USE_X_TOOLKIT
6060 if (popup_activated ())
6064 if (disable_mouse_highlight
)
6067 dpyinfo
->mouse_face_mouse_x
= x
;
6068 dpyinfo
->mouse_face_mouse_y
= y
;
6069 dpyinfo
->mouse_face_mouse_frame
= f
;
6071 if (dpyinfo
->mouse_face_defer
)
6076 dpyinfo
->mouse_face_deferred_gc
= 1;
6080 /* Which window is that in? */
6081 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6083 /* If we were displaying active text in another window, clear that. */
6084 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6085 clear_mouse_face (dpyinfo
);
6087 /* Not on a window -> return. */
6088 if (!WINDOWP (window
))
6091 /* Convert to window-relative pixel coordinates. */
6092 w
= XWINDOW (window
);
6093 frame_to_window_pixel_xy (w
, &x
, &y
);
6095 /* Handle toolbar window differently since it doesn't display a
6097 if (EQ (window
, f
->toolbar_window
))
6099 note_toolbar_highlight (f
, x
, y
);
6103 if (portion
== 1 || portion
== 3)
6105 /* Mouse is on the mode or top line. */
6106 note_mode_line_highlight (w
, x
, portion
== 1);
6110 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6111 f
->output_data
.x
->text_cursor
);
6113 /* Are we in a window whose display is up to date?
6114 And verify the buffer's text has not changed. */
6115 if (/* Within text portion of the window. */
6117 && EQ (w
->window_end_valid
, w
->buffer
)
6118 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6119 && (XFASTINT (w
->last_overlay_modified
)
6120 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6122 int hpos
, vpos
, pos
, i
, area
;
6123 struct glyph
*glyph
;
6125 /* Find the glyph under X/Y. */
6126 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6128 /* Clear mouse face if X/Y not over text. */
6130 || area
!= TEXT_AREA
6131 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6133 clear_mouse_face (dpyinfo
);
6137 pos
= glyph
->charpos
;
6138 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6140 /* Check for mouse-face and help-echo. */
6142 Lisp_Object mouse_face
, overlay
, position
;
6143 Lisp_Object
*overlay_vec
;
6145 struct buffer
*obuf
;
6148 /* If we get an out-of-range value, return now; avoid an error. */
6149 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6152 /* Make the window's buffer temporarily current for
6153 overlays_at and compute_char_face. */
6154 obuf
= current_buffer
;
6155 current_buffer
= XBUFFER (w
->buffer
);
6161 /* Is this char mouse-active or does it have help-echo? */
6162 XSETINT (position
, pos
);
6164 /* Put all the overlays we want in a vector in overlay_vec.
6165 Store the length in len. If there are more than 10, make
6166 enough space for all, and try again. */
6168 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6169 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6170 if (noverlays
> len
)
6173 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6174 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6177 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6179 /* Check mouse-face highlighting. */
6180 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6181 && vpos
>= dpyinfo
->mouse_face_beg_row
6182 && vpos
<= dpyinfo
->mouse_face_end_row
6183 && (vpos
> dpyinfo
->mouse_face_beg_row
6184 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6185 && (vpos
< dpyinfo
->mouse_face_end_row
6186 || hpos
< dpyinfo
->mouse_face_end_col
6187 || dpyinfo
->mouse_face_past_end
)))
6189 /* Clear the display of the old active region, if any. */
6190 clear_mouse_face (dpyinfo
);
6192 /* Find the highest priority overlay that has a mouse-face prop. */
6194 for (i
= 0; i
< noverlays
; i
++)
6196 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6197 if (!NILP (mouse_face
))
6199 overlay
= overlay_vec
[i
];
6204 /* If no overlay applies, get a text property. */
6206 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6208 /* Handle the overlay case. */
6209 if (! NILP (overlay
))
6211 /* Find the range of text around this char that
6212 should be active. */
6213 Lisp_Object before
, after
;
6216 before
= Foverlay_start (overlay
);
6217 after
= Foverlay_end (overlay
);
6218 /* Record this as the current active region. */
6219 fast_find_position (w
, XFASTINT (before
),
6220 &dpyinfo
->mouse_face_beg_col
,
6221 &dpyinfo
->mouse_face_beg_row
,
6222 &dpyinfo
->mouse_face_beg_x
,
6223 &dpyinfo
->mouse_face_beg_y
);
6224 dpyinfo
->mouse_face_past_end
6225 = !fast_find_position (w
, XFASTINT (after
),
6226 &dpyinfo
->mouse_face_end_col
,
6227 &dpyinfo
->mouse_face_end_row
,
6228 &dpyinfo
->mouse_face_end_x
,
6229 &dpyinfo
->mouse_face_end_y
);
6230 dpyinfo
->mouse_face_window
= window
;
6231 dpyinfo
->mouse_face_face_id
6232 = face_at_buffer_position (w
, pos
, 0, 0,
6233 &ignore
, pos
+ 1, 1);
6235 /* Display it as active. */
6236 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6238 /* Handle the text property case. */
6239 else if (! NILP (mouse_face
))
6241 /* Find the range of text around this char that
6242 should be active. */
6243 Lisp_Object before
, after
, beginning
, end
;
6246 beginning
= Fmarker_position (w
->start
);
6247 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6248 - XFASTINT (w
->window_end_pos
)));
6250 = Fprevious_single_property_change (make_number (pos
+ 1),
6252 w
->buffer
, beginning
);
6254 = Fnext_single_property_change (position
, Qmouse_face
,
6256 /* Record this as the current active region. */
6257 fast_find_position (w
, XFASTINT (before
),
6258 &dpyinfo
->mouse_face_beg_col
,
6259 &dpyinfo
->mouse_face_beg_row
,
6260 &dpyinfo
->mouse_face_beg_x
,
6261 &dpyinfo
->mouse_face_beg_y
);
6262 dpyinfo
->mouse_face_past_end
6263 = !fast_find_position (w
, XFASTINT (after
),
6264 &dpyinfo
->mouse_face_end_col
,
6265 &dpyinfo
->mouse_face_end_row
,
6266 &dpyinfo
->mouse_face_end_x
,
6267 &dpyinfo
->mouse_face_end_y
);
6268 dpyinfo
->mouse_face_window
= window
;
6269 dpyinfo
->mouse_face_face_id
6270 = face_at_buffer_position (w
, pos
, 0, 0,
6271 &ignore
, pos
+ 1, 1);
6273 /* Display it as active. */
6274 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6278 /* Look for a `help-echo' property. */
6282 /* Check overlays first. */
6284 for (i
= 0; i
< noverlays
&& !STRINGP (help
); ++i
)
6285 help
= Foverlay_get (overlay_vec
[i
], Qhelp_echo
);
6287 /* Try text properties. */
6289 && ((STRINGP (glyph
->object
)
6290 && glyph
->charpos
>= 0
6291 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6292 || (BUFFERP (glyph
->object
)
6293 && glyph
->charpos
>= BEGV
6294 && glyph
->charpos
< ZV
)))
6295 help
= Fget_text_property (make_number (glyph
->charpos
),
6296 Qhelp_echo
, glyph
->object
);
6304 current_buffer
= obuf
;
6310 redo_mouse_highlight ()
6312 if (!NILP (last_mouse_motion_frame
)
6313 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6314 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6315 last_mouse_motion_event
.x
,
6316 last_mouse_motion_event
.y
);
6321 /***********************************************************************
6323 ***********************************************************************/
6325 static int x_toolbar_item
P_ ((struct frame
*, int, int,
6326 struct glyph
**, int *, int *, int *));
6328 /* Toolbar item index of the item on which a mouse button was pressed
6331 static int last_toolbar_item
;
6334 /* Get information about the toolbar item at position X/Y on frame F.
6335 Return in *GLYPH a pointer to the glyph of the toolbar item in
6336 the current matrix of the toolbar window of F, or NULL if not
6337 on a toolbar item. Return in *PROP_IDX the index of the toolbar
6338 item in F->current_toolbar_items. Value is
6340 -1 if X/Y is not on a toolbar item
6341 0 if X/Y is on the same item that was highlighted before.
6345 x_toolbar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6348 struct glyph
**glyph
;
6349 int *hpos
, *vpos
, *prop_idx
;
6351 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6352 struct window
*w
= XWINDOW (f
->toolbar_window
);
6355 /* Find the glyph under X/Y. */
6356 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6360 /* Get the start of this toolbar item's properties in
6361 f->current_toolbar_items. */
6362 if (!toolbar_item_info (f
, *glyph
, prop_idx
))
6365 /* Is mouse on the highlighted item? */
6366 if (EQ (f
->toolbar_window
, dpyinfo
->mouse_face_window
)
6367 && *vpos
>= dpyinfo
->mouse_face_beg_row
6368 && *vpos
<= dpyinfo
->mouse_face_end_row
6369 && (*vpos
> dpyinfo
->mouse_face_beg_row
6370 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6371 && (*vpos
< dpyinfo
->mouse_face_end_row
6372 || *hpos
< dpyinfo
->mouse_face_end_col
6373 || dpyinfo
->mouse_face_past_end
))
6380 /* Handle mouse button event on the toolbar of frame F, at
6381 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6385 x_handle_toolbar_click (f
, button_event
)
6387 XButtonEvent
*button_event
;
6389 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6390 struct window
*w
= XWINDOW (f
->toolbar_window
);
6391 int hpos
, vpos
, prop_idx
;
6392 struct glyph
*glyph
;
6393 Lisp_Object enabled_p
;
6394 int x
= button_event
->x
;
6395 int y
= button_event
->y
;
6397 /* If not on the highlighted toolbar item, return. */
6398 frame_to_window_pixel_xy (w
, &x
, &y
);
6399 if (x_toolbar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6402 /* If item is disabled, do nothing. */
6403 enabled_p
= (XVECTOR (f
->current_toolbar_items
)
6404 ->contents
[prop_idx
+ TOOLBAR_ITEM_ENABLED_P
]);
6405 if (NILP (enabled_p
))
6408 if (button_event
->type
== ButtonPress
)
6410 /* Show item in pressed state. */
6411 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6412 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6413 last_toolbar_item
= prop_idx
;
6417 Lisp_Object key
, frame
;
6418 struct input_event event
;
6420 /* Show item in released state. */
6421 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6422 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6424 key
= (XVECTOR (f
->current_toolbar_items
)
6425 ->contents
[prop_idx
+ TOOLBAR_ITEM_KEY
]);
6427 XSETFRAME (frame
, f
);
6428 event
.kind
= TOOLBAR_EVENT
;
6429 event
.frame_or_window
= Fcons (frame
, Fcons (Qtoolbar
, Qnil
));
6430 kbd_buffer_store_event (&event
);
6432 event
.kind
= TOOLBAR_EVENT
;
6433 event
.frame_or_window
= Fcons (frame
, key
);
6434 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6435 button_event
->state
);
6436 kbd_buffer_store_event (&event
);
6437 last_toolbar_item
= -1;
6442 /* Possibly highlight a toolbar item on frame F when mouse moves to
6443 toolbar window-relative coordinates X/Y. Called from
6444 note_mouse_highlight. */
6447 note_toolbar_highlight (f
, x
, y
)
6451 Lisp_Object window
= f
->toolbar_window
;
6452 struct window
*w
= XWINDOW (window
);
6453 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6455 struct glyph
*glyph
;
6456 struct glyph_row
*row
;
6458 Lisp_Object enabled_p
;
6460 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6461 int on_highlight_p
, mouse_down_p
, rc
;
6463 /* Function note_mouse_highlight is called with negative x(y
6464 values when mouse moves outside of the frame. */
6465 if (x
<= 0 || y
<= 0)
6467 clear_mouse_face (dpyinfo
);
6471 rc
= x_toolbar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6474 /* Not on toolbar item. */
6475 clear_mouse_face (dpyinfo
);
6479 /* On same toolbar item as before. */
6482 clear_mouse_face (dpyinfo
);
6484 /* Mouse is down, but on different toolbar item? */
6485 mouse_down_p
= (dpyinfo
->grabbed
6486 && f
== last_mouse_frame
6487 && FRAME_LIVE_P (f
));
6489 && last_toolbar_item
!= prop_idx
)
6492 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6493 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6495 /* If toolbar item is not enabled, don't highlight it. */
6496 enabled_p
= (XVECTOR (f
->current_toolbar_items
)
6497 ->contents
[prop_idx
+ TOOLBAR_ITEM_ENABLED_P
]);
6498 if (!NILP (enabled_p
))
6500 /* Compute the x-position of the glyph. In front and past the
6501 image is a space. We include this is the highlighted area. */
6502 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6503 for (i
= x
= 0; i
< hpos
; ++i
)
6504 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6506 /* Record this as the current active region. */
6507 dpyinfo
->mouse_face_beg_col
= hpos
;
6508 dpyinfo
->mouse_face_beg_row
= vpos
;
6509 dpyinfo
->mouse_face_beg_x
= x
;
6510 dpyinfo
->mouse_face_beg_y
= row
->y
;
6511 dpyinfo
->mouse_face_past_end
= 0;
6513 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6514 dpyinfo
->mouse_face_end_row
= vpos
;
6515 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6516 dpyinfo
->mouse_face_end_y
= row
->y
;
6517 dpyinfo
->mouse_face_window
= window
;
6518 dpyinfo
->mouse_face_face_id
= TOOLBAR_FACE_ID
;
6520 /* Display it as active. */
6521 show_mouse_face (dpyinfo
, draw
);
6522 dpyinfo
->mouse_face_image_state
= draw
;
6527 /* Set help_echo to a help string.to display for this toolbar item.
6528 XTread_socket does the rest. */
6529 help_echo
= (XVECTOR (f
->current_toolbar_items
)
6530 ->contents
[prop_idx
+ TOOLBAR_ITEM_HELP
]);
6531 if (!STRINGP (help_echo
))
6532 help_echo
= (XVECTOR (f
->current_toolbar_items
)
6533 ->contents
[prop_idx
+ TOOLBAR_ITEM_CAPTION
]);
6538 /* Find the glyph matrix position of buffer position POS in window W.
6539 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6540 current glyphs must be up to date. If POS is above window start
6541 return (0, 0, 0, 0). If POS is after end of W, return end of
6545 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6548 int *hpos
, *vpos
, *x
, *y
;
6552 int maybe_next_line_p
= 0;
6553 int line_start_position
;
6554 int yb
= window_text_bottom_y (w
);
6555 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6556 struct glyph_row
*best_row
= row
;
6557 int row_vpos
= 0, best_row_vpos
= 0;
6562 if (row
->used
[TEXT_AREA
])
6563 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6565 line_start_position
= 0;
6567 if (line_start_position
> pos
)
6569 /* If the position sought is the end of the buffer,
6570 don't include the blank lines at the bottom of the window. */
6571 else if (line_start_position
== pos
6572 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6574 maybe_next_line_p
= 1;
6577 else if (line_start_position
> 0)
6580 best_row_vpos
= row_vpos
;
6587 /* Find the right column within BEST_ROW. */
6589 current_x
= best_row
->x
;
6590 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6592 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6595 charpos
= glyph
->charpos
;
6599 *vpos
= best_row_vpos
;
6604 else if (charpos
> pos
)
6606 else if (charpos
> 0)
6609 current_x
+= glyph
->pixel_width
;
6612 /* If we're looking for the end of the buffer,
6613 and we didn't find it in the line we scanned,
6614 use the start of the following line. */
6615 if (maybe_next_line_p
)
6620 current_x
= best_row
->x
;
6623 *vpos
= best_row_vpos
;
6624 *hpos
= lastcol
+ 1;
6631 /* Display the active region described by mouse_face_*
6632 in its mouse-face if HL > 0, in its normal face if HL = 0. */
6635 show_mouse_face (dpyinfo
, draw
)
6636 struct x_display_info
*dpyinfo
;
6637 enum draw_glyphs_face draw
;
6639 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
6640 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6642 int cursor_off_p
= 0;
6643 struct cursor_pos saved_cursor
;
6645 saved_cursor
= output_cursor
;
6647 /* If window is in the process of being destroyed, don't bother
6649 if (w
->current_matrix
== NULL
)
6652 /* Recognize when we are called to operate on rows that don't exist
6653 anymore. This can happen when a window is split. */
6654 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
6657 set_output_cursor (&w
->phys_cursor
);
6659 /* Note that mouse_face_beg_row etc. are window relative. */
6660 for (i
= dpyinfo
->mouse_face_beg_row
;
6661 i
<= dpyinfo
->mouse_face_end_row
;
6664 int start_hpos
, end_hpos
, start_x
;
6665 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
6667 /* Don't do anything if row doesn't have valid contents. */
6668 if (!row
->enabled_p
)
6671 /* For all but the first row, the highlight starts at column 0. */
6672 if (i
== dpyinfo
->mouse_face_beg_row
)
6674 start_hpos
= dpyinfo
->mouse_face_beg_col
;
6675 start_x
= dpyinfo
->mouse_face_beg_x
;
6683 if (i
== dpyinfo
->mouse_face_end_row
)
6684 end_hpos
= dpyinfo
->mouse_face_end_col
;
6686 end_hpos
= row
->used
[TEXT_AREA
];
6688 /* If the cursor's in the text we are about to rewrite, turn the
6690 if (!w
->pseudo_window_p
6691 && i
== output_cursor
.vpos
6692 && output_cursor
.hpos
>= start_hpos
- 1
6693 && output_cursor
.hpos
<= end_hpos
)
6695 x_update_window_cursor (w
, 0);
6699 if (end_hpos
> start_hpos
)
6700 x_draw_glyphs (w
, start_x
, row
, updated_area
,
6701 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
6704 /* If we turned the cursor off, turn it back on. */
6706 x_display_cursor (w
, 1,
6707 output_cursor
.hpos
, output_cursor
.vpos
,
6708 output_cursor
.x
, output_cursor
.y
);
6710 output_cursor
= saved_cursor
;
6714 /* Change the mouse cursor. */
6715 if (draw
== DRAW_NORMAL_TEXT
)
6716 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6717 f
->output_data
.x
->text_cursor
);
6718 else if (draw
== DRAW_MOUSE_FACE
)
6719 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6720 f
->output_data
.x
->cross_cursor
);
6722 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6723 f
->output_data
.x
->nontext_cursor
);
6726 /* Clear out the mouse-highlighted active region.
6727 Redraw it un-highlighted first. */
6730 clear_mouse_face (dpyinfo
)
6731 struct x_display_info
*dpyinfo
;
6736 if (! NILP (dpyinfo
->mouse_face_window
))
6737 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
6739 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6740 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6741 dpyinfo
->mouse_face_window
= Qnil
;
6744 /* Just discard the mouse face information for frame F, if any.
6745 This is used when the size of F is changed. */
6748 cancel_mouse_face (f
)
6752 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6754 window
= dpyinfo
->mouse_face_window
;
6755 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
6757 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6758 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6759 dpyinfo
->mouse_face_window
= Qnil
;
6763 static struct scroll_bar
*x_window_to_scroll_bar ();
6764 static void x_scroll_bar_report_motion ();
6766 /* Return the current position of the mouse.
6767 *fp should be a frame which indicates which display to ask about.
6769 If the mouse movement started in a scroll bar, set *fp, *bar_window,
6770 and *part to the frame, window, and scroll bar part that the mouse
6771 is over. Set *x and *y to the portion and whole of the mouse's
6772 position on the scroll bar.
6774 If the mouse movement started elsewhere, set *fp to the frame the
6775 mouse is on, *bar_window to nil, and *x and *y to the character cell
6778 Set *time to the server time-stamp for the time at which the mouse
6779 was at this position.
6781 Don't store anything if we don't have a valid set of values to report.
6783 This clears the mouse_moved flag, so we can wait for the next mouse
6787 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
6790 Lisp_Object
*bar_window
;
6791 enum scroll_bar_part
*part
;
6793 unsigned long *time
;
6799 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
6800 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
6806 Window dummy_window
;
6809 Lisp_Object frame
, tail
;
6811 /* Clear the mouse-moved flag for every frame on this display. */
6812 FOR_EACH_FRAME (tail
, frame
)
6813 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
6814 XFRAME (frame
)->mouse_moved
= 0;
6816 last_mouse_scroll_bar
= Qnil
;
6818 /* Figure out which root window we're on. */
6819 XQueryPointer (FRAME_X_DISPLAY (*fp
),
6820 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
6822 /* The root window which contains the pointer. */
6825 /* Trash which we can't trust if the pointer is on
6826 a different screen. */
6829 /* The position on that root window. */
6832 /* More trash we can't trust. */
6835 /* Modifier keys and pointer buttons, about which
6837 (unsigned int *) &dummy
);
6839 /* Now we have a position on the root; find the innermost window
6840 containing the pointer. */
6844 int parent_x
= 0, parent_y
= 0;
6849 /* XTranslateCoordinates can get errors if the window
6850 structure is changing at the same time this function
6851 is running. So at least we must not crash from them. */
6853 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
6855 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
6856 && FRAME_LIVE_P (last_mouse_frame
))
6858 /* If mouse was grabbed on a frame, give coords for that frame
6859 even if the mouse is now outside it. */
6860 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
6862 /* From-window, to-window. */
6863 root
, FRAME_X_WINDOW (last_mouse_frame
),
6865 /* From-position, to-position. */
6866 root_x
, root_y
, &win_x
, &win_y
,
6870 f1
= last_mouse_frame
;
6876 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
6878 /* From-window, to-window. */
6881 /* From-position, to-position. */
6882 root_x
, root_y
, &win_x
, &win_y
,
6887 if (child
== None
|| child
== win
)
6895 /* Now we know that:
6896 win is the innermost window containing the pointer
6897 (XTC says it has no child containing the pointer),
6898 win_x and win_y are the pointer's position in it
6899 (XTC did this the last time through), and
6900 parent_x and parent_y are the pointer's position in win's parent.
6901 (They are what win_x and win_y were when win was child.
6902 If win is the root window, it has no parent, and
6903 parent_{x,y} are invalid, but that's okay, because we'll
6904 never use them in that case.) */
6906 /* Is win one of our frames? */
6907 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
6910 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
6913 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
6915 /* If not, is it one of our scroll bars? */
6918 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
6922 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6928 if (f1
== 0 && insist
> 0)
6929 f1
= selected_frame
;
6933 /* Ok, we found a frame. Store all the values.
6934 last_mouse_glyph is a rectangle used to reduce the
6935 generation of mouse events. To not miss any motion
6936 events, we must divide the frame into rectangles of the
6937 size of the smallest character that could be displayed
6938 on it, i.e. into the same rectangles that matrices on
6939 the frame are divided into. */
6941 #if OLD_REDISPLAY_CODE
6942 int ignore1
, ignore2
;
6943 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
6945 FRAME_X_DISPLAY_INFO (f1
)->grabbed
6949 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
6950 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
6954 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
6955 round down even for negative values. */
6961 last_mouse_glyph
.width
= width
;
6962 last_mouse_glyph
.height
= height
;
6963 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
6964 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
6971 XSETINT (*x
, win_x
);
6972 XSETINT (*y
, win_y
);
6973 *time
= last_mouse_movement_time
;
6982 DEFUN ("xt-process-timeouts", Fxt_process_timeouts
, Sxt_process_timeouts
,
6984 "Arrange for Xt timeout callbacks to be called.")
6987 #ifdef USE_X_TOOLKIT
6989 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
6990 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
6992 #endif /* USE_X_TOOLKIT */
6999 /* Scroll bar support. */
7001 /* Given an X window ID, find the struct scroll_bar which manages it.
7002 This can be called in GC, so we have to make sure to strip off mark
7004 static struct scroll_bar
*
7005 x_window_to_scroll_bar (window_id
)
7010 for (tail
= Vframe_list
;
7011 XGCTYPE (tail
) == Lisp_Cons
;
7012 tail
= XCONS (tail
)->cdr
)
7014 Lisp_Object frame
, bar
, condemned
;
7016 frame
= XCONS (tail
)->car
;
7017 /* All elements of Vframe_list should be frames. */
7018 if (! GC_FRAMEP (frame
))
7021 /* Scan this frame's scroll bar list for a scroll bar with the
7023 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7024 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7025 /* This trick allows us to search both the ordinary and
7026 condemned scroll bar lists with one loop. */
7027 ! GC_NILP (bar
) || (bar
= condemned
,
7030 bar
= XSCROLL_BAR (bar
)->next
)
7031 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7032 return XSCROLL_BAR (bar
);
7040 /************************************************************************
7042 ************************************************************************/
7044 #if USE_TOOLKIT_SCROLL_BARS
7046 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7047 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7048 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7049 struct scroll_bar
*));
7050 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7054 /* Id of action hook installed for scroll bars. */
7056 static XtActionHookId action_hook_id
;
7058 /* Lisp window being scrolled. Set when starting to interact with
7059 a toolkit scroll bar, reset to nil when ending the interaction. */
7061 static Lisp_Object window_being_scrolled
;
7063 /* Last scroll bar part sent in xm_scroll_callback. */
7065 static int last_scroll_bar_part
;
7068 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7069 bars are used.. The hoos is responsible for detecting when
7070 the user ends an interaction with the scroll bar, and generates
7071 a `end-scroll' scroll_bar_click' event if so. */
7074 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7077 XtPointer client_data
;
7081 Cardinal
*num_params
;
7087 scroll_bar_p
= XmIsScrollBar (widget
);
7088 end_action
= "Release";
7089 #elif defined HAVE_XAW3D
7090 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7091 end_action
= "EndScroll";
7093 #error unknown scroll bar toolkit
7094 #endif /* HAVE_XAW3D */
7096 /* Although LessTif uses XtTimeouts like Xaw3d, the timer hack to
7097 let Xt timeouts be processed doesn't work. */
7099 && strcmp (action_name
, end_action
) == 0
7100 && WINDOWP (window_being_scrolled
))
7104 x_send_scroll_bar_event (window_being_scrolled
,
7105 scroll_bar_end_scroll
, 0, 0);
7106 w
= XWINDOW (window_being_scrolled
);
7107 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7108 window_being_scrolled
= Qnil
;
7109 last_scroll_bar_part
= -1;
7114 /* Send a client message with message type Xatom_Scrollbar for a
7115 scroll action to the frame of WINDOW. PART is a value identifying
7116 the part of the scroll bar that was clicked on. PORTION is the
7117 amount to scroll of a whole of WHOLE. */
7120 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7122 int part
, portion
, whole
;
7125 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7126 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7128 /* Construct a ClientMessage event to send to the frame. */
7129 ev
->type
= ClientMessage
;
7130 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7131 ev
->display
= FRAME_X_DISPLAY (f
);
7132 ev
->window
= FRAME_X_WINDOW (f
);
7134 ev
->data
.l
[0] = (long) window
;
7135 ev
->data
.l
[1] = (long) part
;
7136 ev
->data
.l
[2] = (long) 0;
7137 ev
->data
.l
[3] = (long) portion
;
7138 ev
->data
.l
[4] = (long) whole
;
7140 /* Setting the event mask to zero means that the message will
7141 be sent to the client that created the window, and if that
7142 window no longer exists, no event will be sent. */
7144 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7149 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7153 x_scroll_bar_to_input_event (event
, ievent
)
7155 struct input_event
*ievent
;
7157 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7158 Lisp_Object window
= (Lisp_Object
) ev
->data
.l
[0];
7159 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7161 ievent
->kind
= scroll_bar_click
;
7162 ievent
->frame_or_window
= window
;
7163 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7164 ievent
->part
= ev
->data
.l
[1];
7165 ievent
->code
= ev
->data
.l
[2];
7166 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7167 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7168 ievent
->modifiers
= 0;
7174 /* Minimum and maximum values used for Motif scroll bars. */
7177 #define XM_SB_MAX 10000000
7178 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7181 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7182 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7183 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7186 xm_scroll_callback (widget
, client_data
, call_data
)
7188 XtPointer client_data
, call_data
;
7190 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7191 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7193 int part
= -1, whole
= 0, portion
= 0;
7197 case XmCR_DECREMENT
:
7198 bar
->dragging
= Qnil
;
7199 part
= scroll_bar_up_arrow
;
7202 case XmCR_INCREMENT
:
7203 bar
->dragging
= Qnil
;
7204 part
= scroll_bar_down_arrow
;
7207 case XmCR_PAGE_DECREMENT
:
7208 bar
->dragging
= Qnil
;
7209 part
= scroll_bar_above_handle
;
7212 case XmCR_PAGE_INCREMENT
:
7213 bar
->dragging
= Qnil
;
7214 part
= scroll_bar_below_handle
;
7218 bar
->dragging
= Qnil
;
7219 part
= scroll_bar_to_top
;
7222 case XmCR_TO_BOTTOM
:
7223 bar
->dragging
= Qnil
;
7224 part
= scroll_bar_to_bottom
;
7230 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7231 && XINT (bar
->dragging
) <= cs
->value
);
7233 /* Get the slider size. */
7235 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7238 /* At the max position of the scroll bar, do a line-wise
7239 movement. Without doing anything, the LessTif scroll bar
7240 calls us with the same cs->value again and again. If we
7241 want to make sure that we can reach the end of the buffer,
7242 we have to do something.
7244 Implementation note: setting bar->dragging always to
7245 cs->value gives a smoother movement at the max position.
7246 Setting it to nil when doing line-wise movement gives
7247 a better slider behavior. */
7249 if (cs
->value
+ slider_size
== XM_SB_MAX
7251 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7253 part
= scroll_bar_down_arrow
;
7254 bar
->dragging
= Qnil
;
7258 whole
= XM_SB_RANGE
;
7259 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7260 part
= scroll_bar_handle
;
7261 bar
->dragging
= make_number (cs
->value
);
7266 case XmCR_VALUE_CHANGED
:
7272 window_being_scrolled
= bar
->window
;
7273 last_scroll_bar_part
= part
;
7274 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7279 #else /* not USE_MOTIF, i.e. XAW3D. */
7282 /* Xaw3d scroll bar callback. Invoked when the thumb is dragged.
7283 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7284 scroll bar struct. CALL_DATA is a pointer to a float saying where
7288 xaw3d_jump_callback (widget
, client_data
, call_data
)
7290 XtPointer client_data
, call_data
;
7292 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7293 float top
= *(float *) call_data
;
7296 int dragging_down_p
, part
;
7297 double epsilon
= 0.01;
7299 /* Get the size of the thumb, a value between 0 and 1. */
7301 XtVaGetValues (widget
, XtNshown
, &shown
, NULL
);
7305 portion
= shown
< 1 ? top
* whole
: 0;
7306 dragging_down_p
= (INTEGERP (bar
->dragging
)
7307 && XINT (bar
->dragging
) < portion
);
7310 && (abs (top
+ shown
- 1) < epsilon
7312 && last_scroll_bar_part
== scroll_bar_down_arrow
)))
7313 part
= scroll_bar_down_arrow
;
7315 part
= scroll_bar_handle
;
7317 window_being_scrolled
= bar
->window
;
7318 bar
->dragging
= make_number (portion
);
7319 last_scroll_bar_part
= part
;
7320 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7324 /* Xaw3d scroll bar callback. Invoked for incremental scrolling.,
7325 i.e. line or page up or down. WIDGET is the Xaw3d scroll bar
7326 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7327 the scroll bar. CALL_DATA is an integer specifying the action that
7328 has taken place. It's magnitude is in the range 0..height of the
7329 scroll bar. Negative values mean scroll towards buffer start.
7330 Values < height of scroll bar mean line-wise movement. */
7333 xaw3d_scroll_callback (widget
, client_data
, call_data
)
7335 XtPointer client_data
, call_data
;
7337 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7338 int position
= (int) call_data
;
7342 /* Get the height of the scroll bar. */
7344 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7349 if (abs (position
) < height
)
7350 part
= scroll_bar_up_arrow
;
7352 part
= scroll_bar_above_handle
;
7356 if (abs (position
) < height
)
7357 part
= scroll_bar_down_arrow
;
7359 part
= scroll_bar_below_handle
;
7362 window_being_scrolled
= bar
->window
;
7363 bar
->dragging
= Qnil
;
7364 last_scroll_bar_part
= part
;
7365 x_send_scroll_bar_event (bar
->window
, part
, 0, 0);
7369 #endif /* not USE_MOTIF */
7372 /* Create the widget for scroll bar BAR on frame F. Record the widget
7373 and X window of the scroll bar in BAR. */
7376 x_create_toolkit_scroll_bar (f
, bar
)
7378 struct scroll_bar
*bar
;
7384 char *scroll_bar_name
= "verticalScrollBar";
7385 unsigned long pixel
;
7390 /* LessTif 0.85, problems:
7392 1. When the mouse if over the scroll bar, the scroll bar will
7393 get keyboard events. I didn't find a way to turn this off.
7395 2. Do we have to explicitly set the cursor to get an arrow
7396 cursor (see below)? */
7398 /* Set resources. Create the widget. */
7399 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7400 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7401 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7402 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7403 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7404 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7405 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7407 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7410 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7414 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7417 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7421 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7422 scroll_bar_name
, av
, ac
);
7424 /* Add one callback for everything that can happen. */
7425 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7427 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7429 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7431 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7433 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7435 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7437 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7440 /* Realize the widget. Only after that is the X window created. */
7441 XtRealizeWidget (widget
);
7443 /* Set the cursor to an arrow. I didn't find a resource to do that.
7444 And I'm wondering why it hasn't an arrow cursor by default. */
7445 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7446 f
->output_data
.x
->nontext_cursor
);
7448 #elif defined HAVE_XAW3D
7450 /* Set resources. Create the widget. The background of the
7451 Xaw3d scroll bar widget is a little bit light for my taste.
7452 We don't alter it here to let users change it according
7453 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7454 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7455 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7456 XtSetArg (av
[ac
], XtNcursorName
, "left_ptr"); ++ac
;
7457 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
); ++ac
;
7459 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7462 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7466 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7469 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7473 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7474 f
->output_data
.x
->edit_widget
, av
, ac
);
7476 /* Define callbacks. */
7477 XtAddCallback (widget
, XtNjumpProc
, xaw3d_jump_callback
, (XtPointer
) bar
);
7478 XtAddCallback (widget
, XtNscrollProc
, xaw3d_scroll_callback
,
7481 /* Realize the widget. Only after that is the X window created. */
7482 XtRealizeWidget (widget
);
7484 #endif /* HAVE_XAW3D */
7486 /* Install an action hook that let's us detect when the user
7487 finishes interacting with a scroll bar. */
7488 if (action_hook_id
== 0)
7489 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7491 /* Remember X window and widget in the scroll bar vector. */
7492 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7493 xwindow
= XtWindow (widget
);
7494 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7500 /* Set the thumb size and position of scroll bar BAR. We are currently
7501 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7504 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7505 struct scroll_bar
*bar
;
7506 int portion
, position
, whole
;
7510 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7516 top
= (float) position
/ whole
;
7517 shown
= (float) portion
/ whole
;
7525 Boolean arrow1_selected
, arrow2_selected
;
7526 unsigned char flags
;
7527 XmScrollBarWidget sb
;
7529 /* Slider size. Must be in the range [1 .. MAX - MIN] where NAX
7530 is the scroll bar's maximum and MIN is the scroll bar's minimum
7532 size
= shown
* XM_SB_RANGE
;
7533 size
= min (size
, XM_SB_RANGE
);
7534 size
= max (size
, 1);
7536 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7537 value
= top
* XM_SB_RANGE
;
7538 value
= min (value
, XM_SB_MAX
- size
);
7539 value
= max (value
, XM_SB_MIN
);
7541 /* LessTif: Calling XmScrollBarSetValues after an increment or
7542 decrement turns off auto-repeat LessTif-internally. This can
7543 be seen in ScrollBar.c which resets Arrow1Selected and
7544 Arrow2Selected. It also sets internal flags so that LessTif
7545 believes the mouse is in the slider. We either have to change
7546 our code, or work around that by accessing private data. */
7548 sb
= (XmScrollBarWidget
) widget
;
7549 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
7550 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
7551 flags
= sb
->scrollBar
.flags
;
7553 if (NILP (bar
->dragging
))
7554 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
7555 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7556 /* This has the negative side effect that the slider value is
7557 not would it would be if we scrolled here using line-wise or
7558 page-wise movement. */
7559 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
7562 /* If currently dragging, only update the slider size.
7563 This reduces flicker effects. */
7564 int old_value
, old_size
, increment
, page_increment
;
7566 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
7567 &increment
, &page_increment
);
7568 XmScrollBarSetValues (widget
, old_value
,
7569 min (size
, XM_SB_RANGE
- old_value
),
7573 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
7574 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
7575 sb
->scrollBar
.flags
= flags
;
7577 #elif defined HAVE_XAW3D
7579 /* Restrict to [0 1]. */
7580 top
= max (0, min (1, top
));
7581 shown
= max (0, min (1, shown
));
7583 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
7584 check that your system's configuration file contains a define
7585 for `NARROWPROTO'. See s/freebsd.h for an example. */
7586 if (NILP (bar
->dragging
))
7588 float old_top
, old_shown
;
7589 XtVaGetValues (widget
, XtNtopOfThumb
, &old_top
, XtNshown
, &old_shown
,
7591 if (top
!= old_top
|| shown
!= old_shown
)
7592 XawScrollbarSetThumb (widget
, top
, shown
);
7596 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
7597 int scroll_mode
= sb
->scrollbar
.scroll_mode
;
7599 sb
->scrollbar
.scroll_mode
= 0;
7601 if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7602 XawScrollbarSetThumb (widget
, top
, 1 - top
);
7606 XtVaGetValues (widget
, XtNtopOfThumb
, &old_top
, NULL
);
7607 XawScrollbarSetThumb (widget
, old_top
, min (shown
, 1 - old_top
));
7610 sb
->scrollbar
.scroll_mode
= scroll_mode
;
7613 #endif /* HAVE_XAW3D */
7618 #endif /* USE_TOOLKIT_SCROLL_BARS */
7622 /************************************************************************
7623 Scroll bars, general
7624 ************************************************************************/
7626 /* Create a scroll bar and return the scroll bar vector for it. W is
7627 the Emacs window on which to create the scroll bar. TOP, LEFT,
7628 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7631 static struct scroll_bar
*
7632 x_scroll_bar_create (w
, top
, left
, width
, height
)
7634 int top
, left
, width
, height
;
7636 struct frame
*f
= XFRAME (w
->frame
);
7637 #ifdef USE_X_TOOLKIT
7642 struct scroll_bar
*bar
7643 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7647 #if USE_TOOLKIT_SCROLL_BARS
7648 x_create_toolkit_scroll_bar (f
, bar
);
7649 #else /* not USE_TOOLKIT_SCROLL_BARS */
7651 XSetWindowAttributes a
;
7654 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7655 if (a
.background_pixel
== -1)
7656 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
7658 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
7659 | ButtonMotionMask
| PointerMotionHintMask
7661 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
7663 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
7665 /* Clear the area of W that will serve as a scroll bar. This is
7666 for the case that a window has been split horizontally. In
7667 this case, no clear_frame is generated to reduce flickering. */
7668 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7670 window_box_height (w
), False
);
7672 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7673 /* Position and size of scroll bar. */
7674 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7676 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7678 /* Border width, depth, class, and visual. */
7685 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
7687 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7689 XSETWINDOW (bar
->window
, w
);
7690 XSETINT (bar
->top
, top
);
7691 XSETINT (bar
->left
, left
);
7692 XSETINT (bar
->width
, width
);
7693 XSETINT (bar
->height
, height
);
7694 XSETINT (bar
->start
, 0);
7695 XSETINT (bar
->end
, 0);
7696 bar
->dragging
= Qnil
;
7698 /* Add bar to its frame's list of scroll bars. */
7699 bar
->next
= FRAME_SCROLL_BARS (f
);
7701 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7702 if (!NILP (bar
->next
))
7703 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7705 /* Map the window/widget. */
7706 #if USE_TOOLKIT_SCROLL_BARS
7707 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
7708 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
7709 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7711 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7713 #else /* not USE_TOOLKIT_SCROLL_BARS */
7714 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7715 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7722 /* Draw BAR's handle in the proper position.
7724 If the handle is already drawn from START to END, don't bother
7725 redrawing it, unless REBUILD is non-zero; in that case, always
7726 redraw it. (REBUILD is handy for drawing the handle after expose
7729 Normally, we want to constrain the start and end of the handle to
7730 fit inside its rectangle, but if the user is dragging the scroll
7731 bar handle, we want to let them drag it down all the way, so that
7732 the bar's top is as far down as it goes; otherwise, there's no way
7733 to move to the very end of the buffer. */
7736 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
7737 struct scroll_bar
*bar
;
7741 #ifndef USE_TOOLKIT_SCROLL_BARS
7742 int dragging
= ! NILP (bar
->dragging
);
7743 Window w
= SCROLL_BAR_X_WINDOW (bar
);
7744 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7745 GC gc
= f
->output_data
.x
->normal_gc
;
7747 /* If the display is already accurate, do nothing. */
7749 && start
== XINT (bar
->start
)
7750 && end
== XINT (bar
->end
))
7756 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
7757 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
7758 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7760 /* Make sure the values are reasonable, and try to preserve
7761 the distance between start and end. */
7763 int length
= end
- start
;
7767 else if (start
> top_range
)
7769 end
= start
+ length
;
7773 else if (end
> top_range
&& ! dragging
)
7777 /* Store the adjusted setting in the scroll bar. */
7778 XSETINT (bar
->start
, start
);
7779 XSETINT (bar
->end
, end
);
7781 /* Clip the end position, just for display. */
7782 if (end
> top_range
)
7785 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
7786 below top positions, to make sure the handle is always at least
7787 that many pixels tall. */
7788 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7790 /* Draw the empty space above the handle. Note that we can't clear
7791 zero-height areas; that means "clear to end of window." */
7793 XClearArea (FRAME_X_DISPLAY (f
), w
,
7795 /* x, y, width, height, and exposures. */
7796 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7797 VERTICAL_SCROLL_BAR_TOP_BORDER
,
7798 inside_width
, start
,
7801 /* Change to proper foreground color if one is specified. */
7802 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7803 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7804 f
->output_data
.x
->scroll_bar_foreground_pixel
);
7806 /* Draw the handle itself. */
7807 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
7809 /* x, y, width, height */
7810 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7811 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
7812 inside_width
, end
- start
);
7814 /* Restore the foreground color of the GC if we changed it above. */
7815 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7816 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7817 f
->output_data
.x
->foreground_pixel
);
7819 /* Draw the empty space below the handle. Note that we can't
7820 clear zero-height areas; that means "clear to end of window." */
7821 if (end
< inside_height
)
7822 XClearArea (FRAME_X_DISPLAY (f
), w
,
7824 /* x, y, width, height, and exposures. */
7825 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7826 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
7827 inside_width
, inside_height
- end
,
7833 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7837 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
7841 x_scroll_bar_remove (bar
)
7842 struct scroll_bar
*bar
;
7844 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7848 #if USE_TOOLKIT_SCROLL_BARS
7849 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
7850 #else /* not USE_TOOLKIT_SCROLL_BARS */
7851 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7852 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7854 /* Disassociate this scroll bar from its window. */
7855 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
7861 /* Set the handle of the vertical scroll bar for WINDOW to indicate
7862 that we are displaying PORTION characters out of a total of WHOLE
7863 characters, starting at POSITION. If WINDOW has no scroll bar,
7867 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
7869 int portion
, whole
, position
;
7871 struct frame
*f
= XFRAME (w
->frame
);
7872 struct scroll_bar
*bar
;
7873 int pixel_top
, pixel_left
, pixel_width
, pixel_height
;
7874 int window_x
, window_y
, window_width
, window_height
;
7875 int scroll_bar_area_width
;
7877 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7879 /* Where should this scroll bar be, pixel-wise? */
7880 pixel_top
= window_y
;
7881 pixel_height
= window_height
;
7883 /* The width of the scroll bar itself. */
7884 pixel_width
= (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
7885 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
7886 : (FRAME_SCROLL_BAR_COLS (f
)
7887 * FONT_WIDTH (FRAME_FONT (f
))));
7889 /* The width on the screen reserved for the scroll bar plus maybe
7890 some empty room at both sides of the scroll bar. */
7891 scroll_bar_area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
7893 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7894 pixel_left
= (window_x
7896 + FRAME_FLAGS_AREA_WIDTH (f
)
7897 + scroll_bar_area_width
7900 pixel_left
= (window_x
7901 - FRAME_FLAGS_AREA_WIDTH (f
)
7902 - scroll_bar_area_width
);
7904 /* Does the scroll bar exist yet? */
7905 if (NILP (w
->vertical_scroll_bar
))
7906 bar
= x_scroll_bar_create (w
, pixel_top
, pixel_left
, pixel_width
,
7910 /* It may just need to be moved and resized. */
7911 unsigned int mask
= 0;
7913 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
7917 if (pixel_left
!= XINT (bar
->left
))
7919 if (pixel_top
!= XINT (bar
->top
))
7921 if (pixel_width
!= XINT (bar
->width
))
7923 if (pixel_height
!= XINT (bar
->height
))
7926 #ifdef USE_TOOLKIT_SCROLL_BARS
7928 /* Since toolkit scroll bars are smaller than the space reserved
7929 for them on the frame, we have to clear "under" them. */
7930 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7931 pixel_left
, pixel_top
,
7932 pixel_width
+ 1, pixel_height
, False
);
7934 /* Move/size the scroll bar widget. */
7936 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
7937 pixel_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7939 pixel_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7942 #else /* not USE_TOOLKIT_SCROLL_BARS */
7944 /* Clear areas not covered by the scroll bar. This makes sure a
7945 previous mode line display is cleared after C-x 2 C-x 1, for
7946 example. Non-toolkit scroll bars are as wide as the area
7947 reserved for scroll bars - trim at both sides. */
7948 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7949 pixel_left
, pixel_top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7950 pixel_height
, False
);
7951 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7954 - VERTICAL_SCROLL_BAR_WIDTH_TRIM
),
7956 VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7957 pixel_height
, False
);
7959 /* Move/size the scroll bar window. */
7964 wc
.x
= pixel_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
7966 wc
.width
= pixel_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
7967 wc
.height
= pixel_height
;
7968 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
7972 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7974 /* Remember new settings. */
7975 XSETINT (bar
->left
, pixel_left
);
7976 XSETINT (bar
->top
, pixel_top
);
7977 XSETINT (bar
->width
, pixel_width
);
7978 XSETINT (bar
->height
, pixel_height
);
7983 #if USE_TOOLKIT_SCROLL_BARS
7984 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
7985 #else /* not USE_TOOLKIT_SCROLL_BARS */
7986 /* Set the scroll bar's current state, unless we're currently being
7988 if (NILP (bar
->dragging
))
7990 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, pixel_height
);
7993 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
7996 int start
= ((double) position
* top_range
) / whole
;
7997 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
7998 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8001 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8003 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8007 /* The following three hooks are used when we're doing a thorough
8008 redisplay of the frame. We don't explicitly know which scroll bars
8009 are going to be deleted, because keeping track of when windows go
8010 away is a real pain - "Can you say set-window-configuration, boys
8011 and girls?" Instead, we just assert at the beginning of redisplay
8012 that *all* scroll bars are to be removed, and then save a scroll bar
8013 from the fiery pit when we actually redisplay its window. */
8015 /* Arrange for all scroll bars on FRAME to be removed at the next call
8016 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8017 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8020 XTcondemn_scroll_bars (frame
)
8023 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8024 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8027 bar
= FRAME_SCROLL_BARS (frame
);
8028 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8029 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8030 XSCROLL_BAR (bar
)->prev
= Qnil
;
8031 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8032 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8033 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8037 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8038 Note that WINDOW isn't necessarily condemned at all. */
8040 XTredeem_scroll_bar (window
)
8041 struct window
*window
;
8043 struct scroll_bar
*bar
;
8045 /* We can't redeem this window's scroll bar if it doesn't have one. */
8046 if (NILP (window
->vertical_scroll_bar
))
8049 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8051 /* Unlink it from the condemned list. */
8053 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8055 if (NILP (bar
->prev
))
8057 /* If the prev pointer is nil, it must be the first in one of
8059 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8060 /* It's not condemned. Everything's fine. */
8062 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8063 window
->vertical_scroll_bar
))
8064 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8066 /* If its prev pointer is nil, it must be at the front of
8067 one or the other! */
8071 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8073 if (! NILP (bar
->next
))
8074 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8076 bar
->next
= FRAME_SCROLL_BARS (f
);
8078 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8079 if (! NILP (bar
->next
))
8080 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8084 /* Remove all scroll bars on FRAME that haven't been saved since the
8085 last call to `*condemn_scroll_bars_hook'. */
8088 XTjudge_scroll_bars (f
)
8091 Lisp_Object bar
, next
;
8093 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8095 /* Clear out the condemned list now so we won't try to process any
8096 more events on the hapless scroll bars. */
8097 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8099 for (; ! NILP (bar
); bar
= next
)
8101 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8103 x_scroll_bar_remove (b
);
8106 b
->next
= b
->prev
= Qnil
;
8109 /* Now there should be no references to the condemned scroll bars,
8110 and they should get garbage-collected. */
8114 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8115 is a no-op when using toolkit scroll bars.
8117 This may be called from a signal handler, so we have to ignore GC
8121 x_scroll_bar_expose (bar
, event
)
8122 struct scroll_bar
*bar
;
8125 #ifndef USE_TOOLKIT_SCROLL_BARS
8127 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8128 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8129 GC gc
= f
->output_data
.x
->normal_gc
;
8130 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8134 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8136 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8137 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8139 /* x, y, width, height */
8141 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8142 XINT (bar
->height
) - 1);
8146 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8149 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8150 is set to something other than no_event, it is enqueued.
8152 This may be called from a signal handler, so we have to ignore GC
8156 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8157 struct scroll_bar
*bar
;
8159 struct input_event
*emacs_event
;
8161 if (! GC_WINDOWP (bar
->window
))
8164 emacs_event
->kind
= scroll_bar_click
;
8165 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8166 emacs_event
->modifiers
8167 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8168 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8169 event
->xbutton
.state
)
8170 | (event
->type
== ButtonRelease
8173 emacs_event
->frame_or_window
= bar
->window
;
8174 emacs_event
->timestamp
= event
->xbutton
.time
;
8177 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8179 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8182 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8183 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8186 if (y
> top_range
) y
= top_range
;
8188 if (y
< XINT (bar
->start
))
8189 emacs_event
->part
= scroll_bar_above_handle
;
8190 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8191 emacs_event
->part
= scroll_bar_handle
;
8193 emacs_event
->part
= scroll_bar_below_handle
;
8195 /* Just because the user has clicked on the handle doesn't mean
8196 they want to drag it. Lisp code needs to be able to decide
8197 whether or not we're dragging. */
8199 /* If the user has just clicked on the handle, record where they're
8201 if (event
->type
== ButtonPress
8202 && emacs_event
->part
== scroll_bar_handle
)
8203 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8206 /* If the user has released the handle, set it to its final position. */
8207 if (event
->type
== ButtonRelease
8208 && ! NILP (bar
->dragging
))
8210 int new_start
= y
- XINT (bar
->dragging
);
8211 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8213 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8214 bar
->dragging
= Qnil
;
8217 /* Same deal here as the other #if 0. */
8219 /* Clicks on the handle are always reported as occurring at the top of
8221 if (emacs_event
->part
== scroll_bar_handle
)
8222 emacs_event
->x
= bar
->start
;
8224 XSETINT (emacs_event
->x
, y
);
8226 XSETINT (emacs_event
->x
, y
);
8229 XSETINT (emacs_event
->y
, top_range
);
8233 /* Handle some mouse motion while someone is dragging the scroll bar.
8235 This may be called from a signal handler, so we have to ignore GC
8239 x_scroll_bar_note_movement (bar
, event
)
8240 struct scroll_bar
*bar
;
8243 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8245 last_mouse_movement_time
= event
->xmotion
.time
;
8248 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8250 /* If we're dragging the bar, display it. */
8251 if (! GC_NILP (bar
->dragging
))
8253 /* Where should the handle be now? */
8254 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8256 if (new_start
!= XINT (bar
->start
))
8258 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8260 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8265 /* Return information to the user about the current position of the mouse
8266 on the scroll bar. */
8269 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8271 Lisp_Object
*bar_window
;
8272 enum scroll_bar_part
*part
;
8274 unsigned long *time
;
8276 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8277 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8278 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8280 Window dummy_window
;
8282 unsigned int dummy_mask
;
8286 /* Get the mouse's position relative to the scroll bar window, and
8288 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8290 /* Root, child, root x and root y. */
8291 &dummy_window
, &dummy_window
,
8292 &dummy_coord
, &dummy_coord
,
8294 /* Position relative to scroll bar. */
8297 /* Mouse buttons and modifier keys. */
8304 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8307 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8309 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8311 if (! NILP (bar
->dragging
))
8312 win_y
-= XINT (bar
->dragging
);
8316 if (win_y
> top_range
)
8320 *bar_window
= bar
->window
;
8322 if (! NILP (bar
->dragging
))
8323 *part
= scroll_bar_handle
;
8324 else if (win_y
< XINT (bar
->start
))
8325 *part
= scroll_bar_above_handle
;
8326 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8327 *part
= scroll_bar_handle
;
8329 *part
= scroll_bar_below_handle
;
8331 XSETINT (*x
, win_y
);
8332 XSETINT (*y
, top_range
);
8335 last_mouse_scroll_bar
= Qnil
;
8338 *time
= last_mouse_movement_time
;
8344 /* The screen has been cleared so we may have changed foreground or
8345 background colors, and the scroll bars may need to be redrawn.
8346 Clear out the scroll bars, and ask for expose events, so we can
8350 x_scroll_bar_clear (f
)
8353 #ifndef USE_TOOLKIT_SCROLL_BARS
8356 /* We can have scroll bars even if this is 0,
8357 if we just turned off scroll bar mode.
8358 But in that case we should not clear them. */
8359 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8360 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8361 bar
= XSCROLL_BAR (bar
)->next
)
8362 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8364 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8367 /* This processes Expose events from the menu-bar specific X event
8368 loop in xmenu.c. This allows to redisplay the frame if necessary
8369 when handling menu-bar or pop-up items. */
8372 process_expose_from_menu (event
)
8376 struct x_display_info
*dpyinfo
;
8377 int frame_exposed_p
= 0;
8381 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8382 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8385 if (f
->async_visible
== 0)
8387 f
->async_visible
= 1;
8388 f
->async_iconified
= 0;
8389 f
->output_data
.x
->has_been_visible
= 1;
8390 SET_FRAME_GARBAGED (f
);
8394 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8395 event
.xexpose
.x
, event
.xexpose
.y
,
8396 event
.xexpose
.width
, event
.xexpose
.height
);
8397 frame_exposed_p
= 1;
8402 struct scroll_bar
*bar
8403 = x_window_to_scroll_bar (event
.xexpose
.window
);
8406 x_scroll_bar_expose (bar
, &event
);
8410 return frame_exposed_p
;
8413 /* Define a queue to save up SelectionRequest events for later handling. */
8415 struct selection_event_queue
8418 struct selection_event_queue
*next
;
8421 static struct selection_event_queue
*queue
;
8423 /* Nonzero means queue up certain events--don't process them yet. */
8425 static int x_queue_selection_requests
;
8427 /* Queue up an X event *EVENT, to be processed later. */
8430 x_queue_event (f
, event
)
8434 struct selection_event_queue
*queue_tmp
8435 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8437 if (queue_tmp
!= NULL
)
8439 queue_tmp
->event
= *event
;
8440 queue_tmp
->next
= queue
;
8445 /* Take all the queued events and put them back
8446 so that they get processed afresh. */
8449 x_unqueue_events (display
)
8452 while (queue
!= NULL
)
8454 struct selection_event_queue
*queue_tmp
= queue
;
8455 XPutBackEvent (display
, &queue_tmp
->event
);
8456 queue
= queue_tmp
->next
;
8457 xfree ((char *)queue_tmp
);
8461 /* Start queuing SelectionRequest events. */
8464 x_start_queuing_selection_requests (display
)
8467 x_queue_selection_requests
++;
8470 /* Stop queuing SelectionRequest events. */
8473 x_stop_queuing_selection_requests (display
)
8476 x_queue_selection_requests
--;
8477 x_unqueue_events (display
);
8480 /* The main X event-reading loop - XTread_socket. */
8482 /* Time stamp of enter window event. This is only used by XTread_socket,
8483 but we have to put it out here, since static variables within functions
8484 sometimes don't work. */
8486 static Time enter_timestamp
;
8488 /* This holds the state XLookupString needs to implement dead keys
8489 and other tricks known as "compose processing". _X Window System_
8490 says that a portable program can't use this, but Stephen Gildea assures
8491 me that letting the compiler initialize it to zeros will work okay.
8493 This must be defined outside of XTread_socket, for the same reasons
8494 given for enter_time stamp, above. */
8496 static XComposeStatus compose_status
;
8498 /* Record the last 100 characters stored
8499 to help debug the loss-of-chars-during-GC problem. */
8501 static int temp_index
;
8502 static short temp_buffer
[100];
8504 /* Set this to nonzero to fake an "X I/O error"
8505 on a particular display. */
8507 struct x_display_info
*XTread_socket_fake_io_error
;
8509 /* When we find no input here, we occasionally do a no-op command
8510 to verify that the X server is still running and we can still talk with it.
8511 We try all the open displays, one by one.
8512 This variable is used for cycling thru the displays. */
8514 static struct x_display_info
*next_noop_dpyinfo
;
8516 #define SET_SAVED_MENU_EVENT(size) \
8519 if (f->output_data.x->saved_menu_event == 0) \
8520 f->output_data.x->saved_menu_event \
8521 = (XEvent *) xmalloc (sizeof (XEvent)); \
8522 bcopy (&event, f->output_data.x->saved_menu_event, size); \
8523 if (numchars >= 1) \
8525 bufp->kind = menu_bar_activate_event; \
8526 XSETFRAME (bufp->frame_or_window, f); \
8534 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
8535 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
8537 /* Read events coming from the X server.
8538 This routine is called by the SIGIO handler.
8539 We return as soon as there are no more events to be read.
8541 Events representing keys are stored in buffer BUFP,
8542 which can hold up to NUMCHARS characters.
8543 We return the number of characters stored into the buffer,
8544 thus pretending to be `read'.
8546 EXPECTED is nonzero if the caller knows input is available. */
8549 XTread_socket (sd
, bufp
, numchars
, expected
)
8551 /* register */ struct input_event
*bufp
;
8552 /* register */ int numchars
;
8559 int event_found
= 0;
8560 struct x_display_info
*dpyinfo
;
8562 Status status_return
;
8565 if (interrupt_input_blocked
)
8567 interrupt_input_pending
= 1;
8571 interrupt_input_pending
= 0;
8574 /* So people can tell when we have read the available input. */
8575 input_signal_count
++;
8578 abort (); /* Don't think this happens. */
8580 /* Find the display we are supposed to read input for.
8581 It's the one communicating on descriptor SD. */
8582 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
8584 #if 0 /* This ought to be unnecessary; let's verify it. */
8586 /* If available, Xlib uses FIOSNBIO to make the socket
8587 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
8588 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
8589 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
8590 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
8591 #endif /* ! defined (FIOSNBIO) */
8594 #if 0 /* This code can't be made to work, with multiple displays,
8595 and appears not to be used on any system any more.
8596 Also keyboard.c doesn't turn O_NDELAY on and off
8597 for X connections. */
8600 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
8602 extern int read_alarm_should_throw
;
8603 read_alarm_should_throw
= 1;
8604 XPeekEvent (dpyinfo
->display
, &event
);
8605 read_alarm_should_throw
= 0;
8607 #endif /* HAVE_SELECT */
8611 /* For debugging, this gives a way to fake an I/O error. */
8612 if (dpyinfo
== XTread_socket_fake_io_error
)
8614 XTread_socket_fake_io_error
= 0;
8615 x_io_error_quitter (dpyinfo
->display
);
8618 while (XPending (dpyinfo
->display
))
8620 XNextEvent (dpyinfo
->display
, &event
);
8622 if (display_busy_cursor_p
)
8624 /* Setting inhibit_busy_cursor to 2 inhibits busy-cursor
8625 display until the next X event is read and we come
8626 here again. Setting it to 1 inhibits busy-cursor
8627 display for direct commands. */
8628 if (event
.type
== MotionNotify
8629 || event
.type
== EnterNotify
8630 || (dpyinfo
->grabbed
8631 && event
.type
!= ButtonRelease
))
8632 inhibit_busy_cursor
= 2;
8634 inhibit_busy_cursor
= 1;
8639 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
8640 event
.xclient
.window
);
8641 /* The necessity of the following line took me
8642 a full work-day to decipher from the docs!! */
8643 if (f1
!= 0 && FRAME_XIC (f1
) && XFilterEvent (&event
, None
))
8653 if (event
.xclient
.message_type
8654 == dpyinfo
->Xatom_wm_protocols
8655 && event
.xclient
.format
== 32)
8657 if (event
.xclient
.data
.l
[0]
8658 == dpyinfo
->Xatom_wm_take_focus
)
8660 /* Use x_any_window_to_frame because this
8661 could be the shell widget window
8662 if the frame has no title bar. */
8663 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
8665 /* Not quite sure this is needed -pd */
8666 if (f
&& FRAME_XIC (f
))
8667 XSetICFocus (FRAME_XIC (f
));
8669 /* Since we set WM_TAKE_FOCUS, we must call
8670 XSetInputFocus explicitly. But not if f is null,
8671 since that might be an event for a deleted frame. */
8674 Display
*d
= event
.xclient
.display
;
8675 /* Catch and ignore errors, in case window has been
8676 iconified by a window manager such as GWM. */
8677 int count
= x_catch_errors (d
);
8678 XSetInputFocus (d
, event
.xclient
.window
,
8679 RevertToPointerRoot
,
8680 event
.xclient
.data
.l
[1]);
8681 /* This is needed to detect the error
8682 if there is an error. */
8684 x_uncatch_errors (d
, count
);
8686 /* Not certain about handling scroll bars here */
8688 else if (event
.xclient
.data
.l
[0]
8689 == dpyinfo
->Xatom_wm_save_yourself
)
8691 /* Save state modify the WM_COMMAND property to
8692 something which can reinstate us. This notifies
8693 the session manager, who's looking for such a
8694 PropertyNotify. Can restart processing when
8695 a keyboard or mouse event arrives. */
8698 f
= x_top_window_to_frame (dpyinfo
,
8699 event
.xclient
.window
);
8701 /* This is just so we only give real data once
8702 for a single Emacs process. */
8703 if (f
== selected_frame
)
8704 XSetCommand (FRAME_X_DISPLAY (f
),
8705 event
.xclient
.window
,
8706 initial_argv
, initial_argc
);
8708 XSetCommand (FRAME_X_DISPLAY (f
),
8709 event
.xclient
.window
,
8713 else if (event
.xclient
.data
.l
[0]
8714 == dpyinfo
->Xatom_wm_delete_window
)
8717 = x_any_window_to_frame (dpyinfo
,
8718 event
.xclient
.window
);
8725 bufp
->kind
= delete_window_event
;
8726 XSETFRAME (bufp
->frame_or_window
, f
);
8734 else if (event
.xclient
.message_type
8735 == dpyinfo
->Xatom_wm_configure_denied
)
8738 else if (event
.xclient
.message_type
8739 == dpyinfo
->Xatom_wm_window_moved
)
8743 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
8745 new_x
= event
.xclient
.data
.s
[0];
8746 new_y
= event
.xclient
.data
.s
[1];
8750 f
->output_data
.x
->left_pos
= new_x
;
8751 f
->output_data
.x
->top_pos
= new_y
;
8755 else if (event
.xclient
.message_type
8756 == dpyinfo
->Xatom_editres
)
8759 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
8760 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
8763 #endif /* HACK_EDITRES */
8764 else if ((event
.xclient
.message_type
8765 == dpyinfo
->Xatom_DONE
)
8766 || (event
.xclient
.message_type
8767 == dpyinfo
->Xatom_PAGE
))
8769 /* Ghostview job completed. Kill it. We could
8770 reply with "Next" if we received "Page", but we
8771 currently never do because we are interested in
8772 images, only, which should have 1 page. */
8773 Window gs_window
= (Window
) event
.xclient
.data
.l
[0];
8774 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
8776 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
8777 x_kill_gs_process (pixmap
, f
);
8778 expose_frame (f
, 0, 0, 0, 0);
8780 #ifdef USE_TOOLKIT_SCROLL_BARS
8781 /* Scroll bar callbacks send a ClientMessage from which
8782 we construct an input_event. */
8783 else if (event
.xclient
.message_type
8784 == dpyinfo
->Xatom_Scrollbar
)
8786 x_scroll_bar_to_input_event (&event
, bufp
);
8787 ++bufp
, ++count
, --numchars
;
8790 #endif /* USE_TOOLKIT_SCROLL_BARS */
8796 case SelectionNotify
:
8797 #ifdef USE_X_TOOLKIT
8798 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
8800 #endif /* not USE_X_TOOLKIT */
8801 x_handle_selection_notify (&event
.xselection
);
8804 case SelectionClear
: /* Someone has grabbed ownership. */
8805 #ifdef USE_X_TOOLKIT
8806 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
8808 #endif /* USE_X_TOOLKIT */
8810 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
8815 bufp
->kind
= selection_clear_event
;
8816 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
8817 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
8818 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
8819 bufp
->frame_or_window
= Qnil
;
8827 case SelectionRequest
: /* Someone wants our selection. */
8828 #ifdef USE_X_TOOLKIT
8829 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
8831 #endif /* USE_X_TOOLKIT */
8832 if (x_queue_selection_requests
)
8833 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
8837 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
8842 bufp
->kind
= selection_request_event
;
8843 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
8844 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
8845 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
8846 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
8847 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
8848 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
8849 bufp
->frame_or_window
= Qnil
;
8857 case PropertyNotify
:
8858 #ifdef USE_X_TOOLKIT
8859 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
8861 #endif /* not USE_X_TOOLKIT */
8862 x_handle_property_notify (&event
.xproperty
);
8865 case ReparentNotify
:
8866 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
8870 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
8871 x_real_positions (f
, &x
, &y
);
8872 f
->output_data
.x
->left_pos
= x
;
8873 f
->output_data
.x
->top_pos
= y
;
8878 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8881 if (f
->async_visible
== 0)
8883 f
->async_visible
= 1;
8884 f
->async_iconified
= 0;
8885 f
->output_data
.x
->has_been_visible
= 1;
8886 SET_FRAME_GARBAGED (f
);
8889 expose_frame (x_window_to_frame (dpyinfo
,
8890 event
.xexpose
.window
),
8891 event
.xexpose
.x
, event
.xexpose
.y
,
8892 event
.xexpose
.width
, event
.xexpose
.height
);
8896 #ifdef USE_TOOLKIT_SCROLL_BARS
8897 /* Dispatch event to the widget. */
8899 #else /* not USE_TOOLKIT_SCROLL_BARS */
8900 struct scroll_bar
*bar
8901 = x_window_to_scroll_bar (event
.xexpose
.window
);
8904 x_scroll_bar_expose (bar
, &event
);
8905 #ifdef USE_X_TOOLKIT
8908 #endif /* USE_X_TOOLKIT */
8909 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8913 case GraphicsExpose
: /* This occurs when an XCopyArea's
8914 source area was obscured or not
8916 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
8920 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
8921 event
.xgraphicsexpose
.width
,
8922 event
.xgraphicsexpose
.height
);
8924 #ifdef USE_X_TOOLKIT
8927 #endif /* USE_X_TOOLKIT */
8930 case NoExpose
: /* This occurs when an XCopyArea's
8931 source area was completely
8936 /* Redo the mouse-highlight after the tooltip has gone. */
8937 if (event
.xmap
.window
== tip_window
)
8940 redo_mouse_highlight ();
8943 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
8944 if (f
) /* F may no longer exist if
8945 the frame was deleted. */
8947 /* While a frame is unmapped, display generation is
8948 disabled; you don't want to spend time updating a
8949 display that won't ever be seen. */
8950 f
->async_visible
= 0;
8951 /* We can't distinguish, from the event, whether the window
8952 has become iconified or invisible. So assume, if it
8953 was previously visible, than now it is iconified.
8954 But x_make_frame_invisible clears both
8955 the visible flag and the iconified flag;
8956 and that way, we know the window is not iconified now. */
8957 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
8959 f
->async_iconified
= 1;
8961 bufp
->kind
= iconify_event
;
8962 XSETFRAME (bufp
->frame_or_window
, f
);
8971 if (event
.xmap
.window
== tip_window
)
8972 /* The tooltip has been drawn already. Avoid
8973 the SET_FRAME_GARBAGED below. */
8976 /* We use x_top_window_to_frame because map events can
8977 come for sub-windows and they don't mean that the
8978 frame is visible. */
8979 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
8982 f
->async_visible
= 1;
8983 f
->async_iconified
= 0;
8984 f
->output_data
.x
->has_been_visible
= 1;
8986 /* wait_reading_process_input will notice this and update
8987 the frame's display structures. */
8988 SET_FRAME_GARBAGED (f
);
8992 bufp
->kind
= deiconify_event
;
8993 XSETFRAME (bufp
->frame_or_window
, f
);
8998 else if (! NILP (Vframe_list
)
8999 && ! NILP (XCONS (Vframe_list
)->cdr
))
9000 /* Force a redisplay sooner or later
9001 to update the frame titles
9002 in case this is the second frame. */
9003 record_asynch_buffer_change ();
9008 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9011 /* I couldn't find a way to prevent LessTif scroll bars
9012 from consuming key events. */
9015 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9017 if (widget
&& XmIsScrollBar (widget
))
9019 widget
= XtParent (widget
);
9020 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9023 #endif /* USE_MOTIF */
9027 KeySym keysym
, orig_keysym
;
9028 /* al%imercury@uunet.uu.net says that making this 81 instead of
9029 80 fixed a bug whereby meta chars made his Emacs hang. */
9030 unsigned char copy_buffer
[81];
9034 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9035 extra_keyboard_modifiers
);
9036 modifiers
= event
.xkey
.state
;
9038 /* This will have to go some day... */
9040 /* make_lispy_event turns chars into control chars.
9041 Don't do it here because XLookupString is too eager. */
9042 event
.xkey
.state
&= ~ControlMask
;
9043 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9044 | dpyinfo
->super_mod_mask
9045 | dpyinfo
->hyper_mod_mask
9046 | dpyinfo
->alt_mod_mask
);
9048 /* In case Meta is ComposeCharacter,
9049 clear its status. According to Markus Ehrnsperger
9050 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9051 this enables ComposeCharacter to work whether or
9052 not it is combined with Meta. */
9053 if (modifiers
& dpyinfo
->meta_mod_mask
)
9054 bzero (&compose_status
, sizeof (compose_status
));
9059 /* The necessity of the following line took me
9060 a full work-day to decipher from the docs!! */
9061 if (XFilterEvent (&event
, None
))
9063 nbytes
= XmbLookupString (FRAME_XIC (f
),
9064 &event
.xkey
, copy_buffer
,
9067 if (status_return
== XLookupNone
)
9069 else if (status_return
== XLookupChars
)
9071 else if (status_return
!= XLookupKeySym
9072 && status_return
!= XLookupBoth
)
9076 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9077 80, &keysym
, &compose_status
);
9079 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9080 80, &keysym
, &compose_status
);
9083 orig_keysym
= keysym
;
9087 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9088 || keysym
== XK_Delete
9089 #ifdef XK_ISO_Left_Tab
9090 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9092 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9093 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9094 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9096 /* This recognizes the "extended function keys".
9097 It seems there's no cleaner way.
9098 Test IsModifierKey to avoid handling mode_switch
9100 || ((unsigned) (keysym
) >= XK_Select
9101 && (unsigned)(keysym
) < XK_KP_Space
)
9103 #ifdef XK_dead_circumflex
9104 || orig_keysym
== XK_dead_circumflex
9106 #ifdef XK_dead_grave
9107 || orig_keysym
== XK_dead_grave
9109 #ifdef XK_dead_tilde
9110 || orig_keysym
== XK_dead_tilde
9112 #ifdef XK_dead_diaeresis
9113 || orig_keysym
== XK_dead_diaeresis
9115 #ifdef XK_dead_macron
9116 || orig_keysym
== XK_dead_macron
9118 #ifdef XK_dead_degree
9119 || orig_keysym
== XK_dead_degree
9121 #ifdef XK_dead_acute
9122 || orig_keysym
== XK_dead_acute
9124 #ifdef XK_dead_cedilla
9125 || orig_keysym
== XK_dead_cedilla
9127 #ifdef XK_dead_breve
9128 || orig_keysym
== XK_dead_breve
9130 #ifdef XK_dead_ogonek
9131 || orig_keysym
== XK_dead_ogonek
9133 #ifdef XK_dead_caron
9134 || orig_keysym
== XK_dead_caron
9136 #ifdef XK_dead_doubleacute
9137 || orig_keysym
== XK_dead_doubleacute
9139 #ifdef XK_dead_abovedot
9140 || orig_keysym
== XK_dead_abovedot
9142 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9143 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9144 /* Any "vendor-specific" key is ok. */
9145 || (orig_keysym
& (1 << 28)))
9146 && ! (IsModifierKey (orig_keysym
)
9148 #ifdef XK_Mode_switch
9149 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9152 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9154 #endif /* not HAVE_X11R5 */
9157 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9159 temp_buffer
[temp_index
++] = keysym
;
9160 bufp
->kind
= non_ascii_keystroke
;
9161 bufp
->code
= keysym
;
9162 XSETFRAME (bufp
->frame_or_window
, f
);
9164 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9166 bufp
->timestamp
= event
.xkey
.time
;
9171 if (display_busy_cursor_p
)
9172 if (keysym
!= XK_Return
|| minibuf_level
== 0)
9173 inhibit_busy_cursor
= 2;
9175 else if (numchars
> nbytes
)
9179 for (i
= 0; i
< nbytes
; i
++)
9181 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9183 temp_buffer
[temp_index
++] = copy_buffer
[i
];
9184 bufp
->kind
= ascii_keystroke
;
9185 bufp
->code
= copy_buffer
[i
];
9186 XSETFRAME (bufp
->frame_or_window
, f
);
9188 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9190 bufp
->timestamp
= event
.xkey
.time
;
9197 if (keysym
== NoSymbol
)
9208 /* Here's a possible interpretation of the whole
9209 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9210 you get a FocusIn event, you have to get a FocusOut
9211 event before you relinquish the focus. If you
9212 haven't received a FocusIn event, then a mere
9213 LeaveNotify is enough to free you. */
9217 int from_menu_bar_p
= 0;
9219 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9221 #ifdef LESSTIF_VERSION
9222 /* When clicking outside of a menu bar popup to close
9223 it, we get a FocusIn/ EnterNotify sequence of
9224 events. The flag event.xcrossing.focus is not set
9225 in the EnterNotify event of that sequence because
9226 the focus is in the menu bar,
9227 event.xcrossing.window is the frame's X window.
9228 Unconditionally setting the focus frame to null in
9229 this case is not the right thing, because no event
9230 follows that could set the focus frame to the right
9233 This could be a LessTif bug, but I wasn't able to
9234 reproduce the behavior in a simple test program.
9236 (gerd, LessTif 0.88.1). */
9238 if (!event
.xcrossing
.focus
9240 && f
->output_data
.x
->menubar_widget
)
9245 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9246 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9247 from_menu_bar_p
= 1;
9249 #endif /* LESSTIF_VERSION */
9251 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9253 /* Avoid nasty pop/raise loops. */
9254 if (f
&& (!(f
->auto_raise
)
9256 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9258 x_new_focus_frame (dpyinfo
, f
);
9259 enter_timestamp
= event
.xcrossing
.time
;
9262 else if (f
== dpyinfo
->x_focus_frame
)
9263 x_new_focus_frame (dpyinfo
, 0);
9265 /* EnterNotify counts as mouse movement,
9266 so update things that depend on mouse position. */
9267 if (f
&& !f
->output_data
.x
->busy_p
)
9268 note_mouse_movement (f
, &event
.xmotion
);
9273 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9274 if (event
.xfocus
.detail
!= NotifyPointer
)
9275 dpyinfo
->x_focus_event_frame
= f
;
9277 x_new_focus_frame (dpyinfo
, f
);
9280 if (f
&& FRAME_XIC (f
))
9281 XSetICFocus (FRAME_XIC (f
));
9287 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9291 int from_menu_bar_p
= 0;
9293 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9295 /* If we move outside the frame, then we're
9296 certainly no longer on any text in the frame. */
9297 clear_mouse_face (dpyinfo
);
9298 dpyinfo
->mouse_face_mouse_frame
= 0;
9301 /* Generate a nil HELP_EVENT to cancel a help-echo.
9302 Do it only if there's something to cancel.
9303 Otherwise, the startup message is cleared when
9304 the mouse leaves the frame. */
9305 if (any_help_event_p
)
9307 XSETFRAME (frame
, f
);
9308 bufp
->kind
= HELP_EVENT
;
9309 bufp
->frame_or_window
= Fcons (frame
, Qnil
);
9310 ++bufp
, ++count
, --numchars
;
9313 #ifdef LESSTIF_VERSION
9314 /* Please see the comment at the start of the
9315 EnterNotify case. */
9316 if (!event
.xcrossing
.focus
9317 && f
->output_data
.x
->menubar_widget
)
9321 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9322 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9323 from_menu_bar_p
= 1;
9325 #endif /* LESSTIF_VERSION */
9327 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9328 x_mouse_leave (dpyinfo
);
9331 if (f
== dpyinfo
->x_focus_event_frame
)
9332 dpyinfo
->x_focus_event_frame
= 0;
9333 if (f
== dpyinfo
->x_focus_frame
)
9334 x_new_focus_frame (dpyinfo
, 0);
9340 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9341 if (event
.xfocus
.detail
!= NotifyPointer
9342 && f
== dpyinfo
->x_focus_event_frame
)
9343 dpyinfo
->x_focus_event_frame
= 0;
9344 if (f
&& f
== dpyinfo
->x_focus_frame
)
9345 x_new_focus_frame (dpyinfo
, 0);
9348 if (f
&& FRAME_XIC (f
))
9349 XUnsetICFocus (FRAME_XIC (f
));
9356 previous_help_echo
= help_echo
;
9359 if (dpyinfo
->grabbed
&& last_mouse_frame
9360 && FRAME_LIVE_P (last_mouse_frame
))
9361 f
= last_mouse_frame
;
9363 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9366 note_mouse_movement (f
, &event
.xmotion
);
9369 #ifndef USE_X_TOOLKIT
9370 struct scroll_bar
*bar
9371 = x_window_to_scroll_bar (event
.xmotion
.window
);
9374 x_scroll_bar_note_movement (bar
, &event
);
9375 #endif /* USE_X_TOOLKIT */
9377 /* If we move outside the frame, then we're
9378 certainly no longer on any text in the frame. */
9379 clear_mouse_face (dpyinfo
);
9382 /* If the contents of the global variable help_echo
9383 has changed, generate a HELP_EVENT. */
9384 if (STRINGP (help_echo
)
9385 || STRINGP (previous_help_echo
))
9390 XSETFRAME (frame
, f
);
9394 any_help_event_p
= 1;
9395 bufp
->kind
= HELP_EVENT
;
9396 bufp
->frame_or_window
= Fcons (frame
, help_echo
);
9397 ++bufp
, ++count
, --numchars
;
9403 case ConfigureNotify
:
9404 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
9407 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
9408 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
9410 #ifndef USE_X_TOOLKIT
9411 /* In the toolkit version, change_frame_size
9412 is called by the code that handles resizing
9413 of the EmacsFrame widget. */
9415 /* Even if the number of character rows and columns has
9416 not changed, the font size may have changed, so we need
9417 to check the pixel dimensions as well. */
9418 if (columns
!= f
->width
9419 || rows
!= f
->height
9420 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
9421 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
9423 change_frame_size (f
, rows
, columns
, 0, 1);
9424 SET_FRAME_GARBAGED (f
);
9425 cancel_mouse_face (f
);
9429 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
9430 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
9432 /* What we have now is the position of Emacs's own window.
9433 Convert that to the position of the window manager window. */
9434 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
9435 &f
->output_data
.x
->top_pos
);
9437 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
9439 /* Since the WM decorations come below top_pos now,
9440 we must put them below top_pos in the future. */
9441 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
9442 x_wm_set_size_hint (f
, (long) 0, 0);
9445 /* Some window managers pass (0,0) as the location of
9446 the window, and the Motif event handler stores it
9447 in the emacs widget, which messes up Motif menus. */
9448 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
9450 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
9451 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
9453 #endif /* USE_MOTIF */
9460 /* If we decide we want to generate an event to be seen
9461 by the rest of Emacs, we put it here. */
9462 struct input_event emacs_event
;
9465 emacs_event
.kind
= no_event
;
9466 bzero (&compose_status
, sizeof (compose_status
));
9468 if (dpyinfo
->grabbed
9470 && FRAME_LIVE_P (last_mouse_frame
))
9471 f
= last_mouse_frame
;
9473 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9477 /* Is this in the toolbar? */
9478 if (WINDOWP (f
->toolbar_window
)
9479 && XFASTINT (XWINDOW (f
->toolbar_window
)->height
))
9484 x
= event
.xbutton
.x
;
9485 y
= event
.xbutton
.y
;
9488 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
9489 if (EQ (window
, f
->toolbar_window
))
9491 x_handle_toolbar_click (f
, &event
.xbutton
);
9497 if (!dpyinfo
->x_focus_frame
9498 || f
== dpyinfo
->x_focus_frame
)
9499 construct_mouse_click (&emacs_event
, &event
, f
);
9503 #ifndef USE_TOOLKIT_SCROLL_BARS
9504 struct scroll_bar
*bar
9505 = x_window_to_scroll_bar (event
.xbutton
.window
);
9508 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
9509 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9512 if (event
.type
== ButtonPress
)
9514 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
9515 last_mouse_frame
= f
;
9516 /* Ignore any mouse motion that happened
9517 before this event; any subsequent mouse-movement
9518 Emacs events should reflect only motion after
9524 last_toolbar_item
= -1;
9525 if (display_busy_cursor_p
)
9526 inhibit_busy_cursor
= 2;
9530 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
9533 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
9535 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
9541 #ifdef USE_X_TOOLKIT
9542 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9543 /* For a down-event in the menu bar,
9544 don't pass it to Xt right now.
9545 Instead, save it away
9546 and we will pass it to Xt from kbd_buffer_get_event.
9547 That way, we can run some Lisp code first. */
9548 if (f
&& event
.type
== ButtonPress
9549 /* Verify the event is really within the menu bar
9550 and not just sent to it due to grabbing. */
9551 && event
.xbutton
.x
>= 0
9552 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
9553 && event
.xbutton
.y
>= 0
9554 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
9555 && event
.xbutton
.same_screen
)
9557 SET_SAVED_BUTTON_EVENT
;
9558 XSETFRAME (last_mouse_press_frame
, f
);
9560 else if (event
.type
== ButtonPress
)
9562 last_mouse_press_frame
= Qnil
;
9566 #ifdef USE_MOTIF /* This should do not harm for Lucid,
9567 but I am trying to be cautious. */
9568 else if (event
.type
== ButtonRelease
)
9570 if (!NILP (last_mouse_press_frame
))
9572 f
= XFRAME (last_mouse_press_frame
);
9573 if (f
->output_data
.x
)
9574 SET_SAVED_BUTTON_EVENT
;
9579 #endif /* USE_MOTIF */
9582 #endif /* USE_X_TOOLKIT */
9586 case CirculateNotify
:
9589 case CirculateRequest
:
9592 case VisibilityNotify
:
9596 /* Someone has changed the keyboard mapping - update the
9598 switch (event
.xmapping
.request
)
9600 case MappingModifier
:
9601 x_find_modifier_meanings (dpyinfo
);
9602 /* This is meant to fall through. */
9603 case MappingKeyboard
:
9604 XRefreshKeyboardMapping (&event
.xmapping
);
9610 #ifdef USE_X_TOOLKIT
9612 XtDispatchEvent (&event
);
9614 #endif /* USE_X_TOOLKIT */
9622 /* On some systems, an X bug causes Emacs to get no more events
9623 when the window is destroyed. Detect that. (1994.) */
9626 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
9627 One XNOOP in 100 loops will make Emacs terminate.
9628 B. Bretthauer, 1994 */
9630 if (x_noop_count
>= 100)
9634 if (next_noop_dpyinfo
== 0)
9635 next_noop_dpyinfo
= x_display_list
;
9637 XNoOp (next_noop_dpyinfo
->display
);
9639 /* Each time we get here, cycle through the displays now open. */
9640 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
9644 /* If the focus was just given to an auto-raising frame,
9646 /* ??? This ought to be able to handle more than one such frame. */
9647 if (pending_autoraise_frame
)
9649 x_raise_frame (pending_autoraise_frame
);
9650 pending_autoraise_frame
= 0;
9660 /***********************************************************************
9662 ***********************************************************************/
9664 /* Note if the text cursor of window W has been overwritten by a
9665 drawing operation that outputs N glyphs starting at HPOS in the
9666 line given by output_cursor.vpos. N < 0 means all the rest of the
9667 line after HPOS has been written. */
9670 note_overwritten_text_cursor (w
, hpos
, n
)
9674 if (updated_area
== TEXT_AREA
9675 && output_cursor
.vpos
== w
->phys_cursor
.vpos
9676 && hpos
<= w
->phys_cursor
.hpos
9678 || hpos
+ n
> w
->phys_cursor
.hpos
))
9679 w
->phys_cursor_on_p
= 0;
9683 /* Set clipping for output in glyph row ROW. W is the window in which
9684 we operate. GC is the graphics context to set clipping in.
9685 WHOLE_LINE_P non-zero means include the areas used for truncation
9686 mark display and alike in the clipping rectangle.
9688 ROW may be a text row or, e.g., a mode line. Text rows must be
9689 clipped to the interior of the window dedicated to text display,
9690 mode lines must be clipped to the whole window. */
9693 x_clip_to_row (w
, row
, gc
, whole_line_p
)
9695 struct glyph_row
*row
;
9699 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9700 XRectangle clip_rect
;
9701 int window_x
, window_y
, window_width
, window_height
;
9703 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9705 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
9706 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
9707 clip_rect
.y
= max (clip_rect
.y
, window_y
);
9708 clip_rect
.width
= window_width
;
9709 clip_rect
.height
= row
->visible_height
;
9711 /* If clipping to the whole line, including trunc marks, extend
9712 the rectangle to the left and increase its width. */
9715 clip_rect
.x
-= FRAME_X_FLAGS_AREA_WIDTH (f
);
9716 clip_rect
.width
+= 2 * FRAME_X_FLAGS_AREA_WIDTH (f
);
9719 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
9723 /* Draw a hollow box cursor on window W in glyph row ROW. */
9726 x_draw_hollow_cursor (w
, row
)
9728 struct glyph_row
*row
;
9730 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9731 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9732 Display
*dpy
= FRAME_X_DISPLAY (f
);
9735 struct glyph
*cursor_glyph
;
9738 /* Compute frame-relative coordinates from window-relative
9740 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9741 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
9742 + row
->ascent
- w
->phys_cursor_ascent
);
9743 h
= row
->height
- 1;
9745 /* Get the glyph the cursor is on. If we can't tell because
9746 the current matrix is invalid or such, give up. */
9747 cursor_glyph
= get_phys_cursor_glyph (w
);
9748 if (cursor_glyph
== NULL
)
9751 /* Compute the width of the rectangle to draw. If on a stretch
9752 glyph, and `x-stretch-block-cursor' is nil, don't draw a
9753 rectangle as wide as the glyph, but use a canonical character
9755 wd
= cursor_glyph
->pixel_width
- 1;
9756 if (cursor_glyph
->type
== STRETCH_GLYPH
9757 && !x_stretch_cursor_p
)
9758 wd
= min (CANON_X_UNIT (f
), wd
);
9760 /* The foreground of cursor_gc is typically the same as the normal
9761 background color, which can cause the cursor box to be invisible. */
9762 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9763 if (dpyinfo
->scratch_cursor_gc
)
9764 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
9766 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
9767 GCForeground
, &xgcv
);
9768 gc
= dpyinfo
->scratch_cursor_gc
;
9770 /* Set clipping, draw the rectangle, and reset clipping again. */
9771 x_clip_to_row (w
, row
, gc
, 0);
9772 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
9773 XSetClipMask (dpy
, gc
, None
);
9777 /* Draw a bar cursor on window W in glyph row ROW.
9779 Implementation note: One would like to draw a bar cursor with an
9780 angle equal to the one given by the font property XA_ITALIC_ANGLE.
9781 Unfortunately, I didn't find a font yet that has this property set.
9785 x_draw_bar_cursor (w
, row
)
9787 struct glyph_row
*row
;
9789 /* If cursor hpos is out of bounds, don't draw garbage. This can
9790 happen in mini-buffer windows when switching between echo area
9791 glyphs and mini-buffer. */
9792 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9794 struct frame
*f
= XFRAME (w
->frame
);
9795 struct glyph
*cursor_glyph
;
9803 cursor_glyph
= get_phys_cursor_glyph (w
);
9804 if (cursor_glyph
== NULL
)
9807 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
9808 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9809 xgcv
.graphics_exposures
= 0;
9810 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
9811 dpy
= FRAME_X_DISPLAY (f
);
9812 window
= FRAME_X_WINDOW (f
);
9813 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
9816 XChangeGC (dpy
, gc
, mask
, &xgcv
);
9819 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
9820 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
9823 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9824 x_clip_to_row (w
, row
, gc
, 0);
9825 XFillRectangle (dpy
, window
, gc
,
9827 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9828 min (cursor_glyph
->pixel_width
,
9829 f
->output_data
.x
->cursor_width
),
9831 XSetClipMask (dpy
, gc
, None
);
9836 /* Clear the cursor of window W to background color, and mark the
9837 cursor as not shown. This is used when the text where the cursor
9838 is is about to be rewritten. */
9844 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
9845 x_update_window_cursor (w
, 0);
9849 /* Draw the cursor glyph of window W in glyph row ROW. See the
9850 comment of x_draw_glyphs for the meaning of HL. */
9853 x_draw_phys_cursor_glyph (w
, row
, hl
)
9855 struct glyph_row
*row
;
9856 enum draw_glyphs_face hl
;
9858 /* If cursor hpos is out of bounds, don't draw garbage. This can
9859 happen in mini-buffer windows when switching between echo area
9860 glyphs and mini-buffer. */
9861 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9863 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
9864 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
9867 /* When we erase the cursor, and ROW is overlapped by other
9868 rows, make sure that these overlapping parts of other rows
9870 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
9872 if (row
> w
->current_matrix
->rows
9873 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
9874 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
9876 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
9877 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
9878 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
9884 /* Erase the image of a cursor of window W from the screen. */
9887 x_erase_phys_cursor (w
)
9890 struct frame
*f
= XFRAME (w
->frame
);
9891 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9892 int hpos
= w
->phys_cursor
.hpos
;
9893 int vpos
= w
->phys_cursor
.vpos
;
9894 int mouse_face_here_p
= 0;
9895 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
9896 struct glyph_row
*cursor_row
;
9897 struct glyph
*cursor_glyph
;
9898 enum draw_glyphs_face hl
;
9900 /* No cursor displayed or row invalidated => nothing to do on the
9902 if (w
->phys_cursor_type
== NO_CURSOR
)
9903 goto mark_cursor_off
;
9905 /* VPOS >= active_glyphs->nrows means that window has been resized.
9906 Don't bother to erase the cursor. */
9907 if (vpos
>= active_glyphs
->nrows
)
9908 goto mark_cursor_off
;
9910 /* If row containing cursor is marked invalid, there is nothing we
9912 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9913 if (!cursor_row
->enabled_p
)
9914 goto mark_cursor_off
;
9916 /* This can happen when the new row is shorter than the old one.
9917 In this case, either x_draw_glyphs or clear_end_of_line
9918 should have cleared the cursor. Note that we wouldn't be
9919 able to erase the cursor in this case because we don't have a
9920 cursor glyph at hand. */
9921 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9922 goto mark_cursor_off
;
9924 /* If the cursor is in the mouse face area, redisplay that when
9925 we clear the cursor. */
9926 if (w
== XWINDOW (dpyinfo
->mouse_face_window
)
9927 && (vpos
> dpyinfo
->mouse_face_beg_row
9928 || (vpos
== dpyinfo
->mouse_face_beg_row
9929 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9930 && (vpos
< dpyinfo
->mouse_face_end_row
9931 || (vpos
== dpyinfo
->mouse_face_end_row
9932 && hpos
< dpyinfo
->mouse_face_end_col
))
9933 /* Don't redraw the cursor's spot in mouse face if it is at the
9934 end of a line (on a newline). The cursor appears there, but
9935 mouse highlighting does not. */
9936 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9937 mouse_face_here_p
= 1;
9939 /* Maybe clear the display under the cursor. */
9940 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9943 int top_line_height
= WINDOW_DISPLAY_TOP_LINE_HEIGHT (w
);
9945 cursor_glyph
= get_phys_cursor_glyph (w
);
9946 if (cursor_glyph
== NULL
)
9947 goto mark_cursor_off
;
9949 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
9951 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9953 WINDOW_TO_FRAME_PIXEL_Y (w
, max (top_line_height
,
9955 cursor_glyph
->pixel_width
,
9956 cursor_row
->visible_height
,
9960 /* Erase the cursor by redrawing the character underneath it. */
9961 if (mouse_face_here_p
)
9962 hl
= DRAW_MOUSE_FACE
;
9963 else if (cursor_row
->inverse_p
)
9964 hl
= DRAW_INVERSE_VIDEO
;
9966 hl
= DRAW_NORMAL_TEXT
;
9967 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9970 w
->phys_cursor_on_p
= 0;
9971 w
->phys_cursor_type
= NO_CURSOR
;
9975 /* Display or clear cursor of window W. If ON is zero, clear the
9976 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9977 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9980 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9982 int on
, hpos
, vpos
, x
, y
;
9984 struct frame
*f
= XFRAME (w
->frame
);
9985 int new_cursor_type
;
9986 struct glyph_matrix
*current_glyphs
;
9987 struct glyph_row
*glyph_row
;
9988 struct glyph
*glyph
;
9990 /* This is pointless on invisible frames, and dangerous on garbaged
9991 windows and frames; in the latter case, the frame or window may
9992 be in the midst of changing its size, and x and y may be off the
9994 if (! FRAME_VISIBLE_P (f
)
9995 || FRAME_GARBAGED_P (f
)
9996 || vpos
>= w
->current_matrix
->nrows
9997 || hpos
>= w
->current_matrix
->matrix_w
)
10000 /* If cursor is off and we want it off, return quickly. */
10001 if (!on
&& !w
->phys_cursor_on_p
)
10004 current_glyphs
= w
->current_matrix
;
10005 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10006 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10008 /* If cursor row is not enabled, we don't really know where to
10009 display the cursor. */
10010 if (!glyph_row
->enabled_p
)
10012 w
->phys_cursor_on_p
= 0;
10016 xassert (interrupt_input_blocked
);
10018 /* Set new_cursor_type to the cursor we want to be displayed. In a
10019 mini-buffer window, we want the cursor only to appear if we are
10020 reading input from this window. For the selected window, we want
10021 the cursor type given by the frame parameter. If explicitly
10022 marked off, draw no cursor. In all other cases, we want a hollow
10024 if (cursor_in_echo_area
10025 && FRAME_HAS_MINIBUF_P (f
)
10026 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10028 if (w
== XWINDOW (echo_area_window
))
10029 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10031 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10035 if (w
!= XWINDOW (selected_window
)
10036 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10038 if (MINI_WINDOW_P (w
))
10039 new_cursor_type
= NO_CURSOR
;
10041 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10043 else if (w
->cursor_off_p
)
10044 new_cursor_type
= NO_CURSOR
;
10046 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10049 /* If cursor is currently being shown and we don't want it to be or
10050 it is in the wrong place, or the cursor type is not what we want,
10052 if (w
->phys_cursor_on_p
10054 || w
->phys_cursor
.x
!= x
10055 || w
->phys_cursor
.y
!= y
10056 || new_cursor_type
!= w
->phys_cursor_type
))
10057 x_erase_phys_cursor (w
);
10059 /* If the cursor is now invisible and we want it to be visible,
10061 if (on
&& !w
->phys_cursor_on_p
)
10063 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10064 w
->phys_cursor_height
= glyph_row
->height
;
10066 /* Set phys_cursor_.* before x_draw_.* is called because some
10067 of them may need the information. */
10068 w
->phys_cursor
.x
= x
;
10069 w
->phys_cursor
.y
= glyph_row
->y
;
10070 w
->phys_cursor
.hpos
= hpos
;
10071 w
->phys_cursor
.vpos
= vpos
;
10072 w
->phys_cursor_type
= new_cursor_type
;
10073 w
->phys_cursor_on_p
= 1;
10075 switch (new_cursor_type
)
10077 case HOLLOW_BOX_CURSOR
:
10078 x_draw_hollow_cursor (w
, glyph_row
);
10081 case FILLED_BOX_CURSOR
:
10082 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10086 x_draw_bar_cursor (w
, glyph_row
);
10098 if (updating_frame
!= f
)
10099 XFlush (FRAME_X_DISPLAY (f
));
10104 /* Display the cursor on window W, or clear it. X and Y are window
10105 relative pixel coordinates. HPOS and VPOS are glyph matrix
10106 positions. If W is not the selected window, display a hollow
10107 cursor. ON non-zero means display the cursor at X, Y which
10108 correspond to HPOS, VPOS, otherwise it is cleared. */
10111 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10113 int on
, hpos
, vpos
, x
, y
;
10116 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10121 /* Display the cursor on window W, or clear it, according to ON_P.
10122 Don't change the cursor's position. */
10125 x_update_cursor (f
, on_p
)
10128 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10132 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10133 in the window tree rooted at W. */
10136 x_update_cursor_in_window_tree (w
, on_p
)
10142 if (!NILP (w
->hchild
))
10143 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10144 else if (!NILP (w
->vchild
))
10145 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10147 x_update_window_cursor (w
, on_p
);
10149 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10154 /* Switch the display of W's cursor on or off, according to the value
10158 x_update_window_cursor (w
, on
)
10163 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10164 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10173 /* Refresh bitmap kitchen sink icon for frame F
10174 when we get an expose event for it. */
10180 /* Normally, the window manager handles this function. */
10183 /* Make the x-window of frame F use the gnu icon bitmap. */
10186 x_bitmap_icon (f
, file
)
10192 if (FRAME_X_WINDOW (f
) == 0)
10195 /* Free up our existing icon bitmap if any. */
10196 if (f
->output_data
.x
->icon_bitmap
> 0)
10197 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10198 f
->output_data
.x
->icon_bitmap
= 0;
10200 if (STRINGP (file
))
10201 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10204 /* Create the GNU bitmap if necessary. */
10205 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10206 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10207 = x_create_bitmap_from_data (f
, gnu_bits
,
10208 gnu_width
, gnu_height
);
10210 /* The first time we create the GNU bitmap,
10211 this increments the ref-count one extra time.
10212 As a result, the GNU bitmap is never freed.
10213 That way, we don't have to worry about allocating it again. */
10214 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10216 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10219 x_wm_set_icon_pixmap (f
, bitmap_id
);
10220 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10226 /* Make the x-window of frame F use a rectangle with text.
10227 Use ICON_NAME as the text. */
10230 x_text_icon (f
, icon_name
)
10234 if (FRAME_X_WINDOW (f
) == 0)
10239 XTextProperty text
;
10240 text
.value
= (unsigned char *) icon_name
;
10241 text
.encoding
= XA_STRING
;
10243 text
.nitems
= strlen (icon_name
);
10244 #ifdef USE_X_TOOLKIT
10245 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10247 #else /* not USE_X_TOOLKIT */
10248 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10249 #endif /* not USE_X_TOOLKIT */
10251 #else /* not HAVE_X11R4 */
10252 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10253 #endif /* not HAVE_X11R4 */
10255 if (f
->output_data
.x
->icon_bitmap
> 0)
10256 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10257 f
->output_data
.x
->icon_bitmap
= 0;
10258 x_wm_set_icon_pixmap (f
, 0);
10263 #define X_ERROR_MESSAGE_SIZE 200
10265 /* If non-nil, this should be a string.
10266 It means catch X errors and store the error message in this string. */
10268 static Lisp_Object x_error_message_string
;
10270 /* An X error handler which stores the error message in
10271 x_error_message_string. This is called from x_error_handler if
10272 x_catch_errors is in effect. */
10275 x_error_catcher (display
, error
)
10277 XErrorEvent
*error
;
10279 XGetErrorText (display
, error
->error_code
,
10280 XSTRING (x_error_message_string
)->data
,
10281 X_ERROR_MESSAGE_SIZE
);
10284 /* Begin trapping X errors for display DPY. Actually we trap X errors
10285 for all displays, but DPY should be the display you are actually
10288 After calling this function, X protocol errors no longer cause
10289 Emacs to exit; instead, they are recorded in the string
10290 stored in x_error_message_string.
10292 Calling x_check_errors signals an Emacs error if an X error has
10293 occurred since the last call to x_catch_errors or x_check_errors.
10295 Calling x_uncatch_errors resumes the normal error handling. */
10297 void x_check_errors ();
10298 static Lisp_Object
x_catch_errors_unwind ();
10301 x_catch_errors (dpy
)
10304 int count
= specpdl_ptr
- specpdl
;
10306 /* Make sure any errors from previous requests have been dealt with. */
10307 XSync (dpy
, False
);
10309 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10311 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10312 XSTRING (x_error_message_string
)->data
[0] = 0;
10317 /* Unbind the binding that we made to check for X errors. */
10320 x_catch_errors_unwind (old_val
)
10321 Lisp_Object old_val
;
10323 x_error_message_string
= old_val
;
10327 /* If any X protocol errors have arrived since the last call to
10328 x_catch_errors or x_check_errors, signal an Emacs error using
10329 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10332 x_check_errors (dpy
, format
)
10336 /* Make sure to catch any errors incurred so far. */
10337 XSync (dpy
, False
);
10339 if (XSTRING (x_error_message_string
)->data
[0])
10340 error (format
, XSTRING (x_error_message_string
)->data
);
10343 /* Nonzero if we had any X protocol errors
10344 since we did x_catch_errors on DPY. */
10347 x_had_errors_p (dpy
)
10350 /* Make sure to catch any errors incurred so far. */
10351 XSync (dpy
, False
);
10353 return XSTRING (x_error_message_string
)->data
[0] != 0;
10356 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
10359 x_clear_errors (dpy
)
10362 XSTRING (x_error_message_string
)->data
[0] = 0;
10365 /* Stop catching X protocol errors and let them make Emacs die.
10366 DPY should be the display that was passed to x_catch_errors.
10367 COUNT should be the value that was returned by
10368 the corresponding call to x_catch_errors. */
10371 x_uncatch_errors (dpy
, count
)
10375 unbind_to (count
, Qnil
);
10379 static unsigned int x_wire_count
;
10382 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
10387 /* Handle SIGPIPE, which can happen when the connection to a server
10388 simply goes away. SIGPIPE is handled by x_connection_signal.
10389 Don't need to do anything, because the write which caused the
10390 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
10391 which will do the appropriate cleanup for us. */
10394 x_connection_signal (signalnum
) /* If we don't have an argument, */
10395 int signalnum
; /* some compilers complain in signal calls. */
10398 /* USG systems forget handlers when they are used;
10399 must reestablish each time */
10400 signal (signalnum
, x_connection_signal
);
10404 /* Handling X errors. */
10406 /* Handle the loss of connection to display DISPLAY. */
10409 x_connection_closed (display
, error_message
)
10411 char *error_message
;
10413 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
10414 Lisp_Object frame
, tail
;
10416 /* Indicate that this display is dead. */
10418 #ifdef USE_X_TOOLKIT
10419 XtCloseDisplay (display
);
10422 dpyinfo
->display
= 0;
10424 /* First delete frames whose mini-buffers are on frames
10425 that are on the dead display. */
10426 FOR_EACH_FRAME (tail
, frame
)
10428 Lisp_Object minibuf_frame
;
10430 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
10431 if (FRAME_X_P (XFRAME (frame
))
10432 && FRAME_X_P (XFRAME (minibuf_frame
))
10433 && ! EQ (frame
, minibuf_frame
)
10434 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
10435 Fdelete_frame (frame
, Qt
);
10438 /* Now delete all remaining frames on the dead display.
10439 We are now sure none of these is used as the mini-buffer
10440 for another frame that we need to delete. */
10441 FOR_EACH_FRAME (tail
, frame
)
10442 if (FRAME_X_P (XFRAME (frame
))
10443 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
10445 /* Set this to t so that Fdelete_frame won't get confused
10446 trying to find a replacement. */
10447 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
10448 Fdelete_frame (frame
, Qt
);
10452 x_delete_display (dpyinfo
);
10454 if (x_display_list
== 0)
10456 fprintf (stderr
, "%s\n", error_message
);
10457 shut_down_emacs (0, 0, Qnil
);
10461 /* Ordinary stack unwind doesn't deal with these. */
10463 sigunblock (sigmask (SIGIO
));
10465 sigunblock (sigmask (SIGALRM
));
10466 TOTALLY_UNBLOCK_INPUT
;
10468 clear_waiting_for_input ();
10469 error ("%s", error_message
);
10472 /* This is the usual handler for X protocol errors.
10473 It kills all frames on the display that we got the error for.
10474 If that was the only one, it prints an error message and kills Emacs. */
10477 x_error_quitter (display
, error
)
10479 XErrorEvent
*error
;
10481 char buf
[256], buf1
[356];
10483 /* Note that there is no real way portable across R3/R4 to get the
10484 original error handler. */
10486 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
10487 sprintf (buf1
, "X protocol error: %s on protocol request %d",
10488 buf
, error
->request_code
);
10489 x_connection_closed (display
, buf1
);
10492 /* This is the first-level handler for X protocol errors.
10493 It calls x_error_quitter or x_error_catcher. */
10496 x_error_handler (display
, error
)
10498 XErrorEvent
*error
;
10500 if (! NILP (x_error_message_string
))
10501 x_error_catcher (display
, error
);
10503 x_error_quitter (display
, error
);
10507 /* This is the handler for X IO errors, always.
10508 It kills all frames on the display that we lost touch with.
10509 If that was the only one, it prints an error message and kills Emacs. */
10512 x_io_error_quitter (display
)
10517 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
10518 x_connection_closed (display
, buf
);
10522 /* Changing the font of the frame. */
10524 /* Give frame F the font named FONTNAME as its default font, and
10525 return the full name of that font. FONTNAME may be a wildcard
10526 pattern; in that case, we choose some font that fits the pattern.
10527 The return value shows which font we chose. */
10530 x_new_font (f
, fontname
)
10532 register char *fontname
;
10534 struct font_info
*fontp
10535 = fs_load_font (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
, fontname
, -1);
10540 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
10541 f
->output_data
.x
->font_baseline
10542 = (f
->output_data
.x
->font
->ascent
+ fontp
->baseline_offset
);
10543 f
->output_data
.x
->fontset
= -1;
10545 /* Compute the scroll bar width in character columns. */
10546 if (f
->scroll_bar_pixel_width
> 0)
10548 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10549 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
10553 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10554 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
10557 /* Now make the frame display the given font. */
10558 if (FRAME_X_WINDOW (f
) != 0)
10560 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
10561 f
->output_data
.x
->font
->fid
);
10562 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
10563 f
->output_data
.x
->font
->fid
);
10564 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
10565 f
->output_data
.x
->font
->fid
);
10567 frame_update_line_height (f
);
10568 x_set_window_size (f
, 0, f
->width
, f
->height
);
10571 /* If we are setting a new frame's font for the first time,
10572 there are no faces yet, so this font's height is the line height. */
10573 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
10575 return build_string (fontp
->full_name
);
10578 /* Give frame F the fontset named FONTSETNAME as its default font, and
10579 return the full name of that fontset. FONTSETNAME may be a wildcard
10580 pattern; in that case, we choose some fontset that fits the pattern.
10581 The return value shows which fontset we chose. */
10584 x_new_fontset (f
, fontsetname
)
10588 int fontset
= fs_query_fontset (f
, fontsetname
);
10589 struct fontset_info
*fontsetp
;
10590 Lisp_Object result
;
10595 if (f
->output_data
.x
->fontset
== fontset
)
10596 /* This fontset is already set in frame F. There's nothing more
10598 return build_string (fontsetname
);
10600 fontsetp
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
10602 if (!fontsetp
->fontname
[CHARSET_ASCII
])
10603 /* This fontset doesn't contain ASCII font. */
10606 result
= x_new_font (f
, fontsetp
->fontname
[CHARSET_ASCII
]);
10608 if (!STRINGP (result
))
10609 /* Can't load ASCII font. */
10612 /* Since x_new_font doesn't update any fontset information, do it now. */
10613 f
->output_data
.x
->fontset
= fontset
;
10614 FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
),
10615 CHARSET_ASCII
, fontsetp
->fontname
[CHARSET_ASCII
], fontset
);
10617 return build_string (fontsetname
);
10620 /* Calculate the absolute position in frame F
10621 from its current recorded position values and gravity. */
10624 x_calc_absolute_position (f
)
10628 int win_x
= 0, win_y
= 0;
10629 int flags
= f
->output_data
.x
->size_hint_flags
;
10632 /* We have nothing to do if the current position
10633 is already for the top-left corner. */
10634 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
10637 #ifdef USE_X_TOOLKIT
10638 this_window
= XtWindow (f
->output_data
.x
->widget
);
10640 this_window
= FRAME_X_WINDOW (f
);
10643 /* Find the position of the outside upper-left corner of
10644 the inner window, with respect to the outer window.
10645 But do this only if we will need the results. */
10646 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10651 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
10654 x_clear_errors (FRAME_X_DISPLAY (f
));
10655 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
10657 /* From-window, to-window. */
10659 f
->output_data
.x
->parent_desc
,
10661 /* From-position, to-position. */
10662 0, 0, &win_x
, &win_y
,
10664 /* Child of win. */
10666 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
10668 Window newroot
, newparent
= 0xdeadbeef;
10669 Window
*newchildren
;
10672 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
10673 &newparent
, &newchildren
, &nchildren
))
10676 XFree ((char *) newchildren
);
10678 f
->output_data
.x
->parent_desc
= newparent
;
10684 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
10688 /* Treat negative positions as relative to the leftmost bottommost
10689 position that fits on the screen. */
10690 if (flags
& XNegative
)
10691 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
10692 - 2 * f
->output_data
.x
->border_width
- win_x
10694 + f
->output_data
.x
->left_pos
);
10696 if (flags
& YNegative
)
10698 int menubar_height
= 0;
10700 #ifdef USE_X_TOOLKIT
10701 if (f
->output_data
.x
->menubar_widget
)
10703 = (f
->output_data
.x
->menubar_widget
->core
.height
10704 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
10707 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
10708 - 2 * f
->output_data
.x
->border_width
10712 + f
->output_data
.x
->top_pos
);
10715 /* The left_pos and top_pos
10716 are now relative to the top and left screen edges,
10717 so the flags should correspond. */
10718 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10721 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
10722 to really change the position, and 0 when calling from
10723 x_make_frame_visible (in that case, XOFF and YOFF are the current
10724 position values). It is -1 when calling from x_set_frame_parameters,
10725 which means, do adjust for borders but don't change the gravity. */
10728 x_set_offset (f
, xoff
, yoff
, change_gravity
)
10730 register int xoff
, yoff
;
10731 int change_gravity
;
10733 int modified_top
, modified_left
;
10735 if (change_gravity
> 0)
10737 f
->output_data
.x
->top_pos
= yoff
;
10738 f
->output_data
.x
->left_pos
= xoff
;
10739 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10741 f
->output_data
.x
->size_hint_flags
|= XNegative
;
10743 f
->output_data
.x
->size_hint_flags
|= YNegative
;
10744 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10746 x_calc_absolute_position (f
);
10749 x_wm_set_size_hint (f
, (long) 0, 0);
10751 modified_left
= f
->output_data
.x
->left_pos
;
10752 modified_top
= f
->output_data
.x
->top_pos
;
10753 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
10754 this seems to be unnecessary and incorrect. rms, 4/17/97. */
10755 /* It is a mystery why we need to add the border_width here
10756 when the frame is already visible, but experiment says we do. */
10757 if (change_gravity
!= 0)
10759 modified_left
+= f
->output_data
.x
->border_width
;
10760 modified_top
+= f
->output_data
.x
->border_width
;
10764 #ifdef USE_X_TOOLKIT
10765 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10766 modified_left
, modified_top
);
10767 #else /* not USE_X_TOOLKIT */
10768 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10769 modified_left
, modified_top
);
10770 #endif /* not USE_X_TOOLKIT */
10774 /* Call this to change the size of frame F's x-window.
10775 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
10776 for this size change and subsequent size changes.
10777 Otherwise we leave the window gravity unchanged. */
10780 x_set_window_size (f
, change_gravity
, cols
, rows
)
10782 int change_gravity
;
10785 #ifndef USE_X_TOOLKIT
10786 int pixelwidth
, pixelheight
;
10791 #ifdef USE_X_TOOLKIT
10793 /* The x and y position of the widget is clobbered by the
10794 call to XtSetValues within EmacsFrameSetCharSize.
10795 This is a real kludge, but I don't understand Xt so I can't
10796 figure out a correct fix. Can anyone else tell me? -- rms. */
10797 int xpos
= f
->output_data
.x
->widget
->core
.x
;
10798 int ypos
= f
->output_data
.x
->widget
->core
.y
;
10799 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
10800 f
->output_data
.x
->widget
->core
.x
= xpos
;
10801 f
->output_data
.x
->widget
->core
.y
= ypos
;
10804 #else /* not USE_X_TOOLKIT */
10806 check_frame_size (f
, &rows
, &cols
);
10807 f
->output_data
.x
->vertical_scroll_bar_extra
10808 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
10810 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
10811 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
10812 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
10813 f
->output_data
.x
->flags_areas_extra
10814 = 2 * FRAME_FLAGS_AREA_WIDTH (f
);
10815 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
10816 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
10818 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10819 x_wm_set_size_hint (f
, (long) 0, 0);
10821 XSync (FRAME_X_DISPLAY (f
), False
);
10822 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10823 pixelwidth
, pixelheight
);
10825 /* Now, strictly speaking, we can't be sure that this is accurate,
10826 but the window manager will get around to dealing with the size
10827 change request eventually, and we'll hear how it went when the
10828 ConfigureNotify event gets here.
10830 We could just not bother storing any of this information here,
10831 and let the ConfigureNotify event set everything up, but that
10832 might be kind of confusing to the Lisp code, since size changes
10833 wouldn't be reported in the frame parameters until some random
10834 point in the future when the ConfigureNotify event arrives.
10836 We pass 1 for DELAY since we can't run Lisp code inside of
10838 change_frame_size (f
, rows
, cols
, 0, 1);
10839 PIXEL_WIDTH (f
) = pixelwidth
;
10840 PIXEL_HEIGHT (f
) = pixelheight
;
10842 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
10843 receive in the ConfigureNotify event; if we get what we asked
10844 for, then the event won't cause the screen to become garbaged, so
10845 we have to make sure to do it here. */
10846 SET_FRAME_GARBAGED (f
);
10848 XFlush (FRAME_X_DISPLAY (f
));
10850 #endif /* not USE_X_TOOLKIT */
10852 /* If cursor was outside the new size, mark it as off. */
10853 mark_window_cursors_off (XWINDOW (f
->root_window
));
10855 /* Clear out any recollection of where the mouse highlighting was,
10856 since it might be in a place that's outside the new frame size.
10857 Actually checking whether it is outside is a pain in the neck,
10858 so don't try--just let the highlighting be done afresh with new size. */
10859 cancel_mouse_face (f
);
10864 /* Mouse warping. */
10867 x_set_mouse_position (f
, x
, y
)
10873 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
10874 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
10876 if (pix_x
< 0) pix_x
= 0;
10877 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
10879 if (pix_y
< 0) pix_y
= 0;
10880 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
10884 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
10885 0, 0, 0, 0, pix_x
, pix_y
);
10889 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
10892 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
10898 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
10899 0, 0, 0, 0, pix_x
, pix_y
);
10903 /* focus shifting, raising and lowering. */
10906 x_focus_on_frame (f
)
10909 #if 0 /* This proves to be unpleasant. */
10913 /* I don't think that the ICCCM allows programs to do things like this
10914 without the interaction of the window manager. Whatever you end up
10915 doing with this code, do it to x_unfocus_frame too. */
10916 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10917 RevertToPointerRoot
, CurrentTime
);
10922 x_unfocus_frame (f
)
10926 /* Look at the remarks in x_focus_on_frame. */
10927 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
10928 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
10929 RevertToPointerRoot
, CurrentTime
);
10933 /* Raise frame F. */
10939 if (f
->async_visible
)
10942 #ifdef USE_X_TOOLKIT
10943 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
10944 #else /* not USE_X_TOOLKIT */
10945 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10946 #endif /* not USE_X_TOOLKIT */
10947 XFlush (FRAME_X_DISPLAY (f
));
10952 /* Lower frame F. */
10958 if (f
->async_visible
)
10961 #ifdef USE_X_TOOLKIT
10962 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
10963 #else /* not USE_X_TOOLKIT */
10964 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10965 #endif /* not USE_X_TOOLKIT */
10966 XFlush (FRAME_X_DISPLAY (f
));
10972 XTframe_raise_lower (f
, raise_flag
)
10982 /* Change of visibility. */
10984 /* This tries to wait until the frame is really visible.
10985 However, if the window manager asks the user where to position
10986 the frame, this will return before the user finishes doing that.
10987 The frame will not actually be visible at that time,
10988 but it will become visible later when the window manager
10989 finishes with it. */
10992 x_make_frame_visible (f
)
10996 int original_top
, original_left
;
11000 type
= x_icon_type (f
);
11002 x_bitmap_icon (f
, type
);
11004 if (! FRAME_VISIBLE_P (f
))
11006 /* We test FRAME_GARBAGED_P here to make sure we don't
11007 call x_set_offset a second time
11008 if we get to x_make_frame_visible a second time
11009 before the window gets really visible. */
11010 if (! FRAME_ICONIFIED_P (f
)
11011 && ! f
->output_data
.x
->asked_for_visible
)
11012 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11014 f
->output_data
.x
->asked_for_visible
= 1;
11016 if (! EQ (Vx_no_window_manager
, Qt
))
11017 x_wm_set_window_state (f
, NormalState
);
11018 #ifdef USE_X_TOOLKIT
11019 /* This was XtPopup, but that did nothing for an iconified frame. */
11020 XtMapWidget (f
->output_data
.x
->widget
);
11021 #else /* not USE_X_TOOLKIT */
11022 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11023 #endif /* not USE_X_TOOLKIT */
11024 #if 0 /* This seems to bring back scroll bars in the wrong places
11025 if the window configuration has changed. They seem
11026 to come back ok without this. */
11027 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11028 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11032 XFlush (FRAME_X_DISPLAY (f
));
11034 /* Synchronize to ensure Emacs knows the frame is visible
11035 before we do anything else. We do this loop with input not blocked
11036 so that incoming events are handled. */
11039 int count
= input_signal_count
;
11040 /* This must be before UNBLOCK_INPUT
11041 since events that arrive in response to the actions above
11042 will set it when they are handled. */
11043 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11045 original_left
= f
->output_data
.x
->left_pos
;
11046 original_top
= f
->output_data
.x
->top_pos
;
11048 /* This must come after we set COUNT. */
11051 /* We unblock here so that arriving X events are processed. */
11053 /* Now move the window back to where it was "supposed to be".
11054 But don't do it if the gravity is negative.
11055 When the gravity is negative, this uses a position
11056 that is 3 pixels too low. Perhaps that's really the border width.
11058 Don't do this if the window has never been visible before,
11059 because the window manager may choose the position
11060 and we don't want to override it. */
11062 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11063 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11064 && previously_visible
)
11068 unsigned int width
, height
, border
, depth
;
11072 /* On some window managers (such as FVWM) moving an existing
11073 window, even to the same place, causes the window manager
11074 to introduce an offset. This can cause the window to move
11075 to an unexpected location. Check the geometry (a little
11076 slow here) and then verify that the window is in the right
11077 place. If the window is not in the right place, move it
11078 there, and take the potential window manager hit. */
11079 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11080 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11082 if (original_left
!= x
|| original_top
!= y
)
11083 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11084 original_left
, original_top
);
11089 XSETFRAME (frame
, f
);
11094 /* Once we have handled input events,
11095 we should have received the MapNotify if one is coming.
11096 So if we have not got it yet, stop looping.
11097 Some window managers make their own decisions
11098 about visibility. */
11099 if (input_signal_count
!= count
)
11101 /* Machines that do polling rather than SIGIO have been observed
11102 to go into a busy-wait here. So we'll fake an alarm signal
11103 to let the handler know that there's something to be read.
11104 We used to raise a real alarm, but it seems that the handler
11105 isn't always enabled here. This is probably a bug. */
11106 if (input_polling_used ())
11108 /* It could be confusing if a real alarm arrives while processing
11109 the fake one. Turn it off and let the handler reset it. */
11111 input_poll_signal (0);
11113 /* Once we have handled input events,
11114 we should have received the MapNotify if one is coming.
11115 So if we have not got it yet, stop looping.
11116 Some window managers make their own decisions
11117 about visibility. */
11118 if (input_signal_count
!= count
)
11121 FRAME_SAMPLE_VISIBILITY (f
);
11125 /* Change from mapped state to withdrawn state. */
11127 /* Make the frame visible (mapped and not iconified). */
11130 x_make_frame_invisible (f
)
11135 #ifdef USE_X_TOOLKIT
11136 /* Use the frame's outermost window, not the one we normally draw on. */
11137 window
= XtWindow (f
->output_data
.x
->widget
);
11138 #else /* not USE_X_TOOLKIT */
11139 window
= FRAME_X_WINDOW (f
);
11140 #endif /* not USE_X_TOOLKIT */
11142 /* Don't keep the highlight on an invisible frame. */
11143 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11144 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11146 #if 0/* This might add unreliability; I don't trust it -- rms. */
11147 if (! f
->async_visible
&& ! f
->async_iconified
)
11153 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11154 that the current position of the window is user-specified, rather than
11155 program-specified, so that when the window is mapped again, it will be
11156 placed at the same location, without forcing the user to position it
11157 by hand again (they have already done that once for this window.) */
11158 x_wm_set_size_hint (f
, (long) 0, 1);
11162 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11163 DefaultScreen (FRAME_X_DISPLAY (f
))))
11165 UNBLOCK_INPUT_RESIGNAL
;
11166 error ("Can't notify window manager of window withdrawal");
11168 #else /* ! defined (HAVE_X11R4) */
11170 /* Tell the window manager what we're going to do. */
11171 if (! EQ (Vx_no_window_manager
, Qt
))
11175 unmap
.xunmap
.type
= UnmapNotify
;
11176 unmap
.xunmap
.window
= window
;
11177 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
11178 unmap
.xunmap
.from_configure
= False
;
11179 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11180 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11182 SubstructureRedirectMaskSubstructureNotifyMask
,
11185 UNBLOCK_INPUT_RESIGNAL
;
11186 error ("Can't notify window manager of withdrawal");
11190 /* Unmap the window ourselves. Cheeky! */
11191 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
11192 #endif /* ! defined (HAVE_X11R4) */
11194 /* We can't distinguish this from iconification
11195 just by the event that we get from the server.
11196 So we can't win using the usual strategy of letting
11197 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11198 and synchronize with the server to make sure we agree. */
11200 FRAME_ICONIFIED_P (f
) = 0;
11201 f
->async_visible
= 0;
11202 f
->async_iconified
= 0;
11209 /* Change window state from mapped to iconified. */
11212 x_iconify_frame (f
)
11218 /* Don't keep the highlight on an invisible frame. */
11219 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11220 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11222 if (f
->async_iconified
)
11227 FRAME_SAMPLE_VISIBILITY (f
);
11229 type
= x_icon_type (f
);
11231 x_bitmap_icon (f
, type
);
11233 #ifdef USE_X_TOOLKIT
11235 if (! FRAME_VISIBLE_P (f
))
11237 if (! EQ (Vx_no_window_manager
, Qt
))
11238 x_wm_set_window_state (f
, IconicState
);
11239 /* This was XtPopup, but that did nothing for an iconified frame. */
11240 XtMapWidget (f
->output_data
.x
->widget
);
11241 /* The server won't give us any event to indicate
11242 that an invisible frame was changed to an icon,
11243 so we have to record it here. */
11246 f
->async_iconified
= 1;
11247 f
->async_visible
= 0;
11252 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11253 XtWindow (f
->output_data
.x
->widget
),
11254 DefaultScreen (FRAME_X_DISPLAY (f
)));
11258 error ("Can't notify window manager of iconification");
11260 f
->async_iconified
= 1;
11261 f
->async_visible
= 0;
11265 XFlush (FRAME_X_DISPLAY (f
));
11267 #else /* not USE_X_TOOLKIT */
11269 /* Make sure the X server knows where the window should be positioned,
11270 in case the user deiconifies with the window manager. */
11271 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
11272 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11274 /* Since we don't know which revision of X we're running, we'll use both
11275 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11277 /* X11R4: send a ClientMessage to the window manager using the
11278 WM_CHANGE_STATE type. */
11282 message
.xclient
.window
= FRAME_X_WINDOW (f
);
11283 message
.xclient
.type
= ClientMessage
;
11284 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11285 message
.xclient
.format
= 32;
11286 message
.xclient
.data
.l
[0] = IconicState
;
11288 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11289 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11291 SubstructureRedirectMask
| SubstructureNotifyMask
,
11294 UNBLOCK_INPUT_RESIGNAL
;
11295 error ("Can't notify window manager of iconification");
11299 /* X11R3: set the initial_state field of the window manager hints to
11301 x_wm_set_window_state (f
, IconicState
);
11303 if (!FRAME_VISIBLE_P (f
))
11305 /* If the frame was withdrawn, before, we must map it. */
11306 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11309 f
->async_iconified
= 1;
11310 f
->async_visible
= 0;
11312 XFlush (FRAME_X_DISPLAY (f
));
11314 #endif /* not USE_X_TOOLKIT */
11317 /* Destroy the X window of frame F. */
11320 x_destroy_window (f
)
11323 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11327 /* If a display connection is dead, don't try sending more
11328 commands to the X server. */
11329 if (dpyinfo
->display
!= 0)
11331 if (f
->output_data
.x
->icon_desc
!= 0)
11332 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
11336 XDestroyIC (FRAME_XIC (f
));
11337 #if ! defined (SOLARIS2) || defined (HAVE_X11R6)
11338 /* This line causes crashes on Solaris with Openwin,
11339 due to an apparent bug in XCloseIM.
11340 X11R6 seems not to have the bug. */
11341 XCloseIM (FRAME_XIM (f
));
11345 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
11346 #ifdef USE_X_TOOLKIT
11347 if (f
->output_data
.x
->widget
)
11348 XtDestroyWidget (f
->output_data
.x
->widget
);
11349 free_frame_menubar (f
);
11350 #endif /* USE_X_TOOLKIT */
11352 free_frame_faces (f
);
11353 XFlush (FRAME_X_DISPLAY (f
));
11356 if (f
->output_data
.x
->saved_menu_event
)
11357 xfree (f
->output_data
.x
->saved_menu_event
);
11359 xfree (f
->output_data
.x
);
11360 f
->output_data
.x
= 0;
11361 if (f
== dpyinfo
->x_focus_frame
)
11362 dpyinfo
->x_focus_frame
= 0;
11363 if (f
== dpyinfo
->x_focus_event_frame
)
11364 dpyinfo
->x_focus_event_frame
= 0;
11365 if (f
== dpyinfo
->x_highlight_frame
)
11366 dpyinfo
->x_highlight_frame
= 0;
11368 dpyinfo
->reference_count
--;
11370 if (f
== dpyinfo
->mouse_face_mouse_frame
)
11372 dpyinfo
->mouse_face_beg_row
11373 = dpyinfo
->mouse_face_beg_col
= -1;
11374 dpyinfo
->mouse_face_end_row
11375 = dpyinfo
->mouse_face_end_col
= -1;
11376 dpyinfo
->mouse_face_window
= Qnil
;
11377 dpyinfo
->mouse_face_deferred_gc
= 0;
11378 dpyinfo
->mouse_face_mouse_frame
= 0;
11384 /* Setting window manager hints. */
11386 /* Set the normal size hints for the window manager, for frame F.
11387 FLAGS is the flags word to use--or 0 meaning preserve the flags
11388 that the window now has.
11389 If USER_POSITION is nonzero, we set the USPosition
11390 flag (this is useful when FLAGS is 0). */
11393 x_wm_set_size_hint (f
, flags
, user_position
)
11398 XSizeHints size_hints
;
11400 #ifdef USE_X_TOOLKIT
11403 Dimension widget_width
, widget_height
;
11404 Window window
= XtWindow (f
->output_data
.x
->widget
);
11405 #else /* not USE_X_TOOLKIT */
11406 Window window
= FRAME_X_WINDOW (f
);
11407 #endif /* not USE_X_TOOLKIT */
11409 /* Setting PMaxSize caused various problems. */
11410 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
11412 size_hints
.x
= f
->output_data
.x
->left_pos
;
11413 size_hints
.y
= f
->output_data
.x
->top_pos
;
11415 #ifdef USE_X_TOOLKIT
11416 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
11417 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
11418 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
11419 size_hints
.height
= widget_height
;
11420 size_hints
.width
= widget_width
;
11421 #else /* not USE_X_TOOLKIT */
11422 size_hints
.height
= PIXEL_HEIGHT (f
);
11423 size_hints
.width
= PIXEL_WIDTH (f
);
11424 #endif /* not USE_X_TOOLKIT */
11426 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
11427 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
11428 size_hints
.max_width
11429 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
11430 size_hints
.max_height
11431 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
11433 /* Calculate the base and minimum sizes.
11435 (When we use the X toolkit, we don't do it here.
11436 Instead we copy the values that the widgets are using, below.) */
11437 #ifndef USE_X_TOOLKIT
11439 int base_width
, base_height
;
11440 int min_rows
= 0, min_cols
= 0;
11442 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
11443 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
11445 check_frame_size (f
, &min_rows
, &min_cols
);
11447 /* The window manager uses the base width hints to calculate the
11448 current number of rows and columns in the frame while
11449 resizing; min_width and min_height aren't useful for this
11450 purpose, since they might not give the dimensions for a
11451 zero-row, zero-column frame.
11453 We use the base_width and base_height members if we have
11454 them; otherwise, we set the min_width and min_height members
11455 to the size for a zero x zero frame. */
11458 size_hints
.flags
|= PBaseSize
;
11459 size_hints
.base_width
= base_width
;
11460 size_hints
.base_height
= base_height
;
11461 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
11462 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
11464 size_hints
.min_width
= base_width
;
11465 size_hints
.min_height
= base_height
;
11469 /* If we don't need the old flags, we don't need the old hint at all. */
11472 size_hints
.flags
|= flags
;
11475 #endif /* not USE_X_TOOLKIT */
11478 XSizeHints hints
; /* Sometimes I hate X Windows... */
11479 long supplied_return
;
11483 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
11486 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
11489 #ifdef USE_X_TOOLKIT
11490 size_hints
.base_height
= hints
.base_height
;
11491 size_hints
.base_width
= hints
.base_width
;
11492 size_hints
.min_height
= hints
.min_height
;
11493 size_hints
.min_width
= hints
.min_width
;
11497 size_hints
.flags
|= flags
;
11502 if (hints
.flags
& PSize
)
11503 size_hints
.flags
|= PSize
;
11504 if (hints
.flags
& PPosition
)
11505 size_hints
.flags
|= PPosition
;
11506 if (hints
.flags
& USPosition
)
11507 size_hints
.flags
|= USPosition
;
11508 if (hints
.flags
& USSize
)
11509 size_hints
.flags
|= USSize
;
11513 #ifndef USE_X_TOOLKIT
11518 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
11519 size_hints
.flags
|= PWinGravity
;
11523 size_hints
.flags
&= ~ PPosition
;
11524 size_hints
.flags
|= USPosition
;
11526 #endif /* PWinGravity */
11529 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11531 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11535 /* Used for IconicState or NormalState */
11538 x_wm_set_window_state (f
, state
)
11542 #ifdef USE_X_TOOLKIT
11545 XtSetArg (al
[0], XtNinitialState
, state
);
11546 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11547 #else /* not USE_X_TOOLKIT */
11548 Window window
= FRAME_X_WINDOW (f
);
11550 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
11551 f
->output_data
.x
->wm_hints
.initial_state
= state
;
11553 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11554 #endif /* not USE_X_TOOLKIT */
11558 x_wm_set_icon_pixmap (f
, pixmap_id
)
11562 Pixmap icon_pixmap
;
11564 #ifndef USE_X_TOOLKIT
11565 Window window
= FRAME_X_WINDOW (f
);
11570 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
11571 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
11575 /* It seems there is no way to turn off use of an icon pixmap.
11576 The following line does it, only if no icon has yet been created,
11577 for some window managers. But with mwm it crashes.
11578 Some people say it should clear the IconPixmapHint bit in this case,
11579 but that doesn't work, and the X consortium said it isn't the
11580 right thing at all. Since there is no way to win,
11581 best to explicitly give up. */
11583 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
11589 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
11593 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
11594 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11597 #else /* not USE_X_TOOLKIT */
11599 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
11600 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11602 #endif /* not USE_X_TOOLKIT */
11606 x_wm_set_icon_position (f
, icon_x
, icon_y
)
11608 int icon_x
, icon_y
;
11610 #ifdef USE_X_TOOLKIT
11611 Window window
= XtWindow (f
->output_data
.x
->widget
);
11613 Window window
= FRAME_X_WINDOW (f
);
11616 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
11617 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
11618 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
11620 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11624 /***********************************************************************
11626 ***********************************************************************/
11628 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
11631 x_get_font_info (f
, font_idx
)
11635 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
11639 /* Return a list of names of available fonts matching PATTERN on frame
11640 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
11641 to be listed. Frame F NULL means we have not yet created any
11642 frame on X, and consult the first display in x_display_list.
11643 MAXNAMES sets a limit on how many fonts to match. */
11646 x_list_fonts (f
, pattern
, size
, maxnames
)
11648 Lisp_Object pattern
;
11652 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
11653 Lisp_Object tem
, second_best
;
11654 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
11655 int try_XLoadQueryFont
= 0;
11658 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
11659 if (NILP (patterns
))
11660 patterns
= Fcons (pattern
, Qnil
);
11662 if (maxnames
== 1 && !size
)
11663 /* We can return any single font matching PATTERN. */
11664 try_XLoadQueryFont
= 1;
11666 for (; CONSP (patterns
); patterns
= XCONS (patterns
)->cdr
)
11671 pattern
= XCONS (patterns
)->car
;
11672 /* See if we cached the result for this particular query.
11673 The cache is an alist of the form:
11674 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
11676 if (f
&& (tem
= XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
,
11677 key
= Fcons (pattern
, make_number (maxnames
)),
11678 !NILP (list
= Fassoc (key
, tem
))))
11680 list
= Fcdr_safe (list
);
11681 /* We have a cashed list. Don't have to get the list again. */
11685 /* At first, put PATTERN in the cache. */
11688 count
= x_catch_errors (dpy
);
11690 if (try_XLoadQueryFont
)
11693 unsigned long value
;
11695 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
11696 if (x_had_errors_p (dpy
))
11698 /* This error is perhaps due to insufficient memory on X
11699 server. Let's just ignore it. */
11701 x_clear_errors (dpy
);
11705 && XGetFontProperty (font
, XA_FONT
, &value
))
11707 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
11708 int len
= strlen (name
);
11711 /* If DXPC (a Differential X Protocol Compressor)
11712 Ver.3.7 is running, XGetAtomName will return null
11713 string. We must avoid such a name. */
11715 try_XLoadQueryFont
= 0;
11719 names
= (char **) alloca (sizeof (char *));
11720 /* Some systems only allow alloca assigned to a
11722 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
11723 bcopy (name
, names
[0], len
+ 1);
11728 try_XLoadQueryFont
= 0;
11731 XFreeFont (dpy
, font
);
11734 if (!try_XLoadQueryFont
)
11736 /* We try at least 10 fonts because XListFonts will return
11737 auto-scaled fonts at the head. */
11738 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
11740 if (x_had_errors_p (dpy
))
11742 /* This error is perhaps due to insufficient memory on X
11743 server. Let's just ignore it. */
11745 x_clear_errors (dpy
);
11749 x_uncatch_errors (dpy
, count
);
11756 /* Make a list of all the fonts we got back.
11757 Store that in the font cache for the display. */
11758 for (i
= 0; i
< num_fonts
; i
++)
11761 char *p
= names
[i
];
11762 int average_width
= -1, dashes
= 0;
11764 /* Count the number of dashes in NAMES[I]. If there are
11765 14 dashes, and the field value following 12th dash
11766 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
11767 is usually too ugly to be used for editing. Let's
11773 if (dashes
== 7) /* PIXEL_SIZE field */
11775 else if (dashes
== 12) /* AVERAGE_WIDTH field */
11776 average_width
= atoi (p
);
11778 if (dashes
< 14 || average_width
!= 0)
11780 tem
= build_string (names
[i
]);
11781 if (NILP (Fassoc (tem
, list
)))
11783 if (STRINGP (Vx_pixel_size_width_font_regexp
)
11784 && ((fast_c_string_match_ignore_case
11785 (Vx_pixel_size_width_font_regexp
, names
[i
]))
11787 /* We can set the value of PIXEL_SIZE to the
11788 width of this font. */
11789 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
11791 /* For the moment, width is not known. */
11792 list
= Fcons (Fcons (tem
, Qnil
), list
);
11796 if (!try_XLoadQueryFont
)
11797 XFreeFontNames (names
);
11800 /* Now store the result in the cache. */
11802 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
11803 = Fcons (Fcons (key
, list
),
11804 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
);
11807 if (NILP (list
)) continue; /* Try the remaining alternatives. */
11809 newlist
= second_best
= Qnil
;
11810 /* Make a list of the fonts that have the right width. */
11811 for (; CONSP (list
); list
= XCONS (list
)->cdr
)
11815 tem
= XCONS (list
)->car
;
11817 if (!CONSP (tem
) || NILP (XCONS (tem
)->car
))
11821 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
11825 if (!INTEGERP (XCONS (tem
)->cdr
))
11827 /* Since we have not yet known the size of this font, we
11828 must try slow function call XLoadQueryFont. */
11829 XFontStruct
*thisinfo
;
11832 count
= x_catch_errors (dpy
);
11833 thisinfo
= XLoadQueryFont (dpy
,
11834 XSTRING (XCONS (tem
)->car
)->data
);
11835 if (x_had_errors_p (dpy
))
11837 /* This error is perhaps due to insufficient memory on X
11838 server. Let's just ignore it. */
11840 x_clear_errors (dpy
);
11842 x_uncatch_errors (dpy
, count
);
11848 = (thisinfo
->min_bounds
.width
== 0
11850 : make_number (thisinfo
->max_bounds
.width
));
11851 XFreeFont (dpy
, thisinfo
);
11854 /* For unknown reason, the previous call of XListFont had
11855 returned a font which can't be opened. Record the size
11856 as 0 not to try to open it again. */
11857 XCONS (tem
)->cdr
= make_number (0);
11860 found_size
= XINT (XCONS (tem
)->cdr
);
11861 if (found_size
== size
)
11862 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
11863 else if (found_size
> 0)
11865 if (NILP (second_best
))
11867 else if (found_size
< size
)
11869 if (XINT (XCONS (second_best
)->cdr
) > size
11870 || XINT (XCONS (second_best
)->cdr
) < found_size
)
11875 if (XINT (XCONS (second_best
)->cdr
) > size
11876 && XINT (XCONS (second_best
)->cdr
) > found_size
)
11881 if (!NILP (newlist
))
11883 else if (!NILP (second_best
))
11885 newlist
= Fcons (XCONS (second_best
)->car
, Qnil
);
11896 /* Check that FONT is valid on frame F. It is if it can be found in F's
11900 x_check_font (f
, font
)
11905 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11907 xassert (font
!= NULL
);
11909 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11910 if (dpyinfo
->font_table
[i
].name
11911 && font
== dpyinfo
->font_table
[i
].font
)
11914 xassert (i
< dpyinfo
->n_fonts
);
11917 #endif /* GLYPH_DEBUG != 0 */
11919 /* Set *W to the minimum width, *H to the minimum font height of FONT.
11920 Note: There are (broken) X fonts out there with invalid XFontStruct
11921 min_bounds contents. For example, handa@etl.go.jp reports that
11922 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
11923 have font->min_bounds.width == 0. */
11926 x_font_min_bounds (font
, w
, h
)
11930 *h
= FONT_HEIGHT (font
);
11931 *w
= font
->min_bounds
.width
;
11933 /* Try to handle the case where FONT->min_bounds has invalid
11934 contents. Since the only font known to have invalid min_bounds
11935 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
11937 *w
= font
->max_bounds
.width
;
11941 /* Compute the smallest character width and smallest font height over
11942 all fonts available on frame F. Set the members smallest_char_width
11943 and smallest_font_height in F's x_display_info structure to
11944 the values computed. Value is non-zero if smallest_font_height or
11945 smallest_char_width become smaller than they were before. */
11948 x_compute_min_glyph_bounds (f
)
11952 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11954 int old_width
= dpyinfo
->smallest_char_width
;
11955 int old_height
= dpyinfo
->smallest_font_height
;
11957 dpyinfo
->smallest_font_height
= 100000;
11958 dpyinfo
->smallest_char_width
= 100000;
11960 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
11961 if (dpyinfo
->font_table
[i
].name
)
11963 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
11966 font
= (XFontStruct
*) fontp
->font
;
11967 xassert (font
!= (XFontStruct
*) ~0);
11968 x_font_min_bounds (font
, &w
, &h
);
11970 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
11971 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
11974 xassert (dpyinfo
->smallest_char_width
> 0
11975 && dpyinfo
->smallest_font_height
> 0);
11977 return (dpyinfo
->n_fonts
== 1
11978 || dpyinfo
->smallest_char_width
< old_width
11979 || dpyinfo
->smallest_font_height
< old_height
);
11983 /* Load font named FONTNAME of the size SIZE for frame F, and return a
11984 pointer to the structure font_info while allocating it dynamically.
11985 If SIZE is 0, load any size of font.
11986 If loading is failed, return NULL. */
11989 x_load_font (f
, fontname
, size
)
11991 register char *fontname
;
11994 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11995 Lisp_Object font_names
;
11998 /* Get a list of all the fonts that match this name. Once we
11999 have a list of matching fonts, we compare them against the fonts
12000 we already have by comparing names. */
12001 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12003 if (!NILP (font_names
))
12008 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12009 for (tail
= font_names
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
12010 if (dpyinfo
->font_table
[i
].name
12011 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12012 XSTRING (XCONS (tail
)->car
)->data
)
12013 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12014 XSTRING (XCONS (tail
)->car
)->data
)))
12015 return (dpyinfo
->font_table
+ i
);
12018 /* Load the font and add it to the table. */
12022 struct font_info
*fontp
;
12023 unsigned long value
;
12026 /* If we have found fonts by x_list_font, load one of them. If
12027 not, we still try to load a font by the name given as FONTNAME
12028 because XListFonts (called in x_list_font) of some X server has
12029 a bug of not finding a font even if the font surely exists and
12030 is loadable by XLoadQueryFont. */
12031 if (size
> 0 && !NILP (font_names
))
12032 fontname
= (char *) XSTRING (XCONS (font_names
)->car
)->data
;
12035 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12036 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12037 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12039 /* This error is perhaps due to insufficient memory on X
12040 server. Let's just ignore it. */
12042 x_clear_errors (FRAME_X_DISPLAY (f
));
12044 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12049 /* Find a free slot in the font table. */
12050 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12051 if (dpyinfo
->font_table
[i
].name
== NULL
)
12054 /* If no free slot found, maybe enlarge the font table. */
12055 if (i
== dpyinfo
->n_fonts
12056 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12059 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12060 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12061 dpyinfo
->font_table
12062 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12065 fontp
= dpyinfo
->font_table
+ i
;
12066 if (i
== dpyinfo
->n_fonts
)
12067 ++dpyinfo
->n_fonts
;
12069 /* Now fill in the slots of *FONTP. */
12071 fontp
->font
= font
;
12072 fontp
->font_idx
= i
;
12073 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12074 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12076 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12078 if (XGetFontProperty (font
, XA_FONT
, &value
))
12080 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12084 /* Count the number of dashes in the "full name".
12085 If it is too few, this isn't really the font's full name,
12087 In X11R4, the fonts did not come with their canonical names
12098 full_name
= (char *) xmalloc (p
- name
+ 1);
12099 bcopy (name
, full_name
, p
- name
+ 1);
12105 if (full_name
!= 0)
12106 fontp
->full_name
= full_name
;
12108 fontp
->full_name
= fontp
->name
;
12110 fontp
->size
= font
->max_bounds
.width
;
12111 fontp
->height
= FONT_HEIGHT (font
);
12113 /* For some font, ascent and descent in max_bounds field is
12114 larger than the above value. */
12115 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12116 if (max_height
> fontp
->height
)
12117 fontp
->height
= max_height
;
12120 if (NILP (font_names
))
12122 /* We come here because of a bug of XListFonts mentioned at
12123 the head of this block. Let's store this information in
12124 the cache for x_list_fonts. */
12125 Lisp_Object lispy_name
= build_string (fontname
);
12126 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12128 XCONS (dpyinfo
->name_list_element
)->cdr
12129 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
12130 Fcons (Fcons (lispy_full_name
,
12131 make_number (fontp
->size
)),
12133 XCONS (dpyinfo
->name_list_element
)->cdr
);
12135 XCONS (dpyinfo
->name_list_element
)->cdr
12136 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
12137 Fcons (Fcons (lispy_full_name
,
12138 make_number (fontp
->size
)),
12140 XCONS (dpyinfo
->name_list_element
)->cdr
);
12143 /* The slot `encoding' specifies how to map a character
12144 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
12145 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
12146 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
12147 0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
12148 2:0xA020..0xFF7F). For the moment, we don't know which charset
12149 uses this font. So, we set information in fontp->encoding[1]
12150 which is never used by any charset. If mapping can't be
12151 decided, set FONT_ENCODING_NOT_DECIDED. */
12153 = (font
->max_byte1
== 0
12155 ? (font
->min_char_or_byte2
< 0x80
12156 ? (font
->max_char_or_byte2
< 0x80
12157 ? 0 /* 0x20..0x7F */
12158 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
12159 : 1) /* 0xA0..0xFF */
12161 : (font
->min_byte1
< 0x80
12162 ? (font
->max_byte1
< 0x80
12163 ? (font
->min_char_or_byte2
< 0x80
12164 ? (font
->max_char_or_byte2
< 0x80
12165 ? 0 /* 0x2020..0x7F7F */
12166 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
12167 : 3) /* 0x20A0..0x7FFF */
12168 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
12169 : (font
->min_char_or_byte2
< 0x80
12170 ? (font
->max_char_or_byte2
< 0x80
12171 ? 2 /* 0xA020..0xFF7F */
12172 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
12173 : 1))); /* 0xA0A0..0xFFFF */
12175 fontp
->baseline_offset
12176 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
12177 ? (long) value
: 0);
12178 fontp
->relative_compose
12179 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
12180 ? (long) value
: 0);
12181 fontp
->default_ascent
12182 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
12183 ? (long) value
: 0);
12185 /* Set global flag fonts_changed_p to non-zero if the font loaded
12186 has a character with a smaller width than any other character
12187 before, or if the font loaded has a smalle>r height than any
12188 other font loaded before. If this happens, it will make a
12189 glyph matrix reallocation necessary. */
12190 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
12197 /* Return a pointer to struct font_info of a font named FONTNAME for
12198 frame F. If no such font is loaded, return NULL. */
12201 x_query_font (f
, fontname
)
12203 register char *fontname
;
12205 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12208 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12209 if (dpyinfo
->font_table
[i
].name
12210 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
12211 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
12212 return (dpyinfo
->font_table
+ i
);
12217 /* Find a CCL program for a font specified by FONTP, and set the member
12218 `encoder' of the structure. */
12221 x_find_ccl_program (fontp
)
12222 struct font_info
*fontp
;
12224 Lisp_Object list
, elt
;
12226 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCONS (list
)->cdr
)
12228 elt
= XCONS (list
)->car
;
12230 && STRINGP (XCONS (elt
)->car
)
12231 && (fast_c_string_match_ignore_case (XCONS (elt
)->car
, fontp
->name
)
12237 struct ccl_program
*ccl
12238 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
12240 if (setup_ccl_program (ccl
, XCONS (elt
)->cdr
) < 0)
12243 fontp
->font_encoder
= ccl
;
12249 /***********************************************************************
12251 ***********************************************************************/
12253 #ifdef USE_X_TOOLKIT
12254 static XrmOptionDescRec emacs_options
[] = {
12255 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
12256 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
12258 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
12259 XrmoptionSepArg
, NULL
},
12260 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
12262 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12263 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12264 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12265 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12266 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12267 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
12268 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
12270 #endif /* USE_X_TOOLKIT */
12272 static int x_initialized
;
12274 #ifdef MULTI_KBOARD
12275 /* Test whether two display-name strings agree up to the dot that separates
12276 the screen number from the server number. */
12278 same_x_server (name1
, name2
)
12279 char *name1
, *name2
;
12281 int seen_colon
= 0;
12282 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
12283 int system_name_length
= strlen (system_name
);
12284 int length_until_period
= 0;
12286 while (system_name
[length_until_period
] != 0
12287 && system_name
[length_until_period
] != '.')
12288 length_until_period
++;
12290 /* Treat `unix' like an empty host name. */
12291 if (! strncmp (name1
, "unix:", 5))
12293 if (! strncmp (name2
, "unix:", 5))
12295 /* Treat this host's name like an empty host name. */
12296 if (! strncmp (name1
, system_name
, system_name_length
)
12297 && name1
[system_name_length
] == ':')
12298 name1
+= system_name_length
;
12299 if (! strncmp (name2
, system_name
, system_name_length
)
12300 && name2
[system_name_length
] == ':')
12301 name2
+= system_name_length
;
12302 /* Treat this host's domainless name like an empty host name. */
12303 if (! strncmp (name1
, system_name
, length_until_period
)
12304 && name1
[length_until_period
] == ':')
12305 name1
+= length_until_period
;
12306 if (! strncmp (name2
, system_name
, length_until_period
)
12307 && name2
[length_until_period
] == ':')
12308 name2
+= length_until_period
;
12310 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
12314 if (seen_colon
&& *name1
== '.')
12318 && (*name1
== '.' || *name1
== '\0')
12319 && (*name2
== '.' || *name2
== '\0'));
12323 #if defined (HAVE_X_I18N) || (defined (USE_X_TOOLKIT) && defined (HAVE_X11XTR6))
12324 /* Recover from setlocale (LC_ALL, ""). */
12328 /* Currently we require strerror to use the "C" locale,
12329 since we don't yet support decoding its string result. */
12331 setlocale (LC_MESSAGES
, "C");
12334 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
12335 so that numbers are read and printed properly for Emacs Lisp. */
12336 setlocale (LC_NUMERIC
, "C");
12338 /* Currently we require strftime to use the "C" locale,
12339 since we don't yet support encoding its format argument,
12340 or decoding its string result. */
12341 setlocale (LC_TIME
, "C");
12345 struct x_display_info
*
12346 x_term_init (display_name
, xrm_option
, resource_name
)
12347 Lisp_Object display_name
;
12349 char *resource_name
;
12353 struct x_display_info
*dpyinfo
;
12358 if (!x_initialized
)
12365 setlocale (LC_ALL
, "");
12369 #ifdef USE_X_TOOLKIT
12370 /* weiner@footloose.sps.mot.com reports that this causes
12372 X protocol error: BadAtom (invalid Atom parameter)
12373 on protocol request 18skiloaf.
12374 So let's not use it until R6. */
12375 #ifdef HAVE_X11XTR6
12376 XtSetLanguageProc (NULL
, NULL
, NULL
);
12387 argv
[argc
++] = "-xrm";
12388 argv
[argc
++] = xrm_option
;
12390 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
12391 resource_name
, EMACS_CLASS
,
12392 emacs_options
, XtNumber (emacs_options
),
12395 #ifdef HAVE_X11XTR6
12396 /* I think this is to compensate for XtSetLanguageProc. */
12401 #else /* not USE_X_TOOLKIT */
12403 XSetLocaleModifiers ("");
12405 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
12406 #endif /* not USE_X_TOOLKIT */
12408 /* Detect failure. */
12415 /* We have definitely succeeded. Record the new connection. */
12417 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
12419 #ifdef MULTI_KBOARD
12421 struct x_display_info
*share
;
12424 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
12425 share
= share
->next
, tail
= XCONS (tail
)->cdr
)
12426 if (same_x_server (XSTRING (XCONS (XCONS (tail
)->car
)->car
)->data
,
12427 XSTRING (display_name
)->data
))
12430 dpyinfo
->kboard
= share
->kboard
;
12433 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
12434 init_kboard (dpyinfo
->kboard
);
12435 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
12437 char *vendor
= ServerVendor (dpy
);
12438 dpyinfo
->kboard
->Vsystem_key_alist
12439 = call1 (Qvendor_specific_keysyms
,
12440 build_string (vendor
? vendor
: ""));
12443 dpyinfo
->kboard
->next_kboard
= all_kboards
;
12444 all_kboards
= dpyinfo
->kboard
;
12445 /* Don't let the initial kboard remain current longer than necessary.
12446 That would cause problems if a file loaded on startup tries to
12447 prompt in the mini-buffer. */
12448 if (current_kboard
== initial_kboard
)
12449 current_kboard
= dpyinfo
->kboard
;
12451 dpyinfo
->kboard
->reference_count
++;
12455 /* Put this display on the chain. */
12456 dpyinfo
->next
= x_display_list
;
12457 x_display_list
= dpyinfo
;
12459 /* Put it on x_display_name_list as well, to keep them parallel. */
12460 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
12461 x_display_name_list
);
12462 dpyinfo
->name_list_element
= XCONS (x_display_name_list
)->car
;
12464 dpyinfo
->display
= dpy
;
12467 XSetAfterFunction (x_current_display
, x_trace_wire
);
12471 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
12472 + STRING_BYTES (XSTRING (Vsystem_name
))
12474 sprintf (dpyinfo
->x_id_name
, "%s@%s",
12475 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
12477 /* Figure out which modifier bits mean what. */
12478 x_find_modifier_meanings (dpyinfo
);
12480 /* Get the scroll bar cursor. */
12481 dpyinfo
->vertical_scroll_bar_cursor
12482 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
12484 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
12485 resource_name
, EMACS_CLASS
);
12486 #ifdef HAVE_XRMSETDATABASE
12487 XrmSetDatabase (dpyinfo
->display
, xrdb
);
12489 dpyinfo
->display
->db
= xrdb
;
12491 /* Put the rdb where we can find it in a way that works on
12493 dpyinfo
->xrdb
= xrdb
;
12495 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
12496 DefaultScreen (dpyinfo
->display
));
12497 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
12498 &dpyinfo
->n_planes
);
12499 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
12500 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
12501 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
12502 dpyinfo
->grabbed
= 0;
12503 dpyinfo
->reference_count
= 0;
12504 dpyinfo
->icon_bitmap_id
= -1;
12505 dpyinfo
->font_table
= NULL
;
12506 dpyinfo
->n_fonts
= 0;
12507 dpyinfo
->font_table_size
= 0;
12508 dpyinfo
->bitmaps
= 0;
12509 dpyinfo
->bitmaps_size
= 0;
12510 dpyinfo
->bitmaps_last
= 0;
12511 dpyinfo
->scratch_cursor_gc
= 0;
12512 dpyinfo
->mouse_face_mouse_frame
= 0;
12513 dpyinfo
->mouse_face_deferred_gc
= 0;
12514 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
12515 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
12516 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
12517 dpyinfo
->mouse_face_window
= Qnil
;
12518 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
12519 dpyinfo
->mouse_face_defer
= 0;
12520 dpyinfo
->x_focus_frame
= 0;
12521 dpyinfo
->x_focus_event_frame
= 0;
12522 dpyinfo
->x_highlight_frame
= 0;
12523 dpyinfo
->image_cache
= make_image_cache ();
12526 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
12527 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
12528 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
12529 dpyinfo
->resy
= pixels
* 25.4 / mm
;
12530 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
12531 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
12532 dpyinfo
->resx
= pixels
* 25.4 / mm
;
12535 dpyinfo
->Xatom_wm_protocols
12536 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
12537 dpyinfo
->Xatom_wm_take_focus
12538 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
12539 dpyinfo
->Xatom_wm_save_yourself
12540 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
12541 dpyinfo
->Xatom_wm_delete_window
12542 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
12543 dpyinfo
->Xatom_wm_change_state
12544 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
12545 dpyinfo
->Xatom_wm_configure_denied
12546 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
12547 dpyinfo
->Xatom_wm_window_moved
12548 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
12549 dpyinfo
->Xatom_editres
12550 = XInternAtom (dpyinfo
->display
, "Editres", False
);
12551 dpyinfo
->Xatom_CLIPBOARD
12552 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
12553 dpyinfo
->Xatom_TIMESTAMP
12554 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
12555 dpyinfo
->Xatom_TEXT
12556 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
12557 dpyinfo
->Xatom_COMPOUND_TEXT
12558 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
12559 dpyinfo
->Xatom_DELETE
12560 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
12561 dpyinfo
->Xatom_MULTIPLE
12562 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
12563 dpyinfo
->Xatom_INCR
12564 = XInternAtom (dpyinfo
->display
, "INCR", False
);
12565 dpyinfo
->Xatom_EMACS_TMP
12566 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
12567 dpyinfo
->Xatom_TARGETS
12568 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
12569 dpyinfo
->Xatom_NULL
12570 = XInternAtom (dpyinfo
->display
, "NULL", False
);
12571 dpyinfo
->Xatom_ATOM_PAIR
12572 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
12573 /* For properties of font. */
12574 dpyinfo
->Xatom_PIXEL_SIZE
12575 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
12576 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
12577 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
12578 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
12579 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
12580 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
12581 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
12583 /* Ghostscript support. */
12584 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
12585 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
12587 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
12590 dpyinfo
->cut_buffers_initialized
= 0;
12592 connection
= ConnectionNumber (dpyinfo
->display
);
12593 dpyinfo
->connection
= connection
;
12598 null_bits
[0] = 0x00;
12600 dpyinfo
->null_pixel
12601 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
12602 null_bits
, 1, 1, (long) 0, (long) 0,
12607 extern int gray_bitmap_width
, gray_bitmap_height
;
12608 extern unsigned char *gray_bitmap_bits
;
12610 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
12612 gray_bitmap_width
, gray_bitmap_height
,
12613 (unsigned long) 1, (unsigned long) 0, 1);
12616 #ifdef subprocesses
12617 /* This is only needed for distinguishing keyboard and process input. */
12618 if (connection
!= 0)
12619 add_keyboard_wait_descriptor (connection
);
12622 #ifndef F_SETOWN_BUG
12624 #ifdef F_SETOWN_SOCK_NEG
12625 /* stdin is a socket here */
12626 fcntl (connection
, F_SETOWN
, -getpid ());
12627 #else /* ! defined (F_SETOWN_SOCK_NEG) */
12628 fcntl (connection
, F_SETOWN
, getpid ());
12629 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
12630 #endif /* ! defined (F_SETOWN) */
12631 #endif /* F_SETOWN_BUG */
12634 if (interrupt_input
)
12635 init_sigio (connection
);
12636 #endif /* ! defined (SIGIO) */
12639 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
12640 /* Make sure that we have a valid font for dialog boxes
12641 so that Xt does not crash. */
12643 Display
*dpy
= dpyinfo
->display
;
12644 XrmValue d
, fr
, to
;
12648 d
.addr
= (XPointer
)&dpy
;
12649 d
.size
= sizeof (Display
*);
12650 fr
.addr
= XtDefaultFont
;
12651 fr
.size
= sizeof (XtDefaultFont
);
12652 to
.size
= sizeof (Font
*);
12653 to
.addr
= (XPointer
)&font
;
12654 count
= x_catch_errors (dpy
);
12655 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
12657 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
12658 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
12659 x_uncatch_errors (dpy
, count
);
12669 /* Get rid of display DPYINFO, assuming all frames are already gone,
12670 and without sending any more commands to the X server. */
12673 x_delete_display (dpyinfo
)
12674 struct x_display_info
*dpyinfo
;
12676 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
12678 /* Discard this display from x_display_name_list and x_display_list.
12679 We can't use Fdelq because that can quit. */
12680 if (! NILP (x_display_name_list
)
12681 && EQ (XCONS (x_display_name_list
)->car
, dpyinfo
->name_list_element
))
12682 x_display_name_list
= XCONS (x_display_name_list
)->cdr
;
12687 tail
= x_display_name_list
;
12688 while (CONSP (tail
) && CONSP (XCONS (tail
)->cdr
))
12690 if (EQ (XCONS (XCONS (tail
)->cdr
)->car
,
12691 dpyinfo
->name_list_element
))
12693 XCONS (tail
)->cdr
= XCONS (XCONS (tail
)->cdr
)->cdr
;
12696 tail
= XCONS (tail
)->cdr
;
12700 if (x_display_list
== dpyinfo
)
12701 x_display_list
= dpyinfo
->next
;
12704 struct x_display_info
*tail
;
12706 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
12707 if (tail
->next
== dpyinfo
)
12708 tail
->next
= tail
->next
->next
;
12711 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
12712 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
12713 XrmDestroyDatabase (dpyinfo
->xrdb
);
12716 #ifdef MULTI_KBOARD
12717 if (--dpyinfo
->kboard
->reference_count
== 0)
12718 delete_kboard (dpyinfo
->kboard
);
12720 xfree (dpyinfo
->font_table
);
12721 xfree (dpyinfo
->x_id_name
);
12725 /* Set up use of X before we make the first connection. */
12727 static struct redisplay_interface x_redisplay_interface
=
12732 x_clear_end_of_line
,
12734 x_after_update_window_line
,
12735 x_update_window_begin
,
12736 x_update_window_end
,
12739 x_get_glyph_overhangs
,
12740 x_fix_overlapping_area
12746 rif
= &x_redisplay_interface
;
12748 clear_frame_hook
= x_clear_frame
;
12749 ins_del_lines_hook
= x_ins_del_lines
;
12750 change_line_highlight_hook
= x_change_line_highlight
;
12751 delete_glyphs_hook
= x_delete_glyphs
;
12752 ring_bell_hook
= XTring_bell
;
12753 reset_terminal_modes_hook
= XTreset_terminal_modes
;
12754 set_terminal_modes_hook
= XTset_terminal_modes
;
12755 update_begin_hook
= x_update_begin
;
12756 update_end_hook
= x_update_end
;
12757 set_terminal_window_hook
= XTset_terminal_window
;
12758 read_socket_hook
= XTread_socket
;
12759 frame_up_to_date_hook
= XTframe_up_to_date
;
12760 reassert_line_highlight_hook
= XTreassert_line_highlight
;
12761 mouse_position_hook
= XTmouse_position
;
12762 frame_rehighlight_hook
= XTframe_rehighlight
;
12763 frame_raise_lower_hook
= XTframe_raise_lower
;
12764 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
12765 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
12766 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
12767 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
12768 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
12770 scroll_region_ok
= 1; /* we'll scroll partial frames */
12771 char_ins_del_ok
= 0; /* just as fast to write the line */
12772 line_ins_del_ok
= 1; /* we'll just blt 'em */
12773 fast_clear_end_of_line
= 1; /* X does this well */
12774 memory_below_frame
= 0; /* we don't remember what scrolls
12779 last_toolbar_item
= -1;
12780 any_help_event_p
= 0;
12782 /* Try to use interrupt input; if we can't, then start polling. */
12783 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
12785 #ifdef USE_X_TOOLKIT
12786 XtToolkitInitialize ();
12787 Xt_app_con
= XtCreateApplicationContext ();
12788 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
12791 /* Note that there is no real way portable across R3/R4 to get the
12792 original error handler. */
12793 XSetErrorHandler (x_error_handler
);
12794 XSetIOErrorHandler (x_io_error_quitter
);
12796 /* Disable Window Change signals; they are handled by X events. */
12798 signal (SIGWINCH
, SIG_DFL
);
12799 #endif /* ! defined (SIGWINCH) */
12801 signal (SIGPIPE
, x_connection_signal
);
12808 staticpro (&x_error_message_string
);
12809 x_error_message_string
= Qnil
;
12811 staticpro (&x_display_name_list
);
12812 x_display_name_list
= Qnil
;
12814 staticpro (&last_mouse_scroll_bar
);
12815 last_mouse_scroll_bar
= Qnil
;
12817 staticpro (&Qvendor_specific_keysyms
);
12818 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
12820 staticpro (&last_mouse_press_frame
);
12821 last_mouse_press_frame
= Qnil
;
12823 staticpro (&help_echo
);
12825 staticpro (&previous_help_echo
);
12826 previous_help_echo
= Qnil
;
12828 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
12829 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
12830 For example, if a block cursor is over a tab, it will be drawn as\n\
12831 wide as that tab on the display.");
12832 x_stretch_cursor_p
= 0;
12834 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
12835 "If not nil, Emacs uses toolkit scroll bars.");
12836 #if USE_TOOLKIT_SCROLL_BARS
12837 x_toolkit_scroll_bars_p
= 1;
12839 x_toolkit_scroll_bars_p
= 0;
12842 defsubr (&Sxt_process_timeouts
);
12843 staticpro (&last_mouse_motion_frame
);
12844 last_mouse_motion_frame
= Qnil
;
12847 #endif /* not HAVE_X_WINDOWS */