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 /* Right truncation arrow bitmap `->'. */
202 #define right_width 8
203 #define right_height 8
204 static unsigned char right_bits
[] = {
205 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
207 /* Marker for continued lines. */
209 #define continued_width 8
210 #define continued_height 8
211 static unsigned char continued_bits
[] = {
212 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
214 /* Marker for continuation lines. */
216 #define continuation_width 8
217 #define continuation_height 8
218 static unsigned char continuation_bits
[] = {
219 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
221 /* Overlay arrow bitmap. */
227 static unsigned char ov_bits
[] = {
228 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
230 /* A triangular arrow. */
233 static unsigned char ov_bits
[] = {
234 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
238 extern Lisp_Object Qhelp_echo
;
241 /* Non-zero means Emacs uses toolkit scroll bars. */
243 int x_toolkit_scroll_bars_p
;
245 /* If a string, XTread_socket generates an event to display that string.
246 (The display is done in read_char.) */
248 static Lisp_Object help_echo
;
250 /* Temporary variable for XTread_socket. */
252 static Lisp_Object previous_help_echo
;
254 /* Non-zero means that a HELP_EVENT has been generated since Emacs
257 static int any_help_event_p
;
259 /* Non-zero means draw block and hollow cursor as wide as the glyph
260 under it. For example, if a block cursor is over a tab, it will be
261 drawn as wide as that tab on the display. */
263 int x_stretch_cursor_p
;
265 /* This is a chain of structures for all the X displays currently in
268 struct x_display_info
*x_display_list
;
270 /* This is a list of cons cells, each of the form (NAME
271 . FONT-LIST-CACHE), one for each element of x_display_list and in
272 the same order. NAME is the name of the frame. FONT-LIST-CACHE
273 records previous values returned by x-list-fonts. */
275 Lisp_Object x_display_name_list
;
277 /* Frame being updated by update_frame. This is declared in term.c.
278 This is set by update_begin and looked at by all the XT functions.
279 It is zero while not inside an update. In that case, the XT
280 functions assume that `selected_frame' is the frame to apply to. */
282 extern struct frame
*updating_frame
;
284 extern int waiting_for_input
;
286 /* This is a frame waiting to be auto-raised, within XTread_socket. */
288 struct frame
*pending_autoraise_frame
;
291 /* The application context for Xt use. */
292 XtAppContext Xt_app_con
;
293 static String Xt_default_resources
[] = {0};
294 #endif /* USE_X_TOOLKIT */
296 /* Nominal cursor position -- where to draw output.
297 HPOS and VPOS are window relative glyph matrix coordinates.
298 X and Y are window relative pixel coordinates. */
300 struct cursor_pos output_cursor
;
305 Formerly, we used PointerMotionHintMask (in standard_event_mask)
306 so that we would have to call XQueryPointer after each MotionNotify
307 event to ask for another such event. However, this made mouse tracking
308 slow, and there was a bug that made it eventually stop.
310 Simply asking for MotionNotify all the time seems to work better.
312 In order to avoid asking for motion events and then throwing most
313 of them away or busy-polling the server for mouse positions, we ask
314 the server for pointer motion hints. This means that we get only
315 one event per group of mouse movements. "Groups" are delimited by
316 other kinds of events (focus changes and button clicks, for
317 example), or by XQueryPointer calls; when one of these happens, we
318 get another MotionNotify event the next time the mouse moves. This
319 is at least as efficient as getting motion events when mouse
320 tracking is on, and I suspect only negligibly worse when tracking
323 /* Where the mouse was last time we reported a mouse event. */
325 FRAME_PTR last_mouse_frame
;
326 static XRectangle last_mouse_glyph
;
327 static Lisp_Object last_mouse_press_frame
;
329 /* The scroll bar in which the last X motion event occurred.
331 If the last X motion event occurred in a scroll bar, we set this so
332 XTmouse_position can know whether to report a scroll bar motion or
335 If the last X motion event didn't occur in a scroll bar, we set
336 this to Qnil, to tell XTmouse_position to return an ordinary motion
339 static Lisp_Object last_mouse_scroll_bar
;
341 /* This is a hack. We would really prefer that XTmouse_position would
342 return the time associated with the position it returns, but there
343 doesn't seem to be any way to wrest the time-stamp from the server
344 along with the position query. So, we just keep track of the time
345 of the last movement we received, and return that in hopes that
346 it's somewhat accurate. */
348 static Time last_mouse_movement_time
;
350 /* Incremented by XTread_socket whenever it really tries to read
354 static int volatile input_signal_count
;
356 static int input_signal_count
;
359 /* Used locally within XTread_socket. */
361 static int x_noop_count
;
363 /* Initial values of argv and argc. */
365 extern char **initial_argv
;
366 extern int initial_argc
;
368 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
370 /* Tells if a window manager is present or not. */
372 extern Lisp_Object Vx_no_window_manager
;
374 extern Lisp_Object Qface
, Qmouse_face
;
378 /* A mask of extra modifier bits to put into every keyboard char. */
380 extern int extra_keyboard_modifiers
;
382 static Lisp_Object Qvendor_specific_keysyms
;
384 extern XrmDatabase
x_load_resources ();
385 extern Lisp_Object
x_icon_type ();
388 /* Enumeration for overriding/changing the face to use for drawing
389 glyphs in x_draw_glyphs. */
391 enum draw_glyphs_face
401 static void x_update_window_end
P_ ((struct window
*, int));
402 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
403 void x_delete_display
P_ ((struct x_display_info
*));
404 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
406 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
408 static void set_output_cursor
P_ ((struct cursor_pos
*));
409 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
410 int *, int *, int *));
411 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
412 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
413 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
414 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
415 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
416 static void show_mouse_face
P_ ((struct x_display_info
*,
417 enum draw_glyphs_face
));
418 static int x_io_error_quitter
P_ ((Display
*));
419 int x_catch_errors
P_ ((Display
*));
420 void x_uncatch_errors
P_ ((Display
*, int));
421 void x_lower_frame
P_ ((struct frame
*));
422 void x_scroll_bar_clear
P_ ((struct frame
*));
423 int x_had_errors_p
P_ ((Display
*));
424 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
425 void x_raise_frame
P_ ((struct frame
*));
426 void x_set_window_size
P_ ((struct frame
*, int, int, int));
427 void x_wm_set_window_state
P_ ((struct frame
*, int));
428 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
429 void x_initialize
P_ ((void));
430 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
431 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
432 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
434 enum draw_glyphs_face
));
435 static void x_update_end
P_ ((struct frame
*));
436 static void XTframe_up_to_date
P_ ((struct frame
*));
437 static void XTreassert_line_highlight
P_ ((int, int));
438 static void x_change_line_highlight
P_ ((int, int, int, int));
439 static void XTset_terminal_modes
P_ ((void));
440 static void XTreset_terminal_modes
P_ ((void));
441 static void XTcursor_to
P_ ((int, int, int, int));
442 static void x_write_glyphs
P_ ((struct glyph
*, int));
443 static void x_clear_end_of_line
P_ ((int));
444 static void x_clear_frame
P_ ((void));
445 static void x_clear_cursor
P_ ((struct window
*));
446 static void frame_highlight
P_ ((struct frame
*));
447 static void frame_unhighlight
P_ ((struct frame
*));
448 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
449 static void XTframe_rehighlight
P_ ((struct frame
*));
450 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
451 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
452 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*));
453 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
455 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
456 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
457 static void expose_window
P_ ((struct window
*, XRectangle
*));
458 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
459 XRectangle
*, enum glyph_row_area
));
460 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
462 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
463 static void x_update_window_cursor
P_ ((struct window
*, int));
464 static void x_erase_phys_cursor
P_ ((struct window
*));
465 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
466 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
469 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
471 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
472 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
473 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
474 static void x_flush
P_ ((struct frame
*f
));
477 /* Flush display of frame F, or of all frames if F is null. */
486 Lisp_Object rest
, frame
;
487 FOR_EACH_FRAME (rest
, frame
)
488 x_flush (XFRAME (frame
));
490 else if (FRAME_X_P (f
))
491 XFlush (FRAME_X_DISPLAY (f
));
496 /* Remove calls to XFlush by defining XFlush to an empty replacement.
497 Calls to XFlush should be unnecessary because the X output buffer
498 is flushed automatically as needed by calls to XPending,
499 XNextEvent, or XWindowEvent according to the XFlush man page.
500 XTread_socket calls XPending. Removing XFlush improves
503 #define XFlush(DISPLAY) (void) 0
506 /***********************************************************************
508 ***********************************************************************/
512 /* This is a function useful for recording debugging information about
513 the sequence of occurrences in this file. */
521 struct record event_record
[100];
523 int event_record_index
;
525 record_event (locus
, type
)
529 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
530 event_record_index
= 0;
532 event_record
[event_record_index
].locus
= locus
;
533 event_record
[event_record_index
].type
= type
;
534 event_record_index
++;
541 /* Return the struct x_display_info corresponding to DPY. */
543 struct x_display_info
*
544 x_display_info_for_display (dpy
)
547 struct x_display_info
*dpyinfo
;
549 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
550 if (dpyinfo
->display
== dpy
)
558 /***********************************************************************
559 Starting and ending an update
560 ***********************************************************************/
562 /* Start an update of frame F. This function is installed as a hook
563 for update_begin, i.e. it is called when update_begin is called.
564 This function is called prior to calls to x_update_window_begin for
565 each window being updated. Currently, there is nothing to do here
566 because all interesting stuff is done on a window basis. */
576 /* Start update of window W. Set the global variable updated_window
577 to the window being updated and set output_cursor to the cursor
581 x_update_window_begin (w
)
584 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
585 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
588 set_output_cursor (&w
->cursor
);
592 if (f
== display_info
->mouse_face_mouse_frame
)
594 /* Don't do highlighting for mouse motion during the update. */
595 display_info
->mouse_face_defer
= 1;
597 /* If F needs to be redrawn, simply forget about any prior mouse
599 if (FRAME_GARBAGED_P (f
))
600 display_info
->mouse_face_window
= Qnil
;
602 /* Can we tell that this update does not affect the window
603 where the mouse highlight is? If so, no need to turn off.
604 Likewise, don't do anything if the frame is garbaged;
605 in that case, the frame's current matrix that we would use
606 is all wrong, and we will redisplay that line anyway. */
607 if (!NILP (display_info
->mouse_face_window
)
608 && w
== XWINDOW (display_info
->mouse_face_window
))
612 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
613 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
616 if (i
< w
->desired_matrix
->nrows
)
617 clear_mouse_face (display_info
);
625 /* Draw a vertical window border to the right of window W if W doesn't
626 have vertical scroll bars. */
629 x_draw_vertical_border (w
)
632 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
634 /* Redraw borders between horizontally adjacent windows. Don't
635 do it for frames with vertical scroll bars because either the
636 right scroll bar of a window, or the left scroll bar of its
637 neighbor will suffice as a border. */
638 if (!WINDOW_RIGHTMOST_P (w
)
639 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
643 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
644 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
647 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
648 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
653 /* End update of window W (which is equal to updated_window). Draw
654 vertical borders between horizontally adjacent windows, and display
655 W's cursor if CURSOR_ON_P is non-zero. W may be a menu bar
656 pseudo-window in case we don't have X toolkit support. Such
657 windows don't have a cursor, so don't display it here. */
660 x_update_window_end (w
, cursor_on_p
)
664 if (!w
->pseudo_window_p
)
668 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
670 output_cursor
.x
, output_cursor
.y
);
671 x_draw_vertical_border (w
);
675 updated_window
= NULL
;
679 /* End update of frame F. This function is installed as a hook in
686 /* Mouse highlight may be displayed again. */
687 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
690 XFlush (FRAME_X_DISPLAY (f
));
695 /* This function is called from various places in xdisp.c whenever a
696 complete update has been performed. The global variable
697 updated_window is not available here. */
700 XTframe_up_to_date (f
)
705 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
706 if (dpyinfo
->mouse_face_deferred_gc
707 || f
== dpyinfo
->mouse_face_mouse_frame
)
710 if (dpyinfo
->mouse_face_mouse_frame
)
711 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
712 dpyinfo
->mouse_face_mouse_x
,
713 dpyinfo
->mouse_face_mouse_y
);
714 dpyinfo
->mouse_face_deferred_gc
= 0;
721 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
722 arrow bitmaps, or clear the areas where they would be displayed
723 before DESIRED_ROW is made current. The window being updated is
724 found in updated_window. This function It is called from
725 update_window_line only if it is known that there are differences
726 between bitmaps to be drawn between current row and DESIRED_ROW. */
729 x_after_update_window_line (desired_row
)
730 struct glyph_row
*desired_row
;
732 struct window
*w
= updated_window
;
736 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
739 x_draw_row_bitmaps (w
, desired_row
);
741 /* When a window has disappeared, make sure that no rest of
742 full-width rows stays visible in the internal border. */
743 if (windows_or_buffers_changed
)
745 struct frame
*f
= XFRAME (w
->frame
);
746 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
747 int height
= desired_row
->visible_height
;
748 int x
= (window_box_right (w
, -1)
749 + FRAME_X_RIGHT_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_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
796 case OVERLAY_ARROW_BITMAP
:
800 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
802 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
805 case RIGHT_TRUNCATION_BITMAP
:
809 x
= window_box_right (w
, -1);
810 x
+= (FRAME_X_RIGHT_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_RIGHT_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_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
834 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
836 - (FRAME_X_LEFT_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 header_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_LEFT_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 (header_line_height
< 0)
908 header_line_height
= WINDOW_DISPLAY_HEADER_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_LEFT_FLAGS_AREA_WIDTH (f
)
924 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
926 FRAME_X_LEFT_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_RIGHT_FLAGS_AREA_WIDTH (f
)
948 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
950 int right
= window_box_right (w
, -1);
952 if (header_line_height
< 0)
953 header_line_height
= WINDOW_DISPLAY_HEADER_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 (header_line_height
,
968 FRAME_X_RIGHT_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_HEADER_LINE_HEIGHT (s
->w
);
2440 r
->y
= max (0, s
->row
->y
);
2442 /* If drawing a tool-bar window, draw it over the internal border
2443 at the top of the window. */
2444 if (s
->w
== XWINDOW (s
->f
->tool_bar_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_HEADER_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 #ifdef USE_X_TOOLKIT
2947 /* Allocate the color COLOR->pixel on the screen and display of
2948 widget WIDGET in colormap CMAP. If an exact match cannot be
2949 allocated, try the nearest color available. Value is non-zero
2950 if successful. This is called from lwlib. */
2953 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
2959 struct x_display_info
*dpyinfo
;
2960 Lisp_Object tail
, frame
;
2963 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
2965 /* Find the top-level shell of the widget. Note that this function
2966 can be called when the widget is not yet realized, so XtWindow
2967 (widget) == 0. That's the reason we can't simply use
2968 x_any_window_to_frame. */
2969 while (!XtIsTopLevelShell (widget
))
2970 widget
= XtParent (widget
);
2972 /* Look for a frame with that top-level widget. Allocate the color
2973 on that frame to get the right gamma correction value. */
2974 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
2975 if (GC_FRAMEP (XCAR (tail
))
2976 && (f
= XFRAME (XCAR (tail
)),
2977 (f
->output_data
.nothing
!= 1
2978 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
2979 && f
->output_data
.x
->widget
== widget
)
2980 return x_alloc_nearest_color (f
, cmap
, color
);
2985 #endif /* USE_X_TOOLKIT */
2988 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
2989 CMAP. If an exact match can't be allocated, try the nearest color
2990 available. Value is non-zero if successful. Set *COLOR to the
2994 x_alloc_nearest_color (f
, cmap
, color
)
2999 Display
*display
= FRAME_X_DISPLAY (f
);
3000 Screen
*screen
= FRAME_X_SCREEN (f
);
3003 gamma_correct (f
, color
);
3004 rc
= XAllocColor (display
, cmap
, color
);
3007 /* If we got to this point, the colormap is full, so we're going
3008 to try to get the next closest color. The algorithm used is
3009 a least-squares matching, which is what X uses for closest
3010 color matching with StaticColor visuals. */
3012 unsigned long nearest_delta
= ~0;
3013 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3014 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3016 for (i
= 0; i
< ncells
; ++i
)
3018 XQueryColors (display
, cmap
, cells
, ncells
);
3020 for (nearest
= i
= 0; i
< ncells
; ++i
)
3022 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3023 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3024 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3025 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3027 if (delta
< nearest_delta
)
3030 nearest_delta
= delta
;
3034 color
->red
= cells
[nearest
].red
;
3035 color
->green
= cells
[nearest
].green
;
3036 color
->blue
= cells
[nearest
].blue
;
3037 rc
= XAllocColor (display
, cmap
, color
);
3044 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3045 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3046 If this produces the same color as PIXEL, try a color where all RGB
3047 values have DELTA added. Return the allocated color in *PIXEL.
3048 DISPLAY is the X display, CMAP is the colormap to operate on.
3049 Value is non-zero if successful. */
3052 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3056 unsigned long *pixel
;
3063 /* Get RGB color values. */
3064 color
.pixel
= *pixel
;
3065 XQueryColor (display
, cmap
, &color
);
3067 /* Change RGB values by specified FACTOR. Avoid overflow! */
3068 xassert (factor
>= 0);
3069 new.red
= min (0xffff, factor
* color
.red
);
3070 new.green
= min (0xffff, factor
* color
.green
);
3071 new.blue
= min (0xffff, factor
* color
.blue
);
3073 /* Try to allocate the color. */
3074 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3077 if (new.pixel
== *pixel
)
3079 /* If we end up with the same color as before, try adding
3080 delta to the RGB values. */
3081 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
3083 /* If display has an immutable color map, freeing colors is
3084 not necessary and some servers don't allow it. So don't
3086 if (class != StaticColor
3087 && class != StaticGray
3088 && class != TrueColor
)
3089 XFreeColors (display
, cmap
, &new.pixel
, 1, 0);
3091 new.red
= min (0xffff, delta
+ color
.red
);
3092 new.green
= min (0xffff, delta
+ color
.green
);
3093 new.blue
= min (0xffff, delta
+ color
.blue
);
3094 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3105 /* Set up the foreground color for drawing relief lines of glyph
3106 string S. RELIEF is a pointer to a struct relief containing the GC
3107 with which lines will be drawn. Use a color that is FACTOR or
3108 DELTA lighter or darker than the relief's background which is found
3109 in S->f->output_data.x->relief_background. If such a color cannot
3110 be allocated, use DEFAULT_PIXEL, instead. */
3113 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3115 struct relief
*relief
;
3118 unsigned long default_pixel
;
3121 struct x_output
*di
= f
->output_data
.x
;
3122 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3123 unsigned long pixel
;
3124 unsigned long background
= di
->relief_background
;
3125 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
3126 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3127 Display
*dpy
= FRAME_X_DISPLAY (f
);
3129 xgcv
.graphics_exposures
= False
;
3130 xgcv
.line_width
= 1;
3132 /* Free previously allocated color. The color cell will be reused
3133 when it has been freed as many times as it was allocated, so this
3134 doesn't affect faces using the same colors. */
3136 && relief
->allocated_p
)
3138 /* If display has an immutable color map, freeing colors is not
3139 necessary and some servers don't allow it. So don't do it. */
3140 int class = dpyinfo
->visual
->class;
3141 if (class != StaticColor
3142 && class != StaticGray
3143 && class != TrueColor
)
3144 XFreeColors (dpy
, cmap
, &relief
->pixel
, 1, 0);
3145 relief
->allocated_p
= 0;
3148 /* Allocate new color. */
3149 xgcv
.foreground
= default_pixel
;
3151 if (dpyinfo
->n_planes
!= 1
3152 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3154 relief
->allocated_p
= 1;
3155 xgcv
.foreground
= relief
->pixel
= pixel
;
3158 if (relief
->gc
== 0)
3160 xgcv
.stipple
= dpyinfo
->gray
;
3162 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3165 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3169 /* Set up colors for the relief lines around glyph string S. */
3172 x_setup_relief_colors (s
)
3173 struct glyph_string
*s
;
3175 struct x_output
*di
= s
->f
->output_data
.x
;
3176 unsigned long color
;
3178 if (s
->face
->use_box_color_for_shadows_p
)
3179 color
= s
->face
->box_color
;
3184 /* Get the background color of the face. */
3185 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3186 color
= xgcv
.background
;
3189 if (di
->white_relief
.gc
== 0
3190 || color
!= di
->relief_background
)
3192 di
->relief_background
= color
;
3193 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3194 WHITE_PIX_DEFAULT (s
->f
));
3195 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3196 BLACK_PIX_DEFAULT (s
->f
));
3201 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3202 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3203 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3204 relief. LEFT_P non-zero means draw a relief on the left side of
3205 the rectangle. RIGHT_P non-zero means draw a relief on the right
3206 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3210 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3211 raised_p
, left_p
, right_p
, clip_rect
)
3213 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3214 XRectangle
*clip_rect
;
3220 gc
= f
->output_data
.x
->white_relief
.gc
;
3222 gc
= f
->output_data
.x
->black_relief
.gc
;
3223 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3226 for (i
= 0; i
< width
; ++i
)
3227 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3228 left_x
+ i
* left_p
, top_y
+ i
,
3229 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3233 for (i
= 0; i
< width
; ++i
)
3234 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3235 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3237 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3239 gc
= f
->output_data
.x
->black_relief
.gc
;
3241 gc
= f
->output_data
.x
->white_relief
.gc
;
3242 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3245 for (i
= 0; i
< width
; ++i
)
3246 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3247 left_x
+ i
* left_p
, bottom_y
- i
,
3248 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3252 for (i
= 0; i
< width
; ++i
)
3253 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3254 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3256 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3260 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3261 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3262 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3263 left side of the rectangle. RIGHT_P non-zero means draw a line
3264 on the right side of the rectangle. CLIP_RECT is the clipping
3265 rectangle to use when drawing. */
3268 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3269 left_p
, right_p
, clip_rect
)
3270 struct glyph_string
*s
;
3271 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3272 XRectangle
*clip_rect
;
3276 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3277 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3278 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3281 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3282 left_x
, top_y
, right_x
- left_x
, width
);
3286 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3287 left_x
, top_y
, width
, bottom_y
- top_y
);
3290 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3291 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3295 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3296 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3298 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3299 XSetClipMask (s
->display
, s
->gc
, None
);
3303 /* Draw a box around glyph string S. */
3306 x_draw_glyph_string_box (s
)
3307 struct glyph_string
*s
;
3309 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3310 int left_p
, right_p
;
3311 struct glyph
*last_glyph
;
3312 XRectangle clip_rect
;
3314 last_x
= window_box_right (s
->w
, s
->area
);
3315 if (s
->row
->full_width_p
3316 && !s
->w
->pseudo_window_p
)
3318 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3319 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3320 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3323 /* The glyph that may have a right box line. */
3324 last_glyph
= (s
->cmpcharp
|| s
->img
3326 : s
->first_glyph
+ s
->nchars
- 1);
3328 width
= s
->face
->box_line_width
;
3329 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3331 right_x
= ((s
->row
->full_width_p
3333 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3335 bottom_y
= top_y
+ s
->height
- 1;
3337 left_p
= (s
->first_glyph
->left_box_line_p
3338 || (s
->hl
== DRAW_MOUSE_FACE
3340 || s
->prev
->hl
!= s
->hl
)));
3341 right_p
= (last_glyph
->right_box_line_p
3342 || (s
->hl
== DRAW_MOUSE_FACE
3344 || s
->next
->hl
!= s
->hl
)));
3346 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3348 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3349 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3350 left_p
, right_p
, &clip_rect
);
3353 x_setup_relief_colors (s
);
3354 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3355 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3360 /* Draw foreground of image glyph string S. */
3363 x_draw_image_foreground (s
)
3364 struct glyph_string
*s
;
3367 int y
= s
->ybase
- IMAGE_ASCENT (s
->img
);
3369 /* If first glyph of S has a left box line, start drawing it to the
3370 right of that line. */
3371 if (s
->face
->box
!= FACE_NO_BOX
3372 && s
->first_glyph
->left_box_line_p
)
3373 x
= s
->x
+ s
->face
->box_line_width
;
3377 /* If there is a margin around the image, adjust x- and y-position
3381 x
+= s
->img
->margin
;
3382 y
+= s
->img
->margin
;
3389 /* We can't set both a clip mask and use XSetClipRectangles
3390 because the latter also sets a clip mask. We also can't
3391 trust on the shape extension to be available
3392 (XShapeCombineRegion). So, compute the rectangle to draw
3394 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3397 XRectangle clip_rect
, image_rect
, r
;
3399 xgcv
.clip_mask
= s
->img
->mask
;
3400 xgcv
.clip_x_origin
= x
;
3401 xgcv
.clip_y_origin
= y
;
3402 xgcv
.function
= GXcopy
;
3403 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3405 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3408 image_rect
.width
= s
->img
->width
;
3409 image_rect
.height
= s
->img
->height
;
3410 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3411 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3412 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3416 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3417 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3419 /* When the image has a mask, we can expect that at
3420 least part of a mouse highlight or a block cursor will
3421 be visible. If the image doesn't have a mask, make
3422 a block cursor visible by drawing a rectangle around
3423 the image. I believe it's looking better if we do
3424 nothing here for mouse-face. */
3425 if (s
->hl
== DRAW_CURSOR
)
3426 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3427 s
->img
->width
- 1, s
->img
->height
- 1);
3431 /* Draw a rectangle if image could not be loaded. */
3432 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3433 s
->img
->width
- 1, s
->img
->height
- 1);
3437 /* Draw a relief around the image glyph string S. */
3440 x_draw_image_relief (s
)
3441 struct glyph_string
*s
;
3443 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3446 int y
= s
->ybase
- IMAGE_ASCENT (s
->img
);
3448 /* If first glyph of S has a left box line, start drawing it to the
3449 right of that line. */
3450 if (s
->face
->box
!= FACE_NO_BOX
3451 && s
->first_glyph
->left_box_line_p
)
3452 x
= s
->x
+ s
->face
->box_line_width
;
3456 /* If there is a margin around the image, adjust x- and y-position
3460 x
+= s
->img
->margin
;
3461 y
+= s
->img
->margin
;
3464 if (s
->hl
== DRAW_IMAGE_SUNKEN
3465 || s
->hl
== DRAW_IMAGE_RAISED
)
3467 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3468 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3472 thick
= abs (s
->img
->relief
);
3473 raised_p
= s
->img
->relief
> 0;
3478 x1
= x
+ s
->img
->width
+ thick
- 1;
3479 y1
= y
+ s
->img
->height
+ thick
- 1;
3481 x_setup_relief_colors (s
);
3482 x_get_glyph_string_clip_rect (s
, &r
);
3483 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3487 /* Draw the foreground of image glyph string S to PIXMAP. */
3490 x_draw_image_foreground_1 (s
, pixmap
)
3491 struct glyph_string
*s
;
3495 int y
= s
->ybase
- s
->y
- IMAGE_ASCENT (s
->img
);
3497 /* If first glyph of S has a left box line, start drawing it to the
3498 right of that line. */
3499 if (s
->face
->box
!= FACE_NO_BOX
3500 && s
->first_glyph
->left_box_line_p
)
3501 x
= s
->face
->box_line_width
;
3505 /* If there is a margin around the image, adjust x- and y-position
3509 x
+= s
->img
->margin
;
3510 y
+= s
->img
->margin
;
3517 /* We can't set both a clip mask and use XSetClipRectangles
3518 because the latter also sets a clip mask. We also can't
3519 trust on the shape extension to be available
3520 (XShapeCombineRegion). So, compute the rectangle to draw
3522 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3526 xgcv
.clip_mask
= s
->img
->mask
;
3527 xgcv
.clip_x_origin
= x
;
3528 xgcv
.clip_y_origin
= y
;
3529 xgcv
.function
= GXcopy
;
3530 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3532 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3533 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3534 XSetClipMask (s
->display
, s
->gc
, None
);
3538 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3539 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3541 /* When the image has a mask, we can expect that at
3542 least part of a mouse highlight or a block cursor will
3543 be visible. If the image doesn't have a mask, make
3544 a block cursor visible by drawing a rectangle around
3545 the image. I believe it's looking better if we do
3546 nothing here for mouse-face. */
3547 if (s
->hl
== DRAW_CURSOR
)
3548 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3549 s
->img
->width
- 1, s
->img
->height
- 1);
3553 /* Draw a rectangle if image could not be loaded. */
3554 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3555 s
->img
->width
- 1, s
->img
->height
- 1);
3559 /* Draw part of the background of glyph string S. X, Y, W, and H
3560 give the rectangle to draw. */
3563 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3564 struct glyph_string
*s
;
3569 /* Fill background with a stipple pattern. */
3570 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3571 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3572 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3575 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3579 /* Draw image glyph string S.
3582 s->x +-------------------------
3585 | +-------------------------
3588 | | +-------------------
3594 x_draw_image_glyph_string (s
)
3595 struct glyph_string
*s
;
3598 int box_line_width
= s
->face
->box_line_width
;
3599 int margin
= s
->img
->margin
;
3601 Pixmap pixmap
= None
;
3603 height
= s
->height
- 2 * box_line_width
;
3605 /* Fill background with face under the image. Do it only if row is
3606 taller than image or if image has a clip mask to reduce
3608 s
->stippled_p
= s
->face
->stipple
!= 0;
3609 if (height
> s
->img
->height
3612 || s
->img
->pixmap
== 0
3613 || s
->width
!= s
->background_width
)
3615 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3616 x
= s
->x
+ box_line_width
;
3620 y
= s
->y
+ box_line_width
;
3624 /* Create a pixmap as large as the glyph string Fill it with
3625 the background color. Copy the image to it, using its
3626 mask. Copy the temporary pixmap to the display. */
3627 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3628 int depth
= DefaultDepthOfScreen (screen
);
3630 /* Create a pixmap as large as the glyph string. */
3631 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3632 s
->background_width
,
3635 /* Don't clip in the following because we're working on the
3637 XSetClipMask (s
->display
, s
->gc
, None
);
3639 /* Fill the pixmap with the background color/stipple. */
3642 /* Fill background with a stipple pattern. */
3643 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3644 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3645 0, 0, s
->background_width
, s
->height
);
3646 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3651 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3653 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3654 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3655 0, 0, s
->background_width
, s
->height
);
3656 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3660 /* Implementation idea: Is it possible to construct a mask?
3661 We could look at the color at the margins of the image, and
3662 say that this color is probably the background color of the
3664 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3666 s
->background_filled_p
= 1;
3669 /* Draw the foreground. */
3672 x_draw_image_foreground_1 (s
, pixmap
);
3673 x_set_glyph_string_clipping (s
);
3674 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
3675 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3676 XFreePixmap (s
->display
, pixmap
);
3679 x_draw_image_foreground (s
);
3681 /* If we must draw a relief around the image, do it. */
3683 || s
->hl
== DRAW_IMAGE_RAISED
3684 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3685 x_draw_image_relief (s
);
3689 /* Draw stretch glyph string S. */
3692 x_draw_stretch_glyph_string (s
)
3693 struct glyph_string
*s
;
3695 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3696 s
->stippled_p
= s
->face
->stipple
!= 0;
3698 if (s
->hl
== DRAW_CURSOR
3699 && !x_stretch_cursor_p
)
3701 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3702 as wide as the stretch glyph. */
3703 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
3706 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3708 /* Clear rest using the GC of the original non-cursor face. */
3709 if (width
< s
->background_width
)
3711 GC gc
= s
->face
->gc
;
3712 int x
= s
->x
+ width
, y
= s
->y
;
3713 int w
= s
->background_width
- width
, h
= s
->height
;
3716 x_get_glyph_string_clip_rect (s
, &r
);
3717 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
3719 if (s
->face
->stipple
)
3721 /* Fill background with a stipple pattern. */
3722 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3723 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3724 XSetFillStyle (s
->display
, gc
, FillSolid
);
3729 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
3730 XSetForeground (s
->display
, gc
, xgcv
.background
);
3731 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3732 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
3737 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
3740 s
->background_filled_p
= 1;
3744 /* Draw glyph string S. */
3747 x_draw_glyph_string (s
)
3748 struct glyph_string
*s
;
3750 /* If S draws into the background of its successor, draw the
3751 background of the successor first so that S can draw into it.
3752 This makes S->next use XDrawString instead of XDrawImageString. */
3753 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
3755 xassert (s
->next
->img
== NULL
);
3756 x_set_glyph_string_gc (s
->next
);
3757 x_set_glyph_string_clipping (s
->next
);
3758 x_draw_glyph_string_background (s
->next
, 1);
3761 /* Set up S->gc, set clipping and draw S. */
3762 x_set_glyph_string_gc (s
);
3763 x_set_glyph_string_clipping (s
);
3765 switch (s
->first_glyph
->type
)
3768 x_draw_image_glyph_string (s
);
3772 x_draw_stretch_glyph_string (s
);
3776 if (s
->for_overlaps_p
)
3777 s
->background_filled_p
= 1;
3779 x_draw_glyph_string_background (s
, 0);
3780 x_draw_glyph_string_foreground (s
);
3787 if (!s
->for_overlaps_p
)
3789 /* Draw underline. */
3790 if (s
->face
->underline_p
)
3792 unsigned long dy
, h
;
3794 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
3796 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
3799 if (s
->face
->underline_defaulted_p
)
3800 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3805 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3806 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3807 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3809 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3813 /* Draw overline. */
3814 if (s
->face
->overline_p
)
3816 unsigned long dy
= 0, h
= 1;
3818 if (s
->face
->overline_color_defaulted_p
)
3819 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3824 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3825 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3826 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3828 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3832 /* Draw strike-through. */
3833 if (s
->face
->strike_through_p
)
3835 unsigned long h
= 1;
3836 unsigned long dy
= (s
->height
- h
) / 2;
3838 if (s
->face
->strike_through_color_defaulted_p
)
3839 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3844 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3845 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3846 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3848 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3853 if (s
->face
->box
!= FACE_NO_BOX
)
3854 x_draw_glyph_string_box (s
);
3857 /* Reset clipping. */
3858 XSetClipMask (s
->display
, s
->gc
, None
);
3862 /* A work-list entry used during the construction of glyph_string
3863 structures for a composite character. */
3867 /* Pointer to composite char info defining has the composite
3868 character is drawn. */
3869 struct cmpchar_info
*cmpcharp
;
3871 /* Start index in compcharp->glyph[]. */
3874 /* Next in stack. */
3879 static void x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
3880 int, struct work
**,
3881 struct work
**, int));
3884 /* Load glyph string S with information from the top of *STACK for a
3885 composite character. FACE_ID is the id of the face in which S is
3886 drawn. *NEW is a pointer to a struct work not on the stack, that
3887 can be used if this function needs to push a new structure on the
3888 stack. If it uses it, *NEW is set to null. OVERLAPS_P non-zero
3889 means S should draw the foreground only, and use its lines physical
3890 height for clipping. */
3893 x_fill_composite_glyph_string (s
, face_id
, stack
, new, overlaps_p
)
3894 struct glyph_string
*s
;
3896 struct work
**stack
, **new;
3902 xassert (s
&& *new && *stack
);
3904 s
->for_overlaps_p
= 1;
3906 /* Pop the work stack. */
3908 *stack
= work
->next
;
3910 /* For all glyphs of cmpcharp->glyph, starting at the offset
3911 work->offset, until we reach the end of the definition or
3912 encounter another composite char, get the font and face to use,
3914 for (i
= work
->gidx
; i
< work
->cmpcharp
->glyph_len
; ++i
)
3916 c
= FAST_GLYPH_CHAR (work
->cmpcharp
->glyph
[i
]);
3917 if (CHAR_CHARSET (c
) == CHARSET_COMPOSITION
)
3919 s
->face
= x_get_char_face_and_encoding (s
->f
, c
, face_id
,
3920 s
->char2b
+ s
->nchars
, 1);
3921 s
->font
= s
->face
->font
;
3922 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
3926 /* If we find another composite char in the glyph definition of
3927 work->cmpcharp, put back the rest of the glyphs on the work
3928 stack, and make a new entry for the composite char. */
3929 if (i
< work
->cmpcharp
->glyph_len
)
3931 /* Push back an unprocessed rest of this glyph spec. */
3932 if (i
< work
->cmpcharp
->glyph_len
- 1)
3935 work
->next
= *stack
;
3941 /* Make an entry for the composite char on the work stack. */
3942 work
->cmpcharp
= cmpchar_table
[COMPOSITE_CHAR_ID (c
)];
3944 work
->next
= *stack
;
3948 /* The width of this glyph string equals the width of the first
3949 glyph. All characters are drawn at the same x-position. */
3950 s
->width
= s
->first_glyph
->pixel_width
;
3952 /* If the specified font could not be loaded, use the frame's
3953 default font, but record the fact that we couldn't load it in
3954 the glyph string so that we can draw rectangles for the
3955 characters of the glyph string. */
3956 if (s
->font
== NULL
)
3958 s
->font_not_found_p
= 1;
3959 s
->font
= FRAME_FONT (s
->f
);
3962 /* Adjust base line for subscript/superscript text. */
3963 s
->ybase
+= s
->first_glyph
->voffset
;
3965 xassert (s
->face
&& s
->face
->gc
);
3967 /* This glyph string must always be drawn with 16-bit functions. */
3972 /* Load glyph string S with a sequence of non-composite characters.
3973 FACE_ID is the face id of the string. START is the index of the
3974 first glyph to consider, END is the index of the last + 1.
3975 OVERLAPS_P non-zero means S should draw the foreground only, and
3976 use its lines physical height for clipping.
3978 Value is the index of the first glyph not in S. */
3981 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
3982 struct glyph_string
*s
;
3984 int start
, end
, overlaps_p
;
3986 struct glyph
*glyph
, *last
;
3989 xassert (s
->charset
!= CHARSET_COMPOSITION
);
3990 xassert (s
->f
== XFRAME (s
->w
->frame
));
3991 xassert (s
->nchars
== 0);
3992 xassert (start
>= 0 && end
> start
);
3994 s
->for_overlaps_p
= overlaps_p
,
3995 glyph
= s
->row
->glyphs
[s
->area
] + start
;
3996 last
= s
->row
->glyphs
[s
->area
] + end
;
3997 voffset
= glyph
->voffset
;
4000 && glyph
->type
== CHAR_GLYPH
4001 && glyph
->voffset
== voffset
4002 /* Same face id implies same charset, nowadays. */
4003 && glyph
->u
.ch
.face_id
== face_id
)
4005 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4006 s
->char2b
+ s
->nchars
);
4007 if (s
->char2b
[s
->nchars
].byte2
!= 0)
4011 xassert (s
->nchars
<= end
- start
);
4012 s
->width
+= glyph
->pixel_width
;
4016 s
->font
= s
->face
->font
;
4017 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4019 /* If the specified font could not be loaded, use the frame's font,
4020 but record the fact that we couldn't load it in
4021 S->font_not_found_p so that we can draw rectangles for the
4022 characters of the glyph string. */
4023 if (s
->font
== NULL
)
4025 s
->font_not_found_p
= 1;
4026 s
->font
= FRAME_FONT (s
->f
);
4029 /* Adjust base line for subscript/superscript text. */
4030 s
->ybase
+= voffset
;
4032 xassert (s
->face
&& s
->face
->gc
);
4033 return glyph
- s
->row
->glyphs
[s
->area
];
4037 /* Fill glyph string S from image glyph S->first_glyph. */
4040 x_fill_image_glyph_string (s
)
4041 struct glyph_string
*s
;
4043 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4044 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img
.id
);
4046 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->u
.img
.face_id
);
4047 s
->font
= s
->face
->font
;
4048 s
->width
= s
->first_glyph
->pixel_width
;
4050 /* Adjust base line for subscript/superscript text. */
4051 s
->ybase
+= s
->first_glyph
->voffset
;
4055 /* Fill glyph string S from stretch glyph S->first_glyph. */
4058 x_fill_stretch_glyph_string (s
)
4059 struct glyph_string
*s
;
4061 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4062 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->u
.stretch
.face_id
);
4063 s
->font
= s
->face
->font
;
4064 s
->width
= s
->first_glyph
->pixel_width
;
4066 /* Adjust base line for subscript/superscript text. */
4067 s
->ybase
+= s
->first_glyph
->voffset
;
4071 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4072 of XChar2b structures for S; it can't be allocated in
4073 x_init_glyph_string because it must be allocated via `alloca'. W
4074 is the window on which S is drawn. ROW and AREA are the glyph row
4075 and area within the row from which S is constructed. START is the
4076 index of the first glyph structure covered by S. HL is a
4077 face-override for drawing S. */
4080 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4081 struct glyph_string
*s
;
4084 struct glyph_row
*row
;
4085 enum glyph_row_area area
;
4087 enum draw_glyphs_face hl
;
4089 bzero (s
, sizeof *s
);
4091 s
->f
= XFRAME (w
->frame
);
4092 s
->display
= FRAME_X_DISPLAY (s
->f
);
4093 s
->window
= FRAME_X_WINDOW (s
->f
);
4098 s
->first_glyph
= row
->glyphs
[area
] + start
;
4099 s
->height
= row
->height
;
4100 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4102 /* Display the internal border below the tool-bar window. */
4103 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4104 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4106 s
->ybase
= s
->y
+ row
->ascent
;
4110 /* Set background width of glyph string S. START is the index of the
4111 first glyph following S. LAST_X is the right-most x-position + 1
4112 in the drawing area. */
4115 x_set_glyph_string_background_width (s
, start
, last_x
)
4116 struct glyph_string
*s
;
4120 /* If the face of this glyph string has to be drawn to the end of
4121 the drawing area, set S->extends_to_end_of_line_p. */
4122 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4124 if (start
== s
->row
->used
[s
->area
]
4125 && s
->hl
== DRAW_NORMAL_TEXT
4126 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4127 || s
->face
->background
!= default_face
->background
4128 || s
->face
->stipple
!= default_face
->stipple
))
4129 s
->extends_to_end_of_line_p
= 1;
4131 /* If S extends its face to the end of the line, set its
4132 background_width to the distance to the right edge of the drawing
4134 if (s
->extends_to_end_of_line_p
)
4135 s
->background_width
= last_x
- s
->x
+ 1;
4137 s
->background_width
= s
->width
;
4141 /* Add a glyph string for a stretch glyph to the list of strings
4142 between HEAD and TAIL. START is the index of the stretch glyph in
4143 row area AREA of glyph row ROW. END is the index of the last glyph
4144 in that glyph row area. X is the current output position assigned
4145 to the new glyph string constructed. HL overrides that face of the
4146 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4147 is the right-most x-position of the drawing area. */
4149 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, \
4153 s = (struct glyph_string *) alloca (sizeof *s); \
4154 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4155 x_fill_stretch_glyph_string (s); \
4156 x_append_glyph_string (&HEAD, &TAIL, s); \
4163 /* Add a glyph string for an image glyph to the list of strings
4164 between HEAD and TAIL. START is the index of the image glyph in
4165 row area AREA of glyph row ROW. END is the index of the last glyph
4166 in that glyph row area. X is the current output position assigned
4167 to the new glyph string constructed. HL overrides that face of the
4168 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4169 is the right-most x-position of the drawing area. */
4171 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, \
4175 s = (struct glyph_string *) alloca (sizeof *s); \
4176 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4177 x_fill_image_glyph_string (s); \
4178 x_append_glyph_string (&HEAD, &TAIL, s); \
4185 /* Add a glyph string for a sequence of character glyphs to the list
4186 of strings between HEAD and TAIL. START is the index of the first
4187 glyph in row area AREA of glyph row ROW that is part of the new
4188 glyph string. END is the index of the last glyph in that glyph row
4189 area. X is the current output position assigned to the new glyph
4190 string constructed. HL overrides that face of the glyph; e.g. it
4191 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4192 right-most x-position of the drawing area. */
4194 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, \
4195 X, LAST_X, OVERLAPS_P) \
4198 int c, charset, face_id; \
4201 c = (ROW)->glyphs[AREA][START].u.ch.code; \
4202 charset = CHAR_CHARSET (c); \
4203 face_id = (ROW)->glyphs[AREA][START].u.ch.face_id; \
4205 if (charset == CHARSET_COMPOSITION) \
4207 struct work *stack, *work, *new = NULL; \
4209 struct glyph_string *first_s = NULL; \
4211 /* Push an initial entry for character c on the stack. */ \
4213 work = (struct work *) alloca (sizeof *work); \
4214 work->cmpcharp = cmpchar_table[COMPOSITE_CHAR_ID (c)]; \
4216 work->next = stack; \
4219 /* While the stack is not empty, append glyph_strings \
4220 to head/tail for glyphs to draw. */ \
4223 s = (struct glyph_string *) alloca (sizeof *s); \
4224 char2b = (XChar2b *) alloca (stack->cmpcharp->glyph_len \
4225 * sizeof (XChar2b)); \
4226 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4227 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4228 s->cmpcharp = stack->cmpcharp; \
4229 s->gidx = stack->gidx; \
4230 s->charset = charset; \
4235 /* Don't draw the background except for the \
4236 first glyph string. */ \
4237 s->background_filled_p = n > 0; \
4243 new = (struct work *) alloca (sizeof *new); \
4244 x_fill_composite_glyph_string (s, face_id, &stack, \
4245 &new, OVERLAPS_P); \
4253 s = (struct glyph_string *) alloca (sizeof *s); \
4254 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4255 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4256 x_append_glyph_string (&HEAD, &TAIL, s); \
4257 s->charset = charset; \
4259 START = x_fill_glyph_string (s, face_id, START, END, \
4266 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4267 of AREA of glyph row ROW on window W between indices START and END.
4268 HL overrides the face for drawing glyph strings, e.g. it is
4269 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4270 x-positions of the drawing area.
4272 This is an ugly monster macro construct because we must use alloca
4273 to allocate glyph strings (because x_draw_glyphs can be called
4276 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, \
4277 X, LAST_X, OVERLAPS_P) \
4280 HEAD = TAIL = NULL; \
4281 while (START < END) \
4283 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4284 switch (first_glyph->type) \
4287 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4288 TAIL, HL, X, LAST_X, \
4292 case STRETCH_GLYPH: \
4293 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4294 HEAD, TAIL, HL, X, LAST_X); \
4298 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4299 TAIL, HL, X, LAST_X); \
4306 x_set_glyph_string_background_width (s, START, LAST_X); \
4313 /* Draw glyphs between START and END in AREA of ROW on window W,
4314 starting at x-position X. X is relative to AREA in W. HL is a
4315 face-override with the following meaning:
4317 DRAW_NORMAL_TEXT draw normally
4318 DRAW_CURSOR draw in cursor face
4319 DRAW_MOUSE_FACE draw in mouse face.
4320 DRAW_INVERSE_VIDEO draw in mode line face
4321 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4322 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4324 If REAL_START is non-null, return in *REAL_START the real starting
4325 position for display. This can be different from START in case
4326 overlapping glyphs must be displayed. If REAL_END is non-null,
4327 return in *REAL_END the real end position for display. This can be
4328 different from END in case overlapping glyphs must be displayed.
4330 If OVERLAPS_P is non-zero, draw only the foreground of characters
4331 and clip to the physical height of ROW.
4333 Value is the x-position reached, relative to AREA of W. */
4336 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4340 struct glyph_row
*row
;
4341 enum glyph_row_area area
;
4343 enum draw_glyphs_face hl
;
4344 int *real_start
, *real_end
;
4347 struct glyph_string
*head
, *tail
;
4348 struct glyph_string
*s
;
4349 int last_x
, area_width
;
4353 /* Let's rather be paranoid than getting a SEGV. */
4354 start
= max (0, start
);
4355 end
= min (end
, row
->used
[area
]);
4357 *real_start
= start
;
4361 /* Translate X to frame coordinates. Set last_x to the right
4362 end of the drawing area. */
4363 if (row
->full_width_p
)
4365 /* X is relative to the left edge of W, without scroll bars
4367 struct frame
*f
= XFRAME (w
->frame
);
4368 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4369 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4372 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4373 last_x
= window_left_x
+ area_width
;
4375 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4377 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4378 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4384 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4385 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4389 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4390 area_width
= window_box_width (w
, area
);
4391 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4394 /* Build a doubly-linked list of glyph_string structures between
4395 head and tail from what we have to draw. Note that the macro
4396 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4397 the reason we use a separate variable `i'. */
4399 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4402 x_reached
= tail
->x
+ tail
->background_width
;
4406 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4407 the row, redraw some glyphs in front or following the glyph
4408 strings built above. */
4409 if (!overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4412 struct glyph_string
*h
, *t
;
4414 /* Compute overhangs for all glyph strings. */
4415 for (s
= head
; s
; s
= s
->next
)
4416 x_compute_glyph_string_overhangs (s
);
4418 /* Prepend glyph strings for glyphs in front of the first glyph
4419 string that are overwritten because of the first glyph
4420 string's left overhang. The background of all strings
4421 prepended must be drawn because the first glyph string
4423 i
= x_left_overwritten (head
);
4427 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4428 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4432 *real_start
= start
;
4433 x_compute_overhangs_and_x (t
, head
->x
, 1);
4434 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4437 /* Prepend glyph strings for glyphs in front of the first glyph
4438 string that overwrite that glyph string because of their
4439 right overhang. For these strings, only the foreground must
4440 be drawn, because it draws over the glyph string at `head'.
4441 The background must not be drawn because this would overwrite
4442 right overhangs of preceding glyphs for which no glyph
4444 i
= x_left_overwriting (head
);
4447 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4448 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4450 for (s
= h
; s
; s
= s
->next
)
4451 s
->background_filled_p
= 1;
4454 x_compute_overhangs_and_x (t
, head
->x
, 1);
4455 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4458 /* Append glyphs strings for glyphs following the last glyph
4459 string tail that are overwritten by tail. The background of
4460 these strings has to be drawn because tail's foreground draws
4462 i
= x_right_overwritten (tail
);
4465 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4466 DRAW_NORMAL_TEXT
, x
, last_x
,
4468 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4469 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4474 /* Append glyph strings for glyphs following the last glyph
4475 string tail that overwrite tail. The foreground of such
4476 glyphs has to be drawn because it writes into the background
4477 of tail. The background must not be drawn because it could
4478 paint over the foreground of following glyphs. */
4479 i
= x_right_overwriting (tail
);
4482 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4483 DRAW_NORMAL_TEXT
, x
, last_x
,
4485 for (s
= h
; s
; s
= s
->next
)
4486 s
->background_filled_p
= 1;
4487 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4488 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4494 /* Draw all strings. */
4495 for (s
= head
; s
; s
= s
->next
)
4496 x_draw_glyph_string (s
);
4498 /* Value is the x-position up to which drawn, relative to AREA of W.
4499 This doesn't include parts drawn because of overhangs. */
4500 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4501 if (!row
->full_width_p
)
4503 if (area
> LEFT_MARGIN_AREA
)
4504 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4505 if (area
> TEXT_AREA
)
4506 x_reached
-= window_box_width (w
, TEXT_AREA
);
4512 /* Fix the display of area AREA of overlapping row ROW in window W. */
4515 x_fix_overlapping_area (w
, row
, area
)
4517 struct glyph_row
*row
;
4518 enum glyph_row_area area
;
4524 if (area
== LEFT_MARGIN_AREA
)
4526 else if (area
== TEXT_AREA
)
4527 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4529 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4530 + window_box_width (w
, TEXT_AREA
));
4532 for (i
= 0; i
< row
->used
[area
];)
4534 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4536 int start
= i
, start_x
= x
;
4540 x
+= row
->glyphs
[area
][i
].pixel_width
;
4543 while (i
< row
->used
[area
]
4544 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4546 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4548 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4553 x
+= row
->glyphs
[area
][i
].pixel_width
;
4562 /* Output LEN glyphs starting at START at the nominal cursor position.
4563 Advance the nominal cursor over the text. The global variable
4564 updated_window contains the window being updated, updated_row is
4565 the glyph row being updated, and updated_area is the area of that
4566 row being updated. */
4569 x_write_glyphs (start
, len
)
4570 struct glyph
*start
;
4573 int x
, hpos
, real_start
, real_end
;
4575 xassert (updated_window
&& updated_row
);
4580 hpos
= start
- updated_row
->glyphs
[updated_area
];
4581 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4582 updated_row
, updated_area
,
4584 (updated_row
->inverse_p
4585 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4586 &real_start
, &real_end
, 0);
4588 /* If we drew over the cursor, note that it is not visible any more. */
4589 note_overwritten_text_cursor (updated_window
, real_start
,
4590 real_end
- real_start
);
4594 /* Advance the output cursor. */
4595 output_cursor
.hpos
+= len
;
4596 output_cursor
.x
= x
;
4600 /* Insert LEN glyphs from START at the nominal cursor position. */
4603 x_insert_glyphs (start
, len
)
4604 struct glyph
*start
;
4609 int line_height
, shift_by_width
, shifted_region_width
;
4610 struct glyph_row
*row
;
4611 struct glyph
*glyph
;
4612 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4614 xassert (updated_window
&& updated_row
);
4617 f
= XFRAME (WINDOW_FRAME (w
));
4619 /* Get the height of the line we are in. */
4621 line_height
= row
->height
;
4623 /* Get the width of the glyphs to insert. */
4625 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4626 shift_by_width
+= glyph
->pixel_width
;
4628 /* Get the width of the region to shift right. */
4629 shifted_region_width
= (window_box_width (w
, updated_area
)
4634 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4635 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4636 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4637 f
->output_data
.x
->normal_gc
,
4639 shifted_region_width
, line_height
,
4640 frame_x
+ shift_by_width
, frame_y
);
4642 /* Write the glyphs. */
4643 hpos
= start
- row
->glyphs
[updated_area
];
4644 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4645 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4646 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4648 /* Advance the output cursor. */
4649 output_cursor
.hpos
+= len
;
4650 output_cursor
.x
+= shift_by_width
;
4655 /* Delete N glyphs at the nominal cursor position. Not implemented
4666 /* Erase the current text line from the nominal cursor position
4667 (inclusive) to pixel column TO_X (exclusive). The idea is that
4668 everything from TO_X onward is already erased.
4670 TO_X is a pixel position relative to updated_area of
4671 updated_window. TO_X == -1 means clear to the end of this area. */
4674 x_clear_end_of_line (to_x
)
4678 struct window
*w
= updated_window
;
4679 int max_x
, min_y
, max_y
;
4680 int from_x
, from_y
, to_y
;
4682 xassert (updated_window
&& updated_row
);
4683 f
= XFRAME (w
->frame
);
4685 if (updated_row
->full_width_p
)
4687 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4688 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4689 && !w
->pseudo_window_p
)
4690 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4693 max_x
= window_box_width (w
, updated_area
);
4694 max_y
= window_text_bottom_y (w
);
4696 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
4697 of window. For TO_X > 0, truncate to end of drawing area. */
4703 to_x
= min (to_x
, max_x
);
4705 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
4707 /* Notice if the cursor will be cleared by this operation. */
4708 if (!updated_row
->full_width_p
)
4709 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
4711 from_x
= output_cursor
.x
;
4713 /* Translate to frame coordinates. */
4714 if (updated_row
->full_width_p
)
4716 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
4717 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
4721 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
4722 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
4725 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
4726 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
4727 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
4729 /* Prevent inadvertently clearing to end of the X window. */
4730 if (to_x
> from_x
&& to_y
> from_y
)
4733 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4734 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
4741 /* Clear entire frame. If updating_frame is non-null, clear that
4742 frame. Otherwise clear selected_frame. */
4754 /* Clearing the frame will erase any cursor, so mark them all as no
4756 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4757 output_cursor
.hpos
= output_cursor
.vpos
= 0;
4758 output_cursor
.x
= -1;
4760 /* We don't set the output cursor here because there will always
4761 follow an explicit cursor_to. */
4763 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
4765 /* We have to clear the scroll bars, too. If we have changed
4766 colors or something like that, then they should be notified. */
4767 x_scroll_bar_clear (f
);
4769 XFlush (FRAME_X_DISPLAY (f
));
4775 /* Invert the middle quarter of the frame for .15 sec. */
4777 /* We use the select system call to do the waiting, so we have to make
4778 sure it's available. If it isn't, we just won't do visual bells. */
4780 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4783 /* Subtract the `struct timeval' values X and Y, storing the result in
4784 *RESULT. Return 1 if the difference is negative, otherwise 0. */
4787 timeval_subtract (result
, x
, y
)
4788 struct timeval
*result
, x
, y
;
4790 /* Perform the carry for the later subtraction by updating y. This
4791 is safer because on some systems the tv_sec member is unsigned. */
4792 if (x
.tv_usec
< y
.tv_usec
)
4794 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
4795 y
.tv_usec
-= 1000000 * nsec
;
4799 if (x
.tv_usec
- y
.tv_usec
> 1000000)
4801 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
4802 y
.tv_usec
+= 1000000 * nsec
;
4806 /* Compute the time remaining to wait. tv_usec is certainly
4808 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
4809 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
4811 /* Return indication of whether the result should be considered
4813 return x
.tv_sec
< y
.tv_sec
;
4825 /* Create a GC that will use the GXxor function to flip foreground
4826 pixels into background pixels. */
4830 values
.function
= GXxor
;
4831 values
.foreground
= (f
->output_data
.x
->foreground_pixel
4832 ^ f
->output_data
.x
->background_pixel
);
4834 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4835 GCFunction
| GCForeground
, &values
);
4839 /* Get the height not including a menu bar widget. */
4840 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
4841 /* Height of each line to flash. */
4842 int flash_height
= FRAME_LINE_HEIGHT (f
);
4843 /* These will be the left and right margins of the rectangles. */
4844 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
4845 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
4849 /* Don't flash the area between a scroll bar and the frame
4850 edge it is next to. */
4851 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
4853 case vertical_scroll_bar_left
:
4854 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
4857 case vertical_scroll_bar_right
:
4858 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
4865 width
= flash_right
- flash_left
;
4867 /* If window is tall, flash top and bottom line. */
4868 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4870 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4872 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4873 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
4874 width
, flash_height
);
4875 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4877 (height
- flash_height
4878 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4879 width
, flash_height
);
4882 /* If it is short, flash it all. */
4883 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4884 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4885 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4890 struct timeval wakeup
;
4892 EMACS_GET_TIME (wakeup
);
4894 /* Compute time to wait until, propagating carry from usecs. */
4895 wakeup
.tv_usec
+= 150000;
4896 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
4897 wakeup
.tv_usec
%= 1000000;
4899 /* Keep waiting until past the time wakeup. */
4902 struct timeval timeout
;
4904 EMACS_GET_TIME (timeout
);
4906 /* In effect, timeout = wakeup - timeout.
4907 Break if result would be negative. */
4908 if (timeval_subtract (&timeout
, wakeup
, timeout
))
4911 /* Try to wait that long--but we might wake up sooner. */
4912 select (0, NULL
, NULL
, NULL
, &timeout
);
4916 /* If window is tall, flash top and bottom line. */
4917 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4919 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4921 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4922 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
4923 width
, flash_height
);
4924 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4926 (height
- flash_height
4927 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4928 width
, flash_height
);
4931 /* If it is short, flash it all. */
4932 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4933 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4934 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4936 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
4944 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
4947 /* Make audible bell. */
4949 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
4954 if (FRAME_X_DISPLAY (selected_frame
) == 0)
4957 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4959 XTflash (selected_frame
);
4965 XFlush (FRAME_X_DISPLAY (selected_frame
));
4971 /* Specify how many text lines, from the top of the window,
4972 should be affected by insert-lines and delete-lines operations.
4973 This, and those operations, are used only within an update
4974 that is bounded by calls to x_update_begin and x_update_end. */
4977 XTset_terminal_window (n
)
4980 /* This function intentionally left blank. */
4985 /***********************************************************************
4987 ***********************************************************************/
4989 /* Perform an insert-lines or delete-lines operation, inserting N
4990 lines or deleting -N lines at vertical position VPOS. */
4993 x_ins_del_lines (vpos
, n
)
5000 /* Scroll part of the display as described by RUN. */
5003 x_scroll_run (w
, run
)
5007 struct frame
*f
= XFRAME (w
->frame
);
5008 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5010 /* Get frame-relative bounding box of the text display area of W,
5011 without mode lines. Include in this box the flags areas to the
5012 left and right of W. */
5013 window_box (w
, -1, &x
, &y
, &width
, &height
);
5014 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5015 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5017 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5018 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5019 bottom_y
= y
+ height
;
5023 /* Scrolling up. Make sure we don't copy part of the mode
5024 line at the bottom. */
5025 if (from_y
+ run
->height
> bottom_y
)
5026 height
= bottom_y
- from_y
;
5028 height
= run
->height
;
5032 /* Scolling down. Make sure we don't copy over the mode line.
5034 if (to_y
+ run
->height
> bottom_y
)
5035 height
= bottom_y
- to_y
;
5037 height
= run
->height
;
5042 /* Cursor off. Will be switched on again in x_update_window_end. */
5046 XCopyArea (FRAME_X_DISPLAY (f
),
5047 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5048 f
->output_data
.x
->normal_gc
,
5058 /***********************************************************************
5060 ***********************************************************************/
5062 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5063 corner of the exposed rectangle. W and H are width and height of
5064 the exposed area. All are pixel values. W or H zero means redraw
5065 the entire frame. */
5068 expose_frame (f
, x
, y
, w
, h
)
5074 TRACE ((stderr
, "expose_frame "));
5076 /* No need to redraw if frame will be redrawn soon. */
5077 if (FRAME_GARBAGED_P (f
))
5079 TRACE ((stderr
, " garbaged\n"));
5083 /* If basic faces haven't been realized yet, there is no point in
5084 trying to redraw anything. This can happen when we get an expose
5085 event while Emacs is starting, e.g. by moving another window. */
5086 if (FRAME_FACE_CACHE (f
) == NULL
5087 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5089 TRACE ((stderr
, " no faces\n"));
5093 if (w
== 0 || h
== 0)
5096 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5097 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5107 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5108 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5110 if (WINDOWP (f
->tool_bar_window
))
5112 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5113 XRectangle window_rect
;
5114 XRectangle intersection_rect
;
5115 int window_x
, window_y
, window_width
, window_height
;
5118 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5119 window_rect
.x
= window_x
;
5120 window_rect
.y
= window_y
;
5121 window_rect
.width
= window_width
;
5122 window_rect
.height
= window_height
;
5124 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5125 expose_window (w
, &intersection_rect
);
5128 #ifndef USE_X_TOOLKIT
5129 if (WINDOWP (f
->menu_bar_window
))
5131 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5132 XRectangle window_rect
;
5133 XRectangle intersection_rect
;
5134 int window_x
, window_y
, window_width
, window_height
;
5137 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5138 window_rect
.x
= window_x
;
5139 window_rect
.y
= window_y
;
5140 window_rect
.width
= window_width
;
5141 window_rect
.height
= window_height
;
5143 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5144 expose_window (w
, &intersection_rect
);
5146 #endif /* not USE_X_TOOLKIT */
5150 /* Redraw (parts) of all windows in the window tree rooted at W that
5151 intersect R. R contains frame pixel coordinates. */
5154 expose_window_tree (w
, r
)
5160 if (!NILP (w
->hchild
))
5161 expose_window_tree (XWINDOW (w
->hchild
), r
);
5162 else if (!NILP (w
->vchild
))
5163 expose_window_tree (XWINDOW (w
->vchild
), r
);
5166 XRectangle window_rect
;
5167 XRectangle intersection_rect
;
5168 struct frame
*f
= XFRAME (w
->frame
);
5169 int window_x
, window_y
, window_width
, window_height
;
5171 /* Frame-relative pixel rectangle of W. */
5172 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5176 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5177 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5178 window_rect
.y
= window_y
;
5181 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5182 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5184 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5186 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5187 expose_window (w
, &intersection_rect
);
5190 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5195 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5196 which intersects rectangle R. R is in window-relative coordinates. */
5199 expose_area (w
, row
, r
, area
)
5201 struct glyph_row
*row
;
5203 enum glyph_row_area area
;
5206 struct glyph
*first
= row
->glyphs
[area
];
5207 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5211 /* Set x to the window-relative start position for drawing glyphs of
5212 AREA. The first glyph of the text area can be partially visible.
5213 The first glyphs of other areas cannot. */
5214 if (area
== LEFT_MARGIN_AREA
)
5216 else if (area
== TEXT_AREA
)
5217 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5219 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5220 + window_box_width (w
, TEXT_AREA
));
5222 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5223 /* If row extends face to end of line write the whole line. */
5224 x_draw_glyphs (w
, x
, row
, area
,
5226 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5230 /* Find the first glyph that must be redrawn. */
5232 && x
+ first
->pixel_width
< r
->x
)
5234 x
+= first
->pixel_width
;
5238 /* Find the last one. */
5242 && x
< r
->x
+ r
->width
)
5244 x
+= last
->pixel_width
;
5250 x_draw_glyphs (w
, first_x
, row
, area
,
5251 first
- row
->glyphs
[area
],
5252 last
- row
->glyphs
[area
],
5253 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5259 /* Redraw the parts of the glyph row ROW on window W intersecting
5260 rectangle R. R is in window-relative coordinates. */
5263 expose_line (w
, row
, r
)
5265 struct glyph_row
*row
;
5268 xassert (row
->enabled_p
);
5270 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5271 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5272 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5276 if (row
->used
[LEFT_MARGIN_AREA
])
5277 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5278 if (row
->used
[TEXT_AREA
])
5279 expose_area (w
, row
, r
, TEXT_AREA
);
5280 if (row
->used
[RIGHT_MARGIN_AREA
])
5281 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5282 x_draw_row_bitmaps (w
, row
);
5287 /* Return non-zero if W's cursor intersects rectangle R. */
5290 x_phys_cursor_in_rect_p (w
, r
)
5294 XRectangle cr
, result
;
5295 struct glyph
*cursor_glyph
;
5297 cursor_glyph
= get_phys_cursor_glyph (w
);
5300 cr
.x
= w
->phys_cursor
.x
;
5301 cr
.y
= w
->phys_cursor
.y
;
5302 cr
.width
= cursor_glyph
->pixel_width
;
5303 cr
.height
= w
->phys_cursor_height
;
5304 return x_intersect_rectangles (&cr
, r
, &result
);
5311 /* Redraw a rectangle of window W. R is a rectangle in window
5312 relative coordinates. Call this function with input blocked. */
5315 expose_window (w
, r
)
5319 struct glyph_row
*row
;
5321 int yb
= window_text_bottom_y (w
);
5322 int cursor_cleared_p
;
5324 /* If window is not yet fully initialized, do nothing. This can
5325 happen when toolkit scroll bars are used and a window is split.
5326 Reconfiguring the scroll bar will generate an expose for a newly
5328 if (w
->current_matrix
== NULL
)
5331 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5332 r
->x
, r
->y
, r
->width
, r
->height
));
5334 /* Convert to window coordinates. */
5335 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5336 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5338 /* Turn off the cursor. */
5339 if (!w
->pseudo_window_p
5340 && x_phys_cursor_in_rect_p (w
, r
))
5343 cursor_cleared_p
= 1;
5346 cursor_cleared_p
= 0;
5348 /* Find the first row intersecting the rectangle R. */
5349 row
= w
->current_matrix
->rows
;
5351 while (row
->enabled_p
5353 && y
+ row
->height
< r
->y
)
5359 /* Display the text in the rectangle, one text line at a time. */
5360 while (row
->enabled_p
5362 && y
< r
->y
+ r
->height
)
5364 expose_line (w
, row
, r
);
5369 /* Display the mode line if there is one. */
5370 if (WINDOW_WANTS_MODELINE_P (w
)
5371 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5373 && row
->y
< r
->y
+ r
->height
)
5374 expose_line (w
, row
, r
);
5376 if (!w
->pseudo_window_p
)
5378 /* Draw border between windows. */
5379 x_draw_vertical_border (w
);
5381 /* Turn the cursor on again. */
5382 if (cursor_cleared_p
)
5383 x_update_window_cursor (w
, 1);
5388 /* Determine the intersection of two rectangles R1 and R2. Return
5389 the intersection in *RESULT. Value is non-zero if RESULT is not
5393 x_intersect_rectangles (r1
, r2
, result
)
5394 XRectangle
*r1
, *r2
, *result
;
5396 XRectangle
*left
, *right
;
5397 XRectangle
*upper
, *lower
;
5398 int intersection_p
= 0;
5400 /* Rearrange so that R1 is the left-most rectangle. */
5402 left
= r1
, right
= r2
;
5404 left
= r2
, right
= r1
;
5406 /* X0 of the intersection is right.x0, if this is inside R1,
5407 otherwise there is no intersection. */
5408 if (right
->x
<= left
->x
+ left
->width
)
5410 result
->x
= right
->x
;
5412 /* The right end of the intersection is the minimum of the
5413 the right ends of left and right. */
5414 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5417 /* Same game for Y. */
5419 upper
= r1
, lower
= r2
;
5421 upper
= r2
, lower
= r1
;
5423 /* The upper end of the intersection is lower.y0, if this is inside
5424 of upper. Otherwise, there is no intersection. */
5425 if (lower
->y
<= upper
->y
+ upper
->height
)
5427 result
->y
= lower
->y
;
5429 /* The lower end of the intersection is the minimum of the lower
5430 ends of upper and lower. */
5431 result
->height
= (min (lower
->y
+ lower
->height
,
5432 upper
->y
+ upper
->height
)
5438 return intersection_p
;
5449 /* We used to only do this if Vx_no_window_manager was non-nil, but
5450 the ICCCM (section 4.1.6) says that the window's border pixmap
5451 and border pixel are window attributes which are "private to the
5452 client", so we can always change it to whatever we want. */
5454 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5455 f
->output_data
.x
->border_pixel
);
5457 x_update_cursor (f
, 1);
5461 frame_unhighlight (f
)
5464 /* We used to only do this if Vx_no_window_manager was non-nil, but
5465 the ICCCM (section 4.1.6) says that the window's border pixmap
5466 and border pixel are window attributes which are "private to the
5467 client", so we can always change it to whatever we want. */
5469 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5470 f
->output_data
.x
->border_tile
);
5472 x_update_cursor (f
, 1);
5475 /* The focus has changed. Update the frames as necessary to reflect
5476 the new situation. Note that we can't change the selected frame
5477 here, because the Lisp code we are interrupting might become confused.
5478 Each event gets marked with the frame in which it occurred, so the
5479 Lisp code can tell when the switch took place by examining the events. */
5482 x_new_focus_frame (dpyinfo
, frame
)
5483 struct x_display_info
*dpyinfo
;
5484 struct frame
*frame
;
5486 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5488 if (frame
!= dpyinfo
->x_focus_frame
)
5490 /* Set this before calling other routines, so that they see
5491 the correct value of x_focus_frame. */
5492 dpyinfo
->x_focus_frame
= frame
;
5494 if (old_focus
&& old_focus
->auto_lower
)
5495 x_lower_frame (old_focus
);
5498 selected_frame
= frame
;
5499 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5501 Fselect_window (selected_frame
->selected_window
);
5502 choose_minibuf_frame ();
5505 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5506 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5508 pending_autoraise_frame
= 0;
5511 x_frame_rehighlight (dpyinfo
);
5514 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5517 x_mouse_leave (dpyinfo
)
5518 struct x_display_info
*dpyinfo
;
5520 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5523 /* The focus has changed, or we have redirected a frame's focus to
5524 another frame (this happens when a frame uses a surrogate
5525 mini-buffer frame). Shift the highlight as appropriate.
5527 The FRAME argument doesn't necessarily have anything to do with which
5528 frame is being highlighted or un-highlighted; we only use it to find
5529 the appropriate X display info. */
5532 XTframe_rehighlight (frame
)
5533 struct frame
*frame
;
5535 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5539 x_frame_rehighlight (dpyinfo
)
5540 struct x_display_info
*dpyinfo
;
5542 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5544 if (dpyinfo
->x_focus_frame
)
5546 dpyinfo
->x_highlight_frame
5547 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5548 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5549 : dpyinfo
->x_focus_frame
);
5550 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5552 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5553 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5557 dpyinfo
->x_highlight_frame
= 0;
5559 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5562 frame_unhighlight (old_highlight
);
5563 if (dpyinfo
->x_highlight_frame
)
5564 frame_highlight (dpyinfo
->x_highlight_frame
);
5570 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5572 /* Initialize mode_switch_bit and modifier_meaning. */
5574 x_find_modifier_meanings (dpyinfo
)
5575 struct x_display_info
*dpyinfo
;
5577 int min_code
, max_code
;
5580 XModifierKeymap
*mods
;
5582 dpyinfo
->meta_mod_mask
= 0;
5583 dpyinfo
->shift_lock_mask
= 0;
5584 dpyinfo
->alt_mod_mask
= 0;
5585 dpyinfo
->super_mod_mask
= 0;
5586 dpyinfo
->hyper_mod_mask
= 0;
5589 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5591 min_code
= dpyinfo
->display
->min_keycode
;
5592 max_code
= dpyinfo
->display
->max_keycode
;
5595 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5596 min_code
, max_code
- min_code
+ 1,
5598 mods
= XGetModifierMapping (dpyinfo
->display
);
5600 /* Scan the modifier table to see which modifier bits the Meta and
5601 Alt keysyms are on. */
5603 int row
, col
; /* The row and column in the modifier table. */
5605 for (row
= 3; row
< 8; row
++)
5606 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5609 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5611 /* Zeroes are used for filler. Skip them. */
5615 /* Are any of this keycode's keysyms a meta key? */
5619 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5621 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5627 dpyinfo
->meta_mod_mask
|= (1 << row
);
5632 dpyinfo
->alt_mod_mask
|= (1 << row
);
5637 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5642 dpyinfo
->super_mod_mask
|= (1 << row
);
5646 /* Ignore this if it's not on the lock modifier. */
5647 if ((1 << row
) == LockMask
)
5648 dpyinfo
->shift_lock_mask
= LockMask
;
5656 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5657 if (! dpyinfo
->meta_mod_mask
)
5659 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
5660 dpyinfo
->alt_mod_mask
= 0;
5663 /* If some keys are both alt and meta,
5664 make them just meta, not alt. */
5665 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
5667 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
5670 XFree ((char *) syms
);
5671 XFreeModifiermap (mods
);
5674 /* Convert between the modifier bits X uses and the modifier bits
5678 x_x_to_emacs_modifiers (dpyinfo
, state
)
5679 struct x_display_info
*dpyinfo
;
5682 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
5683 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
5684 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
5685 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
5686 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
5687 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
5691 x_emacs_to_x_modifiers (dpyinfo
, state
)
5692 struct x_display_info
*dpyinfo
;
5695 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
5696 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
5697 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
5698 | ((state
& shift_modifier
) ? ShiftMask
: 0)
5699 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
5700 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
5703 /* Convert a keysym to its name. */
5706 x_get_keysym_name (keysym
)
5712 value
= XKeysymToString (keysym
);
5720 /* Mouse clicks and mouse movement. Rah. */
5722 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5723 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5724 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5725 not force the value into range. */
5728 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5730 register int pix_x
, pix_y
;
5731 register int *x
, *y
;
5735 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5736 even for negative values. */
5738 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
5740 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
5742 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5743 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5747 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
5748 bounds
->height
= f
->output_data
.x
->line_height
;
5749 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5750 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5757 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5758 pix_x
= FRAME_WINDOW_WIDTH (f
);
5762 else if (pix_y
> f
->height
)
5771 /* Given HPOS/VPOS in the current matrix of W, return corresponding
5772 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
5773 can't tell the positions because W's display is not up to date,
5777 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
5780 int *frame_x
, *frame_y
;
5784 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
5785 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
5787 if (display_completed
)
5789 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
5790 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
5791 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
5797 *frame_x
+= glyph
->pixel_width
;
5805 *frame_y
= *frame_x
= 0;
5809 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
5810 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
5815 /* Prepare a mouse-event in *RESULT for placement in the input queue.
5817 If the event is a button press, then note that we have grabbed
5821 construct_mouse_click (result
, event
, f
)
5822 struct input_event
*result
;
5823 XButtonEvent
*event
;
5826 /* Make the event type no_event; we'll change that when we decide
5828 result
->kind
= mouse_click
;
5829 result
->code
= event
->button
- Button1
;
5830 result
->timestamp
= event
->time
;
5831 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
5833 | (event
->type
== ButtonRelease
5837 XSETINT (result
->x
, event
->x
);
5838 XSETINT (result
->y
, event
->y
);
5839 XSETFRAME (result
->frame_or_window
, f
);
5843 #if 0 /* This function isn't called. --gerd */
5845 /* Prepare a menu-event in *RESULT for placement in the input queue. */
5848 construct_menu_click (result
, event
, f
)
5849 struct input_event
*result
;
5850 XButtonEvent
*event
;
5853 /* Make the event type no_event; we'll change that when we decide
5855 result
->kind
= mouse_click
;
5856 result
->code
= event
->button
- Button1
;
5857 result
->timestamp
= event
->time
;
5858 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
5860 | (event
->type
== ButtonRelease
5864 XSETINT (result
->x
, event
->x
);
5865 XSETINT (result
->y
, -1);
5866 XSETFRAME (result
->frame_or_window
, f
);
5872 /* Function to report a mouse movement to the mainstream Emacs code.
5873 The input handler calls this.
5875 We have received a mouse movement event, which is given in *event.
5876 If the mouse is over a different glyph than it was last time, tell
5877 the mainstream emacs code by setting mouse_moved. If not, ask for
5878 another motion event, so we can check again the next time it moves. */
5880 static XMotionEvent last_mouse_motion_event
;
5881 static Lisp_Object last_mouse_motion_frame
;
5884 note_mouse_movement (frame
, event
)
5886 XMotionEvent
*event
;
5888 last_mouse_movement_time
= event
->time
;
5889 last_mouse_motion_event
= *event
;
5890 XSETFRAME (last_mouse_motion_frame
, frame
);
5892 if (event
->window
!= FRAME_X_WINDOW (frame
))
5894 frame
->mouse_moved
= 1;
5895 last_mouse_scroll_bar
= Qnil
;
5896 note_mouse_highlight (frame
, -1, -1);
5899 /* Has the mouse moved off the glyph it was on at the last sighting? */
5900 else if (event
->x
< last_mouse_glyph
.x
5901 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
5902 || event
->y
< last_mouse_glyph
.y
5903 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
5905 frame
->mouse_moved
= 1;
5906 last_mouse_scroll_bar
= Qnil
;
5907 note_mouse_highlight (frame
, event
->x
, event
->y
);
5911 /* This is used for debugging, to turn off note_mouse_highlight. */
5913 int disable_mouse_highlight
;
5917 /************************************************************************
5919 ************************************************************************/
5921 /* Find the glyph under window-relative coordinates X/Y in window W.
5922 Consider only glyphs from buffer text, i.e. no glyphs from overlay
5923 strings. Return in *HPOS and *VPOS the row and column number of
5924 the glyph found. Return in *AREA the glyph area containing X.
5925 Value is a pointer to the glyph found or null if X/Y is not on
5926 text, or we can't tell because W's current matrix is not up to
5929 static struct glyph
*
5930 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
5933 int *hpos
, *vpos
, *area
;
5935 struct glyph
*glyph
, *end
;
5936 struct glyph_row
*row
;
5937 int x0
, i
, left_area_width
;
5939 /* Find row containing Y. Give up if some row is not enabled. */
5940 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
5942 row
= MATRIX_ROW (w
->current_matrix
, i
);
5943 if (!row
->enabled_p
)
5945 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
5952 /* Give up if Y is not in the window. */
5953 if (i
== w
->current_matrix
->nrows
)
5956 /* Get the glyph area containing X. */
5957 if (w
->pseudo_window_p
)
5964 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5965 if (x
< left_area_width
)
5967 *area
= LEFT_MARGIN_AREA
;
5970 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
5973 x0
= row
->x
+ left_area_width
;
5977 *area
= RIGHT_MARGIN_AREA
;
5978 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
5982 /* Find glyph containing X. */
5983 glyph
= row
->glyphs
[*area
];
5984 end
= glyph
+ row
->used
[*area
];
5987 if (x
< x0
+ glyph
->pixel_width
)
5989 if (w
->pseudo_window_p
)
5991 else if (BUFFERP (glyph
->object
))
5995 x0
+= glyph
->pixel_width
;
6002 *hpos
= glyph
- row
->glyphs
[*area
];
6007 /* Convert frame-relative x/y to coordinates relative to window W.
6008 Takes pseudo-windows into account. */
6011 frame_to_window_pixel_xy (w
, x
, y
)
6015 if (w
->pseudo_window_p
)
6017 /* A pseudo-window is always full-width, and starts at the
6018 left edge of the frame, plus a frame border. */
6019 struct frame
*f
= XFRAME (w
->frame
);
6020 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6021 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6025 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6026 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6031 /* Take proper action when mouse has moved to the mode or top line of
6032 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6033 mode line. X is relative to the start of the text display area of
6034 W, so the width of bitmap areas and scroll bars must be subtracted
6035 to get a position relative to the start of the mode line. */
6038 note_mode_line_highlight (w
, x
, mode_line_p
)
6042 struct frame
*f
= XFRAME (w
->frame
);
6043 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6044 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6045 struct glyph_row
*row
;
6048 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6050 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6054 struct glyph
*glyph
, *end
;
6055 Lisp_Object help
, map
;
6058 /* Find the glyph under X. */
6059 glyph
= row
->glyphs
[TEXT_AREA
];
6060 end
= glyph
+ row
->used
[TEXT_AREA
];
6061 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6062 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6064 && x
>= x0
+ glyph
->pixel_width
)
6066 x0
+= glyph
->pixel_width
;
6071 && STRINGP (glyph
->object
)
6072 && XSTRING (glyph
->object
)->intervals
6073 && glyph
->charpos
>= 0
6074 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6076 /* If we're on a string with `help-echo' text property,
6077 arrange for the help to be displayed. This is done by
6078 setting the global variable help_echo to the help string. */
6079 help
= Fget_text_property (make_number (glyph
->charpos
),
6080 Qhelp_echo
, glyph
->object
);
6084 /* Change the mouse pointer according to what is under X/Y. */
6085 map
= Fget_text_property (make_number (glyph
->charpos
),
6086 Qlocal_map
, glyph
->object
);
6087 if (!NILP (Fkeymapp (map
)))
6088 cursor
= f
->output_data
.x
->nontext_cursor
;
6092 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6096 /* Take proper action when the mouse has moved to position X, Y on
6097 frame F as regards highlighting characters that have mouse-face
6098 properties. Also de-highlighting chars where the mouse was before.
6099 X and Y can be negative or out of range. */
6102 note_mouse_highlight (f
, x
, y
)
6106 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6111 /* When a menu is active, don't highlight because this looks odd. */
6112 #ifdef USE_X_TOOLKIT
6113 if (popup_activated ())
6117 if (disable_mouse_highlight
)
6120 dpyinfo
->mouse_face_mouse_x
= x
;
6121 dpyinfo
->mouse_face_mouse_y
= y
;
6122 dpyinfo
->mouse_face_mouse_frame
= f
;
6124 if (dpyinfo
->mouse_face_defer
)
6129 dpyinfo
->mouse_face_deferred_gc
= 1;
6133 /* Which window is that in? */
6134 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6136 /* If we were displaying active text in another window, clear that. */
6137 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6138 clear_mouse_face (dpyinfo
);
6140 /* Not on a window -> return. */
6141 if (!WINDOWP (window
))
6144 /* Convert to window-relative pixel coordinates. */
6145 w
= XWINDOW (window
);
6146 frame_to_window_pixel_xy (w
, &x
, &y
);
6148 /* Handle tool-bar window differently since it doesn't display a
6150 if (EQ (window
, f
->tool_bar_window
))
6152 note_tool_bar_highlight (f
, x
, y
);
6156 if (portion
== 1 || portion
== 3)
6158 /* Mouse is on the mode or top line. */
6159 note_mode_line_highlight (w
, x
, portion
== 1);
6163 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6164 f
->output_data
.x
->text_cursor
);
6166 /* Are we in a window whose display is up to date?
6167 And verify the buffer's text has not changed. */
6168 if (/* Within text portion of the window. */
6170 && EQ (w
->window_end_valid
, w
->buffer
)
6171 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6172 && (XFASTINT (w
->last_overlay_modified
)
6173 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6175 int hpos
, vpos
, pos
, i
, area
;
6176 struct glyph
*glyph
;
6178 /* Find the glyph under X/Y. */
6179 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6181 /* Clear mouse face if X/Y not over text. */
6183 || area
!= TEXT_AREA
6184 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6186 clear_mouse_face (dpyinfo
);
6190 pos
= glyph
->charpos
;
6191 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6193 /* Check for mouse-face and help-echo. */
6195 Lisp_Object mouse_face
, overlay
, position
;
6196 Lisp_Object
*overlay_vec
;
6198 struct buffer
*obuf
;
6201 /* If we get an out-of-range value, return now; avoid an error. */
6202 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6205 /* Make the window's buffer temporarily current for
6206 overlays_at and compute_char_face. */
6207 obuf
= current_buffer
;
6208 current_buffer
= XBUFFER (w
->buffer
);
6214 /* Is this char mouse-active or does it have help-echo? */
6215 XSETINT (position
, pos
);
6217 /* Put all the overlays we want in a vector in overlay_vec.
6218 Store the length in len. If there are more than 10, make
6219 enough space for all, and try again. */
6221 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6222 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6223 if (noverlays
> len
)
6226 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6227 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6230 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6232 /* Check mouse-face highlighting. */
6233 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6234 && vpos
>= dpyinfo
->mouse_face_beg_row
6235 && vpos
<= dpyinfo
->mouse_face_end_row
6236 && (vpos
> dpyinfo
->mouse_face_beg_row
6237 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6238 && (vpos
< dpyinfo
->mouse_face_end_row
6239 || hpos
< dpyinfo
->mouse_face_end_col
6240 || dpyinfo
->mouse_face_past_end
)))
6242 /* Clear the display of the old active region, if any. */
6243 clear_mouse_face (dpyinfo
);
6245 /* Find the highest priority overlay that has a mouse-face prop. */
6247 for (i
= 0; i
< noverlays
; i
++)
6249 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6250 if (!NILP (mouse_face
))
6252 overlay
= overlay_vec
[i
];
6257 /* If no overlay applies, get a text property. */
6259 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6261 /* Handle the overlay case. */
6262 if (! NILP (overlay
))
6264 /* Find the range of text around this char that
6265 should be active. */
6266 Lisp_Object before
, after
;
6269 before
= Foverlay_start (overlay
);
6270 after
= Foverlay_end (overlay
);
6271 /* Record this as the current active region. */
6272 fast_find_position (w
, XFASTINT (before
),
6273 &dpyinfo
->mouse_face_beg_col
,
6274 &dpyinfo
->mouse_face_beg_row
,
6275 &dpyinfo
->mouse_face_beg_x
,
6276 &dpyinfo
->mouse_face_beg_y
);
6277 dpyinfo
->mouse_face_past_end
6278 = !fast_find_position (w
, XFASTINT (after
),
6279 &dpyinfo
->mouse_face_end_col
,
6280 &dpyinfo
->mouse_face_end_row
,
6281 &dpyinfo
->mouse_face_end_x
,
6282 &dpyinfo
->mouse_face_end_y
);
6283 dpyinfo
->mouse_face_window
= window
;
6284 dpyinfo
->mouse_face_face_id
6285 = face_at_buffer_position (w
, pos
, 0, 0,
6286 &ignore
, pos
+ 1, 1);
6288 /* Display it as active. */
6289 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6291 /* Handle the text property case. */
6292 else if (! NILP (mouse_face
))
6294 /* Find the range of text around this char that
6295 should be active. */
6296 Lisp_Object before
, after
, beginning
, end
;
6299 beginning
= Fmarker_position (w
->start
);
6300 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6301 - XFASTINT (w
->window_end_pos
)));
6303 = Fprevious_single_property_change (make_number (pos
+ 1),
6305 w
->buffer
, beginning
);
6307 = Fnext_single_property_change (position
, Qmouse_face
,
6309 /* Record this as the current active region. */
6310 fast_find_position (w
, XFASTINT (before
),
6311 &dpyinfo
->mouse_face_beg_col
,
6312 &dpyinfo
->mouse_face_beg_row
,
6313 &dpyinfo
->mouse_face_beg_x
,
6314 &dpyinfo
->mouse_face_beg_y
);
6315 dpyinfo
->mouse_face_past_end
6316 = !fast_find_position (w
, XFASTINT (after
),
6317 &dpyinfo
->mouse_face_end_col
,
6318 &dpyinfo
->mouse_face_end_row
,
6319 &dpyinfo
->mouse_face_end_x
,
6320 &dpyinfo
->mouse_face_end_y
);
6321 dpyinfo
->mouse_face_window
= window
;
6322 dpyinfo
->mouse_face_face_id
6323 = face_at_buffer_position (w
, pos
, 0, 0,
6324 &ignore
, pos
+ 1, 1);
6326 /* Display it as active. */
6327 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6331 /* Look for a `help-echo' property. */
6335 /* Check overlays first. */
6337 for (i
= 0; i
< noverlays
&& !STRINGP (help
); ++i
)
6338 help
= Foverlay_get (overlay_vec
[i
], Qhelp_echo
);
6340 /* Try text properties. */
6342 && ((STRINGP (glyph
->object
)
6343 && glyph
->charpos
>= 0
6344 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6345 || (BUFFERP (glyph
->object
)
6346 && glyph
->charpos
>= BEGV
6347 && glyph
->charpos
< ZV
)))
6348 help
= Fget_text_property (make_number (glyph
->charpos
),
6349 Qhelp_echo
, glyph
->object
);
6357 current_buffer
= obuf
;
6363 redo_mouse_highlight ()
6365 if (!NILP (last_mouse_motion_frame
)
6366 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6367 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6368 last_mouse_motion_event
.x
,
6369 last_mouse_motion_event
.y
);
6374 /***********************************************************************
6376 ***********************************************************************/
6378 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6379 struct glyph
**, int *, int *, int *));
6381 /* Tool-bar item index of the item on which a mouse button was pressed
6384 static int last_tool_bar_item
;
6387 /* Get information about the tool-bar item at position X/Y on frame F.
6388 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6389 the current matrix of the tool-bar window of F, or NULL if not
6390 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6391 item in F->current_tool_bar_items. Value is
6393 -1 if X/Y is not on a tool-bar item
6394 0 if X/Y is on the same item that was highlighted before.
6398 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6401 struct glyph
**glyph
;
6402 int *hpos
, *vpos
, *prop_idx
;
6404 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6405 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6408 /* Find the glyph under X/Y. */
6409 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6413 /* Get the start of this tool-bar item's properties in
6414 f->current_tool_bar_items. */
6415 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6418 /* Is mouse on the highlighted item? */
6419 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6420 && *vpos
>= dpyinfo
->mouse_face_beg_row
6421 && *vpos
<= dpyinfo
->mouse_face_end_row
6422 && (*vpos
> dpyinfo
->mouse_face_beg_row
6423 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6424 && (*vpos
< dpyinfo
->mouse_face_end_row
6425 || *hpos
< dpyinfo
->mouse_face_end_col
6426 || dpyinfo
->mouse_face_past_end
))
6433 /* Handle mouse button event on the tool-bar of frame F, at
6434 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6438 x_handle_tool_bar_click (f
, button_event
)
6440 XButtonEvent
*button_event
;
6442 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6443 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6444 int hpos
, vpos
, prop_idx
;
6445 struct glyph
*glyph
;
6446 Lisp_Object enabled_p
;
6447 int x
= button_event
->x
;
6448 int y
= button_event
->y
;
6450 /* If not on the highlighted tool-bar item, return. */
6451 frame_to_window_pixel_xy (w
, &x
, &y
);
6452 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6455 /* If item is disabled, do nothing. */
6456 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6457 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6458 if (NILP (enabled_p
))
6461 if (button_event
->type
== ButtonPress
)
6463 /* Show item in pressed state. */
6464 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6465 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6466 last_tool_bar_item
= prop_idx
;
6470 Lisp_Object key
, frame
;
6471 struct input_event event
;
6473 /* Show item in released state. */
6474 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6475 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6477 key
= (XVECTOR (f
->current_tool_bar_items
)
6478 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6480 XSETFRAME (frame
, f
);
6481 event
.kind
= TOOL_BAR_EVENT
;
6482 event
.frame_or_window
= Fcons (frame
, Fcons (Qtool_bar
, Qnil
));
6483 kbd_buffer_store_event (&event
);
6485 event
.kind
= TOOL_BAR_EVENT
;
6486 event
.frame_or_window
= Fcons (frame
, key
);
6487 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6488 button_event
->state
);
6489 kbd_buffer_store_event (&event
);
6490 last_tool_bar_item
= -1;
6495 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6496 tool-bar window-relative coordinates X/Y. Called from
6497 note_mouse_highlight. */
6500 note_tool_bar_highlight (f
, x
, y
)
6504 Lisp_Object window
= f
->tool_bar_window
;
6505 struct window
*w
= XWINDOW (window
);
6506 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6508 struct glyph
*glyph
;
6509 struct glyph_row
*row
;
6511 Lisp_Object enabled_p
;
6513 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6514 int on_highlight_p
, mouse_down_p
, rc
;
6516 /* Function note_mouse_highlight is called with negative x(y
6517 values when mouse moves outside of the frame. */
6518 if (x
<= 0 || y
<= 0)
6520 clear_mouse_face (dpyinfo
);
6524 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6527 /* Not on tool-bar item. */
6528 clear_mouse_face (dpyinfo
);
6532 /* On same tool-bar item as before. */
6535 clear_mouse_face (dpyinfo
);
6537 /* Mouse is down, but on different tool-bar item? */
6538 mouse_down_p
= (dpyinfo
->grabbed
6539 && f
== last_mouse_frame
6540 && FRAME_LIVE_P (f
));
6542 && last_tool_bar_item
!= prop_idx
)
6545 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6546 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6548 /* If tool-bar item is not enabled, don't highlight it. */
6549 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6550 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6551 if (!NILP (enabled_p
))
6553 /* Compute the x-position of the glyph. In front and past the
6554 image is a space. We include this is the highlighted area. */
6555 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6556 for (i
= x
= 0; i
< hpos
; ++i
)
6557 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6559 /* Record this as the current active region. */
6560 dpyinfo
->mouse_face_beg_col
= hpos
;
6561 dpyinfo
->mouse_face_beg_row
= vpos
;
6562 dpyinfo
->mouse_face_beg_x
= x
;
6563 dpyinfo
->mouse_face_beg_y
= row
->y
;
6564 dpyinfo
->mouse_face_past_end
= 0;
6566 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6567 dpyinfo
->mouse_face_end_row
= vpos
;
6568 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6569 dpyinfo
->mouse_face_end_y
= row
->y
;
6570 dpyinfo
->mouse_face_window
= window
;
6571 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6573 /* Display it as active. */
6574 show_mouse_face (dpyinfo
, draw
);
6575 dpyinfo
->mouse_face_image_state
= draw
;
6580 /* Set help_echo to a help string.to display for this tool-bar item.
6581 XTread_socket does the rest. */
6582 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6583 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6584 if (!STRINGP (help_echo
))
6585 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6586 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6591 /* Find the glyph matrix position of buffer position POS in window W.
6592 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6593 current glyphs must be up to date. If POS is above window start
6594 return (0, 0, 0, 0). If POS is after end of W, return end of
6598 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6601 int *hpos
, *vpos
, *x
, *y
;
6605 int maybe_next_line_p
= 0;
6606 int line_start_position
;
6607 int yb
= window_text_bottom_y (w
);
6608 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6609 struct glyph_row
*best_row
= row
;
6610 int row_vpos
= 0, best_row_vpos
= 0;
6615 if (row
->used
[TEXT_AREA
])
6616 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6618 line_start_position
= 0;
6620 if (line_start_position
> pos
)
6622 /* If the position sought is the end of the buffer,
6623 don't include the blank lines at the bottom of the window. */
6624 else if (line_start_position
== pos
6625 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6627 maybe_next_line_p
= 1;
6630 else if (line_start_position
> 0)
6633 best_row_vpos
= row_vpos
;
6640 /* Find the right column within BEST_ROW. */
6642 current_x
= best_row
->x
;
6643 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6645 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6648 charpos
= glyph
->charpos
;
6652 *vpos
= best_row_vpos
;
6657 else if (charpos
> pos
)
6659 else if (charpos
> 0)
6662 current_x
+= glyph
->pixel_width
;
6665 /* If we're looking for the end of the buffer,
6666 and we didn't find it in the line we scanned,
6667 use the start of the following line. */
6668 if (maybe_next_line_p
)
6673 current_x
= best_row
->x
;
6676 *vpos
= best_row_vpos
;
6677 *hpos
= lastcol
+ 1;
6684 /* Display the active region described by mouse_face_*
6685 in its mouse-face if HL > 0, in its normal face if HL = 0. */
6688 show_mouse_face (dpyinfo
, draw
)
6689 struct x_display_info
*dpyinfo
;
6690 enum draw_glyphs_face draw
;
6692 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
6693 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6695 int cursor_off_p
= 0;
6696 struct cursor_pos saved_cursor
;
6698 saved_cursor
= output_cursor
;
6700 /* If window is in the process of being destroyed, don't bother
6702 if (w
->current_matrix
== NULL
)
6705 /* Recognize when we are called to operate on rows that don't exist
6706 anymore. This can happen when a window is split. */
6707 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
6710 set_output_cursor (&w
->phys_cursor
);
6712 /* Note that mouse_face_beg_row etc. are window relative. */
6713 for (i
= dpyinfo
->mouse_face_beg_row
;
6714 i
<= dpyinfo
->mouse_face_end_row
;
6717 int start_hpos
, end_hpos
, start_x
;
6718 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
6720 /* Don't do anything if row doesn't have valid contents. */
6721 if (!row
->enabled_p
)
6724 /* For all but the first row, the highlight starts at column 0. */
6725 if (i
== dpyinfo
->mouse_face_beg_row
)
6727 start_hpos
= dpyinfo
->mouse_face_beg_col
;
6728 start_x
= dpyinfo
->mouse_face_beg_x
;
6736 if (i
== dpyinfo
->mouse_face_end_row
)
6737 end_hpos
= dpyinfo
->mouse_face_end_col
;
6739 end_hpos
= row
->used
[TEXT_AREA
];
6741 /* If the cursor's in the text we are about to rewrite, turn the
6743 if (!w
->pseudo_window_p
6744 && i
== output_cursor
.vpos
6745 && output_cursor
.hpos
>= start_hpos
- 1
6746 && output_cursor
.hpos
<= end_hpos
)
6748 x_update_window_cursor (w
, 0);
6752 if (end_hpos
> start_hpos
)
6753 x_draw_glyphs (w
, start_x
, row
, updated_area
,
6754 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
6757 /* If we turned the cursor off, turn it back on. */
6759 x_display_cursor (w
, 1,
6760 output_cursor
.hpos
, output_cursor
.vpos
,
6761 output_cursor
.x
, output_cursor
.y
);
6763 output_cursor
= saved_cursor
;
6767 /* Change the mouse cursor. */
6768 if (draw
== DRAW_NORMAL_TEXT
)
6769 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6770 f
->output_data
.x
->text_cursor
);
6771 else if (draw
== DRAW_MOUSE_FACE
)
6772 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6773 f
->output_data
.x
->cross_cursor
);
6775 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6776 f
->output_data
.x
->nontext_cursor
);
6779 /* Clear out the mouse-highlighted active region.
6780 Redraw it un-highlighted first. */
6783 clear_mouse_face (dpyinfo
)
6784 struct x_display_info
*dpyinfo
;
6789 if (! NILP (dpyinfo
->mouse_face_window
))
6790 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
6792 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6793 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6794 dpyinfo
->mouse_face_window
= Qnil
;
6797 /* Just discard the mouse face information for frame F, if any.
6798 This is used when the size of F is changed. */
6801 cancel_mouse_face (f
)
6805 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6807 window
= dpyinfo
->mouse_face_window
;
6808 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
6810 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6811 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6812 dpyinfo
->mouse_face_window
= Qnil
;
6816 static struct scroll_bar
*x_window_to_scroll_bar ();
6817 static void x_scroll_bar_report_motion ();
6819 /* Return the current position of the mouse.
6820 *fp should be a frame which indicates which display to ask about.
6822 If the mouse movement started in a scroll bar, set *fp, *bar_window,
6823 and *part to the frame, window, and scroll bar part that the mouse
6824 is over. Set *x and *y to the portion and whole of the mouse's
6825 position on the scroll bar.
6827 If the mouse movement started elsewhere, set *fp to the frame the
6828 mouse is on, *bar_window to nil, and *x and *y to the character cell
6831 Set *time to the server time-stamp for the time at which the mouse
6832 was at this position.
6834 Don't store anything if we don't have a valid set of values to report.
6836 This clears the mouse_moved flag, so we can wait for the next mouse
6840 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
6843 Lisp_Object
*bar_window
;
6844 enum scroll_bar_part
*part
;
6846 unsigned long *time
;
6852 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
6853 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
6859 Window dummy_window
;
6862 Lisp_Object frame
, tail
;
6864 /* Clear the mouse-moved flag for every frame on this display. */
6865 FOR_EACH_FRAME (tail
, frame
)
6866 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
6867 XFRAME (frame
)->mouse_moved
= 0;
6869 last_mouse_scroll_bar
= Qnil
;
6871 /* Figure out which root window we're on. */
6872 XQueryPointer (FRAME_X_DISPLAY (*fp
),
6873 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
6875 /* The root window which contains the pointer. */
6878 /* Trash which we can't trust if the pointer is on
6879 a different screen. */
6882 /* The position on that root window. */
6885 /* More trash we can't trust. */
6888 /* Modifier keys and pointer buttons, about which
6890 (unsigned int *) &dummy
);
6892 /* Now we have a position on the root; find the innermost window
6893 containing the pointer. */
6897 int parent_x
= 0, parent_y
= 0;
6902 /* XTranslateCoordinates can get errors if the window
6903 structure is changing at the same time this function
6904 is running. So at least we must not crash from them. */
6906 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
6908 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
6909 && FRAME_LIVE_P (last_mouse_frame
))
6911 /* If mouse was grabbed on a frame, give coords for that frame
6912 even if the mouse is now outside it. */
6913 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
6915 /* From-window, to-window. */
6916 root
, FRAME_X_WINDOW (last_mouse_frame
),
6918 /* From-position, to-position. */
6919 root_x
, root_y
, &win_x
, &win_y
,
6923 f1
= last_mouse_frame
;
6929 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
6931 /* From-window, to-window. */
6934 /* From-position, to-position. */
6935 root_x
, root_y
, &win_x
, &win_y
,
6940 if (child
== None
|| child
== win
)
6948 /* Now we know that:
6949 win is the innermost window containing the pointer
6950 (XTC says it has no child containing the pointer),
6951 win_x and win_y are the pointer's position in it
6952 (XTC did this the last time through), and
6953 parent_x and parent_y are the pointer's position in win's parent.
6954 (They are what win_x and win_y were when win was child.
6955 If win is the root window, it has no parent, and
6956 parent_{x,y} are invalid, but that's okay, because we'll
6957 never use them in that case.) */
6959 /* Is win one of our frames? */
6960 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
6963 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
6966 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
6968 /* If not, is it one of our scroll bars? */
6971 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
6975 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6981 if (f1
== 0 && insist
> 0)
6982 f1
= selected_frame
;
6986 /* Ok, we found a frame. Store all the values.
6987 last_mouse_glyph is a rectangle used to reduce the
6988 generation of mouse events. To not miss any motion
6989 events, we must divide the frame into rectangles of the
6990 size of the smallest character that could be displayed
6991 on it, i.e. into the same rectangles that matrices on
6992 the frame are divided into. */
6994 #if OLD_REDISPLAY_CODE
6995 int ignore1
, ignore2
;
6996 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
6998 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7002 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7003 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7007 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7008 round down even for negative values. */
7014 last_mouse_glyph
.width
= width
;
7015 last_mouse_glyph
.height
= height
;
7016 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7017 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7024 XSETINT (*x
, win_x
);
7025 XSETINT (*y
, win_y
);
7026 *time
= last_mouse_movement_time
;
7035 DEFUN ("xt-process-timeouts", Fxt_process_timeouts
, Sxt_process_timeouts
,
7037 "Arrange for Xt timeout callbacks to be called.")
7040 #ifdef USE_X_TOOLKIT
7042 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7043 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7045 #endif /* USE_X_TOOLKIT */
7052 /* Scroll bar support. */
7054 /* Given an X window ID, find the struct scroll_bar which manages it.
7055 This can be called in GC, so we have to make sure to strip off mark
7057 static struct scroll_bar
*
7058 x_window_to_scroll_bar (window_id
)
7063 for (tail
= Vframe_list
;
7064 XGCTYPE (tail
) == Lisp_Cons
;
7067 Lisp_Object frame
, bar
, condemned
;
7069 frame
= XCAR (tail
);
7070 /* All elements of Vframe_list should be frames. */
7071 if (! GC_FRAMEP (frame
))
7074 /* Scan this frame's scroll bar list for a scroll bar with the
7076 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7077 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7078 /* This trick allows us to search both the ordinary and
7079 condemned scroll bar lists with one loop. */
7080 ! GC_NILP (bar
) || (bar
= condemned
,
7083 bar
= XSCROLL_BAR (bar
)->next
)
7084 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7085 return XSCROLL_BAR (bar
);
7093 /************************************************************************
7095 ************************************************************************/
7097 #if USE_TOOLKIT_SCROLL_BARS
7099 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7100 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7101 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7102 struct scroll_bar
*));
7103 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7107 /* Id of action hook installed for scroll bars. */
7109 static XtActionHookId action_hook_id
;
7111 /* Lisp window being scrolled. Set when starting to interact with
7112 a toolkit scroll bar, reset to nil when ending the interaction. */
7114 static Lisp_Object window_being_scrolled
;
7116 /* Last scroll bar part sent in xm_scroll_callback. */
7118 static int last_scroll_bar_part
;
7121 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7122 bars are used.. The hoos is responsible for detecting when
7123 the user ends an interaction with the scroll bar, and generates
7124 a `end-scroll' scroll_bar_click' event if so. */
7127 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7130 XtPointer client_data
;
7134 Cardinal
*num_params
;
7140 scroll_bar_p
= XmIsScrollBar (widget
);
7141 end_action
= "Release";
7142 #elif defined HAVE_XAW3D
7143 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7144 end_action
= "EndScroll";
7146 #error unknown scroll bar toolkit
7147 #endif /* HAVE_XAW3D */
7149 /* Although LessTif uses XtTimeouts like Xaw3d, the timer hack to
7150 let Xt timeouts be processed doesn't work. */
7152 && strcmp (action_name
, end_action
) == 0
7153 && WINDOWP (window_being_scrolled
))
7157 x_send_scroll_bar_event (window_being_scrolled
,
7158 scroll_bar_end_scroll
, 0, 0);
7159 w
= XWINDOW (window_being_scrolled
);
7160 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7161 window_being_scrolled
= Qnil
;
7162 last_scroll_bar_part
= -1;
7167 /* Send a client message with message type Xatom_Scrollbar for a
7168 scroll action to the frame of WINDOW. PART is a value identifying
7169 the part of the scroll bar that was clicked on. PORTION is the
7170 amount to scroll of a whole of WHOLE. */
7173 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7175 int part
, portion
, whole
;
7178 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7179 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7181 /* Construct a ClientMessage event to send to the frame. */
7182 ev
->type
= ClientMessage
;
7183 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7184 ev
->display
= FRAME_X_DISPLAY (f
);
7185 ev
->window
= FRAME_X_WINDOW (f
);
7187 ev
->data
.l
[0] = (long) window
;
7188 ev
->data
.l
[1] = (long) part
;
7189 ev
->data
.l
[2] = (long) 0;
7190 ev
->data
.l
[3] = (long) portion
;
7191 ev
->data
.l
[4] = (long) whole
;
7193 /* Setting the event mask to zero means that the message will
7194 be sent to the client that created the window, and if that
7195 window no longer exists, no event will be sent. */
7197 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7202 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7206 x_scroll_bar_to_input_event (event
, ievent
)
7208 struct input_event
*ievent
;
7210 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7211 Lisp_Object window
= (Lisp_Object
) ev
->data
.l
[0];
7212 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7214 ievent
->kind
= scroll_bar_click
;
7215 ievent
->frame_or_window
= window
;
7216 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7217 ievent
->part
= ev
->data
.l
[1];
7218 ievent
->code
= ev
->data
.l
[2];
7219 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7220 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7221 ievent
->modifiers
= 0;
7227 /* Minimum and maximum values used for Motif scroll bars. */
7230 #define XM_SB_MAX 10000000
7231 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7234 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7235 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7236 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7239 xm_scroll_callback (widget
, client_data
, call_data
)
7241 XtPointer client_data
, call_data
;
7243 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7244 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7246 int part
= -1, whole
= 0, portion
= 0;
7250 case XmCR_DECREMENT
:
7251 bar
->dragging
= Qnil
;
7252 part
= scroll_bar_up_arrow
;
7255 case XmCR_INCREMENT
:
7256 bar
->dragging
= Qnil
;
7257 part
= scroll_bar_down_arrow
;
7260 case XmCR_PAGE_DECREMENT
:
7261 bar
->dragging
= Qnil
;
7262 part
= scroll_bar_above_handle
;
7265 case XmCR_PAGE_INCREMENT
:
7266 bar
->dragging
= Qnil
;
7267 part
= scroll_bar_below_handle
;
7271 bar
->dragging
= Qnil
;
7272 part
= scroll_bar_to_top
;
7275 case XmCR_TO_BOTTOM
:
7276 bar
->dragging
= Qnil
;
7277 part
= scroll_bar_to_bottom
;
7283 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7284 && XINT (bar
->dragging
) <= cs
->value
);
7286 /* Get the slider size. */
7288 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7291 /* At the max position of the scroll bar, do a line-wise
7292 movement. Without doing anything, the LessTif scroll bar
7293 calls us with the same cs->value again and again. If we
7294 want to make sure that we can reach the end of the buffer,
7295 we have to do something.
7297 Implementation note: setting bar->dragging always to
7298 cs->value gives a smoother movement at the max position.
7299 Setting it to nil when doing line-wise movement gives
7300 a better slider behavior. */
7302 if (cs
->value
+ slider_size
== XM_SB_MAX
7304 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7306 part
= scroll_bar_down_arrow
;
7307 bar
->dragging
= Qnil
;
7311 whole
= XM_SB_RANGE
;
7312 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7313 part
= scroll_bar_handle
;
7314 bar
->dragging
= make_number (cs
->value
);
7319 case XmCR_VALUE_CHANGED
:
7325 window_being_scrolled
= bar
->window
;
7326 last_scroll_bar_part
= part
;
7327 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7332 #else /* not USE_MOTIF, i.e. XAW3D. */
7335 /* Xaw3d scroll bar callback. Invoked when the thumb is dragged.
7336 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7337 scroll bar struct. CALL_DATA is a pointer to a float saying where
7341 xaw3d_jump_callback (widget
, client_data
, call_data
)
7343 XtPointer client_data
, call_data
;
7345 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7346 float top
= *(float *) call_data
;
7349 int dragging_down_p
, part
;
7350 double epsilon
= 0.01;
7352 /* Get the size of the thumb, a value between 0 and 1. */
7354 XtVaGetValues (widget
, XtNshown
, &shown
, NULL
);
7358 portion
= shown
< 1 ? top
* whole
: 0;
7359 dragging_down_p
= (INTEGERP (bar
->dragging
)
7360 && XINT (bar
->dragging
) < portion
);
7363 && (abs (top
+ shown
- 1) < epsilon
7365 && last_scroll_bar_part
== scroll_bar_down_arrow
)))
7366 part
= scroll_bar_down_arrow
;
7368 part
= scroll_bar_handle
;
7370 window_being_scrolled
= bar
->window
;
7371 bar
->dragging
= make_number (portion
);
7372 last_scroll_bar_part
= part
;
7373 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7377 /* Xaw3d scroll bar callback. Invoked for incremental scrolling.,
7378 i.e. line or page up or down. WIDGET is the Xaw3d scroll bar
7379 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7380 the scroll bar. CALL_DATA is an integer specifying the action that
7381 has taken place. It's magnitude is in the range 0..height of the
7382 scroll bar. Negative values mean scroll towards buffer start.
7383 Values < height of scroll bar mean line-wise movement. */
7386 xaw3d_scroll_callback (widget
, client_data
, call_data
)
7388 XtPointer client_data
, call_data
;
7390 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7391 int position
= (int) call_data
;
7395 /* Get the height of the scroll bar. */
7397 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7402 if (abs (position
) < height
)
7403 part
= scroll_bar_up_arrow
;
7405 part
= scroll_bar_above_handle
;
7409 if (abs (position
) < height
)
7410 part
= scroll_bar_down_arrow
;
7412 part
= scroll_bar_below_handle
;
7415 window_being_scrolled
= bar
->window
;
7416 bar
->dragging
= Qnil
;
7417 last_scroll_bar_part
= part
;
7418 x_send_scroll_bar_event (bar
->window
, part
, 0, 0);
7422 #endif /* not USE_MOTIF */
7425 /* Create the widget for scroll bar BAR on frame F. Record the widget
7426 and X window of the scroll bar in BAR. */
7429 x_create_toolkit_scroll_bar (f
, bar
)
7431 struct scroll_bar
*bar
;
7437 char *scroll_bar_name
= "verticalScrollBar";
7438 unsigned long pixel
;
7443 /* LessTif 0.85, problems:
7445 1. When the mouse if over the scroll bar, the scroll bar will
7446 get keyboard events. I didn't find a way to turn this off.
7448 2. Do we have to explicitly set the cursor to get an arrow
7449 cursor (see below)? */
7451 /* Set resources. Create the widget. */
7452 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7453 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7454 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7455 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7456 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7457 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7458 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7460 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7463 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7467 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7470 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7474 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7475 scroll_bar_name
, av
, ac
);
7477 /* Add one callback for everything that can happen. */
7478 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7480 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7482 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7484 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7486 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7488 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7490 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7493 /* Realize the widget. Only after that is the X window created. */
7494 XtRealizeWidget (widget
);
7496 /* Set the cursor to an arrow. I didn't find a resource to do that.
7497 And I'm wondering why it hasn't an arrow cursor by default. */
7498 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7499 f
->output_data
.x
->nontext_cursor
);
7501 #elif defined HAVE_XAW3D
7503 /* Set resources. Create the widget. The background of the
7504 Xaw3d scroll bar widget is a little bit light for my taste.
7505 We don't alter it here to let users change it according
7506 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7507 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7508 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7509 XtSetArg (av
[ac
], XtNcursorName
, "left_ptr"); ++ac
;
7510 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
); ++ac
;
7512 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7515 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7519 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7522 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7526 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7527 f
->output_data
.x
->edit_widget
, av
, ac
);
7529 /* Define callbacks. */
7530 XtAddCallback (widget
, XtNjumpProc
, xaw3d_jump_callback
, (XtPointer
) bar
);
7531 XtAddCallback (widget
, XtNscrollProc
, xaw3d_scroll_callback
,
7534 /* Realize the widget. Only after that is the X window created. */
7535 XtRealizeWidget (widget
);
7537 #endif /* HAVE_XAW3D */
7539 /* Install an action hook that let's us detect when the user
7540 finishes interacting with a scroll bar. */
7541 if (action_hook_id
== 0)
7542 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7544 /* Remember X window and widget in the scroll bar vector. */
7545 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7546 xwindow
= XtWindow (widget
);
7547 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7553 /* Set the thumb size and position of scroll bar BAR. We are currently
7554 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7557 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7558 struct scroll_bar
*bar
;
7559 int portion
, position
, whole
;
7563 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7569 top
= (float) position
/ whole
;
7570 shown
= (float) portion
/ whole
;
7578 Boolean arrow1_selected
, arrow2_selected
;
7579 unsigned char flags
;
7580 XmScrollBarWidget sb
;
7582 /* Slider size. Must be in the range [1 .. MAX - MIN] where NAX
7583 is the scroll bar's maximum and MIN is the scroll bar's minimum
7585 size
= shown
* XM_SB_RANGE
;
7586 size
= min (size
, XM_SB_RANGE
);
7587 size
= max (size
, 1);
7589 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7590 value
= top
* XM_SB_RANGE
;
7591 value
= min (value
, XM_SB_MAX
- size
);
7592 value
= max (value
, XM_SB_MIN
);
7594 /* LessTif: Calling XmScrollBarSetValues after an increment or
7595 decrement turns off auto-repeat LessTif-internally. This can
7596 be seen in ScrollBar.c which resets Arrow1Selected and
7597 Arrow2Selected. It also sets internal flags so that LessTif
7598 believes the mouse is in the slider. We either have to change
7599 our code, or work around that by accessing private data. */
7601 sb
= (XmScrollBarWidget
) widget
;
7602 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
7603 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
7604 flags
= sb
->scrollBar
.flags
;
7606 if (NILP (bar
->dragging
))
7607 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
7608 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7609 /* This has the negative side effect that the slider value is
7610 not would it would be if we scrolled here using line-wise or
7611 page-wise movement. */
7612 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
7615 /* If currently dragging, only update the slider size.
7616 This reduces flicker effects. */
7617 int old_value
, old_size
, increment
, page_increment
;
7619 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
7620 &increment
, &page_increment
);
7621 XmScrollBarSetValues (widget
, old_value
,
7622 min (size
, XM_SB_RANGE
- old_value
),
7626 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
7627 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
7628 sb
->scrollBar
.flags
= flags
;
7630 #elif defined HAVE_XAW3D
7632 /* Restrict to [0 1]. */
7633 top
= max (0, min (1, top
));
7634 shown
= max (0, min (1, shown
));
7636 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
7637 check that your system's configuration file contains a define
7638 for `NARROWPROTO'. See s/freebsd.h for an example. */
7639 if (NILP (bar
->dragging
))
7641 float old_top
, old_shown
;
7642 XtVaGetValues (widget
, XtNtopOfThumb
, &old_top
, XtNshown
, &old_shown
,
7644 if (top
!= old_top
|| shown
!= old_shown
)
7645 XawScrollbarSetThumb (widget
, top
, shown
);
7649 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
7650 int scroll_mode
= sb
->scrollbar
.scroll_mode
;
7652 sb
->scrollbar
.scroll_mode
= 0;
7654 if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7655 XawScrollbarSetThumb (widget
, top
, 1 - top
);
7659 XtVaGetValues (widget
, XtNtopOfThumb
, &old_top
, NULL
);
7660 XawScrollbarSetThumb (widget
, old_top
, min (shown
, 1 - old_top
));
7663 sb
->scrollbar
.scroll_mode
= scroll_mode
;
7666 #endif /* HAVE_XAW3D */
7671 #endif /* USE_TOOLKIT_SCROLL_BARS */
7675 /************************************************************************
7676 Scroll bars, general
7677 ************************************************************************/
7679 /* Create a scroll bar and return the scroll bar vector for it. W is
7680 the Emacs window on which to create the scroll bar. TOP, LEFT,
7681 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7684 static struct scroll_bar
*
7685 x_scroll_bar_create (w
, top
, left
, width
, height
)
7687 int top
, left
, width
, height
;
7689 struct frame
*f
= XFRAME (w
->frame
);
7690 #ifdef USE_X_TOOLKIT
7695 struct scroll_bar
*bar
7696 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7700 #if USE_TOOLKIT_SCROLL_BARS
7701 x_create_toolkit_scroll_bar (f
, bar
);
7702 #else /* not USE_TOOLKIT_SCROLL_BARS */
7704 XSetWindowAttributes a
;
7707 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7708 if (a
.background_pixel
== -1)
7709 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
7711 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
7712 | ButtonMotionMask
| PointerMotionHintMask
7714 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
7716 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
7718 /* Clear the area of W that will serve as a scroll bar. This is
7719 for the case that a window has been split horizontally. In
7720 this case, no clear_frame is generated to reduce flickering. */
7721 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7723 window_box_height (w
), False
);
7725 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7726 /* Position and size of scroll bar. */
7727 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7729 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7731 /* Border width, depth, class, and visual. */
7738 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
7740 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7742 XSETWINDOW (bar
->window
, w
);
7743 XSETINT (bar
->top
, top
);
7744 XSETINT (bar
->left
, left
);
7745 XSETINT (bar
->width
, width
);
7746 XSETINT (bar
->height
, height
);
7747 XSETINT (bar
->start
, 0);
7748 XSETINT (bar
->end
, 0);
7749 bar
->dragging
= Qnil
;
7751 /* Add bar to its frame's list of scroll bars. */
7752 bar
->next
= FRAME_SCROLL_BARS (f
);
7754 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7755 if (!NILP (bar
->next
))
7756 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7758 /* Map the window/widget. */
7759 #if USE_TOOLKIT_SCROLL_BARS
7760 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
7761 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
7762 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7764 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7766 #else /* not USE_TOOLKIT_SCROLL_BARS */
7767 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7768 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7775 /* Draw BAR's handle in the proper position.
7777 If the handle is already drawn from START to END, don't bother
7778 redrawing it, unless REBUILD is non-zero; in that case, always
7779 redraw it. (REBUILD is handy for drawing the handle after expose
7782 Normally, we want to constrain the start and end of the handle to
7783 fit inside its rectangle, but if the user is dragging the scroll
7784 bar handle, we want to let them drag it down all the way, so that
7785 the bar's top is as far down as it goes; otherwise, there's no way
7786 to move to the very end of the buffer. */
7789 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
7790 struct scroll_bar
*bar
;
7794 #ifndef USE_TOOLKIT_SCROLL_BARS
7795 int dragging
= ! NILP (bar
->dragging
);
7796 Window w
= SCROLL_BAR_X_WINDOW (bar
);
7797 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7798 GC gc
= f
->output_data
.x
->normal_gc
;
7800 /* If the display is already accurate, do nothing. */
7802 && start
== XINT (bar
->start
)
7803 && end
== XINT (bar
->end
))
7809 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
7810 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
7811 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7813 /* Make sure the values are reasonable, and try to preserve
7814 the distance between start and end. */
7816 int length
= end
- start
;
7820 else if (start
> top_range
)
7822 end
= start
+ length
;
7826 else if (end
> top_range
&& ! dragging
)
7830 /* Store the adjusted setting in the scroll bar. */
7831 XSETINT (bar
->start
, start
);
7832 XSETINT (bar
->end
, end
);
7834 /* Clip the end position, just for display. */
7835 if (end
> top_range
)
7838 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
7839 below top positions, to make sure the handle is always at least
7840 that many pixels tall. */
7841 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7843 /* Draw the empty space above the handle. Note that we can't clear
7844 zero-height areas; that means "clear to end of window." */
7846 XClearArea (FRAME_X_DISPLAY (f
), w
,
7848 /* x, y, width, height, and exposures. */
7849 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7850 VERTICAL_SCROLL_BAR_TOP_BORDER
,
7851 inside_width
, start
,
7854 /* Change to proper foreground color if one is specified. */
7855 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7856 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7857 f
->output_data
.x
->scroll_bar_foreground_pixel
);
7859 /* Draw the handle itself. */
7860 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
7862 /* x, y, width, height */
7863 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7864 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
7865 inside_width
, end
- start
);
7867 /* Restore the foreground color of the GC if we changed it above. */
7868 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7869 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7870 f
->output_data
.x
->foreground_pixel
);
7872 /* Draw the empty space below the handle. Note that we can't
7873 clear zero-height areas; that means "clear to end of window." */
7874 if (end
< inside_height
)
7875 XClearArea (FRAME_X_DISPLAY (f
), w
,
7877 /* x, y, width, height, and exposures. */
7878 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7879 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
7880 inside_width
, inside_height
- end
,
7886 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7890 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
7894 x_scroll_bar_remove (bar
)
7895 struct scroll_bar
*bar
;
7897 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7901 #if USE_TOOLKIT_SCROLL_BARS
7902 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
7903 #else /* not USE_TOOLKIT_SCROLL_BARS */
7904 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7905 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7907 /* Disassociate this scroll bar from its window. */
7908 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
7914 /* Set the handle of the vertical scroll bar for WINDOW to indicate
7915 that we are displaying PORTION characters out of a total of WHOLE
7916 characters, starting at POSITION. If WINDOW has no scroll bar,
7920 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
7922 int portion
, whole
, position
;
7924 struct frame
*f
= XFRAME (w
->frame
);
7925 struct scroll_bar
*bar
;
7926 int top
, height
, left
, sb_left
, width
, sb_width
;
7927 int window_x
, window_y
, window_width
, window_height
;
7929 /* Get window dimensions. */
7930 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7932 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
7933 height
= window_height
;
7935 /* Compute the left edge of the scroll bar area. */
7936 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7937 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
7939 left
= XFASTINT (w
->left
);
7940 left
*= CANON_X_UNIT (f
);
7941 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
7943 /* Compute the width of the scroll bar which might be less than
7944 the width of the area reserved for the scroll bar. */
7945 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
7946 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
7950 /* Compute the left edge of the scroll bar. */
7951 #ifdef USE_TOOLKIT_SCROLL_BARS
7952 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7953 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
7955 sb_left
= left
+ (width
- sb_width
) / 2;
7957 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7958 sb_left
= left
+ width
- sb_width
;
7963 /* Does the scroll bar exist yet? */
7964 if (NILP (w
->vertical_scroll_bar
))
7967 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7968 left
, top
, width
, height
, False
);
7970 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
7974 /* It may just need to be moved and resized. */
7975 unsigned int mask
= 0;
7977 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
7981 if (sb_left
!= XINT (bar
->left
))
7983 if (top
!= XINT (bar
->top
))
7985 if (sb_width
!= XINT (bar
->width
))
7987 if (height
!= XINT (bar
->height
))
7990 #ifdef USE_TOOLKIT_SCROLL_BARS
7992 /* Since toolkit scroll bars are smaller than the space reserved
7993 for them on the frame, we have to clear "under" them. */
7994 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7995 left
, top
, width
, height
, False
);
7997 /* Move/size the scroll bar widget. */
7999 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8000 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8002 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8005 #else /* not USE_TOOLKIT_SCROLL_BARS */
8007 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8009 /* Clear areas not covered by the scroll bar. This makes sure a
8010 previous mode line display is cleared after C-x 2 C-x 1, for
8011 example. Non-toolkit scroll bars are as wide as the area
8012 reserved for scroll bars - trim at both sides. */
8013 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8014 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8016 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8017 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8018 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8022 /* Move/size the scroll bar window. */
8027 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8029 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8031 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8035 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8037 /* Remember new settings. */
8038 XSETINT (bar
->left
, sb_left
);
8039 XSETINT (bar
->top
, top
);
8040 XSETINT (bar
->width
, sb_width
);
8041 XSETINT (bar
->height
, height
);
8046 #if USE_TOOLKIT_SCROLL_BARS
8047 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8048 #else /* not USE_TOOLKIT_SCROLL_BARS */
8049 /* Set the scroll bar's current state, unless we're currently being
8051 if (NILP (bar
->dragging
))
8053 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8056 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8059 int start
= ((double) position
* top_range
) / whole
;
8060 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8061 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8064 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8066 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8070 /* The following three hooks are used when we're doing a thorough
8071 redisplay of the frame. We don't explicitly know which scroll bars
8072 are going to be deleted, because keeping track of when windows go
8073 away is a real pain - "Can you say set-window-configuration, boys
8074 and girls?" Instead, we just assert at the beginning of redisplay
8075 that *all* scroll bars are to be removed, and then save a scroll bar
8076 from the fiery pit when we actually redisplay its window. */
8078 /* Arrange for all scroll bars on FRAME to be removed at the next call
8079 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8080 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8083 XTcondemn_scroll_bars (frame
)
8086 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8087 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8090 bar
= FRAME_SCROLL_BARS (frame
);
8091 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8092 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8093 XSCROLL_BAR (bar
)->prev
= Qnil
;
8094 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8095 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8096 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8100 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8101 Note that WINDOW isn't necessarily condemned at all. */
8103 XTredeem_scroll_bar (window
)
8104 struct window
*window
;
8106 struct scroll_bar
*bar
;
8108 /* We can't redeem this window's scroll bar if it doesn't have one. */
8109 if (NILP (window
->vertical_scroll_bar
))
8112 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8114 /* Unlink it from the condemned list. */
8116 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8118 if (NILP (bar
->prev
))
8120 /* If the prev pointer is nil, it must be the first in one of
8122 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8123 /* It's not condemned. Everything's fine. */
8125 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8126 window
->vertical_scroll_bar
))
8127 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8129 /* If its prev pointer is nil, it must be at the front of
8130 one or the other! */
8134 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8136 if (! NILP (bar
->next
))
8137 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8139 bar
->next
= FRAME_SCROLL_BARS (f
);
8141 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8142 if (! NILP (bar
->next
))
8143 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8147 /* Remove all scroll bars on FRAME that haven't been saved since the
8148 last call to `*condemn_scroll_bars_hook'. */
8151 XTjudge_scroll_bars (f
)
8154 Lisp_Object bar
, next
;
8156 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8158 /* Clear out the condemned list now so we won't try to process any
8159 more events on the hapless scroll bars. */
8160 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8162 for (; ! NILP (bar
); bar
= next
)
8164 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8166 x_scroll_bar_remove (b
);
8169 b
->next
= b
->prev
= Qnil
;
8172 /* Now there should be no references to the condemned scroll bars,
8173 and they should get garbage-collected. */
8177 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8178 is a no-op when using toolkit scroll bars.
8180 This may be called from a signal handler, so we have to ignore GC
8184 x_scroll_bar_expose (bar
, event
)
8185 struct scroll_bar
*bar
;
8188 #ifndef USE_TOOLKIT_SCROLL_BARS
8190 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8191 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8192 GC gc
= f
->output_data
.x
->normal_gc
;
8193 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8197 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8199 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8200 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8202 /* x, y, width, height */
8204 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8205 XINT (bar
->height
) - 1);
8209 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8212 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8213 is set to something other than no_event, it is enqueued.
8215 This may be called from a signal handler, so we have to ignore GC
8219 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8220 struct scroll_bar
*bar
;
8222 struct input_event
*emacs_event
;
8224 if (! GC_WINDOWP (bar
->window
))
8227 emacs_event
->kind
= scroll_bar_click
;
8228 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8229 emacs_event
->modifiers
8230 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8231 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8232 event
->xbutton
.state
)
8233 | (event
->type
== ButtonRelease
8236 emacs_event
->frame_or_window
= bar
->window
;
8237 emacs_event
->timestamp
= event
->xbutton
.time
;
8240 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8242 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8245 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8246 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8249 if (y
> top_range
) y
= top_range
;
8251 if (y
< XINT (bar
->start
))
8252 emacs_event
->part
= scroll_bar_above_handle
;
8253 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8254 emacs_event
->part
= scroll_bar_handle
;
8256 emacs_event
->part
= scroll_bar_below_handle
;
8258 /* Just because the user has clicked on the handle doesn't mean
8259 they want to drag it. Lisp code needs to be able to decide
8260 whether or not we're dragging. */
8262 /* If the user has just clicked on the handle, record where they're
8264 if (event
->type
== ButtonPress
8265 && emacs_event
->part
== scroll_bar_handle
)
8266 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8269 /* If the user has released the handle, set it to its final position. */
8270 if (event
->type
== ButtonRelease
8271 && ! NILP (bar
->dragging
))
8273 int new_start
= y
- XINT (bar
->dragging
);
8274 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8276 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8277 bar
->dragging
= Qnil
;
8280 /* Same deal here as the other #if 0. */
8282 /* Clicks on the handle are always reported as occurring at the top of
8284 if (emacs_event
->part
== scroll_bar_handle
)
8285 emacs_event
->x
= bar
->start
;
8287 XSETINT (emacs_event
->x
, y
);
8289 XSETINT (emacs_event
->x
, y
);
8292 XSETINT (emacs_event
->y
, top_range
);
8296 /* Handle some mouse motion while someone is dragging the scroll bar.
8298 This may be called from a signal handler, so we have to ignore GC
8302 x_scroll_bar_note_movement (bar
, event
)
8303 struct scroll_bar
*bar
;
8306 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8308 last_mouse_movement_time
= event
->xmotion
.time
;
8311 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8313 /* If we're dragging the bar, display it. */
8314 if (! GC_NILP (bar
->dragging
))
8316 /* Where should the handle be now? */
8317 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8319 if (new_start
!= XINT (bar
->start
))
8321 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8323 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8328 /* Return information to the user about the current position of the mouse
8329 on the scroll bar. */
8332 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8334 Lisp_Object
*bar_window
;
8335 enum scroll_bar_part
*part
;
8337 unsigned long *time
;
8339 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8340 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8341 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8343 Window dummy_window
;
8345 unsigned int dummy_mask
;
8349 /* Get the mouse's position relative to the scroll bar window, and
8351 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8353 /* Root, child, root x and root y. */
8354 &dummy_window
, &dummy_window
,
8355 &dummy_coord
, &dummy_coord
,
8357 /* Position relative to scroll bar. */
8360 /* Mouse buttons and modifier keys. */
8367 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8370 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8372 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8374 if (! NILP (bar
->dragging
))
8375 win_y
-= XINT (bar
->dragging
);
8379 if (win_y
> top_range
)
8383 *bar_window
= bar
->window
;
8385 if (! NILP (bar
->dragging
))
8386 *part
= scroll_bar_handle
;
8387 else if (win_y
< XINT (bar
->start
))
8388 *part
= scroll_bar_above_handle
;
8389 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8390 *part
= scroll_bar_handle
;
8392 *part
= scroll_bar_below_handle
;
8394 XSETINT (*x
, win_y
);
8395 XSETINT (*y
, top_range
);
8398 last_mouse_scroll_bar
= Qnil
;
8401 *time
= last_mouse_movement_time
;
8407 /* The screen has been cleared so we may have changed foreground or
8408 background colors, and the scroll bars may need to be redrawn.
8409 Clear out the scroll bars, and ask for expose events, so we can
8413 x_scroll_bar_clear (f
)
8416 #ifndef USE_TOOLKIT_SCROLL_BARS
8419 /* We can have scroll bars even if this is 0,
8420 if we just turned off scroll bar mode.
8421 But in that case we should not clear them. */
8422 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8423 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8424 bar
= XSCROLL_BAR (bar
)->next
)
8425 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8427 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8430 /* This processes Expose events from the menu-bar specific X event
8431 loop in xmenu.c. This allows to redisplay the frame if necessary
8432 when handling menu-bar or pop-up items. */
8435 process_expose_from_menu (event
)
8439 struct x_display_info
*dpyinfo
;
8440 int frame_exposed_p
= 0;
8444 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8445 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8448 if (f
->async_visible
== 0)
8450 f
->async_visible
= 1;
8451 f
->async_iconified
= 0;
8452 f
->output_data
.x
->has_been_visible
= 1;
8453 SET_FRAME_GARBAGED (f
);
8457 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8458 event
.xexpose
.x
, event
.xexpose
.y
,
8459 event
.xexpose
.width
, event
.xexpose
.height
);
8460 frame_exposed_p
= 1;
8465 struct scroll_bar
*bar
8466 = x_window_to_scroll_bar (event
.xexpose
.window
);
8469 x_scroll_bar_expose (bar
, &event
);
8473 return frame_exposed_p
;
8476 /* Define a queue to save up SelectionRequest events for later handling. */
8478 struct selection_event_queue
8481 struct selection_event_queue
*next
;
8484 static struct selection_event_queue
*queue
;
8486 /* Nonzero means queue up certain events--don't process them yet. */
8488 static int x_queue_selection_requests
;
8490 /* Queue up an X event *EVENT, to be processed later. */
8493 x_queue_event (f
, event
)
8497 struct selection_event_queue
*queue_tmp
8498 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8500 if (queue_tmp
!= NULL
)
8502 queue_tmp
->event
= *event
;
8503 queue_tmp
->next
= queue
;
8508 /* Take all the queued events and put them back
8509 so that they get processed afresh. */
8512 x_unqueue_events (display
)
8515 while (queue
!= NULL
)
8517 struct selection_event_queue
*queue_tmp
= queue
;
8518 XPutBackEvent (display
, &queue_tmp
->event
);
8519 queue
= queue_tmp
->next
;
8520 xfree ((char *)queue_tmp
);
8524 /* Start queuing SelectionRequest events. */
8527 x_start_queuing_selection_requests (display
)
8530 x_queue_selection_requests
++;
8533 /* Stop queuing SelectionRequest events. */
8536 x_stop_queuing_selection_requests (display
)
8539 x_queue_selection_requests
--;
8540 x_unqueue_events (display
);
8543 /* The main X event-reading loop - XTread_socket. */
8545 /* Time stamp of enter window event. This is only used by XTread_socket,
8546 but we have to put it out here, since static variables within functions
8547 sometimes don't work. */
8549 static Time enter_timestamp
;
8551 /* This holds the state XLookupString needs to implement dead keys
8552 and other tricks known as "compose processing". _X Window System_
8553 says that a portable program can't use this, but Stephen Gildea assures
8554 me that letting the compiler initialize it to zeros will work okay.
8556 This must be defined outside of XTread_socket, for the same reasons
8557 given for enter_time stamp, above. */
8559 static XComposeStatus compose_status
;
8561 /* Record the last 100 characters stored
8562 to help debug the loss-of-chars-during-GC problem. */
8564 static int temp_index
;
8565 static short temp_buffer
[100];
8567 /* Set this to nonzero to fake an "X I/O error"
8568 on a particular display. */
8570 struct x_display_info
*XTread_socket_fake_io_error
;
8572 /* When we find no input here, we occasionally do a no-op command
8573 to verify that the X server is still running and we can still talk with it.
8574 We try all the open displays, one by one.
8575 This variable is used for cycling thru the displays. */
8577 static struct x_display_info
*next_noop_dpyinfo
;
8579 #define SET_SAVED_MENU_EVENT(size) \
8582 if (f->output_data.x->saved_menu_event == 0) \
8583 f->output_data.x->saved_menu_event \
8584 = (XEvent *) xmalloc (sizeof (XEvent)); \
8585 bcopy (&event, f->output_data.x->saved_menu_event, size); \
8586 if (numchars >= 1) \
8588 bufp->kind = menu_bar_activate_event; \
8589 XSETFRAME (bufp->frame_or_window, f); \
8597 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
8598 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
8600 /* Read events coming from the X server.
8601 This routine is called by the SIGIO handler.
8602 We return as soon as there are no more events to be read.
8604 Events representing keys are stored in buffer BUFP,
8605 which can hold up to NUMCHARS characters.
8606 We return the number of characters stored into the buffer,
8607 thus pretending to be `read'.
8609 EXPECTED is nonzero if the caller knows input is available. */
8612 XTread_socket (sd
, bufp
, numchars
, expected
)
8614 /* register */ struct input_event
*bufp
;
8615 /* register */ int numchars
;
8622 int event_found
= 0;
8623 struct x_display_info
*dpyinfo
;
8625 Status status_return
;
8628 if (interrupt_input_blocked
)
8630 interrupt_input_pending
= 1;
8634 interrupt_input_pending
= 0;
8637 /* So people can tell when we have read the available input. */
8638 input_signal_count
++;
8641 abort (); /* Don't think this happens. */
8643 /* Find the display we are supposed to read input for.
8644 It's the one communicating on descriptor SD. */
8645 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
8647 #if 0 /* This ought to be unnecessary; let's verify it. */
8649 /* If available, Xlib uses FIOSNBIO to make the socket
8650 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
8651 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
8652 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
8653 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
8654 #endif /* ! defined (FIOSNBIO) */
8657 #if 0 /* This code can't be made to work, with multiple displays,
8658 and appears not to be used on any system any more.
8659 Also keyboard.c doesn't turn O_NDELAY on and off
8660 for X connections. */
8663 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
8665 extern int read_alarm_should_throw
;
8666 read_alarm_should_throw
= 1;
8667 XPeekEvent (dpyinfo
->display
, &event
);
8668 read_alarm_should_throw
= 0;
8670 #endif /* HAVE_SELECT */
8674 /* For debugging, this gives a way to fake an I/O error. */
8675 if (dpyinfo
== XTread_socket_fake_io_error
)
8677 XTread_socket_fake_io_error
= 0;
8678 x_io_error_quitter (dpyinfo
->display
);
8681 while (XPending (dpyinfo
->display
))
8683 XNextEvent (dpyinfo
->display
, &event
);
8685 if (display_busy_cursor_p
)
8687 /* Setting inhibit_busy_cursor to 2 inhibits busy-cursor
8688 display until the next X event is read and we come
8689 here again. Setting it to 1 inhibits busy-cursor
8690 display for direct commands. */
8691 if (event
.type
== MotionNotify
8692 || event
.type
== EnterNotify
8693 || (dpyinfo
->grabbed
8694 && event
.type
!= ButtonRelease
))
8695 inhibit_busy_cursor
= 2;
8697 inhibit_busy_cursor
= 1;
8702 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
8703 event
.xclient
.window
);
8704 /* The necessity of the following line took me
8705 a full work-day to decipher from the docs!! */
8706 if (f1
!= 0 && FRAME_XIC (f1
) && XFilterEvent (&event
, None
))
8716 if (event
.xclient
.message_type
8717 == dpyinfo
->Xatom_wm_protocols
8718 && event
.xclient
.format
== 32)
8720 if (event
.xclient
.data
.l
[0]
8721 == dpyinfo
->Xatom_wm_take_focus
)
8723 /* Use x_any_window_to_frame because this
8724 could be the shell widget window
8725 if the frame has no title bar. */
8726 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
8728 /* Not quite sure this is needed -pd */
8729 if (f
&& FRAME_XIC (f
))
8730 XSetICFocus (FRAME_XIC (f
));
8732 /* Since we set WM_TAKE_FOCUS, we must call
8733 XSetInputFocus explicitly. But not if f is null,
8734 since that might be an event for a deleted frame. */
8737 Display
*d
= event
.xclient
.display
;
8738 /* Catch and ignore errors, in case window has been
8739 iconified by a window manager such as GWM. */
8740 int count
= x_catch_errors (d
);
8741 XSetInputFocus (d
, event
.xclient
.window
,
8742 /* The ICCCM says this is
8743 the only valid choice. */
8745 event
.xclient
.data
.l
[1]);
8746 /* This is needed to detect the error
8747 if there is an error. */
8749 x_uncatch_errors (d
, count
);
8751 /* Not certain about handling scroll bars here */
8753 else if (event
.xclient
.data
.l
[0]
8754 == dpyinfo
->Xatom_wm_save_yourself
)
8756 /* Save state modify the WM_COMMAND property to
8757 something which can reinstate us. This notifies
8758 the session manager, who's looking for such a
8759 PropertyNotify. Can restart processing when
8760 a keyboard or mouse event arrives. */
8763 f
= x_top_window_to_frame (dpyinfo
,
8764 event
.xclient
.window
);
8766 /* This is just so we only give real data once
8767 for a single Emacs process. */
8768 if (f
== selected_frame
)
8769 XSetCommand (FRAME_X_DISPLAY (f
),
8770 event
.xclient
.window
,
8771 initial_argv
, initial_argc
);
8773 XSetCommand (FRAME_X_DISPLAY (f
),
8774 event
.xclient
.window
,
8778 else if (event
.xclient
.data
.l
[0]
8779 == dpyinfo
->Xatom_wm_delete_window
)
8782 = x_any_window_to_frame (dpyinfo
,
8783 event
.xclient
.window
);
8790 bufp
->kind
= delete_window_event
;
8791 XSETFRAME (bufp
->frame_or_window
, f
);
8799 else if (event
.xclient
.message_type
8800 == dpyinfo
->Xatom_wm_configure_denied
)
8803 else if (event
.xclient
.message_type
8804 == dpyinfo
->Xatom_wm_window_moved
)
8808 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
8810 new_x
= event
.xclient
.data
.s
[0];
8811 new_y
= event
.xclient
.data
.s
[1];
8815 f
->output_data
.x
->left_pos
= new_x
;
8816 f
->output_data
.x
->top_pos
= new_y
;
8820 else if (event
.xclient
.message_type
8821 == dpyinfo
->Xatom_editres
)
8824 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
8825 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
8828 #endif /* HACK_EDITRES */
8829 else if ((event
.xclient
.message_type
8830 == dpyinfo
->Xatom_DONE
)
8831 || (event
.xclient
.message_type
8832 == dpyinfo
->Xatom_PAGE
))
8834 /* Ghostview job completed. Kill it. We could
8835 reply with "Next" if we received "Page", but we
8836 currently never do because we are interested in
8837 images, only, which should have 1 page. */
8838 Window gs_window
= (Window
) event
.xclient
.data
.l
[0];
8839 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
8841 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
8842 x_kill_gs_process (pixmap
, f
);
8843 expose_frame (f
, 0, 0, 0, 0);
8845 #ifdef USE_TOOLKIT_SCROLL_BARS
8846 /* Scroll bar callbacks send a ClientMessage from which
8847 we construct an input_event. */
8848 else if (event
.xclient
.message_type
8849 == dpyinfo
->Xatom_Scrollbar
)
8851 x_scroll_bar_to_input_event (&event
, bufp
);
8852 ++bufp
, ++count
, --numchars
;
8855 #endif /* USE_TOOLKIT_SCROLL_BARS */
8861 case SelectionNotify
:
8862 #ifdef USE_X_TOOLKIT
8863 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
8865 #endif /* not USE_X_TOOLKIT */
8866 x_handle_selection_notify (&event
.xselection
);
8869 case SelectionClear
: /* Someone has grabbed ownership. */
8870 #ifdef USE_X_TOOLKIT
8871 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
8873 #endif /* USE_X_TOOLKIT */
8875 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
8880 bufp
->kind
= selection_clear_event
;
8881 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
8882 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
8883 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
8884 bufp
->frame_or_window
= Qnil
;
8892 case SelectionRequest
: /* Someone wants our selection. */
8893 #ifdef USE_X_TOOLKIT
8894 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
8896 #endif /* USE_X_TOOLKIT */
8897 if (x_queue_selection_requests
)
8898 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
8902 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
8907 bufp
->kind
= selection_request_event
;
8908 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
8909 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
8910 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
8911 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
8912 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
8913 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
8914 bufp
->frame_or_window
= Qnil
;
8922 case PropertyNotify
:
8923 #ifdef USE_X_TOOLKIT
8924 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
8926 #endif /* not USE_X_TOOLKIT */
8927 x_handle_property_notify (&event
.xproperty
);
8930 case ReparentNotify
:
8931 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
8935 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
8936 x_real_positions (f
, &x
, &y
);
8937 f
->output_data
.x
->left_pos
= x
;
8938 f
->output_data
.x
->top_pos
= y
;
8943 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8946 if (f
->async_visible
== 0)
8948 f
->async_visible
= 1;
8949 f
->async_iconified
= 0;
8950 f
->output_data
.x
->has_been_visible
= 1;
8951 SET_FRAME_GARBAGED (f
);
8954 expose_frame (x_window_to_frame (dpyinfo
,
8955 event
.xexpose
.window
),
8956 event
.xexpose
.x
, event
.xexpose
.y
,
8957 event
.xexpose
.width
, event
.xexpose
.height
);
8961 #ifdef USE_TOOLKIT_SCROLL_BARS
8962 /* Dispatch event to the widget. */
8964 #else /* not USE_TOOLKIT_SCROLL_BARS */
8965 struct scroll_bar
*bar
8966 = x_window_to_scroll_bar (event
.xexpose
.window
);
8969 x_scroll_bar_expose (bar
, &event
);
8970 #ifdef USE_X_TOOLKIT
8973 #endif /* USE_X_TOOLKIT */
8974 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8978 case GraphicsExpose
: /* This occurs when an XCopyArea's
8979 source area was obscured or not
8981 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
8985 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
8986 event
.xgraphicsexpose
.width
,
8987 event
.xgraphicsexpose
.height
);
8989 #ifdef USE_X_TOOLKIT
8992 #endif /* USE_X_TOOLKIT */
8995 case NoExpose
: /* This occurs when an XCopyArea's
8996 source area was completely
9001 /* Redo the mouse-highlight after the tooltip has gone. */
9002 if (event
.xmap
.window
== tip_window
)
9005 redo_mouse_highlight ();
9008 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9009 if (f
) /* F may no longer exist if
9010 the frame was deleted. */
9012 /* While a frame is unmapped, display generation is
9013 disabled; you don't want to spend time updating a
9014 display that won't ever be seen. */
9015 f
->async_visible
= 0;
9016 /* We can't distinguish, from the event, whether the window
9017 has become iconified or invisible. So assume, if it
9018 was previously visible, than now it is iconified.
9019 But x_make_frame_invisible clears both
9020 the visible flag and the iconified flag;
9021 and that way, we know the window is not iconified now. */
9022 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9024 f
->async_iconified
= 1;
9026 bufp
->kind
= iconify_event
;
9027 XSETFRAME (bufp
->frame_or_window
, f
);
9036 if (event
.xmap
.window
== tip_window
)
9037 /* The tooltip has been drawn already. Avoid
9038 the SET_FRAME_GARBAGED below. */
9041 /* We use x_top_window_to_frame because map events can
9042 come for sub-windows and they don't mean that the
9043 frame is visible. */
9044 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9047 f
->async_visible
= 1;
9048 f
->async_iconified
= 0;
9049 f
->output_data
.x
->has_been_visible
= 1;
9051 /* wait_reading_process_input will notice this and update
9052 the frame's display structures. */
9053 SET_FRAME_GARBAGED (f
);
9057 bufp
->kind
= deiconify_event
;
9058 XSETFRAME (bufp
->frame_or_window
, f
);
9063 else if (! NILP (Vframe_list
)
9064 && ! NILP (XCDR (Vframe_list
)))
9065 /* Force a redisplay sooner or later
9066 to update the frame titles
9067 in case this is the second frame. */
9068 record_asynch_buffer_change ();
9073 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9076 /* I couldn't find a way to prevent LessTif scroll bars
9077 from consuming key events. */
9080 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9082 if (widget
&& XmIsScrollBar (widget
))
9084 widget
= XtParent (widget
);
9085 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9088 #endif /* USE_MOTIF */
9092 KeySym keysym
, orig_keysym
;
9093 /* al%imercury@uunet.uu.net says that making this 81 instead of
9094 80 fixed a bug whereby meta chars made his Emacs hang. */
9095 unsigned char copy_buffer
[81];
9099 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9100 extra_keyboard_modifiers
);
9101 modifiers
= event
.xkey
.state
;
9103 /* This will have to go some day... */
9105 /* make_lispy_event turns chars into control chars.
9106 Don't do it here because XLookupString is too eager. */
9107 event
.xkey
.state
&= ~ControlMask
;
9108 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9109 | dpyinfo
->super_mod_mask
9110 | dpyinfo
->hyper_mod_mask
9111 | dpyinfo
->alt_mod_mask
);
9113 /* In case Meta is ComposeCharacter,
9114 clear its status. According to Markus Ehrnsperger
9115 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9116 this enables ComposeCharacter to work whether or
9117 not it is combined with Meta. */
9118 if (modifiers
& dpyinfo
->meta_mod_mask
)
9119 bzero (&compose_status
, sizeof (compose_status
));
9124 /* The necessity of the following line took me
9125 a full work-day to decipher from the docs!! */
9126 if (XFilterEvent (&event
, None
))
9128 nbytes
= XmbLookupString (FRAME_XIC (f
),
9129 &event
.xkey
, copy_buffer
,
9132 if (status_return
== XLookupNone
)
9134 else if (status_return
== XLookupChars
)
9136 else if (status_return
!= XLookupKeySym
9137 && status_return
!= XLookupBoth
)
9141 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9142 80, &keysym
, &compose_status
);
9144 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9145 80, &keysym
, &compose_status
);
9148 orig_keysym
= keysym
;
9152 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9153 || keysym
== XK_Delete
9154 #ifdef XK_ISO_Left_Tab
9155 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9157 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9158 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9159 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9161 /* This recognizes the "extended function keys".
9162 It seems there's no cleaner way.
9163 Test IsModifierKey to avoid handling mode_switch
9165 || ((unsigned) (keysym
) >= XK_Select
9166 && (unsigned)(keysym
) < XK_KP_Space
)
9168 #ifdef XK_dead_circumflex
9169 || orig_keysym
== XK_dead_circumflex
9171 #ifdef XK_dead_grave
9172 || orig_keysym
== XK_dead_grave
9174 #ifdef XK_dead_tilde
9175 || orig_keysym
== XK_dead_tilde
9177 #ifdef XK_dead_diaeresis
9178 || orig_keysym
== XK_dead_diaeresis
9180 #ifdef XK_dead_macron
9181 || orig_keysym
== XK_dead_macron
9183 #ifdef XK_dead_degree
9184 || orig_keysym
== XK_dead_degree
9186 #ifdef XK_dead_acute
9187 || orig_keysym
== XK_dead_acute
9189 #ifdef XK_dead_cedilla
9190 || orig_keysym
== XK_dead_cedilla
9192 #ifdef XK_dead_breve
9193 || orig_keysym
== XK_dead_breve
9195 #ifdef XK_dead_ogonek
9196 || orig_keysym
== XK_dead_ogonek
9198 #ifdef XK_dead_caron
9199 || orig_keysym
== XK_dead_caron
9201 #ifdef XK_dead_doubleacute
9202 || orig_keysym
== XK_dead_doubleacute
9204 #ifdef XK_dead_abovedot
9205 || orig_keysym
== XK_dead_abovedot
9207 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9208 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9209 /* Any "vendor-specific" key is ok. */
9210 || (orig_keysym
& (1 << 28)))
9211 && ! (IsModifierKey (orig_keysym
)
9213 #ifdef XK_Mode_switch
9214 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9217 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9219 #endif /* not HAVE_X11R5 */
9222 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9224 temp_buffer
[temp_index
++] = keysym
;
9225 bufp
->kind
= non_ascii_keystroke
;
9226 bufp
->code
= keysym
;
9227 XSETFRAME (bufp
->frame_or_window
, f
);
9229 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9231 bufp
->timestamp
= event
.xkey
.time
;
9236 if (display_busy_cursor_p
)
9237 if (keysym
!= XK_Return
|| minibuf_level
== 0)
9238 inhibit_busy_cursor
= 2;
9240 else if (numchars
> nbytes
)
9244 for (i
= 0; i
< nbytes
; i
++)
9246 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9248 temp_buffer
[temp_index
++] = copy_buffer
[i
];
9249 bufp
->kind
= ascii_keystroke
;
9250 bufp
->code
= copy_buffer
[i
];
9251 XSETFRAME (bufp
->frame_or_window
, f
);
9253 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9255 bufp
->timestamp
= event
.xkey
.time
;
9262 if (keysym
== NoSymbol
)
9273 /* Here's a possible interpretation of the whole
9274 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9275 you get a FocusIn event, you have to get a FocusOut
9276 event before you relinquish the focus. If you
9277 haven't received a FocusIn event, then a mere
9278 LeaveNotify is enough to free you. */
9282 int from_menu_bar_p
= 0;
9284 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9286 #ifdef LESSTIF_VERSION
9287 /* When clicking outside of a menu bar popup to close
9288 it, we get a FocusIn/ EnterNotify sequence of
9289 events. The flag event.xcrossing.focus is not set
9290 in the EnterNotify event of that sequence because
9291 the focus is in the menu bar,
9292 event.xcrossing.window is the frame's X window.
9293 Unconditionally setting the focus frame to null in
9294 this case is not the right thing, because no event
9295 follows that could set the focus frame to the right
9298 This could be a LessTif bug, but I wasn't able to
9299 reproduce the behavior in a simple test program.
9301 (gerd, LessTif 0.88.1). */
9303 if (!event
.xcrossing
.focus
9305 && f
->output_data
.x
->menubar_widget
)
9310 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9311 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9312 from_menu_bar_p
= 1;
9314 #endif /* LESSTIF_VERSION */
9316 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9318 /* Avoid nasty pop/raise loops. */
9319 if (f
&& (!(f
->auto_raise
)
9321 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9323 x_new_focus_frame (dpyinfo
, f
);
9324 enter_timestamp
= event
.xcrossing
.time
;
9327 else if (f
== dpyinfo
->x_focus_frame
)
9328 x_new_focus_frame (dpyinfo
, 0);
9330 /* EnterNotify counts as mouse movement,
9331 so update things that depend on mouse position. */
9332 if (f
&& !f
->output_data
.x
->busy_p
)
9333 note_mouse_movement (f
, &event
.xmotion
);
9338 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9339 if (event
.xfocus
.detail
!= NotifyPointer
)
9340 dpyinfo
->x_focus_event_frame
= f
;
9342 x_new_focus_frame (dpyinfo
, f
);
9345 if (f
&& FRAME_XIC (f
))
9346 XSetICFocus (FRAME_XIC (f
));
9352 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9356 int from_menu_bar_p
= 0;
9358 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9360 /* If we move outside the frame, then we're
9361 certainly no longer on any text in the frame. */
9362 clear_mouse_face (dpyinfo
);
9363 dpyinfo
->mouse_face_mouse_frame
= 0;
9366 /* Generate a nil HELP_EVENT to cancel a help-echo.
9367 Do it only if there's something to cancel.
9368 Otherwise, the startup message is cleared when
9369 the mouse leaves the frame. */
9370 if (any_help_event_p
)
9372 XSETFRAME (frame
, f
);
9373 bufp
->kind
= HELP_EVENT
;
9374 bufp
->frame_or_window
= Fcons (frame
, Qnil
);
9375 ++bufp
, ++count
, --numchars
;
9378 #ifdef LESSTIF_VERSION
9379 /* Please see the comment at the start of the
9380 EnterNotify case. */
9381 if (!event
.xcrossing
.focus
9382 && f
->output_data
.x
->menubar_widget
)
9386 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9387 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9388 from_menu_bar_p
= 1;
9390 #endif /* LESSTIF_VERSION */
9392 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9393 x_mouse_leave (dpyinfo
);
9396 if (f
== dpyinfo
->x_focus_event_frame
)
9397 dpyinfo
->x_focus_event_frame
= 0;
9398 if (f
== dpyinfo
->x_focus_frame
)
9399 x_new_focus_frame (dpyinfo
, 0);
9405 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9406 if (event
.xfocus
.detail
!= NotifyPointer
9407 && f
== dpyinfo
->x_focus_event_frame
)
9408 dpyinfo
->x_focus_event_frame
= 0;
9409 if (f
&& f
== dpyinfo
->x_focus_frame
)
9410 x_new_focus_frame (dpyinfo
, 0);
9413 if (f
&& FRAME_XIC (f
))
9414 XUnsetICFocus (FRAME_XIC (f
));
9421 previous_help_echo
= help_echo
;
9424 if (dpyinfo
->grabbed
&& last_mouse_frame
9425 && FRAME_LIVE_P (last_mouse_frame
))
9426 f
= last_mouse_frame
;
9428 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9431 note_mouse_movement (f
, &event
.xmotion
);
9434 #ifndef USE_X_TOOLKIT
9435 struct scroll_bar
*bar
9436 = x_window_to_scroll_bar (event
.xmotion
.window
);
9439 x_scroll_bar_note_movement (bar
, &event
);
9440 #endif /* USE_X_TOOLKIT */
9442 /* If we move outside the frame, then we're
9443 certainly no longer on any text in the frame. */
9444 clear_mouse_face (dpyinfo
);
9447 /* If the contents of the global variable help_echo
9448 has changed, generate a HELP_EVENT. */
9449 if (STRINGP (help_echo
)
9450 || STRINGP (previous_help_echo
))
9455 XSETFRAME (frame
, f
);
9459 any_help_event_p
= 1;
9460 bufp
->kind
= HELP_EVENT
;
9461 bufp
->frame_or_window
= Fcons (frame
, help_echo
);
9462 ++bufp
, ++count
, --numchars
;
9468 case ConfigureNotify
:
9469 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
9472 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
9473 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
9475 #ifndef USE_X_TOOLKIT
9476 /* In the toolkit version, change_frame_size
9477 is called by the code that handles resizing
9478 of the EmacsFrame widget. */
9480 /* Even if the number of character rows and columns has
9481 not changed, the font size may have changed, so we need
9482 to check the pixel dimensions as well. */
9483 if (columns
!= f
->width
9484 || rows
!= f
->height
9485 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
9486 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
9488 change_frame_size (f
, rows
, columns
, 0, 1, 0);
9489 SET_FRAME_GARBAGED (f
);
9490 cancel_mouse_face (f
);
9494 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
9495 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
9497 /* What we have now is the position of Emacs's own window.
9498 Convert that to the position of the window manager window. */
9499 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
9500 &f
->output_data
.x
->top_pos
);
9502 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
9504 /* Since the WM decorations come below top_pos now,
9505 we must put them below top_pos in the future. */
9506 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
9507 x_wm_set_size_hint (f
, (long) 0, 0);
9510 /* Some window managers pass (0,0) as the location of
9511 the window, and the Motif event handler stores it
9512 in the emacs widget, which messes up Motif menus. */
9513 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
9515 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
9516 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
9518 #endif /* USE_MOTIF */
9525 /* If we decide we want to generate an event to be seen
9526 by the rest of Emacs, we put it here. */
9527 struct input_event emacs_event
;
9530 emacs_event
.kind
= no_event
;
9531 bzero (&compose_status
, sizeof (compose_status
));
9533 if (dpyinfo
->grabbed
9535 && FRAME_LIVE_P (last_mouse_frame
))
9536 f
= last_mouse_frame
;
9538 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9542 /* Is this in the tool-bar? */
9543 if (WINDOWP (f
->tool_bar_window
)
9544 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
9549 x
= event
.xbutton
.x
;
9550 y
= event
.xbutton
.y
;
9553 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
9554 if (EQ (window
, f
->tool_bar_window
))
9556 x_handle_tool_bar_click (f
, &event
.xbutton
);
9562 if (!dpyinfo
->x_focus_frame
9563 || f
== dpyinfo
->x_focus_frame
)
9564 construct_mouse_click (&emacs_event
, &event
, f
);
9568 #ifndef USE_TOOLKIT_SCROLL_BARS
9569 struct scroll_bar
*bar
9570 = x_window_to_scroll_bar (event
.xbutton
.window
);
9573 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
9574 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9577 if (event
.type
== ButtonPress
)
9579 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
9580 last_mouse_frame
= f
;
9581 /* Ignore any mouse motion that happened
9582 before this event; any subsequent mouse-movement
9583 Emacs events should reflect only motion after
9589 last_tool_bar_item
= -1;
9590 if (display_busy_cursor_p
)
9591 inhibit_busy_cursor
= 2;
9595 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
9598 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
9600 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
9606 #ifdef USE_X_TOOLKIT
9607 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9608 /* For a down-event in the menu bar,
9609 don't pass it to Xt right now.
9610 Instead, save it away
9611 and we will pass it to Xt from kbd_buffer_get_event.
9612 That way, we can run some Lisp code first. */
9613 if (f
&& event
.type
== ButtonPress
9614 /* Verify the event is really within the menu bar
9615 and not just sent to it due to grabbing. */
9616 && event
.xbutton
.x
>= 0
9617 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
9618 && event
.xbutton
.y
>= 0
9619 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
9620 && event
.xbutton
.same_screen
)
9622 SET_SAVED_BUTTON_EVENT
;
9623 XSETFRAME (last_mouse_press_frame
, f
);
9625 else if (event
.type
== ButtonPress
)
9627 last_mouse_press_frame
= Qnil
;
9631 #ifdef USE_MOTIF /* This should do not harm for Lucid,
9632 but I am trying to be cautious. */
9633 else if (event
.type
== ButtonRelease
)
9635 if (!NILP (last_mouse_press_frame
))
9637 f
= XFRAME (last_mouse_press_frame
);
9638 if (f
->output_data
.x
)
9639 SET_SAVED_BUTTON_EVENT
;
9644 #endif /* USE_MOTIF */
9647 #endif /* USE_X_TOOLKIT */
9651 case CirculateNotify
:
9654 case CirculateRequest
:
9657 case VisibilityNotify
:
9661 /* Someone has changed the keyboard mapping - update the
9663 switch (event
.xmapping
.request
)
9665 case MappingModifier
:
9666 x_find_modifier_meanings (dpyinfo
);
9667 /* This is meant to fall through. */
9668 case MappingKeyboard
:
9669 XRefreshKeyboardMapping (&event
.xmapping
);
9675 #ifdef USE_X_TOOLKIT
9677 XtDispatchEvent (&event
);
9679 #endif /* USE_X_TOOLKIT */
9687 /* On some systems, an X bug causes Emacs to get no more events
9688 when the window is destroyed. Detect that. (1994.) */
9691 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
9692 One XNOOP in 100 loops will make Emacs terminate.
9693 B. Bretthauer, 1994 */
9695 if (x_noop_count
>= 100)
9699 if (next_noop_dpyinfo
== 0)
9700 next_noop_dpyinfo
= x_display_list
;
9702 XNoOp (next_noop_dpyinfo
->display
);
9704 /* Each time we get here, cycle through the displays now open. */
9705 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
9709 /* If the focus was just given to an auto-raising frame,
9711 /* ??? This ought to be able to handle more than one such frame. */
9712 if (pending_autoraise_frame
)
9714 x_raise_frame (pending_autoraise_frame
);
9715 pending_autoraise_frame
= 0;
9725 /***********************************************************************
9727 ***********************************************************************/
9729 /* Note if the text cursor of window W has been overwritten by a
9730 drawing operation that outputs N glyphs starting at HPOS in the
9731 line given by output_cursor.vpos. N < 0 means all the rest of the
9732 line after HPOS has been written. */
9735 note_overwritten_text_cursor (w
, hpos
, n
)
9739 if (updated_area
== TEXT_AREA
9740 && output_cursor
.vpos
== w
->phys_cursor
.vpos
9741 && hpos
<= w
->phys_cursor
.hpos
9743 || hpos
+ n
> w
->phys_cursor
.hpos
))
9744 w
->phys_cursor_on_p
= 0;
9748 /* Set clipping for output in glyph row ROW. W is the window in which
9749 we operate. GC is the graphics context to set clipping in.
9750 WHOLE_LINE_P non-zero means include the areas used for truncation
9751 mark display and alike in the clipping rectangle.
9753 ROW may be a text row or, e.g., a mode line. Text rows must be
9754 clipped to the interior of the window dedicated to text display,
9755 mode lines must be clipped to the whole window. */
9758 x_clip_to_row (w
, row
, gc
, whole_line_p
)
9760 struct glyph_row
*row
;
9764 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9765 XRectangle clip_rect
;
9766 int window_x
, window_y
, window_width
, window_height
;
9768 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9770 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
9771 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
9772 clip_rect
.y
= max (clip_rect
.y
, window_y
);
9773 clip_rect
.width
= window_width
;
9774 clip_rect
.height
= row
->visible_height
;
9776 /* If clipping to the whole line, including trunc marks, extend
9777 the rectangle to the left and increase its width. */
9780 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
9781 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
9784 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
9788 /* Draw a hollow box cursor on window W in glyph row ROW. */
9791 x_draw_hollow_cursor (w
, row
)
9793 struct glyph_row
*row
;
9795 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9796 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9797 Display
*dpy
= FRAME_X_DISPLAY (f
);
9800 struct glyph
*cursor_glyph
;
9803 /* Compute frame-relative coordinates from window-relative
9805 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9806 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
9807 + row
->ascent
- w
->phys_cursor_ascent
);
9808 h
= row
->height
- 1;
9810 /* Get the glyph the cursor is on. If we can't tell because
9811 the current matrix is invalid or such, give up. */
9812 cursor_glyph
= get_phys_cursor_glyph (w
);
9813 if (cursor_glyph
== NULL
)
9816 /* Compute the width of the rectangle to draw. If on a stretch
9817 glyph, and `x-stretch-block-cursor' is nil, don't draw a
9818 rectangle as wide as the glyph, but use a canonical character
9820 wd
= cursor_glyph
->pixel_width
- 1;
9821 if (cursor_glyph
->type
== STRETCH_GLYPH
9822 && !x_stretch_cursor_p
)
9823 wd
= min (CANON_X_UNIT (f
), wd
);
9825 /* The foreground of cursor_gc is typically the same as the normal
9826 background color, which can cause the cursor box to be invisible. */
9827 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9828 if (dpyinfo
->scratch_cursor_gc
)
9829 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
9831 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
9832 GCForeground
, &xgcv
);
9833 gc
= dpyinfo
->scratch_cursor_gc
;
9835 /* Set clipping, draw the rectangle, and reset clipping again. */
9836 x_clip_to_row (w
, row
, gc
, 0);
9837 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
9838 XSetClipMask (dpy
, gc
, None
);
9842 /* Draw a bar cursor on window W in glyph row ROW.
9844 Implementation note: One would like to draw a bar cursor with an
9845 angle equal to the one given by the font property XA_ITALIC_ANGLE.
9846 Unfortunately, I didn't find a font yet that has this property set.
9850 x_draw_bar_cursor (w
, row
)
9852 struct glyph_row
*row
;
9854 /* If cursor hpos is out of bounds, don't draw garbage. This can
9855 happen in mini-buffer windows when switching between echo area
9856 glyphs and mini-buffer. */
9857 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9859 struct frame
*f
= XFRAME (w
->frame
);
9860 struct glyph
*cursor_glyph
;
9868 cursor_glyph
= get_phys_cursor_glyph (w
);
9869 if (cursor_glyph
== NULL
)
9872 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
9873 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9874 xgcv
.graphics_exposures
= 0;
9875 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
9876 dpy
= FRAME_X_DISPLAY (f
);
9877 window
= FRAME_X_WINDOW (f
);
9878 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
9881 XChangeGC (dpy
, gc
, mask
, &xgcv
);
9884 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
9885 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
9888 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9889 x_clip_to_row (w
, row
, gc
, 0);
9890 XFillRectangle (dpy
, window
, gc
,
9892 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9893 min (cursor_glyph
->pixel_width
,
9894 f
->output_data
.x
->cursor_width
),
9896 XSetClipMask (dpy
, gc
, None
);
9901 /* Clear the cursor of window W to background color, and mark the
9902 cursor as not shown. This is used when the text where the cursor
9903 is is about to be rewritten. */
9909 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
9910 x_update_window_cursor (w
, 0);
9914 /* Draw the cursor glyph of window W in glyph row ROW. See the
9915 comment of x_draw_glyphs for the meaning of HL. */
9918 x_draw_phys_cursor_glyph (w
, row
, hl
)
9920 struct glyph_row
*row
;
9921 enum draw_glyphs_face hl
;
9923 /* If cursor hpos is out of bounds, don't draw garbage. This can
9924 happen in mini-buffer windows when switching between echo area
9925 glyphs and mini-buffer. */
9926 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9928 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
9929 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
9932 /* When we erase the cursor, and ROW is overlapped by other
9933 rows, make sure that these overlapping parts of other rows
9935 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
9937 if (row
> w
->current_matrix
->rows
9938 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
9939 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
9941 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
9942 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
9943 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
9949 /* Erase the image of a cursor of window W from the screen. */
9952 x_erase_phys_cursor (w
)
9955 struct frame
*f
= XFRAME (w
->frame
);
9956 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9957 int hpos
= w
->phys_cursor
.hpos
;
9958 int vpos
= w
->phys_cursor
.vpos
;
9959 int mouse_face_here_p
= 0;
9960 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
9961 struct glyph_row
*cursor_row
;
9962 struct glyph
*cursor_glyph
;
9963 enum draw_glyphs_face hl
;
9965 /* No cursor displayed or row invalidated => nothing to do on the
9967 if (w
->phys_cursor_type
== NO_CURSOR
)
9968 goto mark_cursor_off
;
9970 /* VPOS >= active_glyphs->nrows means that window has been resized.
9971 Don't bother to erase the cursor. */
9972 if (vpos
>= active_glyphs
->nrows
)
9973 goto mark_cursor_off
;
9975 /* If row containing cursor is marked invalid, there is nothing we
9977 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9978 if (!cursor_row
->enabled_p
)
9979 goto mark_cursor_off
;
9981 /* This can happen when the new row is shorter than the old one.
9982 In this case, either x_draw_glyphs or clear_end_of_line
9983 should have cleared the cursor. Note that we wouldn't be
9984 able to erase the cursor in this case because we don't have a
9985 cursor glyph at hand. */
9986 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9987 goto mark_cursor_off
;
9989 /* If the cursor is in the mouse face area, redisplay that when
9990 we clear the cursor. */
9991 if (w
== XWINDOW (dpyinfo
->mouse_face_window
)
9992 && (vpos
> dpyinfo
->mouse_face_beg_row
9993 || (vpos
== dpyinfo
->mouse_face_beg_row
9994 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9995 && (vpos
< dpyinfo
->mouse_face_end_row
9996 || (vpos
== dpyinfo
->mouse_face_end_row
9997 && hpos
< dpyinfo
->mouse_face_end_col
))
9998 /* Don't redraw the cursor's spot in mouse face if it is at the
9999 end of a line (on a newline). The cursor appears there, but
10000 mouse highlighting does not. */
10001 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10002 mouse_face_here_p
= 1;
10004 /* Maybe clear the display under the cursor. */
10005 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10008 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10010 cursor_glyph
= get_phys_cursor_glyph (w
);
10011 if (cursor_glyph
== NULL
)
10012 goto mark_cursor_off
;
10014 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10016 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10018 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10020 cursor_glyph
->pixel_width
,
10021 cursor_row
->visible_height
,
10025 /* Erase the cursor by redrawing the character underneath it. */
10026 if (mouse_face_here_p
)
10027 hl
= DRAW_MOUSE_FACE
;
10028 else if (cursor_row
->inverse_p
)
10029 hl
= DRAW_INVERSE_VIDEO
;
10031 hl
= DRAW_NORMAL_TEXT
;
10032 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10035 w
->phys_cursor_on_p
= 0;
10036 w
->phys_cursor_type
= NO_CURSOR
;
10040 /* Display or clear cursor of window W. If ON is zero, clear the
10041 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10042 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10045 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10047 int on
, hpos
, vpos
, x
, y
;
10049 struct frame
*f
= XFRAME (w
->frame
);
10050 int new_cursor_type
;
10051 struct glyph_matrix
*current_glyphs
;
10052 struct glyph_row
*glyph_row
;
10053 struct glyph
*glyph
;
10055 /* This is pointless on invisible frames, and dangerous on garbaged
10056 windows and frames; in the latter case, the frame or window may
10057 be in the midst of changing its size, and x and y may be off the
10059 if (! FRAME_VISIBLE_P (f
)
10060 || FRAME_GARBAGED_P (f
)
10061 || vpos
>= w
->current_matrix
->nrows
10062 || hpos
>= w
->current_matrix
->matrix_w
)
10065 /* If cursor is off and we want it off, return quickly. */
10066 if (!on
&& !w
->phys_cursor_on_p
)
10069 current_glyphs
= w
->current_matrix
;
10070 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10071 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10073 /* If cursor row is not enabled, we don't really know where to
10074 display the cursor. */
10075 if (!glyph_row
->enabled_p
)
10077 w
->phys_cursor_on_p
= 0;
10081 xassert (interrupt_input_blocked
);
10083 /* Set new_cursor_type to the cursor we want to be displayed. In a
10084 mini-buffer window, we want the cursor only to appear if we are
10085 reading input from this window. For the selected window, we want
10086 the cursor type given by the frame parameter. If explicitly
10087 marked off, draw no cursor. In all other cases, we want a hollow
10089 if (cursor_in_echo_area
10090 && FRAME_HAS_MINIBUF_P (f
)
10091 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10093 if (w
== XWINDOW (echo_area_window
))
10094 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10096 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10100 if (w
!= XWINDOW (selected_window
)
10101 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10103 if (MINI_WINDOW_P (w
))
10104 new_cursor_type
= NO_CURSOR
;
10106 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10108 else if (w
->cursor_off_p
)
10109 new_cursor_type
= NO_CURSOR
;
10111 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10114 /* If cursor is currently being shown and we don't want it to be or
10115 it is in the wrong place, or the cursor type is not what we want,
10117 if (w
->phys_cursor_on_p
10119 || w
->phys_cursor
.x
!= x
10120 || w
->phys_cursor
.y
!= y
10121 || new_cursor_type
!= w
->phys_cursor_type
))
10122 x_erase_phys_cursor (w
);
10124 /* If the cursor is now invisible and we want it to be visible,
10126 if (on
&& !w
->phys_cursor_on_p
)
10128 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10129 w
->phys_cursor_height
= glyph_row
->height
;
10131 /* Set phys_cursor_.* before x_draw_.* is called because some
10132 of them may need the information. */
10133 w
->phys_cursor
.x
= x
;
10134 w
->phys_cursor
.y
= glyph_row
->y
;
10135 w
->phys_cursor
.hpos
= hpos
;
10136 w
->phys_cursor
.vpos
= vpos
;
10137 w
->phys_cursor_type
= new_cursor_type
;
10138 w
->phys_cursor_on_p
= 1;
10140 switch (new_cursor_type
)
10142 case HOLLOW_BOX_CURSOR
:
10143 x_draw_hollow_cursor (w
, glyph_row
);
10146 case FILLED_BOX_CURSOR
:
10147 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10151 x_draw_bar_cursor (w
, glyph_row
);
10163 if (updating_frame
!= f
)
10164 XFlush (FRAME_X_DISPLAY (f
));
10169 /* Display the cursor on window W, or clear it. X and Y are window
10170 relative pixel coordinates. HPOS and VPOS are glyph matrix
10171 positions. If W is not the selected window, display a hollow
10172 cursor. ON non-zero means display the cursor at X, Y which
10173 correspond to HPOS, VPOS, otherwise it is cleared. */
10176 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10178 int on
, hpos
, vpos
, x
, y
;
10181 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10186 /* Display the cursor on window W, or clear it, according to ON_P.
10187 Don't change the cursor's position. */
10190 x_update_cursor (f
, on_p
)
10193 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10197 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10198 in the window tree rooted at W. */
10201 x_update_cursor_in_window_tree (w
, on_p
)
10207 if (!NILP (w
->hchild
))
10208 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10209 else if (!NILP (w
->vchild
))
10210 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10212 x_update_window_cursor (w
, on_p
);
10214 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10219 /* Switch the display of W's cursor on or off, according to the value
10223 x_update_window_cursor (w
, on
)
10228 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10229 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10238 /* Refresh bitmap kitchen sink icon for frame F
10239 when we get an expose event for it. */
10245 /* Normally, the window manager handles this function. */
10248 /* Make the x-window of frame F use the gnu icon bitmap. */
10251 x_bitmap_icon (f
, file
)
10257 if (FRAME_X_WINDOW (f
) == 0)
10260 /* Free up our existing icon bitmap if any. */
10261 if (f
->output_data
.x
->icon_bitmap
> 0)
10262 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10263 f
->output_data
.x
->icon_bitmap
= 0;
10265 if (STRINGP (file
))
10266 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10269 /* Create the GNU bitmap if necessary. */
10270 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10271 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10272 = x_create_bitmap_from_data (f
, gnu_bits
,
10273 gnu_width
, gnu_height
);
10275 /* The first time we create the GNU bitmap,
10276 this increments the ref-count one extra time.
10277 As a result, the GNU bitmap is never freed.
10278 That way, we don't have to worry about allocating it again. */
10279 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10281 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10284 x_wm_set_icon_pixmap (f
, bitmap_id
);
10285 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10291 /* Make the x-window of frame F use a rectangle with text.
10292 Use ICON_NAME as the text. */
10295 x_text_icon (f
, icon_name
)
10299 if (FRAME_X_WINDOW (f
) == 0)
10304 XTextProperty text
;
10305 text
.value
= (unsigned char *) icon_name
;
10306 text
.encoding
= XA_STRING
;
10308 text
.nitems
= strlen (icon_name
);
10309 #ifdef USE_X_TOOLKIT
10310 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10312 #else /* not USE_X_TOOLKIT */
10313 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10314 #endif /* not USE_X_TOOLKIT */
10316 #else /* not HAVE_X11R4 */
10317 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10318 #endif /* not HAVE_X11R4 */
10320 if (f
->output_data
.x
->icon_bitmap
> 0)
10321 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10322 f
->output_data
.x
->icon_bitmap
= 0;
10323 x_wm_set_icon_pixmap (f
, 0);
10328 #define X_ERROR_MESSAGE_SIZE 200
10330 /* If non-nil, this should be a string.
10331 It means catch X errors and store the error message in this string. */
10333 static Lisp_Object x_error_message_string
;
10335 /* An X error handler which stores the error message in
10336 x_error_message_string. This is called from x_error_handler if
10337 x_catch_errors is in effect. */
10340 x_error_catcher (display
, error
)
10342 XErrorEvent
*error
;
10344 XGetErrorText (display
, error
->error_code
,
10345 XSTRING (x_error_message_string
)->data
,
10346 X_ERROR_MESSAGE_SIZE
);
10349 /* Begin trapping X errors for display DPY. Actually we trap X errors
10350 for all displays, but DPY should be the display you are actually
10353 After calling this function, X protocol errors no longer cause
10354 Emacs to exit; instead, they are recorded in the string
10355 stored in x_error_message_string.
10357 Calling x_check_errors signals an Emacs error if an X error has
10358 occurred since the last call to x_catch_errors or x_check_errors.
10360 Calling x_uncatch_errors resumes the normal error handling. */
10362 void x_check_errors ();
10363 static Lisp_Object
x_catch_errors_unwind ();
10366 x_catch_errors (dpy
)
10369 int count
= specpdl_ptr
- specpdl
;
10371 /* Make sure any errors from previous requests have been dealt with. */
10372 XSync (dpy
, False
);
10374 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10376 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10377 XSTRING (x_error_message_string
)->data
[0] = 0;
10382 /* Unbind the binding that we made to check for X errors. */
10385 x_catch_errors_unwind (old_val
)
10386 Lisp_Object old_val
;
10388 x_error_message_string
= old_val
;
10392 /* If any X protocol errors have arrived since the last call to
10393 x_catch_errors or x_check_errors, signal an Emacs error using
10394 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10397 x_check_errors (dpy
, format
)
10401 /* Make sure to catch any errors incurred so far. */
10402 XSync (dpy
, False
);
10404 if (XSTRING (x_error_message_string
)->data
[0])
10405 error (format
, XSTRING (x_error_message_string
)->data
);
10408 /* Nonzero if we had any X protocol errors
10409 since we did x_catch_errors on DPY. */
10412 x_had_errors_p (dpy
)
10415 /* Make sure to catch any errors incurred so far. */
10416 XSync (dpy
, False
);
10418 return XSTRING (x_error_message_string
)->data
[0] != 0;
10421 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
10424 x_clear_errors (dpy
)
10427 XSTRING (x_error_message_string
)->data
[0] = 0;
10430 /* Stop catching X protocol errors and let them make Emacs die.
10431 DPY should be the display that was passed to x_catch_errors.
10432 COUNT should be the value that was returned by
10433 the corresponding call to x_catch_errors. */
10436 x_uncatch_errors (dpy
, count
)
10440 unbind_to (count
, Qnil
);
10444 static unsigned int x_wire_count
;
10447 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
10452 /* Handle SIGPIPE, which can happen when the connection to a server
10453 simply goes away. SIGPIPE is handled by x_connection_signal.
10454 Don't need to do anything, because the write which caused the
10455 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
10456 which will do the appropriate cleanup for us. */
10459 x_connection_signal (signalnum
) /* If we don't have an argument, */
10460 int signalnum
; /* some compilers complain in signal calls. */
10463 /* USG systems forget handlers when they are used;
10464 must reestablish each time */
10465 signal (signalnum
, x_connection_signal
);
10469 /* Handling X errors. */
10471 /* Handle the loss of connection to display DISPLAY. */
10474 x_connection_closed (display
, error_message
)
10476 char *error_message
;
10478 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
10479 Lisp_Object frame
, tail
;
10481 /* Indicate that this display is dead. */
10483 #ifdef USE_X_TOOLKIT
10484 XtCloseDisplay (display
);
10487 dpyinfo
->display
= 0;
10489 /* First delete frames whose mini-buffers are on frames
10490 that are on the dead display. */
10491 FOR_EACH_FRAME (tail
, frame
)
10493 Lisp_Object minibuf_frame
;
10495 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
10496 if (FRAME_X_P (XFRAME (frame
))
10497 && FRAME_X_P (XFRAME (minibuf_frame
))
10498 && ! EQ (frame
, minibuf_frame
)
10499 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
10500 Fdelete_frame (frame
, Qt
);
10503 /* Now delete all remaining frames on the dead display.
10504 We are now sure none of these is used as the mini-buffer
10505 for another frame that we need to delete. */
10506 FOR_EACH_FRAME (tail
, frame
)
10507 if (FRAME_X_P (XFRAME (frame
))
10508 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
10510 /* Set this to t so that Fdelete_frame won't get confused
10511 trying to find a replacement. */
10512 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
10513 Fdelete_frame (frame
, Qt
);
10517 x_delete_display (dpyinfo
);
10519 if (x_display_list
== 0)
10521 fprintf (stderr
, "%s\n", error_message
);
10522 shut_down_emacs (0, 0, Qnil
);
10526 /* Ordinary stack unwind doesn't deal with these. */
10528 sigunblock (sigmask (SIGIO
));
10530 sigunblock (sigmask (SIGALRM
));
10531 TOTALLY_UNBLOCK_INPUT
;
10533 clear_waiting_for_input ();
10534 error ("%s", error_message
);
10537 /* This is the usual handler for X protocol errors.
10538 It kills all frames on the display that we got the error for.
10539 If that was the only one, it prints an error message and kills Emacs. */
10542 x_error_quitter (display
, error
)
10544 XErrorEvent
*error
;
10546 char buf
[256], buf1
[356];
10548 /* Note that there is no real way portable across R3/R4 to get the
10549 original error handler. */
10551 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
10552 sprintf (buf1
, "X protocol error: %s on protocol request %d",
10553 buf
, error
->request_code
);
10554 x_connection_closed (display
, buf1
);
10557 /* This is the first-level handler for X protocol errors.
10558 It calls x_error_quitter or x_error_catcher. */
10561 x_error_handler (display
, error
)
10563 XErrorEvent
*error
;
10565 if (! NILP (x_error_message_string
))
10566 x_error_catcher (display
, error
);
10568 x_error_quitter (display
, error
);
10572 /* This is the handler for X IO errors, always.
10573 It kills all frames on the display that we lost touch with.
10574 If that was the only one, it prints an error message and kills Emacs. */
10577 x_io_error_quitter (display
)
10582 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
10583 x_connection_closed (display
, buf
);
10587 /* Changing the font of the frame. */
10589 /* Give frame F the font named FONTNAME as its default font, and
10590 return the full name of that font. FONTNAME may be a wildcard
10591 pattern; in that case, we choose some font that fits the pattern.
10592 The return value shows which font we chose. */
10595 x_new_font (f
, fontname
)
10597 register char *fontname
;
10599 struct font_info
*fontp
10600 = fs_load_font (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
, fontname
, -1);
10605 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
10606 f
->output_data
.x
->font_baseline
10607 = (f
->output_data
.x
->font
->ascent
+ fontp
->baseline_offset
);
10608 f
->output_data
.x
->fontset
= -1;
10610 /* Compute the scroll bar width in character columns. */
10611 if (f
->scroll_bar_pixel_width
> 0)
10613 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10614 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
10618 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10619 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
10622 /* Now make the frame display the given font. */
10623 if (FRAME_X_WINDOW (f
) != 0)
10625 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
10626 f
->output_data
.x
->font
->fid
);
10627 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
10628 f
->output_data
.x
->font
->fid
);
10629 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
10630 f
->output_data
.x
->font
->fid
);
10632 frame_update_line_height (f
);
10633 x_set_window_size (f
, 0, f
->width
, f
->height
);
10636 /* If we are setting a new frame's font for the first time,
10637 there are no faces yet, so this font's height is the line height. */
10638 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
10640 return build_string (fontp
->full_name
);
10643 /* Give frame F the fontset named FONTSETNAME as its default font, and
10644 return the full name of that fontset. FONTSETNAME may be a wildcard
10645 pattern; in that case, we choose some fontset that fits the pattern.
10646 The return value shows which fontset we chose. */
10649 x_new_fontset (f
, fontsetname
)
10653 int fontset
= fs_query_fontset (f
, fontsetname
);
10654 struct fontset_info
*fontsetp
;
10655 Lisp_Object result
;
10660 if (f
->output_data
.x
->fontset
== fontset
)
10661 /* This fontset is already set in frame F. There's nothing more
10663 return build_string (fontsetname
);
10665 fontsetp
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
10667 if (!fontsetp
->fontname
[CHARSET_ASCII
])
10668 /* This fontset doesn't contain ASCII font. */
10671 result
= x_new_font (f
, fontsetp
->fontname
[CHARSET_ASCII
]);
10673 if (!STRINGP (result
))
10674 /* Can't load ASCII font. */
10677 /* Since x_new_font doesn't update any fontset information, do it now. */
10678 f
->output_data
.x
->fontset
= fontset
;
10679 FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
),
10680 CHARSET_ASCII
, fontsetp
->fontname
[CHARSET_ASCII
], fontset
);
10682 return build_string (fontsetname
);
10685 /* Calculate the absolute position in frame F
10686 from its current recorded position values and gravity. */
10689 x_calc_absolute_position (f
)
10693 int win_x
= 0, win_y
= 0;
10694 int flags
= f
->output_data
.x
->size_hint_flags
;
10697 /* We have nothing to do if the current position
10698 is already for the top-left corner. */
10699 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
10702 #ifdef USE_X_TOOLKIT
10703 this_window
= XtWindow (f
->output_data
.x
->widget
);
10705 this_window
= FRAME_X_WINDOW (f
);
10708 /* Find the position of the outside upper-left corner of
10709 the inner window, with respect to the outer window.
10710 But do this only if we will need the results. */
10711 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10716 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
10719 x_clear_errors (FRAME_X_DISPLAY (f
));
10720 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
10722 /* From-window, to-window. */
10724 f
->output_data
.x
->parent_desc
,
10726 /* From-position, to-position. */
10727 0, 0, &win_x
, &win_y
,
10729 /* Child of win. */
10731 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
10733 Window newroot
, newparent
= 0xdeadbeef;
10734 Window
*newchildren
;
10737 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
10738 &newparent
, &newchildren
, &nchildren
))
10741 XFree ((char *) newchildren
);
10743 f
->output_data
.x
->parent_desc
= newparent
;
10749 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
10753 /* Treat negative positions as relative to the leftmost bottommost
10754 position that fits on the screen. */
10755 if (flags
& XNegative
)
10756 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
10757 - 2 * f
->output_data
.x
->border_width
- win_x
10759 + f
->output_data
.x
->left_pos
);
10761 if (flags
& YNegative
)
10763 int menubar_height
= 0;
10765 #ifdef USE_X_TOOLKIT
10766 if (f
->output_data
.x
->menubar_widget
)
10768 = (f
->output_data
.x
->menubar_widget
->core
.height
10769 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
10772 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
10773 - 2 * f
->output_data
.x
->border_width
10777 + f
->output_data
.x
->top_pos
);
10780 /* The left_pos and top_pos
10781 are now relative to the top and left screen edges,
10782 so the flags should correspond. */
10783 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10786 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
10787 to really change the position, and 0 when calling from
10788 x_make_frame_visible (in that case, XOFF and YOFF are the current
10789 position values). It is -1 when calling from x_set_frame_parameters,
10790 which means, do adjust for borders but don't change the gravity. */
10793 x_set_offset (f
, xoff
, yoff
, change_gravity
)
10795 register int xoff
, yoff
;
10796 int change_gravity
;
10798 int modified_top
, modified_left
;
10800 if (change_gravity
> 0)
10802 f
->output_data
.x
->top_pos
= yoff
;
10803 f
->output_data
.x
->left_pos
= xoff
;
10804 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10806 f
->output_data
.x
->size_hint_flags
|= XNegative
;
10808 f
->output_data
.x
->size_hint_flags
|= YNegative
;
10809 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10811 x_calc_absolute_position (f
);
10814 x_wm_set_size_hint (f
, (long) 0, 0);
10816 modified_left
= f
->output_data
.x
->left_pos
;
10817 modified_top
= f
->output_data
.x
->top_pos
;
10818 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
10819 this seems to be unnecessary and incorrect. rms, 4/17/97. */
10820 /* It is a mystery why we need to add the border_width here
10821 when the frame is already visible, but experiment says we do. */
10822 if (change_gravity
!= 0)
10824 modified_left
+= f
->output_data
.x
->border_width
;
10825 modified_top
+= f
->output_data
.x
->border_width
;
10829 #ifdef USE_X_TOOLKIT
10830 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10831 modified_left
, modified_top
);
10832 #else /* not USE_X_TOOLKIT */
10833 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10834 modified_left
, modified_top
);
10835 #endif /* not USE_X_TOOLKIT */
10839 /* Call this to change the size of frame F's x-window.
10840 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
10841 for this size change and subsequent size changes.
10842 Otherwise we leave the window gravity unchanged. */
10845 x_set_window_size (f
, change_gravity
, cols
, rows
)
10847 int change_gravity
;
10850 #ifndef USE_X_TOOLKIT
10851 int pixelwidth
, pixelheight
;
10856 #ifdef USE_X_TOOLKIT
10858 /* The x and y position of the widget is clobbered by the
10859 call to XtSetValues within EmacsFrameSetCharSize.
10860 This is a real kludge, but I don't understand Xt so I can't
10861 figure out a correct fix. Can anyone else tell me? -- rms. */
10862 int xpos
= f
->output_data
.x
->widget
->core
.x
;
10863 int ypos
= f
->output_data
.x
->widget
->core
.y
;
10864 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
10865 f
->output_data
.x
->widget
->core
.x
= xpos
;
10866 f
->output_data
.x
->widget
->core
.y
= ypos
;
10869 #else /* not USE_X_TOOLKIT */
10871 check_frame_size (f
, &rows
, &cols
);
10872 f
->output_data
.x
->vertical_scroll_bar_extra
10873 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
10875 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
10876 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
10877 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
10878 f
->output_data
.x
->flags_areas_extra
10879 = FRAME_FLAGS_AREA_WIDTH (f
);
10880 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
10881 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
10883 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10884 x_wm_set_size_hint (f
, (long) 0, 0);
10886 XSync (FRAME_X_DISPLAY (f
), False
);
10887 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10888 pixelwidth
, pixelheight
);
10890 /* Now, strictly speaking, we can't be sure that this is accurate,
10891 but the window manager will get around to dealing with the size
10892 change request eventually, and we'll hear how it went when the
10893 ConfigureNotify event gets here.
10895 We could just not bother storing any of this information here,
10896 and let the ConfigureNotify event set everything up, but that
10897 might be kind of confusing to the Lisp code, since size changes
10898 wouldn't be reported in the frame parameters until some random
10899 point in the future when the ConfigureNotify event arrives.
10901 We pass 1 for DELAY since we can't run Lisp code inside of
10903 change_frame_size (f
, rows
, cols
, 0, 1, 0);
10904 PIXEL_WIDTH (f
) = pixelwidth
;
10905 PIXEL_HEIGHT (f
) = pixelheight
;
10907 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
10908 receive in the ConfigureNotify event; if we get what we asked
10909 for, then the event won't cause the screen to become garbaged, so
10910 we have to make sure to do it here. */
10911 SET_FRAME_GARBAGED (f
);
10913 XFlush (FRAME_X_DISPLAY (f
));
10915 #endif /* not USE_X_TOOLKIT */
10917 /* If cursor was outside the new size, mark it as off. */
10918 mark_window_cursors_off (XWINDOW (f
->root_window
));
10920 /* Clear out any recollection of where the mouse highlighting was,
10921 since it might be in a place that's outside the new frame size.
10922 Actually checking whether it is outside is a pain in the neck,
10923 so don't try--just let the highlighting be done afresh with new size. */
10924 cancel_mouse_face (f
);
10929 /* Mouse warping. */
10932 x_set_mouse_position (f
, x
, y
)
10938 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
10939 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
10941 if (pix_x
< 0) pix_x
= 0;
10942 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
10944 if (pix_y
< 0) pix_y
= 0;
10945 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
10949 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
10950 0, 0, 0, 0, pix_x
, pix_y
);
10954 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
10957 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
10963 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
10964 0, 0, 0, 0, pix_x
, pix_y
);
10968 /* focus shifting, raising and lowering. */
10971 x_focus_on_frame (f
)
10974 #if 0 /* This proves to be unpleasant. */
10978 /* I don't think that the ICCCM allows programs to do things like this
10979 without the interaction of the window manager. Whatever you end up
10980 doing with this code, do it to x_unfocus_frame too. */
10981 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10982 RevertToPointerRoot
, CurrentTime
);
10987 x_unfocus_frame (f
)
10991 /* Look at the remarks in x_focus_on_frame. */
10992 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
10993 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
10994 RevertToPointerRoot
, CurrentTime
);
10998 /* Raise frame F. */
11004 if (f
->async_visible
)
11007 #ifdef USE_X_TOOLKIT
11008 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11009 #else /* not USE_X_TOOLKIT */
11010 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11011 #endif /* not USE_X_TOOLKIT */
11012 XFlush (FRAME_X_DISPLAY (f
));
11017 /* Lower frame F. */
11023 if (f
->async_visible
)
11026 #ifdef USE_X_TOOLKIT
11027 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11028 #else /* not USE_X_TOOLKIT */
11029 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11030 #endif /* not USE_X_TOOLKIT */
11031 XFlush (FRAME_X_DISPLAY (f
));
11037 XTframe_raise_lower (f
, raise_flag
)
11047 /* Change of visibility. */
11049 /* This tries to wait until the frame is really visible.
11050 However, if the window manager asks the user where to position
11051 the frame, this will return before the user finishes doing that.
11052 The frame will not actually be visible at that time,
11053 but it will become visible later when the window manager
11054 finishes with it. */
11057 x_make_frame_visible (f
)
11061 int original_top
, original_left
;
11065 type
= x_icon_type (f
);
11067 x_bitmap_icon (f
, type
);
11069 if (! FRAME_VISIBLE_P (f
))
11071 /* We test FRAME_GARBAGED_P here to make sure we don't
11072 call x_set_offset a second time
11073 if we get to x_make_frame_visible a second time
11074 before the window gets really visible. */
11075 if (! FRAME_ICONIFIED_P (f
)
11076 && ! f
->output_data
.x
->asked_for_visible
)
11077 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11079 f
->output_data
.x
->asked_for_visible
= 1;
11081 if (! EQ (Vx_no_window_manager
, Qt
))
11082 x_wm_set_window_state (f
, NormalState
);
11083 #ifdef USE_X_TOOLKIT
11084 /* This was XtPopup, but that did nothing for an iconified frame. */
11085 XtMapWidget (f
->output_data
.x
->widget
);
11086 #else /* not USE_X_TOOLKIT */
11087 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11088 #endif /* not USE_X_TOOLKIT */
11089 #if 0 /* This seems to bring back scroll bars in the wrong places
11090 if the window configuration has changed. They seem
11091 to come back ok without this. */
11092 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11093 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11097 XFlush (FRAME_X_DISPLAY (f
));
11099 /* Synchronize to ensure Emacs knows the frame is visible
11100 before we do anything else. We do this loop with input not blocked
11101 so that incoming events are handled. */
11104 int count
= input_signal_count
;
11105 /* This must be before UNBLOCK_INPUT
11106 since events that arrive in response to the actions above
11107 will set it when they are handled. */
11108 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11110 original_left
= f
->output_data
.x
->left_pos
;
11111 original_top
= f
->output_data
.x
->top_pos
;
11113 /* This must come after we set COUNT. */
11116 /* We unblock here so that arriving X events are processed. */
11118 /* Now move the window back to where it was "supposed to be".
11119 But don't do it if the gravity is negative.
11120 When the gravity is negative, this uses a position
11121 that is 3 pixels too low. Perhaps that's really the border width.
11123 Don't do this if the window has never been visible before,
11124 because the window manager may choose the position
11125 and we don't want to override it. */
11127 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11128 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11129 && previously_visible
)
11133 unsigned int width
, height
, border
, depth
;
11137 /* On some window managers (such as FVWM) moving an existing
11138 window, even to the same place, causes the window manager
11139 to introduce an offset. This can cause the window to move
11140 to an unexpected location. Check the geometry (a little
11141 slow here) and then verify that the window is in the right
11142 place. If the window is not in the right place, move it
11143 there, and take the potential window manager hit. */
11144 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11145 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11147 if (original_left
!= x
|| original_top
!= y
)
11148 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11149 original_left
, original_top
);
11154 XSETFRAME (frame
, f
);
11159 /* Once we have handled input events,
11160 we should have received the MapNotify if one is coming.
11161 So if we have not got it yet, stop looping.
11162 Some window managers make their own decisions
11163 about visibility. */
11164 if (input_signal_count
!= count
)
11166 /* Machines that do polling rather than SIGIO have been observed
11167 to go into a busy-wait here. So we'll fake an alarm signal
11168 to let the handler know that there's something to be read.
11169 We used to raise a real alarm, but it seems that the handler
11170 isn't always enabled here. This is probably a bug. */
11171 if (input_polling_used ())
11173 /* It could be confusing if a real alarm arrives while processing
11174 the fake one. Turn it off and let the handler reset it. */
11176 input_poll_signal (0);
11178 /* Once we have handled input events,
11179 we should have received the MapNotify if one is coming.
11180 So if we have not got it yet, stop looping.
11181 Some window managers make their own decisions
11182 about visibility. */
11183 if (input_signal_count
!= count
)
11186 FRAME_SAMPLE_VISIBILITY (f
);
11190 /* Change from mapped state to withdrawn state. */
11192 /* Make the frame visible (mapped and not iconified). */
11195 x_make_frame_invisible (f
)
11200 #ifdef USE_X_TOOLKIT
11201 /* Use the frame's outermost window, not the one we normally draw on. */
11202 window
= XtWindow (f
->output_data
.x
->widget
);
11203 #else /* not USE_X_TOOLKIT */
11204 window
= FRAME_X_WINDOW (f
);
11205 #endif /* not USE_X_TOOLKIT */
11207 /* Don't keep the highlight on an invisible frame. */
11208 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11209 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11211 #if 0/* This might add unreliability; I don't trust it -- rms. */
11212 if (! f
->async_visible
&& ! f
->async_iconified
)
11218 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11219 that the current position of the window is user-specified, rather than
11220 program-specified, so that when the window is mapped again, it will be
11221 placed at the same location, without forcing the user to position it
11222 by hand again (they have already done that once for this window.) */
11223 x_wm_set_size_hint (f
, (long) 0, 1);
11227 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11228 DefaultScreen (FRAME_X_DISPLAY (f
))))
11230 UNBLOCK_INPUT_RESIGNAL
;
11231 error ("Can't notify window manager of window withdrawal");
11233 #else /* ! defined (HAVE_X11R4) */
11235 /* Tell the window manager what we're going to do. */
11236 if (! EQ (Vx_no_window_manager
, Qt
))
11240 unmap
.xunmap
.type
= UnmapNotify
;
11241 unmap
.xunmap
.window
= window
;
11242 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
11243 unmap
.xunmap
.from_configure
= False
;
11244 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11245 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11247 SubstructureRedirectMaskSubstructureNotifyMask
,
11250 UNBLOCK_INPUT_RESIGNAL
;
11251 error ("Can't notify window manager of withdrawal");
11255 /* Unmap the window ourselves. Cheeky! */
11256 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
11257 #endif /* ! defined (HAVE_X11R4) */
11259 /* We can't distinguish this from iconification
11260 just by the event that we get from the server.
11261 So we can't win using the usual strategy of letting
11262 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11263 and synchronize with the server to make sure we agree. */
11265 FRAME_ICONIFIED_P (f
) = 0;
11266 f
->async_visible
= 0;
11267 f
->async_iconified
= 0;
11274 /* Change window state from mapped to iconified. */
11277 x_iconify_frame (f
)
11283 /* Don't keep the highlight on an invisible frame. */
11284 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11285 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11287 if (f
->async_iconified
)
11292 FRAME_SAMPLE_VISIBILITY (f
);
11294 type
= x_icon_type (f
);
11296 x_bitmap_icon (f
, type
);
11298 #ifdef USE_X_TOOLKIT
11300 if (! FRAME_VISIBLE_P (f
))
11302 if (! EQ (Vx_no_window_manager
, Qt
))
11303 x_wm_set_window_state (f
, IconicState
);
11304 /* This was XtPopup, but that did nothing for an iconified frame. */
11305 XtMapWidget (f
->output_data
.x
->widget
);
11306 /* The server won't give us any event to indicate
11307 that an invisible frame was changed to an icon,
11308 so we have to record it here. */
11311 f
->async_iconified
= 1;
11312 f
->async_visible
= 0;
11317 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11318 XtWindow (f
->output_data
.x
->widget
),
11319 DefaultScreen (FRAME_X_DISPLAY (f
)));
11323 error ("Can't notify window manager of iconification");
11325 f
->async_iconified
= 1;
11326 f
->async_visible
= 0;
11330 XFlush (FRAME_X_DISPLAY (f
));
11332 #else /* not USE_X_TOOLKIT */
11334 /* Make sure the X server knows where the window should be positioned,
11335 in case the user deiconifies with the window manager. */
11336 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
11337 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11339 /* Since we don't know which revision of X we're running, we'll use both
11340 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11342 /* X11R4: send a ClientMessage to the window manager using the
11343 WM_CHANGE_STATE type. */
11347 message
.xclient
.window
= FRAME_X_WINDOW (f
);
11348 message
.xclient
.type
= ClientMessage
;
11349 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11350 message
.xclient
.format
= 32;
11351 message
.xclient
.data
.l
[0] = IconicState
;
11353 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11354 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11356 SubstructureRedirectMask
| SubstructureNotifyMask
,
11359 UNBLOCK_INPUT_RESIGNAL
;
11360 error ("Can't notify window manager of iconification");
11364 /* X11R3: set the initial_state field of the window manager hints to
11366 x_wm_set_window_state (f
, IconicState
);
11368 if (!FRAME_VISIBLE_P (f
))
11370 /* If the frame was withdrawn, before, we must map it. */
11371 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11374 f
->async_iconified
= 1;
11375 f
->async_visible
= 0;
11377 XFlush (FRAME_X_DISPLAY (f
));
11379 #endif /* not USE_X_TOOLKIT */
11382 /* Destroy the X window of frame F. */
11385 x_destroy_window (f
)
11388 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11392 /* If a display connection is dead, don't try sending more
11393 commands to the X server. */
11394 if (dpyinfo
->display
!= 0)
11396 if (f
->output_data
.x
->icon_desc
!= 0)
11397 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
11401 XDestroyIC (FRAME_XIC (f
));
11402 #if ! defined (SOLARIS2) || defined (HAVE_X11R6)
11403 /* This line causes crashes on Solaris with Openwin,
11404 due to an apparent bug in XCloseIM.
11405 X11R6 seems not to have the bug. */
11406 XCloseIM (FRAME_XIM (f
));
11410 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
11411 #ifdef USE_X_TOOLKIT
11412 if (f
->output_data
.x
->widget
)
11413 XtDestroyWidget (f
->output_data
.x
->widget
);
11414 free_frame_menubar (f
);
11415 #endif /* USE_X_TOOLKIT */
11417 free_frame_faces (f
);
11418 XFlush (FRAME_X_DISPLAY (f
));
11421 if (f
->output_data
.x
->saved_menu_event
)
11422 xfree (f
->output_data
.x
->saved_menu_event
);
11424 xfree (f
->output_data
.x
);
11425 f
->output_data
.x
= 0;
11426 if (f
== dpyinfo
->x_focus_frame
)
11427 dpyinfo
->x_focus_frame
= 0;
11428 if (f
== dpyinfo
->x_focus_event_frame
)
11429 dpyinfo
->x_focus_event_frame
= 0;
11430 if (f
== dpyinfo
->x_highlight_frame
)
11431 dpyinfo
->x_highlight_frame
= 0;
11433 dpyinfo
->reference_count
--;
11435 if (f
== dpyinfo
->mouse_face_mouse_frame
)
11437 dpyinfo
->mouse_face_beg_row
11438 = dpyinfo
->mouse_face_beg_col
= -1;
11439 dpyinfo
->mouse_face_end_row
11440 = dpyinfo
->mouse_face_end_col
= -1;
11441 dpyinfo
->mouse_face_window
= Qnil
;
11442 dpyinfo
->mouse_face_deferred_gc
= 0;
11443 dpyinfo
->mouse_face_mouse_frame
= 0;
11449 /* Setting window manager hints. */
11451 /* Set the normal size hints for the window manager, for frame F.
11452 FLAGS is the flags word to use--or 0 meaning preserve the flags
11453 that the window now has.
11454 If USER_POSITION is nonzero, we set the USPosition
11455 flag (this is useful when FLAGS is 0). */
11458 x_wm_set_size_hint (f
, flags
, user_position
)
11463 XSizeHints size_hints
;
11465 #ifdef USE_X_TOOLKIT
11468 Dimension widget_width
, widget_height
;
11469 Window window
= XtWindow (f
->output_data
.x
->widget
);
11470 #else /* not USE_X_TOOLKIT */
11471 Window window
= FRAME_X_WINDOW (f
);
11472 #endif /* not USE_X_TOOLKIT */
11474 /* Setting PMaxSize caused various problems. */
11475 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
11477 size_hints
.x
= f
->output_data
.x
->left_pos
;
11478 size_hints
.y
= f
->output_data
.x
->top_pos
;
11480 #ifdef USE_X_TOOLKIT
11481 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
11482 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
11483 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
11484 size_hints
.height
= widget_height
;
11485 size_hints
.width
= widget_width
;
11486 #else /* not USE_X_TOOLKIT */
11487 size_hints
.height
= PIXEL_HEIGHT (f
);
11488 size_hints
.width
= PIXEL_WIDTH (f
);
11489 #endif /* not USE_X_TOOLKIT */
11491 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
11492 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
11493 size_hints
.max_width
11494 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
11495 size_hints
.max_height
11496 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
11498 /* Calculate the base and minimum sizes.
11500 (When we use the X toolkit, we don't do it here.
11501 Instead we copy the values that the widgets are using, below.) */
11502 #ifndef USE_X_TOOLKIT
11504 int base_width
, base_height
;
11505 int min_rows
= 0, min_cols
= 0;
11507 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
11508 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
11510 check_frame_size (f
, &min_rows
, &min_cols
);
11512 /* The window manager uses the base width hints to calculate the
11513 current number of rows and columns in the frame while
11514 resizing; min_width and min_height aren't useful for this
11515 purpose, since they might not give the dimensions for a
11516 zero-row, zero-column frame.
11518 We use the base_width and base_height members if we have
11519 them; otherwise, we set the min_width and min_height members
11520 to the size for a zero x zero frame. */
11523 size_hints
.flags
|= PBaseSize
;
11524 size_hints
.base_width
= base_width
;
11525 size_hints
.base_height
= base_height
;
11526 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
11527 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
11529 size_hints
.min_width
= base_width
;
11530 size_hints
.min_height
= base_height
;
11534 /* If we don't need the old flags, we don't need the old hint at all. */
11537 size_hints
.flags
|= flags
;
11540 #endif /* not USE_X_TOOLKIT */
11543 XSizeHints hints
; /* Sometimes I hate X Windows... */
11544 long supplied_return
;
11548 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
11551 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
11554 #ifdef USE_X_TOOLKIT
11555 size_hints
.base_height
= hints
.base_height
;
11556 size_hints
.base_width
= hints
.base_width
;
11557 size_hints
.min_height
= hints
.min_height
;
11558 size_hints
.min_width
= hints
.min_width
;
11562 size_hints
.flags
|= flags
;
11567 if (hints
.flags
& PSize
)
11568 size_hints
.flags
|= PSize
;
11569 if (hints
.flags
& PPosition
)
11570 size_hints
.flags
|= PPosition
;
11571 if (hints
.flags
& USPosition
)
11572 size_hints
.flags
|= USPosition
;
11573 if (hints
.flags
& USSize
)
11574 size_hints
.flags
|= USSize
;
11578 #ifndef USE_X_TOOLKIT
11583 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
11584 size_hints
.flags
|= PWinGravity
;
11588 size_hints
.flags
&= ~ PPosition
;
11589 size_hints
.flags
|= USPosition
;
11591 #endif /* PWinGravity */
11594 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11596 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11600 /* Used for IconicState or NormalState */
11603 x_wm_set_window_state (f
, state
)
11607 #ifdef USE_X_TOOLKIT
11610 XtSetArg (al
[0], XtNinitialState
, state
);
11611 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11612 #else /* not USE_X_TOOLKIT */
11613 Window window
= FRAME_X_WINDOW (f
);
11615 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
11616 f
->output_data
.x
->wm_hints
.initial_state
= state
;
11618 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11619 #endif /* not USE_X_TOOLKIT */
11623 x_wm_set_icon_pixmap (f
, pixmap_id
)
11627 Pixmap icon_pixmap
;
11629 #ifndef USE_X_TOOLKIT
11630 Window window
= FRAME_X_WINDOW (f
);
11635 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
11636 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
11640 /* It seems there is no way to turn off use of an icon pixmap.
11641 The following line does it, only if no icon has yet been created,
11642 for some window managers. But with mwm it crashes.
11643 Some people say it should clear the IconPixmapHint bit in this case,
11644 but that doesn't work, and the X consortium said it isn't the
11645 right thing at all. Since there is no way to win,
11646 best to explicitly give up. */
11648 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
11654 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
11658 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
11659 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11662 #else /* not USE_X_TOOLKIT */
11664 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
11665 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11667 #endif /* not USE_X_TOOLKIT */
11671 x_wm_set_icon_position (f
, icon_x
, icon_y
)
11673 int icon_x
, icon_y
;
11675 #ifdef USE_X_TOOLKIT
11676 Window window
= XtWindow (f
->output_data
.x
->widget
);
11678 Window window
= FRAME_X_WINDOW (f
);
11681 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
11682 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
11683 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
11685 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11689 /***********************************************************************
11691 ***********************************************************************/
11693 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
11696 x_get_font_info (f
, font_idx
)
11700 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
11704 /* Return a list of names of available fonts matching PATTERN on frame
11705 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
11706 to be listed. Frame F NULL means we have not yet created any
11707 frame on X, and consult the first display in x_display_list.
11708 MAXNAMES sets a limit on how many fonts to match. */
11711 x_list_fonts (f
, pattern
, size
, maxnames
)
11713 Lisp_Object pattern
;
11717 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
11718 Lisp_Object tem
, second_best
;
11719 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
11720 int try_XLoadQueryFont
= 0;
11723 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
11724 if (NILP (patterns
))
11725 patterns
= Fcons (pattern
, Qnil
);
11727 if (maxnames
== 1 && !size
)
11728 /* We can return any single font matching PATTERN. */
11729 try_XLoadQueryFont
= 1;
11731 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
11736 pattern
= XCAR (patterns
);
11737 /* See if we cached the result for this particular query.
11738 The cache is an alist of the form:
11739 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
11741 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
11742 key
= Fcons (pattern
, make_number (maxnames
)),
11743 !NILP (list
= Fassoc (key
, tem
))))
11745 list
= Fcdr_safe (list
);
11746 /* We have a cashed list. Don't have to get the list again. */
11750 /* At first, put PATTERN in the cache. */
11753 count
= x_catch_errors (dpy
);
11755 if (try_XLoadQueryFont
)
11758 unsigned long value
;
11760 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
11761 if (x_had_errors_p (dpy
))
11763 /* This error is perhaps due to insufficient memory on X
11764 server. Let's just ignore it. */
11766 x_clear_errors (dpy
);
11770 && XGetFontProperty (font
, XA_FONT
, &value
))
11772 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
11773 int len
= strlen (name
);
11776 /* If DXPC (a Differential X Protocol Compressor)
11777 Ver.3.7 is running, XGetAtomName will return null
11778 string. We must avoid such a name. */
11780 try_XLoadQueryFont
= 0;
11784 names
= (char **) alloca (sizeof (char *));
11785 /* Some systems only allow alloca assigned to a
11787 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
11788 bcopy (name
, names
[0], len
+ 1);
11793 try_XLoadQueryFont
= 0;
11796 XFreeFont (dpy
, font
);
11799 if (!try_XLoadQueryFont
)
11801 /* We try at least 10 fonts because XListFonts will return
11802 auto-scaled fonts at the head. */
11803 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
11805 if (x_had_errors_p (dpy
))
11807 /* This error is perhaps due to insufficient memory on X
11808 server. Let's just ignore it. */
11810 x_clear_errors (dpy
);
11814 x_uncatch_errors (dpy
, count
);
11821 /* Make a list of all the fonts we got back.
11822 Store that in the font cache for the display. */
11823 for (i
= 0; i
< num_fonts
; i
++)
11826 char *p
= names
[i
];
11827 int average_width
= -1, dashes
= 0;
11829 /* Count the number of dashes in NAMES[I]. If there are
11830 14 dashes, and the field value following 12th dash
11831 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
11832 is usually too ugly to be used for editing. Let's
11838 if (dashes
== 7) /* PIXEL_SIZE field */
11840 else if (dashes
== 12) /* AVERAGE_WIDTH field */
11841 average_width
= atoi (p
);
11843 if (dashes
< 14 || average_width
!= 0)
11845 tem
= build_string (names
[i
]);
11846 if (NILP (Fassoc (tem
, list
)))
11848 if (STRINGP (Vx_pixel_size_width_font_regexp
)
11849 && ((fast_c_string_match_ignore_case
11850 (Vx_pixel_size_width_font_regexp
, names
[i
]))
11852 /* We can set the value of PIXEL_SIZE to the
11853 width of this font. */
11854 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
11856 /* For the moment, width is not known. */
11857 list
= Fcons (Fcons (tem
, Qnil
), list
);
11861 if (!try_XLoadQueryFont
)
11862 XFreeFontNames (names
);
11865 /* Now store the result in the cache. */
11867 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
11868 = Fcons (Fcons (key
, list
),
11869 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
11872 if (NILP (list
)) continue; /* Try the remaining alternatives. */
11874 newlist
= second_best
= Qnil
;
11875 /* Make a list of the fonts that have the right width. */
11876 for (; CONSP (list
); list
= XCDR (list
))
11882 if (!CONSP (tem
) || NILP (XCAR (tem
)))
11886 newlist
= Fcons (XCAR (tem
), newlist
);
11890 if (!INTEGERP (XCDR (tem
)))
11892 /* Since we have not yet known the size of this font, we
11893 must try slow function call XLoadQueryFont. */
11894 XFontStruct
*thisinfo
;
11897 count
= x_catch_errors (dpy
);
11898 thisinfo
= XLoadQueryFont (dpy
,
11899 XSTRING (XCAR (tem
))->data
);
11900 if (x_had_errors_p (dpy
))
11902 /* This error is perhaps due to insufficient memory on X
11903 server. Let's just ignore it. */
11905 x_clear_errors (dpy
);
11907 x_uncatch_errors (dpy
, count
);
11913 = (thisinfo
->min_bounds
.width
== 0
11915 : make_number (thisinfo
->max_bounds
.width
));
11916 XFreeFont (dpy
, thisinfo
);
11919 /* For unknown reason, the previous call of XListFont had
11920 returned a font which can't be opened. Record the size
11921 as 0 not to try to open it again. */
11922 XCDR (tem
) = make_number (0);
11925 found_size
= XINT (XCDR (tem
));
11926 if (found_size
== size
)
11927 newlist
= Fcons (XCAR (tem
), newlist
);
11928 else if (found_size
> 0)
11930 if (NILP (second_best
))
11932 else if (found_size
< size
)
11934 if (XINT (XCDR (second_best
)) > size
11935 || XINT (XCDR (second_best
)) < found_size
)
11940 if (XINT (XCDR (second_best
)) > size
11941 && XINT (XCDR (second_best
)) > found_size
)
11946 if (!NILP (newlist
))
11948 else if (!NILP (second_best
))
11950 newlist
= Fcons (XCAR (second_best
), Qnil
);
11961 /* Check that FONT is valid on frame F. It is if it can be found in F's
11965 x_check_font (f
, font
)
11970 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11972 xassert (font
!= NULL
);
11974 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11975 if (dpyinfo
->font_table
[i
].name
11976 && font
== dpyinfo
->font_table
[i
].font
)
11979 xassert (i
< dpyinfo
->n_fonts
);
11982 #endif /* GLYPH_DEBUG != 0 */
11984 /* Set *W to the minimum width, *H to the minimum font height of FONT.
11985 Note: There are (broken) X fonts out there with invalid XFontStruct
11986 min_bounds contents. For example, handa@etl.go.jp reports that
11987 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
11988 have font->min_bounds.width == 0. */
11991 x_font_min_bounds (font
, w
, h
)
11995 *h
= FONT_HEIGHT (font
);
11996 *w
= font
->min_bounds
.width
;
11998 /* Try to handle the case where FONT->min_bounds has invalid
11999 contents. Since the only font known to have invalid min_bounds
12000 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12002 *w
= font
->max_bounds
.width
;
12006 /* Compute the smallest character width and smallest font height over
12007 all fonts available on frame F. Set the members smallest_char_width
12008 and smallest_font_height in F's x_display_info structure to
12009 the values computed. Value is non-zero if smallest_font_height or
12010 smallest_char_width become smaller than they were before. */
12013 x_compute_min_glyph_bounds (f
)
12017 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12019 int old_width
= dpyinfo
->smallest_char_width
;
12020 int old_height
= dpyinfo
->smallest_font_height
;
12022 dpyinfo
->smallest_font_height
= 100000;
12023 dpyinfo
->smallest_char_width
= 100000;
12025 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12026 if (dpyinfo
->font_table
[i
].name
)
12028 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12031 font
= (XFontStruct
*) fontp
->font
;
12032 xassert (font
!= (XFontStruct
*) ~0);
12033 x_font_min_bounds (font
, &w
, &h
);
12035 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12036 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12039 xassert (dpyinfo
->smallest_char_width
> 0
12040 && dpyinfo
->smallest_font_height
> 0);
12042 return (dpyinfo
->n_fonts
== 1
12043 || dpyinfo
->smallest_char_width
< old_width
12044 || dpyinfo
->smallest_font_height
< old_height
);
12048 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12049 pointer to the structure font_info while allocating it dynamically.
12050 If SIZE is 0, load any size of font.
12051 If loading is failed, return NULL. */
12054 x_load_font (f
, fontname
, size
)
12056 register char *fontname
;
12059 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12060 Lisp_Object font_names
;
12063 /* Get a list of all the fonts that match this name. Once we
12064 have a list of matching fonts, we compare them against the fonts
12065 we already have by comparing names. */
12066 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12068 if (!NILP (font_names
))
12073 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12074 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12075 if (dpyinfo
->font_table
[i
].name
12076 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12077 XSTRING (XCAR (tail
))->data
)
12078 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12079 XSTRING (XCAR (tail
))->data
)))
12080 return (dpyinfo
->font_table
+ i
);
12083 /* Load the font and add it to the table. */
12087 struct font_info
*fontp
;
12088 unsigned long value
;
12091 /* If we have found fonts by x_list_font, load one of them. If
12092 not, we still try to load a font by the name given as FONTNAME
12093 because XListFonts (called in x_list_font) of some X server has
12094 a bug of not finding a font even if the font surely exists and
12095 is loadable by XLoadQueryFont. */
12096 if (size
> 0 && !NILP (font_names
))
12097 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12100 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12101 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12102 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12104 /* This error is perhaps due to insufficient memory on X
12105 server. Let's just ignore it. */
12107 x_clear_errors (FRAME_X_DISPLAY (f
));
12109 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12114 /* Find a free slot in the font table. */
12115 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12116 if (dpyinfo
->font_table
[i
].name
== NULL
)
12119 /* If no free slot found, maybe enlarge the font table. */
12120 if (i
== dpyinfo
->n_fonts
12121 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12124 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12125 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12126 dpyinfo
->font_table
12127 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12130 fontp
= dpyinfo
->font_table
+ i
;
12131 if (i
== dpyinfo
->n_fonts
)
12132 ++dpyinfo
->n_fonts
;
12134 /* Now fill in the slots of *FONTP. */
12136 fontp
->font
= font
;
12137 fontp
->font_idx
= i
;
12138 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12139 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12141 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12143 if (XGetFontProperty (font
, XA_FONT
, &value
))
12145 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12149 /* Count the number of dashes in the "full name".
12150 If it is too few, this isn't really the font's full name,
12152 In X11R4, the fonts did not come with their canonical names
12163 full_name
= (char *) xmalloc (p
- name
+ 1);
12164 bcopy (name
, full_name
, p
- name
+ 1);
12170 if (full_name
!= 0)
12171 fontp
->full_name
= full_name
;
12173 fontp
->full_name
= fontp
->name
;
12175 fontp
->size
= font
->max_bounds
.width
;
12176 fontp
->height
= FONT_HEIGHT (font
);
12178 /* For some font, ascent and descent in max_bounds field is
12179 larger than the above value. */
12180 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12181 if (max_height
> fontp
->height
)
12182 fontp
->height
= max_height
;
12185 if (NILP (font_names
))
12187 /* We come here because of a bug of XListFonts mentioned at
12188 the head of this block. Let's store this information in
12189 the cache for x_list_fonts. */
12190 Lisp_Object lispy_name
= build_string (fontname
);
12191 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12193 XCDR (dpyinfo
->name_list_element
)
12194 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
12195 Fcons (Fcons (lispy_full_name
,
12196 make_number (fontp
->size
)),
12198 XCDR (dpyinfo
->name_list_element
));
12200 XCDR (dpyinfo
->name_list_element
)
12201 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
12202 Fcons (Fcons (lispy_full_name
,
12203 make_number (fontp
->size
)),
12205 XCDR (dpyinfo
->name_list_element
));
12208 /* The slot `encoding' specifies how to map a character
12209 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
12210 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
12211 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
12212 0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
12213 2:0xA020..0xFF7F). For the moment, we don't know which charset
12214 uses this font. So, we set information in fontp->encoding[1]
12215 which is never used by any charset. If mapping can't be
12216 decided, set FONT_ENCODING_NOT_DECIDED. */
12218 = (font
->max_byte1
== 0
12220 ? (font
->min_char_or_byte2
< 0x80
12221 ? (font
->max_char_or_byte2
< 0x80
12222 ? 0 /* 0x20..0x7F */
12223 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
12224 : 1) /* 0xA0..0xFF */
12226 : (font
->min_byte1
< 0x80
12227 ? (font
->max_byte1
< 0x80
12228 ? (font
->min_char_or_byte2
< 0x80
12229 ? (font
->max_char_or_byte2
< 0x80
12230 ? 0 /* 0x2020..0x7F7F */
12231 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
12232 : 3) /* 0x20A0..0x7FFF */
12233 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
12234 : (font
->min_char_or_byte2
< 0x80
12235 ? (font
->max_char_or_byte2
< 0x80
12236 ? 2 /* 0xA020..0xFF7F */
12237 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
12238 : 1))); /* 0xA0A0..0xFFFF */
12240 fontp
->baseline_offset
12241 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
12242 ? (long) value
: 0);
12243 fontp
->relative_compose
12244 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
12245 ? (long) value
: 0);
12246 fontp
->default_ascent
12247 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
12248 ? (long) value
: 0);
12250 /* Set global flag fonts_changed_p to non-zero if the font loaded
12251 has a character with a smaller width than any other character
12252 before, or if the font loaded has a smalle>r height than any
12253 other font loaded before. If this happens, it will make a
12254 glyph matrix reallocation necessary. */
12255 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
12262 /* Return a pointer to struct font_info of a font named FONTNAME for
12263 frame F. If no such font is loaded, return NULL. */
12266 x_query_font (f
, fontname
)
12268 register char *fontname
;
12270 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12273 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12274 if (dpyinfo
->font_table
[i
].name
12275 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
12276 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
12277 return (dpyinfo
->font_table
+ i
);
12282 /* Find a CCL program for a font specified by FONTP, and set the member
12283 `encoder' of the structure. */
12286 x_find_ccl_program (fontp
)
12287 struct font_info
*fontp
;
12289 Lisp_Object list
, elt
;
12291 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
12295 && STRINGP (XCAR (elt
))
12296 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
12302 struct ccl_program
*ccl
12303 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
12305 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
12308 fontp
->font_encoder
= ccl
;
12314 /***********************************************************************
12316 ***********************************************************************/
12318 #ifdef USE_X_TOOLKIT
12319 static XrmOptionDescRec emacs_options
[] = {
12320 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
12321 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
12323 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
12324 XrmoptionSepArg
, NULL
},
12325 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
12327 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12328 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12329 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12330 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12331 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12332 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
12333 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
12335 #endif /* USE_X_TOOLKIT */
12337 static int x_initialized
;
12339 #ifdef MULTI_KBOARD
12340 /* Test whether two display-name strings agree up to the dot that separates
12341 the screen number from the server number. */
12343 same_x_server (name1
, name2
)
12344 char *name1
, *name2
;
12346 int seen_colon
= 0;
12347 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
12348 int system_name_length
= strlen (system_name
);
12349 int length_until_period
= 0;
12351 while (system_name
[length_until_period
] != 0
12352 && system_name
[length_until_period
] != '.')
12353 length_until_period
++;
12355 /* Treat `unix' like an empty host name. */
12356 if (! strncmp (name1
, "unix:", 5))
12358 if (! strncmp (name2
, "unix:", 5))
12360 /* Treat this host's name like an empty host name. */
12361 if (! strncmp (name1
, system_name
, system_name_length
)
12362 && name1
[system_name_length
] == ':')
12363 name1
+= system_name_length
;
12364 if (! strncmp (name2
, system_name
, system_name_length
)
12365 && name2
[system_name_length
] == ':')
12366 name2
+= system_name_length
;
12367 /* Treat this host's domainless name like an empty host name. */
12368 if (! strncmp (name1
, system_name
, length_until_period
)
12369 && name1
[length_until_period
] == ':')
12370 name1
+= length_until_period
;
12371 if (! strncmp (name2
, system_name
, length_until_period
)
12372 && name2
[length_until_period
] == ':')
12373 name2
+= length_until_period
;
12375 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
12379 if (seen_colon
&& *name1
== '.')
12383 && (*name1
== '.' || *name1
== '\0')
12384 && (*name2
== '.' || *name2
== '\0'));
12388 #if defined (HAVE_X_I18N) || (defined (USE_X_TOOLKIT) && defined (HAVE_X11XTR6))
12389 /* Recover from setlocale (LC_ALL, ""). */
12393 /* Currently we require strerror to use the "C" locale,
12394 since we don't yet support decoding its string result. */
12396 setlocale (LC_MESSAGES
, "C");
12399 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
12400 so that numbers are read and printed properly for Emacs Lisp. */
12401 setlocale (LC_NUMERIC
, "C");
12403 /* Currently we require strftime to use the "C" locale,
12404 since we don't yet support encoding its format argument,
12405 or decoding its string result. */
12406 setlocale (LC_TIME
, "C");
12410 struct x_display_info
*
12411 x_term_init (display_name
, xrm_option
, resource_name
)
12412 Lisp_Object display_name
;
12414 char *resource_name
;
12418 struct x_display_info
*dpyinfo
;
12423 if (!x_initialized
)
12430 setlocale (LC_ALL
, "");
12434 #ifdef USE_X_TOOLKIT
12435 /* weiner@footloose.sps.mot.com reports that this causes
12437 X protocol error: BadAtom (invalid Atom parameter)
12438 on protocol request 18skiloaf.
12439 So let's not use it until R6. */
12440 #ifdef HAVE_X11XTR6
12441 XtSetLanguageProc (NULL
, NULL
, NULL
);
12452 argv
[argc
++] = "-xrm";
12453 argv
[argc
++] = xrm_option
;
12455 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
12456 resource_name
, EMACS_CLASS
,
12457 emacs_options
, XtNumber (emacs_options
),
12460 #ifdef HAVE_X11XTR6
12461 /* I think this is to compensate for XtSetLanguageProc. */
12466 #else /* not USE_X_TOOLKIT */
12468 XSetLocaleModifiers ("");
12470 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
12471 #endif /* not USE_X_TOOLKIT */
12473 /* Detect failure. */
12480 /* We have definitely succeeded. Record the new connection. */
12482 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
12484 #ifdef MULTI_KBOARD
12486 struct x_display_info
*share
;
12489 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
12490 share
= share
->next
, tail
= XCDR (tail
))
12491 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
12492 XSTRING (display_name
)->data
))
12495 dpyinfo
->kboard
= share
->kboard
;
12498 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
12499 init_kboard (dpyinfo
->kboard
);
12500 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
12502 char *vendor
= ServerVendor (dpy
);
12503 dpyinfo
->kboard
->Vsystem_key_alist
12504 = call1 (Qvendor_specific_keysyms
,
12505 build_string (vendor
? vendor
: ""));
12508 dpyinfo
->kboard
->next_kboard
= all_kboards
;
12509 all_kboards
= dpyinfo
->kboard
;
12510 /* Don't let the initial kboard remain current longer than necessary.
12511 That would cause problems if a file loaded on startup tries to
12512 prompt in the mini-buffer. */
12513 if (current_kboard
== initial_kboard
)
12514 current_kboard
= dpyinfo
->kboard
;
12516 dpyinfo
->kboard
->reference_count
++;
12520 /* Put this display on the chain. */
12521 dpyinfo
->next
= x_display_list
;
12522 x_display_list
= dpyinfo
;
12524 /* Put it on x_display_name_list as well, to keep them parallel. */
12525 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
12526 x_display_name_list
);
12527 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
12529 dpyinfo
->display
= dpy
;
12532 XSetAfterFunction (x_current_display
, x_trace_wire
);
12536 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
12537 + STRING_BYTES (XSTRING (Vsystem_name
))
12539 sprintf (dpyinfo
->x_id_name
, "%s@%s",
12540 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
12542 /* Figure out which modifier bits mean what. */
12543 x_find_modifier_meanings (dpyinfo
);
12545 /* Get the scroll bar cursor. */
12546 dpyinfo
->vertical_scroll_bar_cursor
12547 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
12549 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
12550 resource_name
, EMACS_CLASS
);
12551 #ifdef HAVE_XRMSETDATABASE
12552 XrmSetDatabase (dpyinfo
->display
, xrdb
);
12554 dpyinfo
->display
->db
= xrdb
;
12556 /* Put the rdb where we can find it in a way that works on
12558 dpyinfo
->xrdb
= xrdb
;
12560 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
12561 DefaultScreen (dpyinfo
->display
));
12562 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
12563 &dpyinfo
->n_planes
);
12564 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
12565 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
12566 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
12567 dpyinfo
->grabbed
= 0;
12568 dpyinfo
->reference_count
= 0;
12569 dpyinfo
->icon_bitmap_id
= -1;
12570 dpyinfo
->font_table
= NULL
;
12571 dpyinfo
->n_fonts
= 0;
12572 dpyinfo
->font_table_size
= 0;
12573 dpyinfo
->bitmaps
= 0;
12574 dpyinfo
->bitmaps_size
= 0;
12575 dpyinfo
->bitmaps_last
= 0;
12576 dpyinfo
->scratch_cursor_gc
= 0;
12577 dpyinfo
->mouse_face_mouse_frame
= 0;
12578 dpyinfo
->mouse_face_deferred_gc
= 0;
12579 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
12580 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
12581 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
12582 dpyinfo
->mouse_face_window
= Qnil
;
12583 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
12584 dpyinfo
->mouse_face_defer
= 0;
12585 dpyinfo
->x_focus_frame
= 0;
12586 dpyinfo
->x_focus_event_frame
= 0;
12587 dpyinfo
->x_highlight_frame
= 0;
12588 dpyinfo
->image_cache
= make_image_cache ();
12591 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
12592 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
12593 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
12594 dpyinfo
->resy
= pixels
* 25.4 / mm
;
12595 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
12596 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
12597 dpyinfo
->resx
= pixels
* 25.4 / mm
;
12600 dpyinfo
->Xatom_wm_protocols
12601 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
12602 dpyinfo
->Xatom_wm_take_focus
12603 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
12604 dpyinfo
->Xatom_wm_save_yourself
12605 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
12606 dpyinfo
->Xatom_wm_delete_window
12607 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
12608 dpyinfo
->Xatom_wm_change_state
12609 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
12610 dpyinfo
->Xatom_wm_configure_denied
12611 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
12612 dpyinfo
->Xatom_wm_window_moved
12613 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
12614 dpyinfo
->Xatom_editres
12615 = XInternAtom (dpyinfo
->display
, "Editres", False
);
12616 dpyinfo
->Xatom_CLIPBOARD
12617 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
12618 dpyinfo
->Xatom_TIMESTAMP
12619 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
12620 dpyinfo
->Xatom_TEXT
12621 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
12622 dpyinfo
->Xatom_COMPOUND_TEXT
12623 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
12624 dpyinfo
->Xatom_DELETE
12625 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
12626 dpyinfo
->Xatom_MULTIPLE
12627 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
12628 dpyinfo
->Xatom_INCR
12629 = XInternAtom (dpyinfo
->display
, "INCR", False
);
12630 dpyinfo
->Xatom_EMACS_TMP
12631 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
12632 dpyinfo
->Xatom_TARGETS
12633 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
12634 dpyinfo
->Xatom_NULL
12635 = XInternAtom (dpyinfo
->display
, "NULL", False
);
12636 dpyinfo
->Xatom_ATOM_PAIR
12637 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
12638 /* For properties of font. */
12639 dpyinfo
->Xatom_PIXEL_SIZE
12640 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
12641 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
12642 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
12643 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
12644 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
12645 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
12646 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
12648 /* Ghostscript support. */
12649 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
12650 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
12652 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
12655 dpyinfo
->cut_buffers_initialized
= 0;
12657 connection
= ConnectionNumber (dpyinfo
->display
);
12658 dpyinfo
->connection
= connection
;
12663 null_bits
[0] = 0x00;
12665 dpyinfo
->null_pixel
12666 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
12667 null_bits
, 1, 1, (long) 0, (long) 0,
12672 extern int gray_bitmap_width
, gray_bitmap_height
;
12673 extern unsigned char *gray_bitmap_bits
;
12675 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
12677 gray_bitmap_width
, gray_bitmap_height
,
12678 (unsigned long) 1, (unsigned long) 0, 1);
12681 #ifdef subprocesses
12682 /* This is only needed for distinguishing keyboard and process input. */
12683 if (connection
!= 0)
12684 add_keyboard_wait_descriptor (connection
);
12687 #ifndef F_SETOWN_BUG
12689 #ifdef F_SETOWN_SOCK_NEG
12690 /* stdin is a socket here */
12691 fcntl (connection
, F_SETOWN
, -getpid ());
12692 #else /* ! defined (F_SETOWN_SOCK_NEG) */
12693 fcntl (connection
, F_SETOWN
, getpid ());
12694 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
12695 #endif /* ! defined (F_SETOWN) */
12696 #endif /* F_SETOWN_BUG */
12699 if (interrupt_input
)
12700 init_sigio (connection
);
12701 #endif /* ! defined (SIGIO) */
12704 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
12705 /* Make sure that we have a valid font for dialog boxes
12706 so that Xt does not crash. */
12708 Display
*dpy
= dpyinfo
->display
;
12709 XrmValue d
, fr
, to
;
12713 d
.addr
= (XPointer
)&dpy
;
12714 d
.size
= sizeof (Display
*);
12715 fr
.addr
= XtDefaultFont
;
12716 fr
.size
= sizeof (XtDefaultFont
);
12717 to
.size
= sizeof (Font
*);
12718 to
.addr
= (XPointer
)&font
;
12719 count
= x_catch_errors (dpy
);
12720 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
12722 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
12723 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
12724 x_uncatch_errors (dpy
, count
);
12734 /* Get rid of display DPYINFO, assuming all frames are already gone,
12735 and without sending any more commands to the X server. */
12738 x_delete_display (dpyinfo
)
12739 struct x_display_info
*dpyinfo
;
12741 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
12743 /* Discard this display from x_display_name_list and x_display_list.
12744 We can't use Fdelq because that can quit. */
12745 if (! NILP (x_display_name_list
)
12746 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
12747 x_display_name_list
= XCDR (x_display_name_list
);
12752 tail
= x_display_name_list
;
12753 while (CONSP (tail
) && CONSP (XCDR (tail
)))
12755 if (EQ (XCAR (XCDR (tail
)),
12756 dpyinfo
->name_list_element
))
12758 XCDR (tail
) = XCDR (XCDR (tail
));
12761 tail
= XCDR (tail
);
12765 if (x_display_list
== dpyinfo
)
12766 x_display_list
= dpyinfo
->next
;
12769 struct x_display_info
*tail
;
12771 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
12772 if (tail
->next
== dpyinfo
)
12773 tail
->next
= tail
->next
->next
;
12776 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
12777 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
12778 XrmDestroyDatabase (dpyinfo
->xrdb
);
12781 #ifdef MULTI_KBOARD
12782 if (--dpyinfo
->kboard
->reference_count
== 0)
12783 delete_kboard (dpyinfo
->kboard
);
12785 xfree (dpyinfo
->font_table
);
12786 xfree (dpyinfo
->x_id_name
);
12790 /* Set up use of X before we make the first connection. */
12792 static struct redisplay_interface x_redisplay_interface
=
12797 x_clear_end_of_line
,
12799 x_after_update_window_line
,
12800 x_update_window_begin
,
12801 x_update_window_end
,
12804 x_get_glyph_overhangs
,
12805 x_fix_overlapping_area
12811 rif
= &x_redisplay_interface
;
12813 clear_frame_hook
= x_clear_frame
;
12814 ins_del_lines_hook
= x_ins_del_lines
;
12815 change_line_highlight_hook
= x_change_line_highlight
;
12816 delete_glyphs_hook
= x_delete_glyphs
;
12817 ring_bell_hook
= XTring_bell
;
12818 reset_terminal_modes_hook
= XTreset_terminal_modes
;
12819 set_terminal_modes_hook
= XTset_terminal_modes
;
12820 update_begin_hook
= x_update_begin
;
12821 update_end_hook
= x_update_end
;
12822 set_terminal_window_hook
= XTset_terminal_window
;
12823 read_socket_hook
= XTread_socket
;
12824 frame_up_to_date_hook
= XTframe_up_to_date
;
12825 reassert_line_highlight_hook
= XTreassert_line_highlight
;
12826 mouse_position_hook
= XTmouse_position
;
12827 frame_rehighlight_hook
= XTframe_rehighlight
;
12828 frame_raise_lower_hook
= XTframe_raise_lower
;
12829 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
12830 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
12831 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
12832 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
12833 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
12835 scroll_region_ok
= 1; /* we'll scroll partial frames */
12836 char_ins_del_ok
= 0; /* just as fast to write the line */
12837 line_ins_del_ok
= 1; /* we'll just blt 'em */
12838 fast_clear_end_of_line
= 1; /* X does this well */
12839 memory_below_frame
= 0; /* we don't remember what scrolls
12844 last_tool_bar_item
= -1;
12845 any_help_event_p
= 0;
12847 /* Try to use interrupt input; if we can't, then start polling. */
12848 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
12850 #ifdef USE_X_TOOLKIT
12851 XtToolkitInitialize ();
12852 Xt_app_con
= XtCreateApplicationContext ();
12853 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
12856 /* Note that there is no real way portable across R3/R4 to get the
12857 original error handler. */
12858 XSetErrorHandler (x_error_handler
);
12859 XSetIOErrorHandler (x_io_error_quitter
);
12861 /* Disable Window Change signals; they are handled by X events. */
12863 signal (SIGWINCH
, SIG_DFL
);
12864 #endif /* ! defined (SIGWINCH) */
12866 signal (SIGPIPE
, x_connection_signal
);
12873 staticpro (&x_error_message_string
);
12874 x_error_message_string
= Qnil
;
12876 staticpro (&x_display_name_list
);
12877 x_display_name_list
= Qnil
;
12879 staticpro (&last_mouse_scroll_bar
);
12880 last_mouse_scroll_bar
= Qnil
;
12882 staticpro (&Qvendor_specific_keysyms
);
12883 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
12885 staticpro (&last_mouse_press_frame
);
12886 last_mouse_press_frame
= Qnil
;
12888 staticpro (&help_echo
);
12890 staticpro (&previous_help_echo
);
12891 previous_help_echo
= Qnil
;
12893 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
12894 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
12895 For example, if a block cursor is over a tab, it will be drawn as\n\
12896 wide as that tab on the display.");
12897 x_stretch_cursor_p
= 0;
12899 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
12900 "If not nil, Emacs uses toolkit scroll bars.");
12901 #if USE_TOOLKIT_SCROLL_BARS
12902 x_toolkit_scroll_bars_p
= 1;
12904 x_toolkit_scroll_bars_p
= 0;
12907 defsubr (&Sxt_process_timeouts
);
12908 staticpro (&last_mouse_motion_frame
);
12909 last_mouse_motion_frame
= Qnil
;
12912 #endif /* not HAVE_X_WINDOWS */