1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
48 /* Load sys/types.h if not already loaded.
49 In some systems loading it twice is suicidal. */
51 #include <sys/types.h>
56 #include <sys/ioctl.h>
57 #endif /* ! defined (BSD_SYSTEM) */
62 #ifndef INCLUDED_FCNTL
69 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
70 /* #include <sys/param.h> */
75 #include "dispextern.h"
77 #include "termhooks.h"
89 #include "intervals.h"
94 #include <X11/Shell.h>
97 #include <sys/types.h>
98 #ifdef HAVE_SYS_TIME_H
107 extern void free_frame_menubar ();
108 extern FRAME_PTR
x_menubar_window_to_frame ();
110 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
112 extern void _XEditResCheckMessages ();
113 #endif /* not NO_EDITRES */
115 /* Include toolkit specific headers for the scroll bar widget. */
117 #ifdef USE_TOOLKIT_SCROLL_BARS
118 #if defined USE_MOTIF
119 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
120 #include <Xm/ScrollBar.h>
121 #include <Xm/ScrollBarP.h>
122 #else /* !USE_MOTIF i.e. use Xaw */
125 #include <X11/Xaw3d/Simple.h>
126 #include <X11/Xaw3d/Scrollbar.h>
127 #define ARROW_SCROLLBAR
128 #include <X11/Xaw3d/ScrollbarP.h>
129 #else /* !HAVE_XAW3D */
130 #include <X11/Xaw/Simple.h>
131 #include <X11/Xaw/Scrollbar.h>
132 #endif /* !HAVE_XAW3D */
134 #define XtNpickTop "pickTop"
135 #endif /* !XtNpickTop */
136 #endif /* !USE_MOTIF */
137 #endif /* USE_TOOLKIT_SCROLL_BARS */
139 #endif /* USE_X_TOOLKIT */
141 #ifndef USE_X_TOOLKIT
142 #define x_any_window_to_frame x_window_to_frame
143 #define x_top_window_to_frame x_window_to_frame
148 #ifndef XtNinitialState
149 #define XtNinitialState "initialState"
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
;
302 /* Non-zero means user is interacting with a toolkit scroll bar. */
304 static int toolkit_scroll_bar_interaction
;
308 Formerly, we used PointerMotionHintMask (in standard_event_mask)
309 so that we would have to call XQueryPointer after each MotionNotify
310 event to ask for another such event. However, this made mouse tracking
311 slow, and there was a bug that made it eventually stop.
313 Simply asking for MotionNotify all the time seems to work better.
315 In order to avoid asking for motion events and then throwing most
316 of them away or busy-polling the server for mouse positions, we ask
317 the server for pointer motion hints. This means that we get only
318 one event per group of mouse movements. "Groups" are delimited by
319 other kinds of events (focus changes and button clicks, for
320 example), or by XQueryPointer calls; when one of these happens, we
321 get another MotionNotify event the next time the mouse moves. This
322 is at least as efficient as getting motion events when mouse
323 tracking is on, and I suspect only negligibly worse when tracking
326 /* Where the mouse was last time we reported a mouse event. */
328 FRAME_PTR last_mouse_frame
;
329 static XRectangle last_mouse_glyph
;
330 static Lisp_Object last_mouse_press_frame
;
332 /* The scroll bar in which the last X motion event occurred.
334 If the last X motion event occurred in a scroll bar, we set this so
335 XTmouse_position can know whether to report a scroll bar motion or
338 If the last X motion event didn't occur in a scroll bar, we set
339 this to Qnil, to tell XTmouse_position to return an ordinary motion
342 static Lisp_Object last_mouse_scroll_bar
;
344 /* This is a hack. We would really prefer that XTmouse_position would
345 return the time associated with the position it returns, but there
346 doesn't seem to be any way to wrest the time-stamp from the server
347 along with the position query. So, we just keep track of the time
348 of the last movement we received, and return that in hopes that
349 it's somewhat accurate. */
351 static Time last_mouse_movement_time
;
353 /* Incremented by XTread_socket whenever it really tries to read
357 static int volatile input_signal_count
;
359 static int input_signal_count
;
362 /* Used locally within XTread_socket. */
364 static int x_noop_count
;
366 /* Initial values of argv and argc. */
368 extern char **initial_argv
;
369 extern int initial_argc
;
371 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
373 /* Tells if a window manager is present or not. */
375 extern Lisp_Object Vx_no_window_manager
;
377 extern Lisp_Object Qface
, Qmouse_face
;
381 /* A mask of extra modifier bits to put into every keyboard char. */
383 extern int extra_keyboard_modifiers
;
385 static Lisp_Object Qvendor_specific_keysyms
;
387 extern XrmDatabase
x_load_resources ();
388 extern Lisp_Object
x_icon_type ();
391 /* Enumeration for overriding/changing the face to use for drawing
392 glyphs in x_draw_glyphs. */
394 enum draw_glyphs_face
404 static void x_update_window_end
P_ ((struct window
*, int));
405 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
406 void x_delete_display
P_ ((struct x_display_info
*));
407 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
409 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
411 static void set_output_cursor
P_ ((struct cursor_pos
*));
412 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
413 int *, int *, int *));
414 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
415 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
416 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
417 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
418 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
419 static void show_mouse_face
P_ ((struct x_display_info
*,
420 enum draw_glyphs_face
));
421 static int x_io_error_quitter
P_ ((Display
*));
422 int x_catch_errors
P_ ((Display
*));
423 void x_uncatch_errors
P_ ((Display
*, int));
424 void x_lower_frame
P_ ((struct frame
*));
425 void x_scroll_bar_clear
P_ ((struct frame
*));
426 int x_had_errors_p
P_ ((Display
*));
427 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
428 void x_raise_frame
P_ ((struct frame
*));
429 void x_set_window_size
P_ ((struct frame
*, int, int, int));
430 void x_wm_set_window_state
P_ ((struct frame
*, int));
431 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
432 void x_initialize
P_ ((void));
433 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
434 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
435 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
437 enum draw_glyphs_face
));
438 static void x_update_end
P_ ((struct frame
*));
439 static void XTframe_up_to_date
P_ ((struct frame
*));
440 static void XTreassert_line_highlight
P_ ((int, int));
441 static void x_change_line_highlight
P_ ((int, int, int, int));
442 static void XTset_terminal_modes
P_ ((void));
443 static void XTreset_terminal_modes
P_ ((void));
444 static void XTcursor_to
P_ ((int, int, int, int));
445 static void x_write_glyphs
P_ ((struct glyph
*, int));
446 static void x_clear_end_of_line
P_ ((int));
447 static void x_clear_frame
P_ ((void));
448 static void x_clear_cursor
P_ ((struct window
*));
449 static void frame_highlight
P_ ((struct frame
*));
450 static void frame_unhighlight
P_ ((struct frame
*));
451 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
452 static void XTframe_rehighlight
P_ ((struct frame
*));
453 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
454 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
455 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
456 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
458 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
459 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
460 static void expose_window
P_ ((struct window
*, XRectangle
*));
461 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
462 XRectangle
*, enum glyph_row_area
));
463 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
465 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
466 static void x_update_window_cursor
P_ ((struct window
*, int));
467 static void x_erase_phys_cursor
P_ ((struct window
*));
468 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
469 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
472 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
474 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
475 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
476 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
477 static void x_flush
P_ ((struct frame
*f
));
480 /* Flush display of frame F, or of all frames if F is null. */
489 Lisp_Object rest
, frame
;
490 FOR_EACH_FRAME (rest
, frame
)
491 x_flush (XFRAME (frame
));
493 else if (FRAME_X_P (f
))
494 XFlush (FRAME_X_DISPLAY (f
));
499 /* Remove calls to XFlush by defining XFlush to an empty replacement.
500 Calls to XFlush should be unnecessary because the X output buffer
501 is flushed automatically as needed by calls to XPending,
502 XNextEvent, or XWindowEvent according to the XFlush man page.
503 XTread_socket calls XPending. Removing XFlush improves
506 #define XFlush(DISPLAY) (void) 0
509 /***********************************************************************
511 ***********************************************************************/
515 /* This is a function useful for recording debugging information about
516 the sequence of occurrences in this file. */
524 struct record event_record
[100];
526 int event_record_index
;
528 record_event (locus
, type
)
532 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
533 event_record_index
= 0;
535 event_record
[event_record_index
].locus
= locus
;
536 event_record
[event_record_index
].type
= type
;
537 event_record_index
++;
544 /* Return the struct x_display_info corresponding to DPY. */
546 struct x_display_info
*
547 x_display_info_for_display (dpy
)
550 struct x_display_info
*dpyinfo
;
552 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
553 if (dpyinfo
->display
== dpy
)
561 /***********************************************************************
562 Starting and ending an update
563 ***********************************************************************/
565 /* Start an update of frame F. This function is installed as a hook
566 for update_begin, i.e. it is called when update_begin is called.
567 This function is called prior to calls to x_update_window_begin for
568 each window being updated. Currently, there is nothing to do here
569 because all interesting stuff is done on a window basis. */
579 /* Start update of window W. Set the global variable updated_window
580 to the window being updated and set output_cursor to the cursor
584 x_update_window_begin (w
)
587 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
588 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
591 set_output_cursor (&w
->cursor
);
595 if (f
== display_info
->mouse_face_mouse_frame
)
597 /* Don't do highlighting for mouse motion during the update. */
598 display_info
->mouse_face_defer
= 1;
600 /* If F needs to be redrawn, simply forget about any prior mouse
602 if (FRAME_GARBAGED_P (f
))
603 display_info
->mouse_face_window
= Qnil
;
605 /* Can we tell that this update does not affect the window
606 where the mouse highlight is? If so, no need to turn off.
607 Likewise, don't do anything if the frame is garbaged;
608 in that case, the frame's current matrix that we would use
609 is all wrong, and we will redisplay that line anyway. */
610 if (!NILP (display_info
->mouse_face_window
)
611 && w
== XWINDOW (display_info
->mouse_face_window
))
615 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
616 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
619 if (i
< w
->desired_matrix
->nrows
)
620 clear_mouse_face (display_info
);
628 /* Draw a vertical window border to the right of window W if W doesn't
629 have vertical scroll bars. */
632 x_draw_vertical_border (w
)
635 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
637 /* Redraw borders between horizontally adjacent windows. Don't
638 do it for frames with vertical scroll bars because either the
639 right scroll bar of a window, or the left scroll bar of its
640 neighbor will suffice as a border. */
641 if (!WINDOW_RIGHTMOST_P (w
)
642 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
646 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
647 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
650 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
651 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
656 /* End update of window W (which is equal to updated_window). Draw
657 vertical borders between horizontally adjacent windows, and display
658 W's cursor if CURSOR_ON_P is non-zero. W may be a menu bar
659 pseudo-window in case we don't have X toolkit support. Such
660 windows don't have a cursor, so don't display it here. */
663 x_update_window_end (w
, cursor_on_p
)
667 if (!w
->pseudo_window_p
)
671 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
673 output_cursor
.x
, output_cursor
.y
);
674 x_draw_vertical_border (w
);
678 updated_window
= NULL
;
682 /* End update of frame F. This function is installed as a hook in
689 /* Mouse highlight may be displayed again. */
690 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
693 XFlush (FRAME_X_DISPLAY (f
));
698 /* This function is called from various places in xdisp.c whenever a
699 complete update has been performed. The global variable
700 updated_window is not available here. */
703 XTframe_up_to_date (f
)
708 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
709 if (dpyinfo
->mouse_face_deferred_gc
710 || f
== dpyinfo
->mouse_face_mouse_frame
)
713 if (dpyinfo
->mouse_face_mouse_frame
)
714 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
715 dpyinfo
->mouse_face_mouse_x
,
716 dpyinfo
->mouse_face_mouse_y
);
717 dpyinfo
->mouse_face_deferred_gc
= 0;
724 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
725 arrow bitmaps, or clear the areas where they would be displayed
726 before DESIRED_ROW is made current. The window being updated is
727 found in updated_window. This function It is called from
728 update_window_line only if it is known that there are differences
729 between bitmaps to be drawn between current row and DESIRED_ROW. */
732 x_after_update_window_line (desired_row
)
733 struct glyph_row
*desired_row
;
735 struct window
*w
= updated_window
;
739 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
742 x_draw_row_bitmaps (w
, desired_row
);
744 /* When a window has disappeared, make sure that no rest of
745 full-width rows stays visible in the internal border. */
746 if (windows_or_buffers_changed
)
748 struct frame
*f
= XFRAME (w
->frame
);
749 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
750 int height
= desired_row
->visible_height
;
751 int x
= (window_box_right (w
, -1)
752 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
753 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
755 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
756 x
, y
, width
, height
, False
);
764 /* Draw the bitmap WHICH in one of the areas to the left or right of
765 window W. ROW is the glyph row for which to display the bitmap; it
766 determines the vertical position at which the bitmap has to be
770 x_draw_bitmap (w
, row
, which
)
772 struct glyph_row
*row
;
773 enum bitmap_type which
;
775 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
776 Display
*display
= FRAME_X_DISPLAY (f
);
777 Window window
= FRAME_X_WINDOW (f
);
781 GC gc
= f
->output_data
.x
->normal_gc
;
783 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
785 /* Must clip because of partially visible lines. */
786 x_clip_to_row (w
, row
, gc
, 1);
790 case LEFT_TRUNCATION_BITMAP
:
794 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
796 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
799 case OVERLAY_ARROW_BITMAP
:
803 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
805 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
808 case RIGHT_TRUNCATION_BITMAP
:
812 x
= window_box_right (w
, -1);
813 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
816 case CONTINUED_LINE_BITMAP
:
819 bits
= continued_bits
;
820 x
= window_box_right (w
, -1);
821 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
824 case CONTINUATION_LINE_BITMAP
:
825 wd
= continuation_width
;
826 h
= continuation_height
;
827 bits
= continuation_bits
;
828 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
830 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
837 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
839 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
846 /* Convert to frame coordinates. Set dy to the offset in the row to
847 start drawing the bitmap. */
848 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
849 dy
= (row
->height
- h
) / 2;
851 /* Draw the bitmap. I believe these small pixmaps can be cached
853 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
854 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
856 face
->background
, depth
);
857 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
858 XFreePixmap (display
, pixmap
);
859 XSetClipMask (display
, gc
, None
);
863 /* Draw flags bitmaps for glyph row ROW on window W. Call this
864 function with input blocked. */
867 x_draw_row_bitmaps (w
, row
)
869 struct glyph_row
*row
;
871 struct frame
*f
= XFRAME (w
->frame
);
872 enum bitmap_type bitmap
;
874 int header_line_height
= -1;
876 xassert (interrupt_input_blocked
);
878 /* If row is completely invisible, because of vscrolling, we
879 don't have to draw anything. */
880 if (row
->visible_height
<= 0)
883 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
884 PREPARE_FACE_FOR_DISPLAY (f
, face
);
886 /* Decide which bitmap to draw at the left side. */
887 if (row
->overlay_arrow_p
)
888 bitmap
= OVERLAY_ARROW_BITMAP
;
889 else if (row
->truncated_on_left_p
)
890 bitmap
= LEFT_TRUNCATION_BITMAP
;
891 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
892 bitmap
= CONTINUATION_LINE_BITMAP
;
893 else if (row
->indicate_empty_line_p
)
894 bitmap
= ZV_LINE_BITMAP
;
898 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
900 if (bitmap
== NO_BITMAP
901 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
902 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
904 /* If W has a vertical border to its left, don't draw over it. */
905 int border
= ((XFASTINT (w
->left
) > 0
906 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
908 int left
= window_box_left (w
, -1);
910 if (header_line_height
< 0)
911 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
913 /* In case the same realized face is used for bitmap areas and
914 for something displayed in the text (e.g. face `region' on
915 mono-displays, the fill style may have been changed to
916 FillSolid in x_draw_glyph_string_background. */
918 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
920 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
922 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
925 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
927 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
929 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
930 row
->visible_height
);
932 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
935 /* Draw the left bitmap. */
936 if (bitmap
!= NO_BITMAP
)
937 x_draw_bitmap (w
, row
, bitmap
);
939 /* Decide which bitmap to draw at the right side. */
940 if (row
->truncated_on_right_p
)
941 bitmap
= RIGHT_TRUNCATION_BITMAP
;
942 else if (row
->continued_p
)
943 bitmap
= CONTINUED_LINE_BITMAP
;
947 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
949 if (bitmap
== NO_BITMAP
950 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
951 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
953 int right
= window_box_right (w
, -1);
955 if (header_line_height
< 0)
956 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
958 /* In case the same realized face is used for bitmap areas and
959 for something displayed in the text (e.g. face `region' on
960 mono-displays, the fill style may have been changed to
961 FillSolid in x_draw_glyph_string_background. */
963 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
965 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
966 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
969 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
971 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
972 row
->visible_height
);
974 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
977 /* Draw the right bitmap. */
978 if (bitmap
!= NO_BITMAP
)
979 x_draw_bitmap (w
, row
, bitmap
);
983 /***********************************************************************
985 ***********************************************************************/
987 /* External interface to control of standout mode. Not used for X
988 frames. Aborts when called. */
991 XTreassert_line_highlight (new, vpos
)
998 /* Call this when about to modify line at position VPOS and change
999 whether it is highlighted. Not used for X frames. Aborts when
1003 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1004 int new_highlight
, vpos
, y
, first_unused_hpos
;
1010 /* This is called when starting Emacs and when restarting after
1011 suspend. When starting Emacs, no X window is mapped. And nothing
1012 must be done to Emacs's own window if it is suspended (though that
1016 XTset_terminal_modes ()
1020 /* This is called when exiting or suspending Emacs. Exiting will make
1021 the X-windows go away, and suspending requires no action. */
1024 XTreset_terminal_modes ()
1030 /***********************************************************************
1032 ***********************************************************************/
1034 /* Set the global variable output_cursor to CURSOR. All cursor
1035 positions are relative to updated_window. */
1038 set_output_cursor (cursor
)
1039 struct cursor_pos
*cursor
;
1041 output_cursor
.hpos
= cursor
->hpos
;
1042 output_cursor
.vpos
= cursor
->vpos
;
1043 output_cursor
.x
= cursor
->x
;
1044 output_cursor
.y
= cursor
->y
;
1048 /* Set a nominal cursor position.
1050 HPOS and VPOS are column/row positions in a window glyph matrix. X
1051 and Y are window text area relative pixel positions.
1053 If this is done during an update, updated_window will contain the
1054 window that is being updated and the position is the future output
1055 cursor position for that window. If updated_window is null, use
1056 selected_window and display the cursor at the given position. */
1059 XTcursor_to (vpos
, hpos
, y
, x
)
1060 int vpos
, hpos
, y
, x
;
1064 /* If updated_window is not set, work on selected_window. */
1068 w
= XWINDOW (selected_window
);
1070 /* Set the output cursor. */
1071 output_cursor
.hpos
= hpos
;
1072 output_cursor
.vpos
= vpos
;
1073 output_cursor
.x
= x
;
1074 output_cursor
.y
= y
;
1076 /* If not called as part of an update, really display the cursor.
1077 This will also set the cursor position of W. */
1078 if (updated_window
== NULL
)
1081 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1082 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1089 /***********************************************************************
1091 ***********************************************************************/
1093 /* Function prototypes of this page. */
1095 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1099 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1100 int, XChar2b
*, int));
1101 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1102 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1103 static void x_append_glyph
P_ ((struct it
*));
1104 static void x_append_composite_glyph
P_ ((struct it
*));
1105 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1107 static void x_produce_glyphs
P_ ((struct it
*));
1108 static void x_produce_image_glyph
P_ ((struct it
*it
));
1111 /* Return a pointer to per-char metric information in FONT of a
1112 character pointed by B which is a pointer to an XChar2b. */
1114 #define PER_CHAR_METRIC(font, b) \
1116 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1117 + (((font)->min_byte1 || (font)->max_byte1) \
1118 ? (((b)->byte1 - (font)->min_byte1) \
1119 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1121 : &((font)->max_bounds))
1124 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1125 is not contained in the font. */
1127 static INLINE XCharStruct
*
1128 x_per_char_metric (font
, char2b
)
1132 /* The result metric information. */
1133 XCharStruct
*pcm
= NULL
;
1135 xassert (font
&& char2b
);
1137 if (font
->per_char
!= NULL
)
1139 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1141 /* min_char_or_byte2 specifies the linear character index
1142 corresponding to the first element of the per_char array,
1143 max_char_or_byte2 is the index of the last character. A
1144 character with non-zero CHAR2B->byte1 is not in the font.
1145 A character with byte2 less than min_char_or_byte2 or
1146 greater max_char_or_byte2 is not in the font. */
1147 if (char2b
->byte1
== 0
1148 && char2b
->byte2
>= font
->min_char_or_byte2
1149 && char2b
->byte2
<= font
->max_char_or_byte2
)
1150 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1154 /* If either min_byte1 or max_byte1 are nonzero, both
1155 min_char_or_byte2 and max_char_or_byte2 are less than
1156 256, and the 2-byte character index values corresponding
1157 to the per_char array element N (counting from 0) are:
1159 byte1 = N/D + min_byte1
1160 byte2 = N\D + min_char_or_byte2
1164 D = max_char_or_byte2 - min_char_or_byte2 + 1
1165 / = integer division
1166 \ = integer modulus */
1167 if (char2b
->byte1
>= font
->min_byte1
1168 && char2b
->byte1
<= font
->max_byte1
1169 && char2b
->byte2
>= font
->min_char_or_byte2
1170 && char2b
->byte2
<= font
->max_char_or_byte2
)
1172 pcm
= (font
->per_char
1173 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1174 * (char2b
->byte1
- font
->min_byte1
))
1175 + (char2b
->byte2
- font
->min_char_or_byte2
));
1181 /* If the per_char pointer is null, all glyphs between the first
1182 and last character indexes inclusive have the same
1183 information, as given by both min_bounds and max_bounds. */
1184 if (char2b
->byte2
>= font
->min_char_or_byte2
1185 && char2b
->byte2
<= font
->max_char_or_byte2
)
1186 pcm
= &font
->max_bounds
;
1189 return ((pcm
== NULL
1190 || pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0)
1195 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1196 the two-byte form of C. Encoding is returned in *CHAR2B. */
1199 x_encode_char (c
, char2b
, font_info
)
1202 struct font_info
*font_info
;
1204 int charset
= CHAR_CHARSET (c
);
1205 XFontStruct
*font
= font_info
->font
;
1207 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1208 This may be either a program in a special encoder language or a
1210 if (font_info
->font_encoder
)
1212 /* It's a program. */
1213 struct ccl_program
*ccl
= font_info
->font_encoder
;
1215 if (CHARSET_DIMENSION (charset
) == 1)
1217 ccl
->reg
[0] = charset
;
1218 ccl
->reg
[1] = char2b
->byte2
;
1222 ccl
->reg
[0] = charset
;
1223 ccl
->reg
[1] = char2b
->byte1
;
1224 ccl
->reg
[2] = char2b
->byte2
;
1227 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1229 /* We assume that MSBs are appropriately set/reset by CCL
1231 if (font
->max_byte1
== 0) /* 1-byte font */
1232 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1234 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1236 else if (font_info
->encoding
[charset
])
1238 /* Fixed encoding scheme. See fontset.h for the meaning of the
1239 encoding numbers. */
1240 int enc
= font_info
->encoding
[charset
];
1242 if ((enc
== 1 || enc
== 2)
1243 && CHARSET_DIMENSION (charset
) == 2)
1244 char2b
->byte1
|= 0x80;
1246 if (enc
== 1 || enc
== 3)
1247 char2b
->byte2
|= 0x80;
1252 /* Get face and two-byte form of character C in face FACE_ID on frame
1253 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1254 means we want to display multibyte text. Value is a pointer to a
1255 realized face that is ready for display. */
1257 static INLINE
struct face
*
1258 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1264 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1268 /* Unibyte case. We don't have to encode, but we have to make
1269 sure to use a face suitable for unibyte. */
1272 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1273 face
= FACE_FROM_ID (f
, face_id
);
1275 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1277 /* Case of ASCII in a face known to fit ASCII. */
1283 int c1
, c2
, charset
;
1285 /* Split characters into bytes. If c2 is -1 afterwards, C is
1286 really a one-byte character so that byte1 is zero. */
1287 SPLIT_CHAR (c
, charset
, c1
, c2
);
1289 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1291 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1293 /* Maybe encode the character in *CHAR2B. */
1294 if (face
->font
!= NULL
)
1296 struct font_info
*font_info
1297 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1299 x_encode_char (c
, char2b
, font_info
);
1303 /* Make sure X resources of the face are allocated. */
1304 xassert (face
!= NULL
);
1305 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1311 /* Get face and two-byte form of character glyph GLYPH on frame F.
1312 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1313 a pointer to a realized face that is ready for display. */
1315 static INLINE
struct face
*
1316 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1318 struct glyph
*glyph
;
1324 xassert (glyph
->type
== CHAR_GLYPH
);
1325 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1330 if (!glyph
->multibyte_p
)
1332 /* Unibyte case. We don't have to encode, but we have to make
1333 sure to use a face suitable for unibyte. */
1335 char2b
->byte2
= glyph
->u
.ch
;
1337 else if (glyph
->u
.ch
< 128
1338 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1340 /* Case of ASCII in a face known to fit ASCII. */
1342 char2b
->byte2
= glyph
->u
.ch
;
1346 int c1
, c2
, charset
;
1348 /* Split characters into bytes. If c2 is -1 afterwards, C is
1349 really a one-byte character so that byte1 is zero. */
1350 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1352 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1354 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1356 /* Maybe encode the character in *CHAR2B. */
1357 if (charset
!= CHARSET_ASCII
)
1359 struct font_info
*font_info
1360 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1363 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1366 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1371 /* Make sure X resources of the face are allocated. */
1372 xassert (face
!= NULL
);
1373 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1378 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1379 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1385 struct glyph
*glyph
;
1386 enum glyph_row_area area
= it
->area
;
1388 xassert (it
->glyph_row
);
1389 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1391 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1392 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1394 /* Play it safe. If sub-structures of the glyph are not all the
1395 same size, it otherwise be that some bits stay set. This
1396 would prevent a comparison with GLYPH_EQUAL_P. */
1399 glyph
->type
= CHAR_GLYPH
;
1400 glyph
->pixel_width
= it
->pixel_width
;
1401 glyph
->u
.ch
= it
->char_to_display
;
1402 glyph
->face_id
= it
->face_id
;
1403 glyph
->charpos
= CHARPOS (it
->position
);
1404 glyph
->object
= it
->object
;
1405 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1406 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1407 glyph
->voffset
= it
->voffset
;
1408 glyph
->multibyte_p
= it
->multibyte_p
;
1409 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1410 || it
->phys_descent
> it
->descent
);
1411 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1412 ++it
->glyph_row
->used
[area
];
1416 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1417 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1420 x_append_composite_glyph (it
)
1423 struct glyph
*glyph
;
1424 enum glyph_row_area area
= it
->area
;
1426 xassert (it
->glyph_row
);
1428 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1429 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1431 /* Play it safe. If sub-structures of the glyph are not all the
1432 same size, it otherwise be that some bits stay set. This
1433 would prevent a comparison with GLYPH_EQUAL_P. */
1436 glyph
->type
= COMPOSITE_GLYPH
;
1437 glyph
->pixel_width
= it
->pixel_width
;
1438 glyph
->u
.cmp_id
= it
->cmp_id
;
1439 glyph
->face_id
= it
->face_id
;
1440 glyph
->charpos
= CHARPOS (it
->position
);
1441 glyph
->object
= it
->object
;
1442 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1443 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1444 glyph
->voffset
= it
->voffset
;
1445 glyph
->multibyte_p
= it
->multibyte_p
;
1446 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1447 || it
->phys_descent
> it
->descent
);
1448 ++it
->glyph_row
->used
[area
];
1453 /* Change IT->ascent and IT->height according to the setting of
1457 take_vertical_position_into_account (it
)
1462 if (it
->voffset
< 0)
1463 /* Increase the ascent so that we can display the text higher
1465 it
->ascent
+= abs (it
->voffset
);
1467 /* Increase the descent so that we can display the text lower
1469 it
->descent
+= it
->voffset
;
1474 /* Produce glyphs/get display metrics for the image IT is loaded with.
1475 See the description of struct display_iterator in dispextern.h for
1476 an overview of struct display_iterator. */
1479 x_produce_image_glyph (it
)
1485 xassert (it
->what
== IT_IMAGE
);
1487 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1488 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1491 /* Make sure X resources of the face and image are loaded. */
1492 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1493 prepare_image_for_display (it
->f
, img
);
1495 it
->ascent
= it
->phys_ascent
= IMAGE_ASCENT (img
);
1496 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->margin
- it
->ascent
;
1497 it
->pixel_width
= img
->width
+ 2 * img
->margin
;
1501 if (face
->box
!= FACE_NO_BOX
)
1503 it
->ascent
+= face
->box_line_width
;
1504 it
->descent
+= face
->box_line_width
;
1506 if (it
->start_of_box_run_p
)
1507 it
->pixel_width
+= face
->box_line_width
;
1508 if (it
->end_of_box_run_p
)
1509 it
->pixel_width
+= face
->box_line_width
;
1512 take_vertical_position_into_account (it
);
1516 struct glyph
*glyph
;
1517 enum glyph_row_area area
= it
->area
;
1519 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1520 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1522 glyph
->type
= IMAGE_GLYPH
;
1523 glyph
->u
.img_id
= img
->id
;
1524 glyph
->face_id
= it
->face_id
;
1525 glyph
->pixel_width
= it
->pixel_width
;
1526 glyph
->charpos
= CHARPOS (it
->position
);
1527 glyph
->object
= it
->object
;
1528 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1529 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1530 glyph
->voffset
= it
->voffset
;
1531 glyph
->multibyte_p
= it
->multibyte_p
;
1532 ++it
->glyph_row
->used
[area
];
1538 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1539 of the glyph, WIDTH and HEIGHT are the width and height of the
1540 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1541 ascent of the glyph (0 <= ASCENT <= 1). */
1544 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1550 struct glyph
*glyph
;
1551 enum glyph_row_area area
= it
->area
;
1553 xassert (ascent
>= 0 && ascent
<= 1);
1555 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1556 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1558 glyph
->type
= STRETCH_GLYPH
;
1559 glyph
->u
.stretch
.ascent
= height
* ascent
;
1560 glyph
->u
.stretch
.height
= height
;
1561 glyph
->face_id
= it
->face_id
;
1562 glyph
->pixel_width
= width
;
1563 glyph
->charpos
= CHARPOS (it
->position
);
1564 glyph
->object
= object
;
1565 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1566 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1567 glyph
->voffset
= it
->voffset
;
1568 glyph
->multibyte_p
= it
->multibyte_p
;
1569 ++it
->glyph_row
->used
[area
];
1574 /* Produce a stretch glyph for iterator IT. IT->object is the value
1575 of the glyph property displayed. The value must be a list
1576 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1579 1. `:width WIDTH' specifies that the space should be WIDTH *
1580 canonical char width wide. WIDTH may be an integer or floating
1583 2. `:relative-width FACTOR' specifies that the width of the stretch
1584 should be computed from the width of the first character having the
1585 `glyph' property, and should be FACTOR times that width.
1587 3. `:align-to HPOS' specifies that the space should be wide enough
1588 to reach HPOS, a value in canonical character units.
1590 Exactly one of the above pairs must be present.
1592 4. `:height HEIGHT' specifies that the height of the stretch produced
1593 should be HEIGHT, measured in canonical character units.
1595 5. `:relative-height FACTOR' specifies that the height of the the
1596 stretch should be FACTOR times the height of the characters having
1599 Either none or exactly one of 4 or 5 must be present.
1601 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1602 of the stretch should be used for the ascent of the stretch.
1603 ASCENT must be in the range 0 <= ASCENT <= 100. */
1606 ((INTEGERP (X) || FLOATP (X)) \
1612 x_produce_stretch_glyph (it
)
1615 /* (space :width WIDTH :height HEIGHT. */
1616 extern Lisp_Object QCwidth
, QCheight
, QCascent
, Qspace
;
1617 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1618 extern Lisp_Object QCalign_to
;
1619 Lisp_Object prop
, plist
;
1620 double width
= 0, height
= 0, ascent
= 0;
1621 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1622 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1624 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1626 /* List should start with `space'. */
1627 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1628 plist
= XCDR (it
->object
);
1630 /* Compute the width of the stretch. */
1631 if (prop
= Fplist_get (plist
, QCwidth
),
1633 /* Absolute width `:width WIDTH' specified and valid. */
1634 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1635 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1638 /* Relative width `:relative-width FACTOR' specified and valid.
1639 Compute the width of the characters having the `glyph'
1642 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1645 if (it
->multibyte_p
)
1647 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1648 - IT_BYTEPOS (*it
));
1649 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1652 it2
.c
= *p
, it2
.len
= 1;
1654 it2
.glyph_row
= NULL
;
1655 it2
.what
= IT_CHARACTER
;
1656 x_produce_glyphs (&it2
);
1657 width
= NUMVAL (prop
) * it2
.pixel_width
;
1659 else if (prop
= Fplist_get (plist
, QCalign_to
),
1661 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1663 /* Nothing specified -> width defaults to canonical char width. */
1664 width
= CANON_X_UNIT (it
->f
);
1666 /* Compute height. */
1667 if (prop
= Fplist_get (plist
, QCheight
),
1669 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1670 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1672 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1674 height
= FONT_HEIGHT (font
);
1676 /* Compute percentage of height used for ascent. If
1677 `:ascent ASCENT' is present and valid, use that. Otherwise,
1678 derive the ascent from the font in use. */
1679 if (prop
= Fplist_get (plist
, QCascent
),
1680 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1681 ascent
= NUMVAL (prop
) / 100.0;
1683 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1692 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1693 if (!STRINGP (object
))
1694 object
= it
->w
->buffer
;
1695 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1698 it
->pixel_width
= width
;
1699 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1700 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1703 if (face
->box
!= FACE_NO_BOX
)
1705 it
->ascent
+= face
->box_line_width
;
1706 it
->descent
+= face
->box_line_width
;
1708 if (it
->start_of_box_run_p
)
1709 it
->pixel_width
+= face
->box_line_width
;
1710 if (it
->end_of_box_run_p
)
1711 it
->pixel_width
+= face
->box_line_width
;
1714 take_vertical_position_into_account (it
);
1717 /* Return proper value to be used as baseline offset of font that has
1718 ASCENT and DESCENT to draw characters by the font at the vertical
1719 center of the line of frame F.
1721 Here, out task is to find the value of BOFF in the following figure;
1723 -------------------------+-----------+-
1724 -+-+---------+-+ | |
1726 | | | | F_ASCENT F_HEIGHT
1729 | | |-|-+------+-----------|------- baseline
1731 | |---------|-+-+ | |
1733 -+-+---------+-+ F_DESCENT |
1734 -------------------------+-----------+-
1736 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1737 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1738 DESCENT = FONT->descent
1739 HEIGHT = FONT_HEIGHT (FONT)
1740 F_DESCENT = (F->output_data.x->font->descent
1741 - F->output_data.x->baseline_offset)
1742 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1745 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1747 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT))) / 2 \
1748 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1750 /* Produce glyphs/get display metrics for the display element IT is
1751 loaded with. See the description of struct display_iterator in
1752 dispextern.h for an overview of struct display_iterator. */
1755 x_produce_glyphs (it
)
1758 it
->glyph_not_available_p
= 0;
1760 if (it
->what
== IT_CHARACTER
)
1764 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1766 int font_not_found_p
;
1767 struct font_info
*font_info
;
1768 int boff
; /* baseline offset */
1770 /* Maybe translate single-byte characters to multibyte, or the
1772 it
->char_to_display
= it
->c
;
1773 if (!ASCII_BYTE_P (it
->c
))
1775 if (unibyte_display_via_language_environment
1776 && SINGLE_BYTE_CHAR_P (it
->c
)
1778 || !NILP (Vnonascii_translation_table
)))
1780 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1781 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1782 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1784 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1785 && !it
->multibyte_p
)
1787 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1788 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1789 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1793 /* Get font to use. Encode IT->char_to_display. */
1794 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1795 it
->face_id
, &char2b
,
1799 /* When no suitable font found, use the default font. */
1800 font_not_found_p
= font
== NULL
;
1801 if (font_not_found_p
)
1803 font
= FRAME_FONT (it
->f
);
1804 boff
= it
->f
->output_data
.x
->baseline_offset
;
1809 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1810 boff
= font_info
->baseline_offset
;
1811 if (font_info
->vertical_centering
)
1812 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1815 if (it
->char_to_display
>= ' '
1816 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1818 /* Either unibyte or ASCII. */
1823 pcm
= x_per_char_metric (font
, &char2b
);
1824 it
->ascent
= font
->ascent
+ boff
;
1825 it
->descent
= font
->descent
- boff
;
1829 it
->phys_ascent
= pcm
->ascent
+ boff
;
1830 it
->phys_descent
= pcm
->descent
- boff
;
1831 it
->pixel_width
= pcm
->width
;
1835 it
->glyph_not_available_p
= 1;
1836 it
->phys_ascent
= font
->ascent
+ boff
;
1837 it
->phys_descent
= font
->descent
- boff
;
1838 it
->pixel_width
= FONT_WIDTH (font
);
1841 /* If this is a space inside a region of text with
1842 `space-width' property, change its width. */
1843 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1845 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1847 /* If face has a box, add the box thickness to the character
1848 height. If character has a box line to the left and/or
1849 right, add the box line width to the character's width. */
1850 if (face
->box
!= FACE_NO_BOX
)
1852 int thick
= face
->box_line_width
;
1854 it
->ascent
+= thick
;
1855 it
->descent
+= thick
;
1857 if (it
->start_of_box_run_p
)
1858 it
->pixel_width
+= thick
;
1859 if (it
->end_of_box_run_p
)
1860 it
->pixel_width
+= thick
;
1863 /* If face has an overline, add the height of the overline
1864 (1 pixel) and a 1 pixel margin to the character height. */
1865 if (face
->overline_p
)
1868 take_vertical_position_into_account (it
);
1870 /* If we have to actually produce glyphs, do it. */
1875 /* Translate a space with a `space-width' property
1876 into a stretch glyph. */
1877 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1878 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1879 it
->ascent
+ it
->descent
, ascent
);
1882 x_append_glyph (it
);
1884 /* If characters with lbearing or rbearing are displayed
1885 in this line, record that fact in a flag of the
1886 glyph row. This is used to optimize X output code. */
1887 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1888 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1891 else if (it
->char_to_display
== '\n')
1893 /* A newline has no width but we need the height of the line. */
1894 it
->pixel_width
= 0;
1896 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1897 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1899 if (face
->box
!= FACE_NO_BOX
)
1901 int thick
= face
->box_line_width
;
1902 it
->ascent
+= thick
;
1903 it
->descent
+= thick
;
1906 else if (it
->char_to_display
== '\t')
1908 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1909 int x
= it
->current_x
+ it
->continuation_lines_width
;
1910 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1912 it
->pixel_width
= next_tab_x
- x
;
1914 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1915 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1919 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1920 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1921 it
->ascent
+ it
->descent
, ascent
);
1926 /* A multi-byte character. Assume that the display width of the
1927 character is the width of the character multiplied by the
1928 width of the font. */
1930 /* If we found a font, this font should give us the right
1931 metrics. If we didn't find a font, use the frame's
1932 default font and calculate the width of the character
1933 from the charset width; this is what old redisplay code
1935 pcm
= x_per_char_metric (font
, &char2b
);
1936 if (font_not_found_p
|| !pcm
)
1938 int charset
= CHAR_CHARSET (it
->char_to_display
);
1940 it
->glyph_not_available_p
= 1;
1941 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1942 * CHARSET_WIDTH (charset
));
1943 it
->phys_ascent
= font
->ascent
+ boff
;
1944 it
->phys_descent
= font
->descent
- boff
;
1948 it
->pixel_width
= pcm
->width
;
1949 it
->phys_ascent
= pcm
->ascent
+ boff
;
1950 it
->phys_descent
= pcm
->descent
- boff
;
1952 && (pcm
->lbearing
< 0
1953 || pcm
->rbearing
> pcm
->width
))
1954 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1957 it
->ascent
= font
->ascent
+ boff
;
1958 it
->descent
= font
->descent
- boff
;
1959 if (face
->box
!= FACE_NO_BOX
)
1961 int thick
= face
->box_line_width
;
1962 it
->ascent
+= thick
;
1963 it
->descent
+= thick
;
1965 if (it
->start_of_box_run_p
)
1966 it
->pixel_width
+= thick
;
1967 if (it
->end_of_box_run_p
)
1968 it
->pixel_width
+= thick
;
1971 /* If face has an overline, add the height of the overline
1972 (1 pixel) and a 1 pixel margin to the character height. */
1973 if (face
->overline_p
)
1976 take_vertical_position_into_account (it
);
1979 x_append_glyph (it
);
1982 else if (it
->what
== IT_COMPOSITION
)
1984 /* Note: A composition is represented as one glyph in the
1985 glyph matrix. There are no padding glyphs. */
1988 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1990 int font_not_found_p
;
1991 struct font_info
*font_info
;
1992 int boff
; /* baseline offset */
1993 struct composition
*cmp
= composition_table
[it
->cmp_id
];
1995 /* Maybe translate single-byte characters to multibyte. */
1996 it
->char_to_display
= it
->c
;
1997 if (unibyte_display_via_language_environment
1998 && SINGLE_BYTE_CHAR_P (it
->c
)
2001 && !NILP (Vnonascii_translation_table
))))
2003 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2006 /* Get face and font to use. Encode IT->char_to_display. */
2007 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2008 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2009 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2010 it
->face_id
, &char2b
, it
->multibyte_p
);
2013 /* When no suitable font found, use the default font. */
2014 font_not_found_p
= font
== NULL
;
2015 if (font_not_found_p
)
2017 font
= FRAME_FONT (it
->f
);
2018 boff
= it
->f
->output_data
.x
->baseline_offset
;
2023 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2024 boff
= font_info
->baseline_offset
;
2025 if (font_info
->vertical_centering
)
2026 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2029 /* There are no padding glyphs, so there is only one glyph to
2030 produce for the composition. Important is that pixel_width,
2031 ascent and descent are the values of what is drawn by
2032 draw_glyphs (i.e. the values of the overall glyphs composed). */
2035 /* If we have not yet calculated pixel size data of glyphs of
2036 the composition for the current face font, calculate them
2037 now. Theoretically, we have to check all fonts for the
2038 glyphs, but that requires much time and memory space. So,
2039 here we check only the font of the first glyph. This leads
2040 to incorrect display very rarely, and C-l (recenter) can
2041 correct the display anyway. */
2042 if (cmp
->font
!= (void *) font
)
2044 /* Ascent and descent of the font of the first character of
2045 this composition (adjusted by baseline offset). Ascent
2046 and descent of overall glyphs should not be less than
2047 them respectively. */
2048 int font_ascent
= font
->ascent
+ boff
;
2049 int font_descent
= font
->descent
- boff
;
2050 /* Bounding box of the overall glyphs. */
2051 int leftmost
, rightmost
, lowest
, highest
;
2054 cmp
->font
= (void *) font
;
2056 /* Initialize the bounding box. */
2057 pcm
= x_per_char_metric (font
, &char2b
);
2059 rightmost
= pcm
->width
;
2060 lowest
= - pcm
->descent
+ boff
;
2061 highest
= pcm
->ascent
+ boff
;
2063 && font_info
->default_ascent
2064 && CHAR_TABLE_P (Vuse_default_ascent
)
2065 && !NILP (Faref (Vuse_default_ascent
,
2066 make_number (it
->char_to_display
))))
2067 highest
= font_info
->default_ascent
+ boff
;
2069 /* Draw the first glyph at the normal position. It may be
2070 shifted to right later if some other glyphs are drawn at
2072 cmp
->offsets
[0] = 0;
2073 cmp
->offsets
[1] = boff
;
2075 /* Set cmp->offsets for the remaining glyphs. */
2076 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2078 int left
, right
, btm
, top
;
2079 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2080 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2082 face
= FACE_FROM_ID (it
->f
, face_id
);
2083 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2088 font
= FRAME_FONT (it
->f
);
2089 boff
= it
->f
->output_data
.x
->baseline_offset
;
2095 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2096 boff
= font_info
->baseline_offset
;
2097 if (font_info
->vertical_centering
)
2098 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2101 pcm
= x_per_char_metric (font
, &char2b
);
2103 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2105 /* Relative composition with or without
2107 left
= (leftmost
+ rightmost
- pcm
->width
) / 2;
2108 btm
= - pcm
->descent
+ boff
;
2109 if (font_info
&& font_info
->relative_compose
2110 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2111 || NILP (Faref (Vignore_relative_composition
,
2112 make_number (ch
)))))
2116 >= font_info
->relative_compose
)
2117 /* One extra pixel between two glyphs. */
2119 else if (pcm
->ascent
<= 0)
2120 /* One extra pixel between two glyphs. */
2121 btm
= lowest
- 1 - pcm
->ascent
- pcm
->descent
;
2126 /* A composition rule is specified by an integer
2127 value that encodes global and new reference
2128 points (GREF and NREF). GREF and NREF are
2129 specified by numbers as below:
2137 ---3---4---5--- baseline
2139 6---7---8 -- descent
2141 int rule
= COMPOSITION_RULE (cmp
, i
);
2142 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2144 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2145 grefx
= gref
% 3, nrefx
= nref
% 3;
2146 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2149 + grefx
* (rightmost
- leftmost
) / 2
2150 - nrefx
* pcm
->width
/ 2);
2151 btm
= ((grefy
== 0 ? highest
2153 : grefy
== 2 ? lowest
2154 : (highest
+ lowest
) / 2)
2155 - (nrefy
== 0 ? pcm
->ascent
+ pcm
->descent
2156 : nrefy
== 1 ? pcm
->descent
- boff
2158 : (pcm
->ascent
+ pcm
->descent
) / 2));
2161 cmp
->offsets
[i
* 2] = left
;
2162 cmp
->offsets
[i
* 2 + 1] = btm
+ pcm
->descent
;
2164 /* Update the bounding box of the overall glyphs. */
2165 right
= left
+ pcm
->width
;
2166 top
= btm
+ pcm
->descent
+ pcm
->ascent
;
2167 if (left
< leftmost
)
2169 if (right
> rightmost
)
2177 /* If there are glyphs whose x-offsets are negative,
2178 shift all glyphs to the right and make all x-offsets
2182 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2183 cmp
->offsets
[i
* 2] -= leftmost
;
2184 rightmost
-= leftmost
;
2187 cmp
->pixel_width
= rightmost
;
2188 cmp
->ascent
= highest
;
2189 cmp
->descent
= - lowest
;
2190 if (cmp
->ascent
< font_ascent
)
2191 cmp
->ascent
= font_ascent
;
2192 if (cmp
->descent
< font_descent
)
2193 cmp
->descent
= font_descent
;
2196 it
->pixel_width
= cmp
->pixel_width
;
2197 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2198 it
->descent
= it
->phys_descent
= cmp
->descent
;
2200 if (face
->box
!= FACE_NO_BOX
)
2202 int thick
= face
->box_line_width
;
2203 it
->ascent
+= thick
;
2204 it
->descent
+= thick
;
2206 if (it
->start_of_box_run_p
)
2207 it
->pixel_width
+= thick
;
2208 if (it
->end_of_box_run_p
)
2209 it
->pixel_width
+= thick
;
2212 /* If face has an overline, add the height of the overline
2213 (1 pixel) and a 1 pixel margin to the character height. */
2214 if (face
->overline_p
)
2217 take_vertical_position_into_account (it
);
2220 x_append_composite_glyph (it
);
2222 else if (it
->what
== IT_IMAGE
)
2223 x_produce_image_glyph (it
);
2224 else if (it
->what
== IT_STRETCH
)
2225 x_produce_stretch_glyph (it
);
2227 /* Accumulate dimensions. */
2228 xassert (it
->ascent
>= 0 && it
->descent
> 0);
2229 if (it
->area
== TEXT_AREA
)
2230 it
->current_x
+= it
->pixel_width
;
2232 it
->descent
+= it
->extra_line_spacing
;
2234 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2235 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2236 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2237 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2241 /* Estimate the pixel height of the mode or top line on frame F.
2242 FACE_ID specifies what line's height to estimate. */
2245 x_estimate_mode_line_height (f
, face_id
)
2247 enum face_id face_id
;
2251 /* This function is called so early when Emacs starts that the face
2252 cache and mode line face are not yet initialized. */
2253 if (FRAME_FACE_CACHE (f
))
2255 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2257 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
2264 /***********************************************************************
2266 ***********************************************************************/
2268 /* A sequence of glyphs to be drawn in the same face.
2270 This data structure is not really completely X specific, so it
2271 could possibly, at least partially, be useful for other systems. It
2272 is currently not part of the external redisplay interface because
2273 it's not clear what other systems will need. */
2277 /* X-origin of the string. */
2280 /* Y-origin and y-position of the base line of this string. */
2283 /* The width of the string, not including a face extension. */
2286 /* The width of the string, including a face extension. */
2287 int background_width
;
2289 /* The height of this string. This is the height of the line this
2290 string is drawn in, and can be different from the height of the
2291 font the string is drawn in. */
2294 /* Number of pixels this string overwrites in front of its x-origin.
2295 This number is zero if the string has an lbearing >= 0; it is
2296 -lbearing, if the string has an lbearing < 0. */
2299 /* Number of pixels this string overwrites past its right-most
2300 nominal x-position, i.e. x + width. Zero if the string's
2301 rbearing is <= its nominal width, rbearing - width otherwise. */
2304 /* The frame on which the glyph string is drawn. */
2307 /* The window on which the glyph string is drawn. */
2310 /* X display and window for convenience. */
2314 /* The glyph row for which this string was built. It determines the
2315 y-origin and height of the string. */
2316 struct glyph_row
*row
;
2318 /* The area within row. */
2319 enum glyph_row_area area
;
2321 /* Characters to be drawn, and number of characters. */
2325 /* A face-override for drawing cursors, mouse face and similar. */
2326 enum draw_glyphs_face hl
;
2328 /* Face in which this string is to be drawn. */
2331 /* Font in which this string is to be drawn. */
2334 /* Font info for this string. */
2335 struct font_info
*font_info
;
2337 /* Non-null means this string describes (part of) a composition.
2338 All characters from char2b are drawn composed. */
2339 struct composition
*cmp
;
2341 /* Index of this glyph string's first character in the glyph
2342 definition of CMP. If this is zero, this glyph string describes
2343 the first character of a composition. */
2346 /* 1 means this glyph strings face has to be drawn to the right end
2347 of the window's drawing area. */
2348 unsigned extends_to_end_of_line_p
: 1;
2350 /* 1 means the background of this string has been drawn. */
2351 unsigned background_filled_p
: 1;
2353 /* 1 means glyph string must be drawn with 16-bit functions. */
2354 unsigned two_byte_p
: 1;
2356 /* 1 means that the original font determined for drawing this glyph
2357 string could not be loaded. The member `font' has been set to
2358 the frame's default font in this case. */
2359 unsigned font_not_found_p
: 1;
2361 /* 1 means that the face in which this glyph string is drawn has a
2363 unsigned stippled_p
: 1;
2365 /* 1 means only the foreground of this glyph string must be drawn,
2366 and we should use the physical height of the line this glyph
2367 string appears in as clip rect. */
2368 unsigned for_overlaps_p
: 1;
2370 /* The GC to use for drawing this glyph string. */
2373 /* A pointer to the first glyph in the string. This glyph
2374 corresponds to char2b[0]. Needed to draw rectangles if
2375 font_not_found_p is 1. */
2376 struct glyph
*first_glyph
;
2378 /* Image, if any. */
2381 struct glyph_string
*next
, *prev
;
2388 x_dump_glyph_string (s
)
2389 struct glyph_string
*s
;
2391 fprintf (stderr
, "glyph string\n");
2392 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2393 s
->x
, s
->y
, s
->width
, s
->height
);
2394 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2395 fprintf (stderr
, " hl = %d\n", s
->hl
);
2396 fprintf (stderr
, " left overhang = %d, right = %d\n",
2397 s
->left_overhang
, s
->right_overhang
);
2398 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2399 fprintf (stderr
, " extends to end of line = %d\n",
2400 s
->extends_to_end_of_line_p
);
2401 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2402 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2405 #endif /* GLYPH_DEBUG */
2409 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2410 struct glyph_string
**,
2411 struct glyph_string
*,
2412 struct glyph_string
*));
2413 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2414 struct glyph_string
**,
2415 struct glyph_string
*,
2416 struct glyph_string
*));
2417 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2418 struct glyph_string
**,
2419 struct glyph_string
*));
2420 static int x_left_overwritten
P_ ((struct glyph_string
*));
2421 static int x_left_overwriting
P_ ((struct glyph_string
*));
2422 static int x_right_overwritten
P_ ((struct glyph_string
*));
2423 static int x_right_overwriting
P_ ((struct glyph_string
*));
2424 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2426 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2427 XChar2b
*, struct window
*,
2429 enum glyph_row_area
, int,
2430 enum draw_glyphs_face
));
2431 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2432 enum glyph_row_area
, int, int,
2433 enum draw_glyphs_face
, int *, int *, int));
2434 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2435 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2436 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2438 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2439 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2440 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2441 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2442 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2443 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2444 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2445 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2446 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2448 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2449 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2450 unsigned long *, double, int));
2451 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2452 double, int, unsigned long));
2453 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2454 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2455 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2456 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2457 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2458 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2459 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2461 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2462 int, int, int, int, XRectangle
*));
2463 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2464 int, int, int, XRectangle
*));
2465 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2466 enum glyph_row_area
));
2469 /* Append the list of glyph strings with head H and tail T to the list
2470 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2473 x_append_glyph_string_lists (head
, tail
, h
, t
)
2474 struct glyph_string
**head
, **tail
;
2475 struct glyph_string
*h
, *t
;
2489 /* Prepend the list of glyph strings with head H and tail T to the
2490 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2494 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2495 struct glyph_string
**head
, **tail
;
2496 struct glyph_string
*h
, *t
;
2510 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2511 Set *HEAD and *TAIL to the resulting list. */
2514 x_append_glyph_string (head
, tail
, s
)
2515 struct glyph_string
**head
, **tail
;
2516 struct glyph_string
*s
;
2518 s
->next
= s
->prev
= NULL
;
2519 x_append_glyph_string_lists (head
, tail
, s
, s
);
2523 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2528 struct glyph_string
*s
;
2530 if (s
->font
== FRAME_FONT (s
->f
)
2531 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2532 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2534 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2537 /* Cursor on non-default face: must merge. */
2541 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2542 xgcv
.foreground
= s
->face
->background
;
2544 /* If the glyph would be invisible, try a different foreground. */
2545 if (xgcv
.foreground
== xgcv
.background
)
2546 xgcv
.foreground
= s
->face
->foreground
;
2547 if (xgcv
.foreground
== xgcv
.background
)
2548 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2549 if (xgcv
.foreground
== xgcv
.background
)
2550 xgcv
.foreground
= s
->face
->foreground
;
2552 /* Make sure the cursor is distinct from text in this face. */
2553 if (xgcv
.background
== s
->face
->background
2554 && xgcv
.foreground
== s
->face
->foreground
)
2556 xgcv
.background
= s
->face
->foreground
;
2557 xgcv
.foreground
= s
->face
->background
;
2560 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2561 xgcv
.font
= s
->font
->fid
;
2562 xgcv
.graphics_exposures
= False
;
2563 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2565 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2566 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2569 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2570 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2572 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2577 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2580 x_set_mouse_face_gc (s
)
2581 struct glyph_string
*s
;
2586 /* What face has to be used for the mouse face? */
2587 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2588 face
= FACE_FROM_ID (s
->f
, face_id
);
2589 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2590 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2591 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2593 /* If font in this face is same as S->font, use it. */
2594 if (s
->font
== s
->face
->font
)
2595 s
->gc
= s
->face
->gc
;
2598 /* Otherwise construct scratch_cursor_gc with values from FACE
2603 xgcv
.background
= s
->face
->background
;
2604 xgcv
.foreground
= s
->face
->foreground
;
2605 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2606 xgcv
.font
= s
->font
->fid
;
2607 xgcv
.graphics_exposures
= False
;
2608 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2610 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2611 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2614 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2615 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2617 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2620 xassert (s
->gc
!= 0);
2624 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2625 Faces to use in the mode line have already been computed when the
2626 matrix was built, so there isn't much to do, here. */
2629 x_set_mode_line_face_gc (s
)
2630 struct glyph_string
*s
;
2632 s
->gc
= s
->face
->gc
;
2633 xassert (s
->gc
!= 0);
2637 /* Set S->gc of glyph string S for drawing that glyph string. Set
2638 S->stippled_p to a non-zero value if the face of S has a stipple
2642 x_set_glyph_string_gc (s
)
2643 struct glyph_string
*s
;
2645 if (s
->hl
== DRAW_NORMAL_TEXT
)
2647 s
->gc
= s
->face
->gc
;
2648 s
->stippled_p
= s
->face
->stipple
!= 0;
2650 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2652 x_set_mode_line_face_gc (s
);
2653 s
->stippled_p
= s
->face
->stipple
!= 0;
2655 else if (s
->hl
== DRAW_CURSOR
)
2657 x_set_cursor_gc (s
);
2660 else if (s
->hl
== DRAW_MOUSE_FACE
)
2662 x_set_mouse_face_gc (s
);
2663 s
->stippled_p
= s
->face
->stipple
!= 0;
2665 else if (s
->hl
== DRAW_IMAGE_RAISED
2666 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2668 s
->gc
= s
->face
->gc
;
2669 s
->stippled_p
= s
->face
->stipple
!= 0;
2673 s
->gc
= s
->face
->gc
;
2674 s
->stippled_p
= s
->face
->stipple
!= 0;
2677 /* GC must have been set. */
2678 xassert (s
->gc
!= 0);
2682 /* Return in *R the clipping rectangle for glyph string S. */
2685 x_get_glyph_string_clip_rect (s
, r
)
2686 struct glyph_string
*s
;
2689 if (s
->row
->full_width_p
)
2691 /* Draw full-width. X coordinates are relative to S->w->left. */
2692 int canon_x
= CANON_X_UNIT (s
->f
);
2694 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2695 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2697 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2699 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2700 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2704 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2706 /* Unless displaying a mode or menu bar line, which are always
2707 fully visible, clip to the visible part of the row. */
2708 if (s
->w
->pseudo_window_p
)
2709 r
->height
= s
->row
->visible_height
;
2711 r
->height
= s
->height
;
2715 /* This is a text line that may be partially visible. */
2716 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2717 r
->width
= window_box_width (s
->w
, s
->area
);
2718 r
->height
= s
->row
->visible_height
;
2721 /* Don't use S->y for clipping because it doesn't take partially
2722 visible lines into account. For example, it can be negative for
2723 partially visible lines at the top of a window. */
2724 if (!s
->row
->full_width_p
2725 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2726 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2728 r
->y
= max (0, s
->row
->y
);
2730 /* If drawing a tool-bar window, draw it over the internal border
2731 at the top of the window. */
2732 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2733 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2735 /* If S draws overlapping rows, it's sufficient to use the top and
2736 bottom of the window for clipping because this glyph string
2737 intentionally draws over other lines. */
2738 if (s
->for_overlaps_p
)
2740 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2741 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2744 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2748 /* Set clipping for output of glyph string S. S may be part of a mode
2749 line or menu if we don't have X toolkit support. */
2752 x_set_glyph_string_clipping (s
)
2753 struct glyph_string
*s
;
2756 x_get_glyph_string_clip_rect (s
, &r
);
2757 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2761 /* Compute left and right overhang of glyph string S. If S is a glyph
2762 string for a composition, assume overhangs don't exist. */
2765 x_compute_glyph_string_overhangs (s
)
2766 struct glyph_string
*s
;
2769 && s
->first_glyph
->type
== CHAR_GLYPH
)
2772 int direction
, font_ascent
, font_descent
;
2773 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2774 &font_ascent
, &font_descent
, &cs
);
2775 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2776 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2781 /* Compute overhangs and x-positions for glyph string S and its
2782 predecessors, or successors. X is the starting x-position for S.
2783 BACKWARD_P non-zero means process predecessors. */
2786 x_compute_overhangs_and_x (s
, x
, backward_p
)
2787 struct glyph_string
*s
;
2795 x_compute_glyph_string_overhangs (s
);
2805 x_compute_glyph_string_overhangs (s
);
2814 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2815 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2816 assumed to be zero. */
2819 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2820 struct glyph
*glyph
;
2828 if (glyph
->type
== CHAR_GLYPH
)
2832 struct font_info
*font_info
;
2836 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2838 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2840 && (pcm
= x_per_char_metric (font
, &char2b
)))
2842 if (pcm
->rbearing
> pcm
->width
)
2843 *right
= pcm
->rbearing
- pcm
->width
;
2844 if (pcm
->lbearing
< 0)
2845 *left
= -pcm
->lbearing
;
2851 /* Return the index of the first glyph preceding glyph string S that
2852 is overwritten by S because of S's left overhang. Value is -1
2853 if no glyphs are overwritten. */
2856 x_left_overwritten (s
)
2857 struct glyph_string
*s
;
2861 if (s
->left_overhang
)
2864 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2865 int first
= s
->first_glyph
- glyphs
;
2867 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2868 x
-= glyphs
[i
].pixel_width
;
2879 /* Return the index of the first glyph preceding glyph string S that
2880 is overwriting S because of its right overhang. Value is -1 if no
2881 glyph in front of S overwrites S. */
2884 x_left_overwriting (s
)
2885 struct glyph_string
*s
;
2888 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2889 int first
= s
->first_glyph
- glyphs
;
2893 for (i
= first
- 1; i
>= 0; --i
)
2896 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2899 x
-= glyphs
[i
].pixel_width
;
2906 /* Return the index of the last glyph following glyph string S that is
2907 not overwritten by S because of S's right overhang. Value is -1 if
2908 no such glyph is found. */
2911 x_right_overwritten (s
)
2912 struct glyph_string
*s
;
2916 if (s
->right_overhang
)
2919 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2920 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2921 int end
= s
->row
->used
[s
->area
];
2923 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
2924 x
+= glyphs
[i
].pixel_width
;
2933 /* Return the index of the last glyph following glyph string S that
2934 overwrites S because of its left overhang. Value is negative
2935 if no such glyph is found. */
2938 x_right_overwriting (s
)
2939 struct glyph_string
*s
;
2942 int end
= s
->row
->used
[s
->area
];
2943 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2944 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2948 for (i
= first
; i
< end
; ++i
)
2951 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2954 x
+= glyphs
[i
].pixel_width
;
2961 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2964 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2965 struct glyph_string
*s
;
2969 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
2970 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2971 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2972 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2976 /* Draw the background of glyph_string S. If S->background_filled_p
2977 is non-zero don't draw it. FORCE_P non-zero means draw the
2978 background even if it wouldn't be drawn normally. This is used
2979 when a string preceding S draws into the background of S, or S
2980 contains the first component of a composition. */
2983 x_draw_glyph_string_background (s
, force_p
)
2984 struct glyph_string
*s
;
2987 /* Nothing to do if background has already been drawn or if it
2988 shouldn't be drawn in the first place. */
2989 if (!s
->background_filled_p
)
2993 /* Fill background with a stipple pattern. */
2994 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2995 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2996 s
->y
+ s
->face
->box_line_width
,
2997 s
->background_width
,
2998 s
->height
- 2 * s
->face
->box_line_width
);
2999 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3000 s
->background_filled_p
= 1;
3002 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
3003 || s
->font_not_found_p
3004 || s
->extends_to_end_of_line_p
3007 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
3008 s
->background_width
,
3009 s
->height
- 2 * s
->face
->box_line_width
);
3010 s
->background_filled_p
= 1;
3016 /* Draw the foreground of glyph string S. */
3019 x_draw_glyph_string_foreground (s
)
3020 struct glyph_string
*s
;
3024 /* If first glyph of S has a left box line, start drawing the text
3025 of S to the right of that box line. */
3026 if (s
->face
->box
!= FACE_NO_BOX
3027 && s
->first_glyph
->left_box_line_p
)
3028 x
= s
->x
+ s
->face
->box_line_width
;
3032 /* Draw characters of S as rectangles if S's font could not be
3034 if (s
->font_not_found_p
)
3036 for (i
= 0; i
< s
->nchars
; ++i
)
3038 struct glyph
*g
= s
->first_glyph
+ i
;
3039 XDrawRectangle (s
->display
, s
->window
,
3040 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3042 x
+= g
->pixel_width
;
3047 char *char1b
= (char *) s
->char2b
;
3048 int boff
= s
->font_info
->baseline_offset
;
3050 if (s
->font_info
->vertical_centering
)
3051 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3053 /* If we can use 8-bit functions, condense S->char2b. */
3055 for (i
= 0; i
< s
->nchars
; ++i
)
3056 char1b
[i
] = s
->char2b
[i
].byte2
;
3058 /* Draw text with XDrawString if background has already been
3059 filled. Otherwise, use XDrawImageString. (Note that
3060 XDrawImageString is usually faster than XDrawString.) Always
3061 use XDrawImageString when drawing the cursor so that there is
3062 no chance that characters under a box cursor are invisible. */
3063 if (s
->for_overlaps_p
3064 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3066 /* Draw characters with 16-bit or 8-bit functions. */
3068 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3069 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3071 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3072 s
->ybase
- boff
, char1b
, s
->nchars
);
3077 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3078 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3080 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3081 s
->ybase
- boff
, char1b
, s
->nchars
);
3086 /* Draw the foreground of composite glyph string S. */
3089 x_draw_composite_glyph_string_foreground (s
)
3090 struct glyph_string
*s
;
3094 /* If first glyph of S has a left box line, start drawing the text
3095 of S to the right of that box line. */
3096 if (s
->face
->box
!= FACE_NO_BOX
3097 && s
->first_glyph
->left_box_line_p
)
3098 x
= s
->x
+ s
->face
->box_line_width
;
3102 /* S is a glyph string for a composition. S->gidx is the index of
3103 the first character drawn for glyphs of this composition.
3104 S->gidx == 0 means we are drawing the very first character of
3105 this composition. */
3107 /* Draw a rectangle for the composition if the font for the very
3108 first character of the composition could not be loaded. */
3109 if (s
->font_not_found_p
)
3112 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3113 s
->width
- 1, s
->height
- 1);
3117 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3118 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3119 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3120 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3126 #ifdef USE_X_TOOLKIT
3128 /* Allocate the color COLOR->pixel on the screen and display of
3129 widget WIDGET in colormap CMAP. If an exact match cannot be
3130 allocated, try the nearest color available. Value is non-zero
3131 if successful. This is called from lwlib. */
3134 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3140 struct x_display_info
*dpyinfo
;
3143 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3145 /* Find the top-level shell of the widget. Note that this function
3146 can be called when the widget is not yet realized, so XtWindow
3147 (widget) == 0. That's the reason we can't simply use
3148 x_any_window_to_frame. */
3149 while (!XtIsTopLevelShell (widget
))
3150 widget
= XtParent (widget
);
3152 /* Look for a frame with that top-level widget. Allocate the color
3153 on that frame to get the right gamma correction value. */
3154 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3155 if (GC_FRAMEP (XCAR (tail
))
3156 && (f
= XFRAME (XCAR (tail
)),
3157 (f
->output_data
.nothing
!= 1
3158 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3159 && f
->output_data
.x
->widget
== widget
)
3160 return x_alloc_nearest_color (f
, cmap
, color
);
3165 #endif /* USE_X_TOOLKIT */
3168 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3169 CMAP. If an exact match can't be allocated, try the nearest color
3170 available. Value is non-zero if successful. Set *COLOR to the
3174 x_alloc_nearest_color (f
, cmap
, color
)
3179 Display
*display
= FRAME_X_DISPLAY (f
);
3180 Screen
*screen
= FRAME_X_SCREEN (f
);
3183 gamma_correct (f
, color
);
3184 rc
= XAllocColor (display
, cmap
, color
);
3187 /* If we got to this point, the colormap is full, so we're going
3188 to try to get the next closest color. The algorithm used is
3189 a least-squares matching, which is what X uses for closest
3190 color matching with StaticColor visuals. */
3192 unsigned long nearest_delta
= ~0;
3193 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3194 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3196 for (i
= 0; i
< ncells
; ++i
)
3198 XQueryColors (display
, cmap
, cells
, ncells
);
3200 for (nearest
= i
= 0; i
< ncells
; ++i
)
3202 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3203 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3204 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3205 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3207 if (delta
< nearest_delta
)
3210 nearest_delta
= delta
;
3214 color
->red
= cells
[nearest
].red
;
3215 color
->green
= cells
[nearest
].green
;
3216 color
->blue
= cells
[nearest
].blue
;
3217 rc
= XAllocColor (display
, cmap
, color
);
3220 #ifdef DEBUG_X_COLORS
3222 register_color (color
->pixel
);
3223 #endif /* DEBUG_X_COLORS */
3229 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3230 It's necessary to do this instead of just using PIXEL directly to
3231 get color reference counts right. */
3234 x_copy_color (f
, pixel
)
3236 unsigned long pixel
;
3240 color
.pixel
= pixel
;
3242 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3243 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3245 #ifdef DEBUG_X_COLORS
3246 register_color (pixel
);
3252 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3253 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3254 If this produces the same color as PIXEL, try a color where all RGB
3255 values have DELTA added. Return the allocated color in *PIXEL.
3256 DISPLAY is the X display, CMAP is the colormap to operate on.
3257 Value is non-zero if successful. */
3260 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3264 unsigned long *pixel
;
3271 /* Get RGB color values. */
3272 color
.pixel
= *pixel
;
3273 XQueryColor (display
, cmap
, &color
);
3275 /* Change RGB values by specified FACTOR. Avoid overflow! */
3276 xassert (factor
>= 0);
3277 new.red
= min (0xffff, factor
* color
.red
);
3278 new.green
= min (0xffff, factor
* color
.green
);
3279 new.blue
= min (0xffff, factor
* color
.blue
);
3281 /* Try to allocate the color. */
3282 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3285 if (new.pixel
== *pixel
)
3287 /* If we end up with the same color as before, try adding
3288 delta to the RGB values. */
3289 x_free_colors (f
, &new.pixel
, 1);
3291 new.red
= min (0xffff, delta
+ color
.red
);
3292 new.green
= min (0xffff, delta
+ color
.green
);
3293 new.blue
= min (0xffff, delta
+ color
.blue
);
3294 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3305 /* Set up the foreground color for drawing relief lines of glyph
3306 string S. RELIEF is a pointer to a struct relief containing the GC
3307 with which lines will be drawn. Use a color that is FACTOR or
3308 DELTA lighter or darker than the relief's background which is found
3309 in S->f->output_data.x->relief_background. If such a color cannot
3310 be allocated, use DEFAULT_PIXEL, instead. */
3313 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3315 struct relief
*relief
;
3318 unsigned long default_pixel
;
3321 struct x_output
*di
= f
->output_data
.x
;
3322 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3323 unsigned long pixel
;
3324 unsigned long background
= di
->relief_background
;
3325 Colormap cmap
= FRAME_X_COLORMAP (f
);
3326 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3327 Display
*dpy
= FRAME_X_DISPLAY (f
);
3329 xgcv
.graphics_exposures
= False
;
3330 xgcv
.line_width
= 1;
3332 /* Free previously allocated color. The color cell will be reused
3333 when it has been freed as many times as it was allocated, so this
3334 doesn't affect faces using the same colors. */
3336 && relief
->allocated_p
)
3338 /* If display has an immutable color map, freeing colors is not
3339 necessary and some servers don't allow it. So don't do it. */
3340 x_free_colors (f
, &relief
->pixel
, 1);
3341 relief
->allocated_p
= 0;
3344 /* Allocate new color. */
3345 xgcv
.foreground
= default_pixel
;
3347 if (dpyinfo
->n_planes
!= 1
3348 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3350 relief
->allocated_p
= 1;
3351 xgcv
.foreground
= relief
->pixel
= pixel
;
3354 if (relief
->gc
== 0)
3356 xgcv
.stipple
= dpyinfo
->gray
;
3358 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3361 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3365 /* Set up colors for the relief lines around glyph string S. */
3368 x_setup_relief_colors (s
)
3369 struct glyph_string
*s
;
3371 struct x_output
*di
= s
->f
->output_data
.x
;
3372 unsigned long color
;
3374 if (s
->face
->use_box_color_for_shadows_p
)
3375 color
= s
->face
->box_color
;
3380 /* Get the background color of the face. */
3381 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3382 color
= xgcv
.background
;
3385 if (di
->white_relief
.gc
== 0
3386 || color
!= di
->relief_background
)
3388 di
->relief_background
= color
;
3389 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3390 WHITE_PIX_DEFAULT (s
->f
));
3391 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3392 BLACK_PIX_DEFAULT (s
->f
));
3397 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3398 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3399 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3400 relief. LEFT_P non-zero means draw a relief on the left side of
3401 the rectangle. RIGHT_P non-zero means draw a relief on the right
3402 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3406 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3407 raised_p
, left_p
, right_p
, clip_rect
)
3409 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3410 XRectangle
*clip_rect
;
3416 gc
= f
->output_data
.x
->white_relief
.gc
;
3418 gc
= f
->output_data
.x
->black_relief
.gc
;
3419 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3422 for (i
= 0; i
< width
; ++i
)
3423 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3424 left_x
+ i
* left_p
, top_y
+ i
,
3425 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3429 for (i
= 0; i
< width
; ++i
)
3430 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3431 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3433 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3435 gc
= f
->output_data
.x
->black_relief
.gc
;
3437 gc
= f
->output_data
.x
->white_relief
.gc
;
3438 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3441 for (i
= 0; i
< width
; ++i
)
3442 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3443 left_x
+ i
* left_p
, bottom_y
- i
,
3444 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3448 for (i
= 0; i
< width
; ++i
)
3449 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3450 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3452 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3456 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3457 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3458 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3459 left side of the rectangle. RIGHT_P non-zero means draw a line
3460 on the right side of the rectangle. CLIP_RECT is the clipping
3461 rectangle to use when drawing. */
3464 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3465 left_p
, right_p
, clip_rect
)
3466 struct glyph_string
*s
;
3467 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3468 XRectangle
*clip_rect
;
3472 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3473 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3474 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3477 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3478 left_x
, top_y
, right_x
- left_x
, width
);
3482 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3483 left_x
, top_y
, width
, bottom_y
- top_y
);
3486 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3487 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3491 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3492 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3494 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3495 XSetClipMask (s
->display
, s
->gc
, None
);
3499 /* Draw a box around glyph string S. */
3502 x_draw_glyph_string_box (s
)
3503 struct glyph_string
*s
;
3505 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3506 int left_p
, right_p
;
3507 struct glyph
*last_glyph
;
3508 XRectangle clip_rect
;
3510 last_x
= window_box_right (s
->w
, s
->area
);
3511 if (s
->row
->full_width_p
3512 && !s
->w
->pseudo_window_p
)
3514 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3515 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3516 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3519 /* The glyph that may have a right box line. */
3520 last_glyph
= (s
->cmp
|| s
->img
3522 : s
->first_glyph
+ s
->nchars
- 1);
3524 width
= s
->face
->box_line_width
;
3525 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3527 right_x
= ((s
->row
->full_width_p
3529 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3531 bottom_y
= top_y
+ s
->height
- 1;
3533 left_p
= (s
->first_glyph
->left_box_line_p
3534 || (s
->hl
== DRAW_MOUSE_FACE
3536 || s
->prev
->hl
!= s
->hl
)));
3537 right_p
= (last_glyph
->right_box_line_p
3538 || (s
->hl
== DRAW_MOUSE_FACE
3540 || s
->next
->hl
!= s
->hl
)));
3542 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3544 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3545 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3546 left_p
, right_p
, &clip_rect
);
3549 x_setup_relief_colors (s
);
3550 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3551 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3556 /* Draw foreground of image glyph string S. */
3559 x_draw_image_foreground (s
)
3560 struct glyph_string
*s
;
3563 int y
= s
->ybase
- IMAGE_ASCENT (s
->img
);
3565 /* If first glyph of S has a left box line, start drawing it to the
3566 right of that line. */
3567 if (s
->face
->box
!= FACE_NO_BOX
3568 && s
->first_glyph
->left_box_line_p
)
3569 x
= s
->x
+ s
->face
->box_line_width
;
3573 /* If there is a margin around the image, adjust x- and y-position
3577 x
+= s
->img
->margin
;
3578 y
+= s
->img
->margin
;
3585 /* We can't set both a clip mask and use XSetClipRectangles
3586 because the latter also sets a clip mask. We also can't
3587 trust on the shape extension to be available
3588 (XShapeCombineRegion). So, compute the rectangle to draw
3590 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3593 XRectangle clip_rect
, image_rect
, r
;
3595 xgcv
.clip_mask
= s
->img
->mask
;
3596 xgcv
.clip_x_origin
= x
;
3597 xgcv
.clip_y_origin
= y
;
3598 xgcv
.function
= GXcopy
;
3599 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3601 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3604 image_rect
.width
= s
->img
->width
;
3605 image_rect
.height
= s
->img
->height
;
3606 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3607 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3608 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3612 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3613 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3615 /* When the image has a mask, we can expect that at
3616 least part of a mouse highlight or a block cursor will
3617 be visible. If the image doesn't have a mask, make
3618 a block cursor visible by drawing a rectangle around
3619 the image. I believe it's looking better if we do
3620 nothing here for mouse-face. */
3621 if (s
->hl
== DRAW_CURSOR
)
3622 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3623 s
->img
->width
- 1, s
->img
->height
- 1);
3627 /* Draw a rectangle if image could not be loaded. */
3628 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3629 s
->img
->width
- 1, s
->img
->height
- 1);
3633 /* Draw a relief around the image glyph string S. */
3636 x_draw_image_relief (s
)
3637 struct glyph_string
*s
;
3639 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3642 int y
= s
->ybase
- IMAGE_ASCENT (s
->img
);
3644 /* If first glyph of S has a left box line, start drawing it to the
3645 right of that line. */
3646 if (s
->face
->box
!= FACE_NO_BOX
3647 && s
->first_glyph
->left_box_line_p
)
3648 x
= s
->x
+ s
->face
->box_line_width
;
3652 /* If there is a margin around the image, adjust x- and y-position
3656 x
+= s
->img
->margin
;
3657 y
+= s
->img
->margin
;
3660 if (s
->hl
== DRAW_IMAGE_SUNKEN
3661 || s
->hl
== DRAW_IMAGE_RAISED
)
3663 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3664 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3668 thick
= abs (s
->img
->relief
);
3669 raised_p
= s
->img
->relief
> 0;
3674 x1
= x
+ s
->img
->width
+ thick
- 1;
3675 y1
= y
+ s
->img
->height
+ thick
- 1;
3677 x_setup_relief_colors (s
);
3678 x_get_glyph_string_clip_rect (s
, &r
);
3679 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3683 /* Draw the foreground of image glyph string S to PIXMAP. */
3686 x_draw_image_foreground_1 (s
, pixmap
)
3687 struct glyph_string
*s
;
3691 int y
= s
->ybase
- s
->y
- IMAGE_ASCENT (s
->img
);
3693 /* If first glyph of S has a left box line, start drawing it to the
3694 right of that line. */
3695 if (s
->face
->box
!= FACE_NO_BOX
3696 && s
->first_glyph
->left_box_line_p
)
3697 x
= s
->face
->box_line_width
;
3701 /* If there is a margin around the image, adjust x- and y-position
3705 x
+= s
->img
->margin
;
3706 y
+= s
->img
->margin
;
3713 /* We can't set both a clip mask and use XSetClipRectangles
3714 because the latter also sets a clip mask. We also can't
3715 trust on the shape extension to be available
3716 (XShapeCombineRegion). So, compute the rectangle to draw
3718 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3722 xgcv
.clip_mask
= s
->img
->mask
;
3723 xgcv
.clip_x_origin
= x
;
3724 xgcv
.clip_y_origin
= y
;
3725 xgcv
.function
= GXcopy
;
3726 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3728 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3729 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3730 XSetClipMask (s
->display
, s
->gc
, None
);
3734 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3735 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3737 /* When the image has a mask, we can expect that at
3738 least part of a mouse highlight or a block cursor will
3739 be visible. If the image doesn't have a mask, make
3740 a block cursor visible by drawing a rectangle around
3741 the image. I believe it's looking better if we do
3742 nothing here for mouse-face. */
3743 if (s
->hl
== DRAW_CURSOR
)
3744 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3745 s
->img
->width
- 1, s
->img
->height
- 1);
3749 /* Draw a rectangle if image could not be loaded. */
3750 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3751 s
->img
->width
- 1, s
->img
->height
- 1);
3755 /* Draw part of the background of glyph string S. X, Y, W, and H
3756 give the rectangle to draw. */
3759 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3760 struct glyph_string
*s
;
3765 /* Fill background with a stipple pattern. */
3766 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3767 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3768 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3771 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3775 /* Draw image glyph string S.
3778 s->x +-------------------------
3781 | +-------------------------
3784 | | +-------------------
3790 x_draw_image_glyph_string (s
)
3791 struct glyph_string
*s
;
3794 int box_line_width
= s
->face
->box_line_width
;
3795 int margin
= s
->img
->margin
;
3797 Pixmap pixmap
= None
;
3799 height
= s
->height
- 2 * box_line_width
;
3801 /* Fill background with face under the image. Do it only if row is
3802 taller than image or if image has a clip mask to reduce
3804 s
->stippled_p
= s
->face
->stipple
!= 0;
3805 if (height
> s
->img
->height
3808 || s
->img
->pixmap
== 0
3809 || s
->width
!= s
->background_width
)
3811 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3812 x
= s
->x
+ box_line_width
;
3816 y
= s
->y
+ box_line_width
;
3820 /* Create a pixmap as large as the glyph string Fill it with
3821 the background color. Copy the image to it, using its
3822 mask. Copy the temporary pixmap to the display. */
3823 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3824 int depth
= DefaultDepthOfScreen (screen
);
3826 /* Create a pixmap as large as the glyph string. */
3827 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3828 s
->background_width
,
3831 /* Don't clip in the following because we're working on the
3833 XSetClipMask (s
->display
, s
->gc
, None
);
3835 /* Fill the pixmap with the background color/stipple. */
3838 /* Fill background with a stipple pattern. */
3839 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3840 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3841 0, 0, s
->background_width
, s
->height
);
3842 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3847 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3849 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3850 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3851 0, 0, s
->background_width
, s
->height
);
3852 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3856 /* Implementation idea: Is it possible to construct a mask?
3857 We could look at the color at the margins of the image, and
3858 say that this color is probably the background color of the
3860 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3862 s
->background_filled_p
= 1;
3865 /* Draw the foreground. */
3868 x_draw_image_foreground_1 (s
, pixmap
);
3869 x_set_glyph_string_clipping (s
);
3870 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
3871 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3872 XFreePixmap (s
->display
, pixmap
);
3875 x_draw_image_foreground (s
);
3877 /* If we must draw a relief around the image, do it. */
3879 || s
->hl
== DRAW_IMAGE_RAISED
3880 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3881 x_draw_image_relief (s
);
3885 /* Draw stretch glyph string S. */
3888 x_draw_stretch_glyph_string (s
)
3889 struct glyph_string
*s
;
3891 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3892 s
->stippled_p
= s
->face
->stipple
!= 0;
3894 if (s
->hl
== DRAW_CURSOR
3895 && !x_stretch_cursor_p
)
3897 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3898 as wide as the stretch glyph. */
3899 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
3902 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3904 /* Clear rest using the GC of the original non-cursor face. */
3905 if (width
< s
->background_width
)
3907 GC gc
= s
->face
->gc
;
3908 int x
= s
->x
+ width
, y
= s
->y
;
3909 int w
= s
->background_width
- width
, h
= s
->height
;
3912 x_get_glyph_string_clip_rect (s
, &r
);
3913 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
3915 if (s
->face
->stipple
)
3917 /* Fill background with a stipple pattern. */
3918 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3919 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3920 XSetFillStyle (s
->display
, gc
, FillSolid
);
3925 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
3926 XSetForeground (s
->display
, gc
, xgcv
.background
);
3927 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3928 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
3933 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
3936 s
->background_filled_p
= 1;
3940 /* Draw glyph string S. */
3943 x_draw_glyph_string (s
)
3944 struct glyph_string
*s
;
3946 /* If S draws into the background of its successor, draw the
3947 background of the successor first so that S can draw into it.
3948 This makes S->next use XDrawString instead of XDrawImageString. */
3949 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
3951 xassert (s
->next
->img
== NULL
);
3952 x_set_glyph_string_gc (s
->next
);
3953 x_set_glyph_string_clipping (s
->next
);
3954 x_draw_glyph_string_background (s
->next
, 1);
3957 /* Set up S->gc, set clipping and draw S. */
3958 x_set_glyph_string_gc (s
);
3959 x_set_glyph_string_clipping (s
);
3961 switch (s
->first_glyph
->type
)
3964 x_draw_image_glyph_string (s
);
3968 x_draw_stretch_glyph_string (s
);
3972 if (s
->for_overlaps_p
)
3973 s
->background_filled_p
= 1;
3975 x_draw_glyph_string_background (s
, 0);
3976 x_draw_glyph_string_foreground (s
);
3979 case COMPOSITE_GLYPH
:
3980 if (s
->for_overlaps_p
|| s
->gidx
> 0)
3981 s
->background_filled_p
= 1;
3983 x_draw_glyph_string_background (s
, 1);
3984 x_draw_composite_glyph_string_foreground (s
);
3991 if (!s
->for_overlaps_p
)
3993 /* Draw underline. */
3994 if (s
->face
->underline_p
)
3996 unsigned long dy
, h
;
3998 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4000 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
4003 if (s
->face
->underline_defaulted_p
)
4004 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4009 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4010 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4011 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4013 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4017 /* Draw overline. */
4018 if (s
->face
->overline_p
)
4020 unsigned long dy
= 0, h
= 1;
4022 if (s
->face
->overline_color_defaulted_p
)
4023 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4028 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4029 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4030 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4032 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4036 /* Draw strike-through. */
4037 if (s
->face
->strike_through_p
)
4039 unsigned long h
= 1;
4040 unsigned long dy
= (s
->height
- h
) / 2;
4042 if (s
->face
->strike_through_color_defaulted_p
)
4043 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4048 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4049 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4050 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4052 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4057 if (s
->face
->box
!= FACE_NO_BOX
)
4058 x_draw_glyph_string_box (s
);
4061 /* Reset clipping. */
4062 XSetClipMask (s
->display
, s
->gc
, None
);
4066 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4067 struct face
**, int));
4070 /* Load glyph string S with a composition components specified by S->cmp.
4071 FACES is an array of faces for all components of this composition.
4072 S->gidx is the index of the first component for S.
4073 OVERLAPS_P non-zero means S should draw the foreground only, and
4074 use its lines physical height for clipping.
4076 Value is the index of a component not in S. */
4079 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4080 struct glyph_string
*s
;
4081 struct face
**faces
;
4088 s
->for_overlaps_p
= overlaps_p
;
4090 s
->face
= faces
[s
->gidx
];
4091 s
->font
= s
->face
->font
;
4092 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4094 /* For all glyphs of this composition, starting at the offset
4095 S->gidx, until we reach the end of the definition or encounter a
4096 glyph that requires the different face, add it to S. */
4098 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4101 /* All glyph strings for the same composition has the same width,
4102 i.e. the width set for the first component of the composition. */
4104 s
->width
= s
->first_glyph
->pixel_width
;
4106 /* If the specified font could not be loaded, use the frame's
4107 default font, but record the fact that we couldn't load it in
4108 the glyph string so that we can draw rectangles for the
4109 characters of the glyph string. */
4110 if (s
->font
== NULL
)
4112 s
->font_not_found_p
= 1;
4113 s
->font
= FRAME_FONT (s
->f
);
4116 /* Adjust base line for subscript/superscript text. */
4117 s
->ybase
+= s
->first_glyph
->voffset
;
4119 xassert (s
->face
&& s
->face
->gc
);
4121 /* This glyph string must always be drawn with 16-bit functions. */
4124 return s
->gidx
+ s
->nchars
;
4128 /* Load glyph string S with a sequence characters.
4129 FACE_ID is the face id of the string. START is the index of the
4130 first glyph to consider, END is the index of the last + 1.
4131 OVERLAPS_P non-zero means S should draw the foreground only, and
4132 use its lines physical height for clipping.
4134 Value is the index of the first glyph not in S. */
4137 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4138 struct glyph_string
*s
;
4140 int start
, end
, overlaps_p
;
4142 struct glyph
*glyph
, *last
;
4144 int glyph_not_available_p
;
4146 xassert (s
->f
== XFRAME (s
->w
->frame
));
4147 xassert (s
->nchars
== 0);
4148 xassert (start
>= 0 && end
> start
);
4150 s
->for_overlaps_p
= overlaps_p
,
4151 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4152 last
= s
->row
->glyphs
[s
->area
] + end
;
4153 voffset
= glyph
->voffset
;
4155 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4158 && glyph
->type
== CHAR_GLYPH
4159 && glyph
->voffset
== voffset
4160 /* Same face id implies same font, nowadays. */
4161 && glyph
->face_id
== face_id
4162 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4166 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4167 s
->char2b
+ s
->nchars
,
4169 s
->two_byte_p
= two_byte_p
;
4171 xassert (s
->nchars
<= end
- start
);
4172 s
->width
+= glyph
->pixel_width
;
4176 s
->font
= s
->face
->font
;
4177 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4179 /* If the specified font could not be loaded, use the frame's font,
4180 but record the fact that we couldn't load it in
4181 S->font_not_found_p so that we can draw rectangles for the
4182 characters of the glyph string. */
4183 if (s
->font
== NULL
|| glyph_not_available_p
)
4185 s
->font_not_found_p
= 1;
4186 s
->font
= FRAME_FONT (s
->f
);
4189 /* Adjust base line for subscript/superscript text. */
4190 s
->ybase
+= voffset
;
4192 xassert (s
->face
&& s
->face
->gc
);
4193 return glyph
- s
->row
->glyphs
[s
->area
];
4197 /* Fill glyph string S from image glyph S->first_glyph. */
4200 x_fill_image_glyph_string (s
)
4201 struct glyph_string
*s
;
4203 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4204 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4206 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4207 s
->font
= s
->face
->font
;
4208 s
->width
= s
->first_glyph
->pixel_width
;
4210 /* Adjust base line for subscript/superscript text. */
4211 s
->ybase
+= s
->first_glyph
->voffset
;
4215 /* Fill glyph string S from stretch glyph S->first_glyph. */
4218 x_fill_stretch_glyph_string (s
)
4219 struct glyph_string
*s
;
4221 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4222 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4223 s
->font
= s
->face
->font
;
4224 s
->width
= s
->first_glyph
->pixel_width
;
4226 /* Adjust base line for subscript/superscript text. */
4227 s
->ybase
+= s
->first_glyph
->voffset
;
4231 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4232 of XChar2b structures for S; it can't be allocated in
4233 x_init_glyph_string because it must be allocated via `alloca'. W
4234 is the window on which S is drawn. ROW and AREA are the glyph row
4235 and area within the row from which S is constructed. START is the
4236 index of the first glyph structure covered by S. HL is a
4237 face-override for drawing S. */
4240 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4241 struct glyph_string
*s
;
4244 struct glyph_row
*row
;
4245 enum glyph_row_area area
;
4247 enum draw_glyphs_face hl
;
4249 bzero (s
, sizeof *s
);
4251 s
->f
= XFRAME (w
->frame
);
4252 s
->display
= FRAME_X_DISPLAY (s
->f
);
4253 s
->window
= FRAME_X_WINDOW (s
->f
);
4258 s
->first_glyph
= row
->glyphs
[area
] + start
;
4259 s
->height
= row
->height
;
4260 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4262 /* Display the internal border below the tool-bar window. */
4263 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4264 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4266 s
->ybase
= s
->y
+ row
->ascent
;
4270 /* Set background width of glyph string S. START is the index of the
4271 first glyph following S. LAST_X is the right-most x-position + 1
4272 in the drawing area. */
4275 x_set_glyph_string_background_width (s
, start
, last_x
)
4276 struct glyph_string
*s
;
4280 /* If the face of this glyph string has to be drawn to the end of
4281 the drawing area, set S->extends_to_end_of_line_p. */
4282 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4284 if (start
== s
->row
->used
[s
->area
]
4285 && s
->hl
== DRAW_NORMAL_TEXT
4286 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4287 || s
->face
->background
!= default_face
->background
4288 || s
->face
->stipple
!= default_face
->stipple
))
4289 s
->extends_to_end_of_line_p
= 1;
4291 /* If S extends its face to the end of the line, set its
4292 background_width to the distance to the right edge of the drawing
4294 if (s
->extends_to_end_of_line_p
)
4295 s
->background_width
= last_x
- s
->x
+ 1;
4297 s
->background_width
= s
->width
;
4301 /* Add a glyph string for a stretch glyph to the list of strings
4302 between HEAD and TAIL. START is the index of the stretch glyph in
4303 row area AREA of glyph row ROW. END is the index of the last glyph
4304 in that glyph row area. X is the current output position assigned
4305 to the new glyph string constructed. HL overrides that face of the
4306 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4307 is the right-most x-position of the drawing area. */
4309 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4310 and below -- keep them on one line. */
4311 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4314 s = (struct glyph_string *) alloca (sizeof *s); \
4315 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4316 x_fill_stretch_glyph_string (s); \
4317 x_append_glyph_string (&HEAD, &TAIL, s); \
4324 /* Add a glyph string for an image glyph to the list of strings
4325 between HEAD and TAIL. START is the index of the image glyph in
4326 row area AREA of glyph row ROW. END is the index of the last glyph
4327 in that glyph row area. X is the current output position assigned
4328 to the new glyph string constructed. HL overrides that face of the
4329 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4330 is the right-most x-position of the drawing area. */
4332 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4335 s = (struct glyph_string *) alloca (sizeof *s); \
4336 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4337 x_fill_image_glyph_string (s); \
4338 x_append_glyph_string (&HEAD, &TAIL, s); \
4345 /* Add a glyph string for a sequence of character glyphs to the list
4346 of strings between HEAD and TAIL. START is the index of the first
4347 glyph in row area AREA of glyph row ROW that is part of the new
4348 glyph string. END is the index of the last glyph in that glyph row
4349 area. X is the current output position assigned to the new glyph
4350 string constructed. HL overrides that face of the glyph; e.g. it
4351 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4352 right-most x-position of the drawing area. */
4354 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4357 int c, charset, face_id; \
4360 c = (ROW)->glyphs[AREA][START].u.ch; \
4361 face_id = (ROW)->glyphs[AREA][START].face_id; \
4363 s = (struct glyph_string *) alloca (sizeof *s); \
4364 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4365 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4366 x_append_glyph_string (&HEAD, &TAIL, s); \
4368 START = x_fill_glyph_string (s, face_id, START, END, \
4374 /* Add a glyph string for a composite sequence to the list of strings
4375 between HEAD and TAIL. START is the index of the first glyph in
4376 row area AREA of glyph row ROW that is part of the new glyph
4377 string. END is the index of the last glyph in that glyph row area.
4378 X is the current output position assigned to the new glyph string
4379 constructed. HL overrides that face of the glyph; e.g. it is
4380 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4381 x-position of the drawing area. */
4383 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4385 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4386 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4387 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4388 struct composition *cmp = composition_table[cmp_id]; \
4389 int glyph_len = cmp->glyph_len; \
4391 struct face **faces; \
4392 struct glyph_string *first_s = NULL; \
4395 base_face = base_face->ascii_face; \
4396 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4397 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4398 /* At first, fill in `char2b' and `faces'. */ \
4399 for (n = 0; n < glyph_len; n++) \
4401 int c = COMPOSITION_GLYPH (cmp, n); \
4402 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4403 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4404 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4405 this_face_id, char2b + n, 1); \
4408 /* Make glyph_strings for each glyph sequence that is drawable by \
4409 the same face, and append them to HEAD/TAIL. */ \
4410 for (n = 0; n < cmp->glyph_len;) \
4412 s = (struct glyph_string *) alloca (sizeof *s); \
4413 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4414 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4422 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4430 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4431 of AREA of glyph row ROW on window W between indices START and END.
4432 HL overrides the face for drawing glyph strings, e.g. it is
4433 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4434 x-positions of the drawing area.
4436 This is an ugly monster macro construct because we must use alloca
4437 to allocate glyph strings (because x_draw_glyphs can be called
4440 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4443 HEAD = TAIL = NULL; \
4444 while (START < END) \
4446 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4447 switch (first_glyph->type) \
4450 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4451 TAIL, HL, X, LAST_X, \
4455 case COMPOSITE_GLYPH: \
4456 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4457 HEAD, TAIL, HL, X, LAST_X,\
4461 case STRETCH_GLYPH: \
4462 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4463 HEAD, TAIL, HL, X, LAST_X); \
4467 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4468 TAIL, HL, X, LAST_X); \
4475 x_set_glyph_string_background_width (s, START, LAST_X); \
4482 /* Draw glyphs between START and END in AREA of ROW on window W,
4483 starting at x-position X. X is relative to AREA in W. HL is a
4484 face-override with the following meaning:
4486 DRAW_NORMAL_TEXT draw normally
4487 DRAW_CURSOR draw in cursor face
4488 DRAW_MOUSE_FACE draw in mouse face.
4489 DRAW_INVERSE_VIDEO draw in mode line face
4490 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4491 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4493 If REAL_START is non-null, return in *REAL_START the real starting
4494 position for display. This can be different from START in case
4495 overlapping glyphs must be displayed. If REAL_END is non-null,
4496 return in *REAL_END the real end position for display. This can be
4497 different from END in case overlapping glyphs must be displayed.
4499 If OVERLAPS_P is non-zero, draw only the foreground of characters
4500 and clip to the physical height of ROW.
4502 Value is the x-position reached, relative to AREA of W. */
4505 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4509 struct glyph_row
*row
;
4510 enum glyph_row_area area
;
4512 enum draw_glyphs_face hl
;
4513 int *real_start
, *real_end
;
4516 struct glyph_string
*head
, *tail
;
4517 struct glyph_string
*s
;
4518 int last_x
, area_width
;
4522 /* Let's rather be paranoid than getting a SEGV. */
4523 start
= max (0, start
);
4524 end
= min (end
, row
->used
[area
]);
4526 *real_start
= start
;
4530 /* Translate X to frame coordinates. Set last_x to the right
4531 end of the drawing area. */
4532 if (row
->full_width_p
)
4534 /* X is relative to the left edge of W, without scroll bars
4536 struct frame
*f
= XFRAME (w
->frame
);
4537 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4538 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4541 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4542 last_x
= window_left_x
+ area_width
;
4544 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4546 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4547 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4553 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4554 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4558 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4559 area_width
= window_box_width (w
, area
);
4560 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4563 /* Build a doubly-linked list of glyph_string structures between
4564 head and tail from what we have to draw. Note that the macro
4565 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4566 the reason we use a separate variable `i'. */
4568 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4571 x_reached
= tail
->x
+ tail
->background_width
;
4575 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4576 the row, redraw some glyphs in front or following the glyph
4577 strings built above. */
4578 if (!overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4581 struct glyph_string
*h
, *t
;
4583 /* Compute overhangs for all glyph strings. */
4584 for (s
= head
; s
; s
= s
->next
)
4585 x_compute_glyph_string_overhangs (s
);
4587 /* Prepend glyph strings for glyphs in front of the first glyph
4588 string that are overwritten because of the first glyph
4589 string's left overhang. The background of all strings
4590 prepended must be drawn because the first glyph string
4592 i
= x_left_overwritten (head
);
4596 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4597 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4601 *real_start
= start
;
4602 x_compute_overhangs_and_x (t
, head
->x
, 1);
4603 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4606 /* Prepend glyph strings for glyphs in front of the first glyph
4607 string that overwrite that glyph string because of their
4608 right overhang. For these strings, only the foreground must
4609 be drawn, because it draws over the glyph string at `head'.
4610 The background must not be drawn because this would overwrite
4611 right overhangs of preceding glyphs for which no glyph
4613 i
= x_left_overwriting (head
);
4616 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4617 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4619 for (s
= h
; s
; s
= s
->next
)
4620 s
->background_filled_p
= 1;
4623 x_compute_overhangs_and_x (t
, head
->x
, 1);
4624 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4627 /* Append glyphs strings for glyphs following the last glyph
4628 string tail that are overwritten by tail. The background of
4629 these strings has to be drawn because tail's foreground draws
4631 i
= x_right_overwritten (tail
);
4634 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4635 DRAW_NORMAL_TEXT
, x
, last_x
,
4637 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4638 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4643 /* Append glyph strings for glyphs following the last glyph
4644 string tail that overwrite tail. The foreground of such
4645 glyphs has to be drawn because it writes into the background
4646 of tail. The background must not be drawn because it could
4647 paint over the foreground of following glyphs. */
4648 i
= x_right_overwriting (tail
);
4651 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4652 DRAW_NORMAL_TEXT
, x
, last_x
,
4654 for (s
= h
; s
; s
= s
->next
)
4655 s
->background_filled_p
= 1;
4656 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4657 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4663 /* Draw all strings. */
4664 for (s
= head
; s
; s
= s
->next
)
4665 x_draw_glyph_string (s
);
4667 /* Value is the x-position up to which drawn, relative to AREA of W.
4668 This doesn't include parts drawn because of overhangs. */
4669 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4670 if (!row
->full_width_p
)
4672 if (area
> LEFT_MARGIN_AREA
)
4673 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4674 if (area
> TEXT_AREA
)
4675 x_reached
-= window_box_width (w
, TEXT_AREA
);
4681 /* Fix the display of area AREA of overlapping row ROW in window W. */
4684 x_fix_overlapping_area (w
, row
, area
)
4686 struct glyph_row
*row
;
4687 enum glyph_row_area area
;
4693 if (area
== LEFT_MARGIN_AREA
)
4695 else if (area
== TEXT_AREA
)
4696 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4698 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4699 + window_box_width (w
, TEXT_AREA
));
4701 for (i
= 0; i
< row
->used
[area
];)
4703 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4705 int start
= i
, start_x
= x
;
4709 x
+= row
->glyphs
[area
][i
].pixel_width
;
4712 while (i
< row
->used
[area
]
4713 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4715 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4717 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4722 x
+= row
->glyphs
[area
][i
].pixel_width
;
4731 /* Output LEN glyphs starting at START at the nominal cursor position.
4732 Advance the nominal cursor over the text. The global variable
4733 updated_window contains the window being updated, updated_row is
4734 the glyph row being updated, and updated_area is the area of that
4735 row being updated. */
4738 x_write_glyphs (start
, len
)
4739 struct glyph
*start
;
4742 int x
, hpos
, real_start
, real_end
;
4744 xassert (updated_window
&& updated_row
);
4749 hpos
= start
- updated_row
->glyphs
[updated_area
];
4750 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4751 updated_row
, updated_area
,
4753 (updated_row
->inverse_p
4754 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4755 &real_start
, &real_end
, 0);
4757 /* If we drew over the cursor, note that it is not visible any more. */
4758 note_overwritten_text_cursor (updated_window
, real_start
,
4759 real_end
- real_start
);
4763 /* Advance the output cursor. */
4764 output_cursor
.hpos
+= len
;
4765 output_cursor
.x
= x
;
4769 /* Insert LEN glyphs from START at the nominal cursor position. */
4772 x_insert_glyphs (start
, len
)
4773 struct glyph
*start
;
4778 int line_height
, shift_by_width
, shifted_region_width
;
4779 struct glyph_row
*row
;
4780 struct glyph
*glyph
;
4781 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4783 xassert (updated_window
&& updated_row
);
4786 f
= XFRAME (WINDOW_FRAME (w
));
4788 /* Get the height of the line we are in. */
4790 line_height
= row
->height
;
4792 /* Get the width of the glyphs to insert. */
4794 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4795 shift_by_width
+= glyph
->pixel_width
;
4797 /* Get the width of the region to shift right. */
4798 shifted_region_width
= (window_box_width (w
, updated_area
)
4803 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4804 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4805 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4806 f
->output_data
.x
->normal_gc
,
4808 shifted_region_width
, line_height
,
4809 frame_x
+ shift_by_width
, frame_y
);
4811 /* Write the glyphs. */
4812 hpos
= start
- row
->glyphs
[updated_area
];
4813 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4814 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4815 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4817 /* Advance the output cursor. */
4818 output_cursor
.hpos
+= len
;
4819 output_cursor
.x
+= shift_by_width
;
4824 /* Delete N glyphs at the nominal cursor position. Not implemented
4835 /* Erase the current text line from the nominal cursor position
4836 (inclusive) to pixel column TO_X (exclusive). The idea is that
4837 everything from TO_X onward is already erased.
4839 TO_X is a pixel position relative to updated_area of
4840 updated_window. TO_X == -1 means clear to the end of this area. */
4843 x_clear_end_of_line (to_x
)
4847 struct window
*w
= updated_window
;
4848 int max_x
, min_y
, max_y
;
4849 int from_x
, from_y
, to_y
;
4851 xassert (updated_window
&& updated_row
);
4852 f
= XFRAME (w
->frame
);
4854 if (updated_row
->full_width_p
)
4856 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4857 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4858 && !w
->pseudo_window_p
)
4859 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4862 max_x
= window_box_width (w
, updated_area
);
4863 max_y
= window_text_bottom_y (w
);
4865 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
4866 of window. For TO_X > 0, truncate to end of drawing area. */
4872 to_x
= min (to_x
, max_x
);
4874 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
4876 /* Notice if the cursor will be cleared by this operation. */
4877 if (!updated_row
->full_width_p
)
4878 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
4880 from_x
= output_cursor
.x
;
4882 /* Translate to frame coordinates. */
4883 if (updated_row
->full_width_p
)
4885 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
4886 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
4890 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
4891 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
4894 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
4895 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
4896 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
4898 /* Prevent inadvertently clearing to end of the X window. */
4899 if (to_x
> from_x
&& to_y
> from_y
)
4902 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4903 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
4910 /* Clear entire frame. If updating_frame is non-null, clear that
4911 frame. Otherwise clear the selected frame. */
4921 f
= SELECTED_FRAME ();
4923 /* Clearing the frame will erase any cursor, so mark them all as no
4925 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4926 output_cursor
.hpos
= output_cursor
.vpos
= 0;
4927 output_cursor
.x
= -1;
4929 /* We don't set the output cursor here because there will always
4930 follow an explicit cursor_to. */
4932 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
4934 /* We have to clear the scroll bars, too. If we have changed
4935 colors or something like that, then they should be notified. */
4936 x_scroll_bar_clear (f
);
4938 XFlush (FRAME_X_DISPLAY (f
));
4944 /* Invert the middle quarter of the frame for .15 sec. */
4946 /* We use the select system call to do the waiting, so we have to make
4947 sure it's available. If it isn't, we just won't do visual bells. */
4949 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4952 /* Subtract the `struct timeval' values X and Y, storing the result in
4953 *RESULT. Return 1 if the difference is negative, otherwise 0. */
4956 timeval_subtract (result
, x
, y
)
4957 struct timeval
*result
, x
, y
;
4959 /* Perform the carry for the later subtraction by updating y. This
4960 is safer because on some systems the tv_sec member is unsigned. */
4961 if (x
.tv_usec
< y
.tv_usec
)
4963 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
4964 y
.tv_usec
-= 1000000 * nsec
;
4968 if (x
.tv_usec
- y
.tv_usec
> 1000000)
4970 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
4971 y
.tv_usec
+= 1000000 * nsec
;
4975 /* Compute the time remaining to wait. tv_usec is certainly
4977 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
4978 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
4980 /* Return indication of whether the result should be considered
4982 return x
.tv_sec
< y
.tv_sec
;
4994 /* Create a GC that will use the GXxor function to flip foreground
4995 pixels into background pixels. */
4999 values
.function
= GXxor
;
5000 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5001 ^ f
->output_data
.x
->background_pixel
);
5003 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5004 GCFunction
| GCForeground
, &values
);
5008 /* Get the height not including a menu bar widget. */
5009 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5010 /* Height of each line to flash. */
5011 int flash_height
= FRAME_LINE_HEIGHT (f
);
5012 /* These will be the left and right margins of the rectangles. */
5013 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5014 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5018 /* Don't flash the area between a scroll bar and the frame
5019 edge it is next to. */
5020 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5022 case vertical_scroll_bar_left
:
5023 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5026 case vertical_scroll_bar_right
:
5027 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5034 width
= flash_right
- flash_left
;
5036 /* If window is tall, flash top and bottom line. */
5037 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5039 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5041 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5042 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5043 width
, flash_height
);
5044 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5046 (height
- flash_height
5047 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5048 width
, flash_height
);
5051 /* If it is short, flash it all. */
5052 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5053 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5054 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5059 struct timeval wakeup
;
5061 EMACS_GET_TIME (wakeup
);
5063 /* Compute time to wait until, propagating carry from usecs. */
5064 wakeup
.tv_usec
+= 150000;
5065 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5066 wakeup
.tv_usec
%= 1000000;
5068 /* Keep waiting until past the time wakeup. */
5071 struct timeval timeout
;
5073 EMACS_GET_TIME (timeout
);
5075 /* In effect, timeout = wakeup - timeout.
5076 Break if result would be negative. */
5077 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5080 /* Try to wait that long--but we might wake up sooner. */
5081 select (0, NULL
, NULL
, NULL
, &timeout
);
5085 /* If window is tall, flash top and bottom line. */
5086 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5088 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5090 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5091 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5092 width
, flash_height
);
5093 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5095 (height
- flash_height
5096 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5097 width
, flash_height
);
5100 /* If it is short, flash it all. */
5101 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5102 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5103 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5105 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5113 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5116 /* Make audible bell. */
5121 struct frame
*f
= SELECTED_FRAME ();
5123 if (FRAME_X_DISPLAY (f
))
5125 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5132 XBell (FRAME_X_DISPLAY (f
), 0);
5133 XFlush (FRAME_X_DISPLAY (f
));
5140 /* Specify how many text lines, from the top of the window,
5141 should be affected by insert-lines and delete-lines operations.
5142 This, and those operations, are used only within an update
5143 that is bounded by calls to x_update_begin and x_update_end. */
5146 XTset_terminal_window (n
)
5149 /* This function intentionally left blank. */
5154 /***********************************************************************
5156 ***********************************************************************/
5158 /* Perform an insert-lines or delete-lines operation, inserting N
5159 lines or deleting -N lines at vertical position VPOS. */
5162 x_ins_del_lines (vpos
, n
)
5169 /* Scroll part of the display as described by RUN. */
5172 x_scroll_run (w
, run
)
5176 struct frame
*f
= XFRAME (w
->frame
);
5177 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5179 /* Get frame-relative bounding box of the text display area of W,
5180 without mode lines. Include in this box the flags areas to the
5181 left and right of W. */
5182 window_box (w
, -1, &x
, &y
, &width
, &height
);
5183 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5184 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5186 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5187 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5188 bottom_y
= y
+ height
;
5192 /* Scrolling up. Make sure we don't copy part of the mode
5193 line at the bottom. */
5194 if (from_y
+ run
->height
> bottom_y
)
5195 height
= bottom_y
- from_y
;
5197 height
= run
->height
;
5201 /* Scolling down. Make sure we don't copy over the mode line.
5203 if (to_y
+ run
->height
> bottom_y
)
5204 height
= bottom_y
- to_y
;
5206 height
= run
->height
;
5211 /* Cursor off. Will be switched on again in x_update_window_end. */
5215 XCopyArea (FRAME_X_DISPLAY (f
),
5216 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5217 f
->output_data
.x
->normal_gc
,
5227 /***********************************************************************
5229 ***********************************************************************/
5231 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5232 corner of the exposed rectangle. W and H are width and height of
5233 the exposed area. All are pixel values. W or H zero means redraw
5234 the entire frame. */
5237 expose_frame (f
, x
, y
, w
, h
)
5243 TRACE ((stderr
, "expose_frame "));
5245 /* No need to redraw if frame will be redrawn soon. */
5246 if (FRAME_GARBAGED_P (f
))
5248 TRACE ((stderr
, " garbaged\n"));
5252 /* If basic faces haven't been realized yet, there is no point in
5253 trying to redraw anything. This can happen when we get an expose
5254 event while Emacs is starting, e.g. by moving another window. */
5255 if (FRAME_FACE_CACHE (f
) == NULL
5256 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5258 TRACE ((stderr
, " no faces\n"));
5262 if (w
== 0 || h
== 0)
5265 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5266 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5276 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5277 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5279 if (WINDOWP (f
->tool_bar_window
))
5281 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5282 XRectangle window_rect
;
5283 XRectangle intersection_rect
;
5284 int window_x
, window_y
, window_width
, window_height
;
5287 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5288 window_rect
.x
= window_x
;
5289 window_rect
.y
= window_y
;
5290 window_rect
.width
= window_width
;
5291 window_rect
.height
= window_height
;
5293 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5294 expose_window (w
, &intersection_rect
);
5297 #ifndef USE_X_TOOLKIT
5298 if (WINDOWP (f
->menu_bar_window
))
5300 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5301 XRectangle window_rect
;
5302 XRectangle intersection_rect
;
5303 int window_x
, window_y
, window_width
, window_height
;
5306 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5307 window_rect
.x
= window_x
;
5308 window_rect
.y
= window_y
;
5309 window_rect
.width
= window_width
;
5310 window_rect
.height
= window_height
;
5312 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5313 expose_window (w
, &intersection_rect
);
5315 #endif /* not USE_X_TOOLKIT */
5319 /* Redraw (parts) of all windows in the window tree rooted at W that
5320 intersect R. R contains frame pixel coordinates. */
5323 expose_window_tree (w
, r
)
5329 if (!NILP (w
->hchild
))
5330 expose_window_tree (XWINDOW (w
->hchild
), r
);
5331 else if (!NILP (w
->vchild
))
5332 expose_window_tree (XWINDOW (w
->vchild
), r
);
5335 XRectangle window_rect
;
5336 XRectangle intersection_rect
;
5337 struct frame
*f
= XFRAME (w
->frame
);
5338 int window_x
, window_y
, window_width
, window_height
;
5340 /* Frame-relative pixel rectangle of W. */
5341 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5345 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5346 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5347 window_rect
.y
= window_y
;
5350 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5351 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5353 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5355 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5356 expose_window (w
, &intersection_rect
);
5359 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5364 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5365 which intersects rectangle R. R is in window-relative coordinates. */
5368 expose_area (w
, row
, r
, area
)
5370 struct glyph_row
*row
;
5372 enum glyph_row_area area
;
5375 struct glyph
*first
= row
->glyphs
[area
];
5376 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5380 /* Set x to the window-relative start position for drawing glyphs of
5381 AREA. The first glyph of the text area can be partially visible.
5382 The first glyphs of other areas cannot. */
5383 if (area
== LEFT_MARGIN_AREA
)
5385 else if (area
== TEXT_AREA
)
5386 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5388 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5389 + window_box_width (w
, TEXT_AREA
));
5391 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5392 /* If row extends face to end of line write the whole line. */
5393 x_draw_glyphs (w
, x
, row
, area
,
5395 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5399 /* Find the first glyph that must be redrawn. */
5401 && x
+ first
->pixel_width
< r
->x
)
5403 x
+= first
->pixel_width
;
5407 /* Find the last one. */
5411 && x
< r
->x
+ r
->width
)
5413 x
+= last
->pixel_width
;
5419 x_draw_glyphs (w
, first_x
, row
, area
,
5420 first
- row
->glyphs
[area
],
5421 last
- row
->glyphs
[area
],
5422 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5428 /* Redraw the parts of the glyph row ROW on window W intersecting
5429 rectangle R. R is in window-relative coordinates. */
5432 expose_line (w
, row
, r
)
5434 struct glyph_row
*row
;
5437 xassert (row
->enabled_p
);
5439 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5440 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5441 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5445 if (row
->used
[LEFT_MARGIN_AREA
])
5446 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5447 if (row
->used
[TEXT_AREA
])
5448 expose_area (w
, row
, r
, TEXT_AREA
);
5449 if (row
->used
[RIGHT_MARGIN_AREA
])
5450 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5451 x_draw_row_bitmaps (w
, row
);
5456 /* Return non-zero if W's cursor intersects rectangle R. */
5459 x_phys_cursor_in_rect_p (w
, r
)
5463 XRectangle cr
, result
;
5464 struct glyph
*cursor_glyph
;
5466 cursor_glyph
= get_phys_cursor_glyph (w
);
5469 cr
.x
= w
->phys_cursor
.x
;
5470 cr
.y
= w
->phys_cursor
.y
;
5471 cr
.width
= cursor_glyph
->pixel_width
;
5472 cr
.height
= w
->phys_cursor_height
;
5473 return x_intersect_rectangles (&cr
, r
, &result
);
5480 /* Redraw a rectangle of window W. R is a rectangle in window
5481 relative coordinates. Call this function with input blocked. */
5484 expose_window (w
, r
)
5488 struct glyph_row
*row
;
5490 int yb
= window_text_bottom_y (w
);
5491 int cursor_cleared_p
;
5493 /* If window is not yet fully initialized, do nothing. This can
5494 happen when toolkit scroll bars are used and a window is split.
5495 Reconfiguring the scroll bar will generate an expose for a newly
5497 if (w
->current_matrix
== NULL
)
5500 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5501 r
->x
, r
->y
, r
->width
, r
->height
));
5503 /* Convert to window coordinates. */
5504 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5505 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5507 /* Turn off the cursor. */
5508 if (!w
->pseudo_window_p
5509 && x_phys_cursor_in_rect_p (w
, r
))
5512 cursor_cleared_p
= 1;
5515 cursor_cleared_p
= 0;
5517 /* Find the first row intersecting the rectangle R. */
5518 row
= w
->current_matrix
->rows
;
5520 while (row
->enabled_p
5522 && y
+ row
->height
< r
->y
)
5528 /* Display the text in the rectangle, one text line at a time. */
5529 while (row
->enabled_p
5531 && y
< r
->y
+ r
->height
)
5533 expose_line (w
, row
, r
);
5538 /* Display the mode line if there is one. */
5539 if (WINDOW_WANTS_MODELINE_P (w
)
5540 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5542 && row
->y
< r
->y
+ r
->height
)
5543 expose_line (w
, row
, r
);
5545 if (!w
->pseudo_window_p
)
5547 /* Draw border between windows. */
5548 x_draw_vertical_border (w
);
5550 /* Turn the cursor on again. */
5551 if (cursor_cleared_p
)
5552 x_update_window_cursor (w
, 1);
5557 /* Determine the intersection of two rectangles R1 and R2. Return
5558 the intersection in *RESULT. Value is non-zero if RESULT is not
5562 x_intersect_rectangles (r1
, r2
, result
)
5563 XRectangle
*r1
, *r2
, *result
;
5565 XRectangle
*left
, *right
;
5566 XRectangle
*upper
, *lower
;
5567 int intersection_p
= 0;
5569 /* Rearrange so that R1 is the left-most rectangle. */
5571 left
= r1
, right
= r2
;
5573 left
= r2
, right
= r1
;
5575 /* X0 of the intersection is right.x0, if this is inside R1,
5576 otherwise there is no intersection. */
5577 if (right
->x
<= left
->x
+ left
->width
)
5579 result
->x
= right
->x
;
5581 /* The right end of the intersection is the minimum of the
5582 the right ends of left and right. */
5583 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5586 /* Same game for Y. */
5588 upper
= r1
, lower
= r2
;
5590 upper
= r2
, lower
= r1
;
5592 /* The upper end of the intersection is lower.y0, if this is inside
5593 of upper. Otherwise, there is no intersection. */
5594 if (lower
->y
<= upper
->y
+ upper
->height
)
5596 result
->y
= lower
->y
;
5598 /* The lower end of the intersection is the minimum of the lower
5599 ends of upper and lower. */
5600 result
->height
= (min (lower
->y
+ lower
->height
,
5601 upper
->y
+ upper
->height
)
5607 return intersection_p
;
5618 /* We used to only do this if Vx_no_window_manager was non-nil, but
5619 the ICCCM (section 4.1.6) says that the window's border pixmap
5620 and border pixel are window attributes which are "private to the
5621 client", so we can always change it to whatever we want. */
5623 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5624 f
->output_data
.x
->border_pixel
);
5626 x_update_cursor (f
, 1);
5630 frame_unhighlight (f
)
5633 /* We used to only do this if Vx_no_window_manager was non-nil, but
5634 the ICCCM (section 4.1.6) says that the window's border pixmap
5635 and border pixel are window attributes which are "private to the
5636 client", so we can always change it to whatever we want. */
5638 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5639 f
->output_data
.x
->border_tile
);
5641 x_update_cursor (f
, 1);
5644 /* The focus has changed. Update the frames as necessary to reflect
5645 the new situation. Note that we can't change the selected frame
5646 here, because the Lisp code we are interrupting might become confused.
5647 Each event gets marked with the frame in which it occurred, so the
5648 Lisp code can tell when the switch took place by examining the events. */
5651 x_new_focus_frame (dpyinfo
, frame
)
5652 struct x_display_info
*dpyinfo
;
5653 struct frame
*frame
;
5655 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5657 if (frame
!= dpyinfo
->x_focus_frame
)
5659 /* Set this before calling other routines, so that they see
5660 the correct value of x_focus_frame. */
5661 dpyinfo
->x_focus_frame
= frame
;
5663 if (old_focus
&& old_focus
->auto_lower
)
5664 x_lower_frame (old_focus
);
5667 selected_frame
= frame
;
5668 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5670 Fselect_window (selected_frame
->selected_window
);
5671 choose_minibuf_frame ();
5674 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5675 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5677 pending_autoraise_frame
= 0;
5680 x_frame_rehighlight (dpyinfo
);
5683 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5686 x_mouse_leave (dpyinfo
)
5687 struct x_display_info
*dpyinfo
;
5689 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5692 /* The focus has changed, or we have redirected a frame's focus to
5693 another frame (this happens when a frame uses a surrogate
5694 mini-buffer frame). Shift the highlight as appropriate.
5696 The FRAME argument doesn't necessarily have anything to do with which
5697 frame is being highlighted or un-highlighted; we only use it to find
5698 the appropriate X display info. */
5701 XTframe_rehighlight (frame
)
5702 struct frame
*frame
;
5704 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5708 x_frame_rehighlight (dpyinfo
)
5709 struct x_display_info
*dpyinfo
;
5711 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5713 if (dpyinfo
->x_focus_frame
)
5715 dpyinfo
->x_highlight_frame
5716 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5717 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5718 : dpyinfo
->x_focus_frame
);
5719 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5721 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5722 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5726 dpyinfo
->x_highlight_frame
= 0;
5728 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5731 frame_unhighlight (old_highlight
);
5732 if (dpyinfo
->x_highlight_frame
)
5733 frame_highlight (dpyinfo
->x_highlight_frame
);
5739 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5741 /* Initialize mode_switch_bit and modifier_meaning. */
5743 x_find_modifier_meanings (dpyinfo
)
5744 struct x_display_info
*dpyinfo
;
5746 int min_code
, max_code
;
5749 XModifierKeymap
*mods
;
5751 dpyinfo
->meta_mod_mask
= 0;
5752 dpyinfo
->shift_lock_mask
= 0;
5753 dpyinfo
->alt_mod_mask
= 0;
5754 dpyinfo
->super_mod_mask
= 0;
5755 dpyinfo
->hyper_mod_mask
= 0;
5758 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5760 min_code
= dpyinfo
->display
->min_keycode
;
5761 max_code
= dpyinfo
->display
->max_keycode
;
5764 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5765 min_code
, max_code
- min_code
+ 1,
5767 mods
= XGetModifierMapping (dpyinfo
->display
);
5769 /* Scan the modifier table to see which modifier bits the Meta and
5770 Alt keysyms are on. */
5772 int row
, col
; /* The row and column in the modifier table. */
5774 for (row
= 3; row
< 8; row
++)
5775 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5778 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5780 /* Zeroes are used for filler. Skip them. */
5784 /* Are any of this keycode's keysyms a meta key? */
5788 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5790 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5796 dpyinfo
->meta_mod_mask
|= (1 << row
);
5801 dpyinfo
->alt_mod_mask
|= (1 << row
);
5806 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5811 dpyinfo
->super_mod_mask
|= (1 << row
);
5815 /* Ignore this if it's not on the lock modifier. */
5816 if ((1 << row
) == LockMask
)
5817 dpyinfo
->shift_lock_mask
= LockMask
;
5825 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5826 if (! dpyinfo
->meta_mod_mask
)
5828 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
5829 dpyinfo
->alt_mod_mask
= 0;
5832 /* If some keys are both alt and meta,
5833 make them just meta, not alt. */
5834 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
5836 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
5839 XFree ((char *) syms
);
5840 XFreeModifiermap (mods
);
5843 /* Convert between the modifier bits X uses and the modifier bits
5847 x_x_to_emacs_modifiers (dpyinfo
, state
)
5848 struct x_display_info
*dpyinfo
;
5851 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
5852 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
5853 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
5854 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
5855 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
5856 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
5860 x_emacs_to_x_modifiers (dpyinfo
, state
)
5861 struct x_display_info
*dpyinfo
;
5864 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
5865 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
5866 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
5867 | ((state
& shift_modifier
) ? ShiftMask
: 0)
5868 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
5869 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
5872 /* Convert a keysym to its name. */
5875 x_get_keysym_name (keysym
)
5881 value
= XKeysymToString (keysym
);
5889 /* Mouse clicks and mouse movement. Rah. */
5891 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5892 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5893 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5894 not force the value into range. */
5897 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5899 register int pix_x
, pix_y
;
5900 register int *x
, *y
;
5904 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5905 even for negative values. */
5907 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
5909 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
5911 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5912 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5916 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
5917 bounds
->height
= f
->output_data
.x
->line_height
;
5918 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5919 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5926 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5927 pix_x
= FRAME_WINDOW_WIDTH (f
);
5931 else if (pix_y
> f
->height
)
5940 /* Given HPOS/VPOS in the current matrix of W, return corresponding
5941 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
5942 can't tell the positions because W's display is not up to date,
5946 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
5949 int *frame_x
, *frame_y
;
5953 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
5954 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
5956 if (display_completed
)
5958 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
5959 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
5960 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
5966 *frame_x
+= glyph
->pixel_width
;
5974 *frame_y
= *frame_x
= 0;
5978 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
5979 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
5984 /* Prepare a mouse-event in *RESULT for placement in the input queue.
5986 If the event is a button press, then note that we have grabbed
5990 construct_mouse_click (result
, event
, f
)
5991 struct input_event
*result
;
5992 XButtonEvent
*event
;
5995 /* Make the event type no_event; we'll change that when we decide
5997 result
->kind
= mouse_click
;
5998 result
->code
= event
->button
- Button1
;
5999 result
->timestamp
= event
->time
;
6000 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6002 | (event
->type
== ButtonRelease
6006 XSETINT (result
->x
, event
->x
);
6007 XSETINT (result
->y
, event
->y
);
6008 XSETFRAME (result
->frame_or_window
, f
);
6012 #if 0 /* This function isn't called. --gerd */
6014 /* Prepare a menu-event in *RESULT for placement in the input queue. */
6017 construct_menu_click (result
, event
, f
)
6018 struct input_event
*result
;
6019 XButtonEvent
*event
;
6022 /* Make the event type no_event; we'll change that when we decide
6024 result
->kind
= mouse_click
;
6025 result
->code
= event
->button
- Button1
;
6026 result
->timestamp
= event
->time
;
6027 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6029 | (event
->type
== ButtonRelease
6033 XSETINT (result
->x
, event
->x
);
6034 XSETINT (result
->y
, -1);
6035 XSETFRAME (result
->frame_or_window
, f
);
6041 /* Function to report a mouse movement to the mainstream Emacs code.
6042 The input handler calls this.
6044 We have received a mouse movement event, which is given in *event.
6045 If the mouse is over a different glyph than it was last time, tell
6046 the mainstream emacs code by setting mouse_moved. If not, ask for
6047 another motion event, so we can check again the next time it moves. */
6049 static XMotionEvent last_mouse_motion_event
;
6050 static Lisp_Object last_mouse_motion_frame
;
6053 note_mouse_movement (frame
, event
)
6055 XMotionEvent
*event
;
6057 last_mouse_movement_time
= event
->time
;
6058 last_mouse_motion_event
= *event
;
6059 XSETFRAME (last_mouse_motion_frame
, frame
);
6061 if (event
->window
!= FRAME_X_WINDOW (frame
))
6063 frame
->mouse_moved
= 1;
6064 last_mouse_scroll_bar
= Qnil
;
6065 note_mouse_highlight (frame
, -1, -1);
6068 /* Has the mouse moved off the glyph it was on at the last sighting? */
6069 else if (event
->x
< last_mouse_glyph
.x
6070 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6071 || event
->y
< last_mouse_glyph
.y
6072 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6074 frame
->mouse_moved
= 1;
6075 last_mouse_scroll_bar
= Qnil
;
6076 note_mouse_highlight (frame
, event
->x
, event
->y
);
6080 /* This is used for debugging, to turn off note_mouse_highlight. */
6082 int disable_mouse_highlight
;
6086 /************************************************************************
6088 ************************************************************************/
6090 /* Find the glyph under window-relative coordinates X/Y in window W.
6091 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6092 strings. Return in *HPOS and *VPOS the row and column number of
6093 the glyph found. Return in *AREA the glyph area containing X.
6094 Value is a pointer to the glyph found or null if X/Y is not on
6095 text, or we can't tell because W's current matrix is not up to
6098 static struct glyph
*
6099 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6102 int *hpos
, *vpos
, *area
;
6104 struct glyph
*glyph
, *end
;
6105 struct glyph_row
*row
;
6106 int x0
, i
, left_area_width
;
6108 /* Find row containing Y. Give up if some row is not enabled. */
6109 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6111 row
= MATRIX_ROW (w
->current_matrix
, i
);
6112 if (!row
->enabled_p
)
6114 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6121 /* Give up if Y is not in the window. */
6122 if (i
== w
->current_matrix
->nrows
)
6125 /* Get the glyph area containing X. */
6126 if (w
->pseudo_window_p
)
6133 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6134 if (x
< left_area_width
)
6136 *area
= LEFT_MARGIN_AREA
;
6139 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6142 x0
= row
->x
+ left_area_width
;
6146 *area
= RIGHT_MARGIN_AREA
;
6147 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6151 /* Find glyph containing X. */
6152 glyph
= row
->glyphs
[*area
];
6153 end
= glyph
+ row
->used
[*area
];
6156 if (x
< x0
+ glyph
->pixel_width
)
6158 if (w
->pseudo_window_p
)
6160 else if (BUFFERP (glyph
->object
))
6164 x0
+= glyph
->pixel_width
;
6171 *hpos
= glyph
- row
->glyphs
[*area
];
6176 /* Convert frame-relative x/y to coordinates relative to window W.
6177 Takes pseudo-windows into account. */
6180 frame_to_window_pixel_xy (w
, x
, y
)
6184 if (w
->pseudo_window_p
)
6186 /* A pseudo-window is always full-width, and starts at the
6187 left edge of the frame, plus a frame border. */
6188 struct frame
*f
= XFRAME (w
->frame
);
6189 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6190 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6194 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6195 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6200 /* Take proper action when mouse has moved to the mode or top line of
6201 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6202 mode line. X is relative to the start of the text display area of
6203 W, so the width of bitmap areas and scroll bars must be subtracted
6204 to get a position relative to the start of the mode line. */
6207 note_mode_line_highlight (w
, x
, mode_line_p
)
6211 struct frame
*f
= XFRAME (w
->frame
);
6212 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6213 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6214 struct glyph_row
*row
;
6217 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6219 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6223 struct glyph
*glyph
, *end
;
6224 Lisp_Object help
, map
;
6227 /* Find the glyph under X. */
6228 glyph
= row
->glyphs
[TEXT_AREA
];
6229 end
= glyph
+ row
->used
[TEXT_AREA
];
6230 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6231 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6233 && x
>= x0
+ glyph
->pixel_width
)
6235 x0
+= glyph
->pixel_width
;
6240 && STRINGP (glyph
->object
)
6241 && XSTRING (glyph
->object
)->intervals
6242 && glyph
->charpos
>= 0
6243 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6245 /* If we're on a string with `help-echo' text property,
6246 arrange for the help to be displayed. This is done by
6247 setting the global variable help_echo to the help string. */
6248 help
= Fget_text_property (make_number (glyph
->charpos
),
6249 Qhelp_echo
, glyph
->object
);
6253 /* Change the mouse pointer according to what is under X/Y. */
6254 map
= Fget_text_property (make_number (glyph
->charpos
),
6255 Qlocal_map
, glyph
->object
);
6256 if (!NILP (Fkeymapp (map
)))
6257 cursor
= f
->output_data
.x
->nontext_cursor
;
6261 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6265 /* Take proper action when the mouse has moved to position X, Y on
6266 frame F as regards highlighting characters that have mouse-face
6267 properties. Also de-highlighting chars where the mouse was before.
6268 X and Y can be negative or out of range. */
6271 note_mouse_highlight (f
, x
, y
)
6275 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6280 /* When a menu is active, don't highlight because this looks odd. */
6281 #ifdef USE_X_TOOLKIT
6282 if (popup_activated ())
6286 if (disable_mouse_highlight
6287 || !f
->glyphs_initialized_p
)
6290 dpyinfo
->mouse_face_mouse_x
= x
;
6291 dpyinfo
->mouse_face_mouse_y
= y
;
6292 dpyinfo
->mouse_face_mouse_frame
= f
;
6294 if (dpyinfo
->mouse_face_defer
)
6299 dpyinfo
->mouse_face_deferred_gc
= 1;
6303 /* Which window is that in? */
6304 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6306 /* If we were displaying active text in another window, clear that. */
6307 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6308 clear_mouse_face (dpyinfo
);
6310 /* Not on a window -> return. */
6311 if (!WINDOWP (window
))
6314 /* Convert to window-relative pixel coordinates. */
6315 w
= XWINDOW (window
);
6316 frame_to_window_pixel_xy (w
, &x
, &y
);
6318 /* Handle tool-bar window differently since it doesn't display a
6320 if (EQ (window
, f
->tool_bar_window
))
6322 note_tool_bar_highlight (f
, x
, y
);
6326 if (portion
== 1 || portion
== 3)
6328 /* Mouse is on the mode or top line. */
6329 note_mode_line_highlight (w
, x
, portion
== 1);
6333 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6334 f
->output_data
.x
->text_cursor
);
6336 /* Are we in a window whose display is up to date?
6337 And verify the buffer's text has not changed. */
6338 if (/* Within text portion of the window. */
6340 && EQ (w
->window_end_valid
, w
->buffer
)
6341 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6342 && (XFASTINT (w
->last_overlay_modified
)
6343 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6345 int hpos
, vpos
, pos
, i
, area
;
6346 struct glyph
*glyph
;
6348 /* Find the glyph under X/Y. */
6349 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6351 /* Clear mouse face if X/Y not over text. */
6353 || area
!= TEXT_AREA
6354 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6356 clear_mouse_face (dpyinfo
);
6360 pos
= glyph
->charpos
;
6361 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6363 /* Check for mouse-face and help-echo. */
6365 Lisp_Object mouse_face
, overlay
, position
;
6366 Lisp_Object
*overlay_vec
;
6368 struct buffer
*obuf
;
6371 /* If we get an out-of-range value, return now; avoid an error. */
6372 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6375 /* Make the window's buffer temporarily current for
6376 overlays_at and compute_char_face. */
6377 obuf
= current_buffer
;
6378 current_buffer
= XBUFFER (w
->buffer
);
6384 /* Is this char mouse-active or does it have help-echo? */
6385 XSETINT (position
, pos
);
6387 /* Put all the overlays we want in a vector in overlay_vec.
6388 Store the length in len. If there are more than 10, make
6389 enough space for all, and try again. */
6391 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6392 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6393 if (noverlays
> len
)
6396 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6397 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6400 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6402 /* Check mouse-face highlighting. */
6403 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6404 && vpos
>= dpyinfo
->mouse_face_beg_row
6405 && vpos
<= dpyinfo
->mouse_face_end_row
6406 && (vpos
> dpyinfo
->mouse_face_beg_row
6407 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6408 && (vpos
< dpyinfo
->mouse_face_end_row
6409 || hpos
< dpyinfo
->mouse_face_end_col
6410 || dpyinfo
->mouse_face_past_end
)))
6412 /* Clear the display of the old active region, if any. */
6413 clear_mouse_face (dpyinfo
);
6415 /* Find the highest priority overlay that has a mouse-face prop. */
6417 for (i
= 0; i
< noverlays
; i
++)
6419 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6420 if (!NILP (mouse_face
))
6422 overlay
= overlay_vec
[i
];
6427 /* If no overlay applies, get a text property. */
6429 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6431 /* Handle the overlay case. */
6432 if (! NILP (overlay
))
6434 /* Find the range of text around this char that
6435 should be active. */
6436 Lisp_Object before
, after
;
6439 before
= Foverlay_start (overlay
);
6440 after
= Foverlay_end (overlay
);
6441 /* Record this as the current active region. */
6442 fast_find_position (w
, XFASTINT (before
),
6443 &dpyinfo
->mouse_face_beg_col
,
6444 &dpyinfo
->mouse_face_beg_row
,
6445 &dpyinfo
->mouse_face_beg_x
,
6446 &dpyinfo
->mouse_face_beg_y
);
6447 dpyinfo
->mouse_face_past_end
6448 = !fast_find_position (w
, XFASTINT (after
),
6449 &dpyinfo
->mouse_face_end_col
,
6450 &dpyinfo
->mouse_face_end_row
,
6451 &dpyinfo
->mouse_face_end_x
,
6452 &dpyinfo
->mouse_face_end_y
);
6453 dpyinfo
->mouse_face_window
= window
;
6454 dpyinfo
->mouse_face_face_id
6455 = face_at_buffer_position (w
, pos
, 0, 0,
6456 &ignore
, pos
+ 1, 1);
6458 /* Display it as active. */
6459 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6461 /* Handle the text property case. */
6462 else if (! NILP (mouse_face
))
6464 /* Find the range of text around this char that
6465 should be active. */
6466 Lisp_Object before
, after
, beginning
, end
;
6469 beginning
= Fmarker_position (w
->start
);
6470 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6471 - XFASTINT (w
->window_end_pos
)));
6473 = Fprevious_single_property_change (make_number (pos
+ 1),
6475 w
->buffer
, beginning
);
6477 = Fnext_single_property_change (position
, Qmouse_face
,
6479 /* Record this as the current active region. */
6480 fast_find_position (w
, XFASTINT (before
),
6481 &dpyinfo
->mouse_face_beg_col
,
6482 &dpyinfo
->mouse_face_beg_row
,
6483 &dpyinfo
->mouse_face_beg_x
,
6484 &dpyinfo
->mouse_face_beg_y
);
6485 dpyinfo
->mouse_face_past_end
6486 = !fast_find_position (w
, XFASTINT (after
),
6487 &dpyinfo
->mouse_face_end_col
,
6488 &dpyinfo
->mouse_face_end_row
,
6489 &dpyinfo
->mouse_face_end_x
,
6490 &dpyinfo
->mouse_face_end_y
);
6491 dpyinfo
->mouse_face_window
= window
;
6492 dpyinfo
->mouse_face_face_id
6493 = face_at_buffer_position (w
, pos
, 0, 0,
6494 &ignore
, pos
+ 1, 1);
6496 /* Display it as active. */
6497 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6501 /* Look for a `help-echo' property. */
6505 /* Check overlays first. */
6507 for (i
= 0; i
< noverlays
&& !STRINGP (help
); ++i
)
6508 help
= Foverlay_get (overlay_vec
[i
], Qhelp_echo
);
6510 /* Try text properties. */
6512 && ((STRINGP (glyph
->object
)
6513 && glyph
->charpos
>= 0
6514 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6515 || (BUFFERP (glyph
->object
)
6516 && glyph
->charpos
>= BEGV
6517 && glyph
->charpos
< ZV
)))
6518 help
= Fget_text_property (make_number (glyph
->charpos
),
6519 Qhelp_echo
, glyph
->object
);
6527 current_buffer
= obuf
;
6533 redo_mouse_highlight ()
6535 if (!NILP (last_mouse_motion_frame
)
6536 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6537 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6538 last_mouse_motion_event
.x
,
6539 last_mouse_motion_event
.y
);
6544 /***********************************************************************
6546 ***********************************************************************/
6548 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6549 struct glyph
**, int *, int *, int *));
6551 /* Tool-bar item index of the item on which a mouse button was pressed
6554 static int last_tool_bar_item
;
6557 /* Get information about the tool-bar item at position X/Y on frame F.
6558 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6559 the current matrix of the tool-bar window of F, or NULL if not
6560 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6561 item in F->current_tool_bar_items. Value is
6563 -1 if X/Y is not on a tool-bar item
6564 0 if X/Y is on the same item that was highlighted before.
6568 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6571 struct glyph
**glyph
;
6572 int *hpos
, *vpos
, *prop_idx
;
6574 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6575 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6578 /* Find the glyph under X/Y. */
6579 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6583 /* Get the start of this tool-bar item's properties in
6584 f->current_tool_bar_items. */
6585 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6588 /* Is mouse on the highlighted item? */
6589 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6590 && *vpos
>= dpyinfo
->mouse_face_beg_row
6591 && *vpos
<= dpyinfo
->mouse_face_end_row
6592 && (*vpos
> dpyinfo
->mouse_face_beg_row
6593 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6594 && (*vpos
< dpyinfo
->mouse_face_end_row
6595 || *hpos
< dpyinfo
->mouse_face_end_col
6596 || dpyinfo
->mouse_face_past_end
))
6603 /* Handle mouse button event on the tool-bar of frame F, at
6604 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6608 x_handle_tool_bar_click (f
, button_event
)
6610 XButtonEvent
*button_event
;
6612 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6613 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6614 int hpos
, vpos
, prop_idx
;
6615 struct glyph
*glyph
;
6616 Lisp_Object enabled_p
;
6617 int x
= button_event
->x
;
6618 int y
= button_event
->y
;
6620 /* If not on the highlighted tool-bar item, return. */
6621 frame_to_window_pixel_xy (w
, &x
, &y
);
6622 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6625 /* If item is disabled, do nothing. */
6626 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6627 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6628 if (NILP (enabled_p
))
6631 if (button_event
->type
== ButtonPress
)
6633 /* Show item in pressed state. */
6634 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6635 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6636 last_tool_bar_item
= prop_idx
;
6640 Lisp_Object key
, frame
;
6641 struct input_event event
;
6643 /* Show item in released state. */
6644 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6645 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6647 key
= (XVECTOR (f
->current_tool_bar_items
)
6648 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6650 XSETFRAME (frame
, f
);
6651 event
.kind
= TOOL_BAR_EVENT
;
6652 event
.frame_or_window
= Fcons (frame
, Fcons (Qtool_bar
, Qnil
));
6653 kbd_buffer_store_event (&event
);
6655 event
.kind
= TOOL_BAR_EVENT
;
6656 event
.frame_or_window
= Fcons (frame
, key
);
6657 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6658 button_event
->state
);
6659 kbd_buffer_store_event (&event
);
6660 last_tool_bar_item
= -1;
6665 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6666 tool-bar window-relative coordinates X/Y. Called from
6667 note_mouse_highlight. */
6670 note_tool_bar_highlight (f
, x
, y
)
6674 Lisp_Object window
= f
->tool_bar_window
;
6675 struct window
*w
= XWINDOW (window
);
6676 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6678 struct glyph
*glyph
;
6679 struct glyph_row
*row
;
6681 Lisp_Object enabled_p
;
6683 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6684 int mouse_down_p
, rc
;
6686 /* Function note_mouse_highlight is called with negative x(y
6687 values when mouse moves outside of the frame. */
6688 if (x
<= 0 || y
<= 0)
6690 clear_mouse_face (dpyinfo
);
6694 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6697 /* Not on tool-bar item. */
6698 clear_mouse_face (dpyinfo
);
6702 /* On same tool-bar item as before. */
6705 clear_mouse_face (dpyinfo
);
6707 /* Mouse is down, but on different tool-bar item? */
6708 mouse_down_p
= (dpyinfo
->grabbed
6709 && f
== last_mouse_frame
6710 && FRAME_LIVE_P (f
));
6712 && last_tool_bar_item
!= prop_idx
)
6715 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6716 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6718 /* If tool-bar item is not enabled, don't highlight it. */
6719 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6720 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6721 if (!NILP (enabled_p
))
6723 /* Compute the x-position of the glyph. In front and past the
6724 image is a space. We include this is the highlighted area. */
6725 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6726 for (i
= x
= 0; i
< hpos
; ++i
)
6727 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6729 /* Record this as the current active region. */
6730 dpyinfo
->mouse_face_beg_col
= hpos
;
6731 dpyinfo
->mouse_face_beg_row
= vpos
;
6732 dpyinfo
->mouse_face_beg_x
= x
;
6733 dpyinfo
->mouse_face_beg_y
= row
->y
;
6734 dpyinfo
->mouse_face_past_end
= 0;
6736 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6737 dpyinfo
->mouse_face_end_row
= vpos
;
6738 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6739 dpyinfo
->mouse_face_end_y
= row
->y
;
6740 dpyinfo
->mouse_face_window
= window
;
6741 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6743 /* Display it as active. */
6744 show_mouse_face (dpyinfo
, draw
);
6745 dpyinfo
->mouse_face_image_state
= draw
;
6750 /* Set help_echo to a help string.to display for this tool-bar item.
6751 XTread_socket does the rest. */
6752 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6753 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6754 if (!STRINGP (help_echo
))
6755 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6756 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6761 /* Find the glyph matrix position of buffer position POS in window W.
6762 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6763 current glyphs must be up to date. If POS is above window start
6764 return (0, 0, 0, 0). If POS is after end of W, return end of
6768 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6771 int *hpos
, *vpos
, *x
, *y
;
6775 int maybe_next_line_p
= 0;
6776 int line_start_position
;
6777 int yb
= window_text_bottom_y (w
);
6778 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6779 struct glyph_row
*best_row
= row
;
6780 int row_vpos
= 0, best_row_vpos
= 0;
6785 if (row
->used
[TEXT_AREA
])
6786 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6788 line_start_position
= 0;
6790 if (line_start_position
> pos
)
6792 /* If the position sought is the end of the buffer,
6793 don't include the blank lines at the bottom of the window. */
6794 else if (line_start_position
== pos
6795 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6797 maybe_next_line_p
= 1;
6800 else if (line_start_position
> 0)
6803 best_row_vpos
= row_vpos
;
6806 if (row
->y
+ row
->height
>= yb
)
6813 /* Find the right column within BEST_ROW. */
6815 current_x
= best_row
->x
;
6816 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6818 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6821 charpos
= glyph
->charpos
;
6825 *vpos
= best_row_vpos
;
6830 else if (charpos
> pos
)
6832 else if (charpos
> 0)
6835 current_x
+= glyph
->pixel_width
;
6838 /* If we're looking for the end of the buffer,
6839 and we didn't find it in the line we scanned,
6840 use the start of the following line. */
6841 if (maybe_next_line_p
)
6846 current_x
= best_row
->x
;
6849 *vpos
= best_row_vpos
;
6850 *hpos
= lastcol
+ 1;
6857 /* Display the active region described by mouse_face_*
6858 in its mouse-face if HL > 0, in its normal face if HL = 0. */
6861 show_mouse_face (dpyinfo
, draw
)
6862 struct x_display_info
*dpyinfo
;
6863 enum draw_glyphs_face draw
;
6865 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
6866 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6868 int cursor_off_p
= 0;
6869 struct cursor_pos saved_cursor
;
6871 saved_cursor
= output_cursor
;
6873 /* If window is in the process of being destroyed, don't bother
6875 if (w
->current_matrix
== NULL
)
6878 /* Recognize when we are called to operate on rows that don't exist
6879 anymore. This can happen when a window is split. */
6880 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
6883 set_output_cursor (&w
->phys_cursor
);
6885 /* Note that mouse_face_beg_row etc. are window relative. */
6886 for (i
= dpyinfo
->mouse_face_beg_row
;
6887 i
<= dpyinfo
->mouse_face_end_row
;
6890 int start_hpos
, end_hpos
, start_x
;
6891 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
6893 /* Don't do anything if row doesn't have valid contents. */
6894 if (!row
->enabled_p
)
6897 /* For all but the first row, the highlight starts at column 0. */
6898 if (i
== dpyinfo
->mouse_face_beg_row
)
6900 start_hpos
= dpyinfo
->mouse_face_beg_col
;
6901 start_x
= dpyinfo
->mouse_face_beg_x
;
6909 if (i
== dpyinfo
->mouse_face_end_row
)
6910 end_hpos
= dpyinfo
->mouse_face_end_col
;
6912 end_hpos
= row
->used
[TEXT_AREA
];
6914 /* If the cursor's in the text we are about to rewrite, turn the
6916 if (!w
->pseudo_window_p
6917 && i
== output_cursor
.vpos
6918 && output_cursor
.hpos
>= start_hpos
- 1
6919 && output_cursor
.hpos
<= end_hpos
)
6921 x_update_window_cursor (w
, 0);
6925 if (end_hpos
> start_hpos
)
6926 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
6927 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
6930 /* If we turned the cursor off, turn it back on. */
6932 x_display_cursor (w
, 1,
6933 output_cursor
.hpos
, output_cursor
.vpos
,
6934 output_cursor
.x
, output_cursor
.y
);
6936 output_cursor
= saved_cursor
;
6940 /* Change the mouse cursor. */
6941 if (draw
== DRAW_NORMAL_TEXT
)
6942 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6943 f
->output_data
.x
->text_cursor
);
6944 else if (draw
== DRAW_MOUSE_FACE
)
6945 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6946 f
->output_data
.x
->cross_cursor
);
6948 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6949 f
->output_data
.x
->nontext_cursor
);
6952 /* Clear out the mouse-highlighted active region.
6953 Redraw it un-highlighted first. */
6956 clear_mouse_face (dpyinfo
)
6957 struct x_display_info
*dpyinfo
;
6962 if (! NILP (dpyinfo
->mouse_face_window
))
6963 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
6965 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6966 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6967 dpyinfo
->mouse_face_window
= Qnil
;
6970 /* Just discard the mouse face information for frame F, if any.
6971 This is used when the size of F is changed. */
6974 cancel_mouse_face (f
)
6978 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6980 window
= dpyinfo
->mouse_face_window
;
6981 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
6983 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6984 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6985 dpyinfo
->mouse_face_window
= Qnil
;
6989 static struct scroll_bar
*x_window_to_scroll_bar ();
6990 static void x_scroll_bar_report_motion ();
6992 /* Return the current position of the mouse.
6993 *fp should be a frame which indicates which display to ask about.
6995 If the mouse movement started in a scroll bar, set *fp, *bar_window,
6996 and *part to the frame, window, and scroll bar part that the mouse
6997 is over. Set *x and *y to the portion and whole of the mouse's
6998 position on the scroll bar.
7000 If the mouse movement started elsewhere, set *fp to the frame the
7001 mouse is on, *bar_window to nil, and *x and *y to the character cell
7004 Set *time to the server time-stamp for the time at which the mouse
7005 was at this position.
7007 Don't store anything if we don't have a valid set of values to report.
7009 This clears the mouse_moved flag, so we can wait for the next mouse
7013 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7016 Lisp_Object
*bar_window
;
7017 enum scroll_bar_part
*part
;
7019 unsigned long *time
;
7025 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7026 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7032 Window dummy_window
;
7035 Lisp_Object frame
, tail
;
7037 /* Clear the mouse-moved flag for every frame on this display. */
7038 FOR_EACH_FRAME (tail
, frame
)
7039 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7040 XFRAME (frame
)->mouse_moved
= 0;
7042 last_mouse_scroll_bar
= Qnil
;
7044 /* Figure out which root window we're on. */
7045 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7046 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7048 /* The root window which contains the pointer. */
7051 /* Trash which we can't trust if the pointer is on
7052 a different screen. */
7055 /* The position on that root window. */
7058 /* More trash we can't trust. */
7061 /* Modifier keys and pointer buttons, about which
7063 (unsigned int *) &dummy
);
7065 /* Now we have a position on the root; find the innermost window
7066 containing the pointer. */
7070 int parent_x
= 0, parent_y
= 0;
7075 /* XTranslateCoordinates can get errors if the window
7076 structure is changing at the same time this function
7077 is running. So at least we must not crash from them. */
7079 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7081 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7082 && FRAME_LIVE_P (last_mouse_frame
))
7084 /* If mouse was grabbed on a frame, give coords for that frame
7085 even if the mouse is now outside it. */
7086 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7088 /* From-window, to-window. */
7089 root
, FRAME_X_WINDOW (last_mouse_frame
),
7091 /* From-position, to-position. */
7092 root_x
, root_y
, &win_x
, &win_y
,
7096 f1
= last_mouse_frame
;
7102 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7104 /* From-window, to-window. */
7107 /* From-position, to-position. */
7108 root_x
, root_y
, &win_x
, &win_y
,
7113 if (child
== None
|| child
== win
)
7121 /* Now we know that:
7122 win is the innermost window containing the pointer
7123 (XTC says it has no child containing the pointer),
7124 win_x and win_y are the pointer's position in it
7125 (XTC did this the last time through), and
7126 parent_x and parent_y are the pointer's position in win's parent.
7127 (They are what win_x and win_y were when win was child.
7128 If win is the root window, it has no parent, and
7129 parent_{x,y} are invalid, but that's okay, because we'll
7130 never use them in that case.) */
7132 /* Is win one of our frames? */
7133 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7136 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7139 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7141 /* If not, is it one of our scroll bars? */
7144 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7148 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7154 if (f1
== 0 && insist
> 0)
7155 f1
= SELECTED_FRAME ();
7159 /* Ok, we found a frame. Store all the values.
7160 last_mouse_glyph is a rectangle used to reduce the
7161 generation of mouse events. To not miss any motion
7162 events, we must divide the frame into rectangles of the
7163 size of the smallest character that could be displayed
7164 on it, i.e. into the same rectangles that matrices on
7165 the frame are divided into. */
7167 #if OLD_REDISPLAY_CODE
7168 int ignore1
, ignore2
;
7169 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7171 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7175 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7176 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7180 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7181 round down even for negative values. */
7187 last_mouse_glyph
.width
= width
;
7188 last_mouse_glyph
.height
= height
;
7189 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7190 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7197 XSETINT (*x
, win_x
);
7198 XSETINT (*y
, win_y
);
7199 *time
= last_mouse_movement_time
;
7208 #ifdef USE_X_TOOLKIT
7210 /* Atimer callback function for TIMER. Called every 0.1s to process
7211 Xt timeouts, if needed. We must avoid calling XtAppPending as
7212 much as possible because that function does an implicit XFlush
7213 that slows us down. */
7216 x_process_timeouts (timer
)
7217 struct atimer
*timer
;
7219 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7222 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7223 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7228 #endif /* USE_X_TOOLKIT */
7231 /* Scroll bar support. */
7233 /* Given an X window ID, find the struct scroll_bar which manages it.
7234 This can be called in GC, so we have to make sure to strip off mark
7237 static struct scroll_bar
*
7238 x_window_to_scroll_bar (window_id
)
7243 for (tail
= Vframe_list
;
7244 XGCTYPE (tail
) == Lisp_Cons
;
7247 Lisp_Object frame
, bar
, condemned
;
7249 frame
= XCAR (tail
);
7250 /* All elements of Vframe_list should be frames. */
7251 if (! GC_FRAMEP (frame
))
7254 /* Scan this frame's scroll bar list for a scroll bar with the
7256 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7257 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7258 /* This trick allows us to search both the ordinary and
7259 condemned scroll bar lists with one loop. */
7260 ! GC_NILP (bar
) || (bar
= condemned
,
7263 bar
= XSCROLL_BAR (bar
)->next
)
7264 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7265 return XSCROLL_BAR (bar
);
7273 /************************************************************************
7275 ************************************************************************/
7277 #if USE_TOOLKIT_SCROLL_BARS
7279 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7280 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7281 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7282 struct scroll_bar
*));
7283 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7287 /* Id of action hook installed for scroll bars. */
7289 static XtActionHookId action_hook_id
;
7291 /* Lisp window being scrolled. Set when starting to interact with
7292 a toolkit scroll bar, reset to nil when ending the interaction. */
7294 static Lisp_Object window_being_scrolled
;
7296 /* Last scroll bar part sent in xm_scroll_callback. */
7298 static int last_scroll_bar_part
;
7300 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7301 that movements of 1/20 of the screen size are mapped to up/down. */
7303 static Boolean xaw3d_arrow_scroll
;
7305 /* Whether the drag scrolling maintains the mouse at the top of the
7306 thumb. If not, resizing the thumb needs to be done more carefully
7307 to avoid jerkyness. */
7309 static Boolean xaw3d_pick_top
;
7312 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7313 bars are used.. The hook is responsible for detecting when
7314 the user ends an interaction with the scroll bar, and generates
7315 a `end-scroll' scroll_bar_click' event if so. */
7318 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7321 XtPointer client_data
;
7325 Cardinal
*num_params
;
7331 scroll_bar_p
= XmIsScrollBar (widget
);
7332 end_action
= "Release";
7333 #else /* !USE_MOTIF i.e. use Xaw */
7334 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7335 end_action
= "EndScroll";
7336 #endif /* USE_MOTIF */
7339 && strcmp (action_name
, end_action
) == 0
7340 && WINDOWP (window_being_scrolled
))
7344 x_send_scroll_bar_event (window_being_scrolled
,
7345 scroll_bar_end_scroll
, 0, 0);
7346 w
= XWINDOW (window_being_scrolled
);
7347 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7348 window_being_scrolled
= Qnil
;
7349 last_scroll_bar_part
= -1;
7351 /* Xt timeouts no longer needed. */
7352 toolkit_scroll_bar_interaction
= 0;
7357 /* Send a client message with message type Xatom_Scrollbar for a
7358 scroll action to the frame of WINDOW. PART is a value identifying
7359 the part of the scroll bar that was clicked on. PORTION is the
7360 amount to scroll of a whole of WHOLE. */
7363 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7365 int part
, portion
, whole
;
7368 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7369 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7371 /* Construct a ClientMessage event to send to the frame. */
7372 ev
->type
= ClientMessage
;
7373 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7374 ev
->display
= FRAME_X_DISPLAY (f
);
7375 ev
->window
= FRAME_X_WINDOW (f
);
7377 ev
->data
.l
[0] = (long) window
;
7378 ev
->data
.l
[1] = (long) part
;
7379 ev
->data
.l
[2] = (long) 0;
7380 ev
->data
.l
[3] = (long) portion
;
7381 ev
->data
.l
[4] = (long) whole
;
7383 /* Make Xt timeouts work while the scroll bar is active. */
7384 toolkit_scroll_bar_interaction
= 1;
7386 /* Setting the event mask to zero means that the message will
7387 be sent to the client that created the window, and if that
7388 window no longer exists, no event will be sent. */
7390 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7395 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7399 x_scroll_bar_to_input_event (event
, ievent
)
7401 struct input_event
*ievent
;
7403 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7404 Lisp_Object window
= (Lisp_Object
) ev
->data
.l
[0];
7405 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7407 ievent
->kind
= scroll_bar_click
;
7408 ievent
->frame_or_window
= window
;
7409 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7410 ievent
->part
= ev
->data
.l
[1];
7411 ievent
->code
= ev
->data
.l
[2];
7412 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7413 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7414 ievent
->modifiers
= 0;
7420 /* Minimum and maximum values used for Motif scroll bars. */
7423 #define XM_SB_MAX 10000000
7424 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7427 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7428 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7429 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7432 xm_scroll_callback (widget
, client_data
, call_data
)
7434 XtPointer client_data
, call_data
;
7436 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7437 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7439 int part
= -1, whole
= 0, portion
= 0;
7443 case XmCR_DECREMENT
:
7444 bar
->dragging
= Qnil
;
7445 part
= scroll_bar_up_arrow
;
7448 case XmCR_INCREMENT
:
7449 bar
->dragging
= Qnil
;
7450 part
= scroll_bar_down_arrow
;
7453 case XmCR_PAGE_DECREMENT
:
7454 bar
->dragging
= Qnil
;
7455 part
= scroll_bar_above_handle
;
7458 case XmCR_PAGE_INCREMENT
:
7459 bar
->dragging
= Qnil
;
7460 part
= scroll_bar_below_handle
;
7464 bar
->dragging
= Qnil
;
7465 part
= scroll_bar_to_top
;
7468 case XmCR_TO_BOTTOM
:
7469 bar
->dragging
= Qnil
;
7470 part
= scroll_bar_to_bottom
;
7476 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7477 && XINT (bar
->dragging
) <= cs
->value
);
7479 /* Get the slider size. */
7481 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7484 /* At the max position of the scroll bar, do a line-wise
7485 movement. Without doing anything, the LessTif scroll bar
7486 calls us with the same cs->value again and again. If we
7487 want to make sure that we can reach the end of the buffer,
7488 we have to do something.
7490 Implementation note: setting bar->dragging always to
7491 cs->value gives a smoother movement at the max position.
7492 Setting it to nil when doing line-wise movement gives
7493 a better slider behavior. */
7495 if (cs
->value
+ slider_size
== XM_SB_MAX
7497 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7499 part
= scroll_bar_down_arrow
;
7500 bar
->dragging
= Qnil
;
7504 whole
= XM_SB_RANGE
;
7505 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7506 part
= scroll_bar_handle
;
7507 bar
->dragging
= make_number (cs
->value
);
7512 case XmCR_VALUE_CHANGED
:
7518 window_being_scrolled
= bar
->window
;
7519 last_scroll_bar_part
= part
;
7520 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7525 #else /* !USE_MOTIF, i.e. Xaw. */
7528 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7529 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7530 scroll bar struct. CALL_DATA is a pointer to a float saying where
7534 xaw_jump_callback (widget
, client_data
, call_data
)
7536 XtPointer client_data
, call_data
;
7538 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7539 float top
= *(float *) call_data
;
7541 int whole
, portion
, height
;
7544 /* Get the size of the thumb, a value between 0 and 1. */
7546 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7550 portion
= shown
< 1 ? top
* whole
: 0;
7552 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7553 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7554 the bottom, so we force the scrolling whenever we see that we're
7555 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7556 we try to ensure that we always stay two pixels away from the
7558 part
= scroll_bar_down_arrow
;
7560 part
= scroll_bar_handle
;
7562 window_being_scrolled
= bar
->window
;
7563 bar
->dragging
= make_number (portion
);
7564 last_scroll_bar_part
= part
;
7565 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7569 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7570 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7571 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7572 the scroll bar. CALL_DATA is an integer specifying the action that
7573 has taken place. It's magnitude is in the range 0..height of the
7574 scroll bar. Negative values mean scroll towards buffer start.
7575 Values < height of scroll bar mean line-wise movement. */
7578 xaw_scroll_callback (widget
, client_data
, call_data
)
7580 XtPointer client_data
, call_data
;
7582 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7583 int position
= (int) call_data
;
7587 /* Get the height of the scroll bar. */
7589 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7592 if (abs (position
) >= height
)
7593 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
7595 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
7596 it maps line-movement to call_data = max(5, height/20). */
7597 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
7598 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
7600 part
= scroll_bar_move_ratio
;
7602 window_being_scrolled
= bar
->window
;
7603 bar
->dragging
= Qnil
;
7604 last_scroll_bar_part
= part
;
7605 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
7609 #endif /* not USE_MOTIF */
7612 /* Create the widget for scroll bar BAR on frame F. Record the widget
7613 and X window of the scroll bar in BAR. */
7616 x_create_toolkit_scroll_bar (f
, bar
)
7618 struct scroll_bar
*bar
;
7624 char *scroll_bar_name
= "verticalScrollBar";
7625 unsigned long pixel
;
7630 /* LessTif 0.85, problems:
7632 1. When the mouse if over the scroll bar, the scroll bar will
7633 get keyboard events. I didn't find a way to turn this off.
7635 2. Do we have to explicitly set the cursor to get an arrow
7636 cursor (see below)? */
7638 /* Set resources. Create the widget. */
7639 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7640 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7641 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7642 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7643 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7644 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7645 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7647 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7650 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7654 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7657 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7661 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7662 scroll_bar_name
, av
, ac
);
7664 /* Add one callback for everything that can happen. */
7665 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7667 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7669 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7671 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7673 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7675 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7677 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7680 /* Realize the widget. Only after that is the X window created. */
7681 XtRealizeWidget (widget
);
7683 /* Set the cursor to an arrow. I didn't find a resource to do that.
7684 And I'm wondering why it hasn't an arrow cursor by default. */
7685 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7686 f
->output_data
.x
->nontext_cursor
);
7688 #else /* !USE_MOTIF i.e. use Xaw */
7690 /* Set resources. Create the widget. The background of the
7691 Xaw3d scroll bar widget is a little bit light for my taste.
7692 We don't alter it here to let users change it according
7693 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7694 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7695 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7696 /* For smoother scrolling with Xaw3d -sm */
7697 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
7698 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
7700 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7703 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7707 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7710 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7714 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7715 f
->output_data
.x
->edit_widget
, av
, ac
);
7719 char *val
= initial
;
7720 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
7721 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
7723 { /* ARROW_SCROLL */
7724 xaw3d_arrow_scroll
= True
;
7725 /* Isn't that just a personal preference ? -sm */
7726 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
7730 /* Define callbacks. */
7731 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
7732 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
7735 /* Realize the widget. Only after that is the X window created. */
7736 XtRealizeWidget (widget
);
7738 #endif /* !USE_MOTIF */
7740 /* Install an action hook that let's us detect when the user
7741 finishes interacting with a scroll bar. */
7742 if (action_hook_id
== 0)
7743 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7745 /* Remember X window and widget in the scroll bar vector. */
7746 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7747 xwindow
= XtWindow (widget
);
7748 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7754 /* Set the thumb size and position of scroll bar BAR. We are currently
7755 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7758 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7759 struct scroll_bar
*bar
;
7760 int portion
, position
, whole
;
7763 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7769 top
= (float) position
/ whole
;
7770 shown
= (float) portion
/ whole
;
7778 Boolean arrow1_selected
, arrow2_selected
;
7779 unsigned char flags
;
7780 XmScrollBarWidget sb
;
7782 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
7783 is the scroll bar's maximum and MIN is the scroll bar's minimum
7785 size
= shown
* XM_SB_RANGE
;
7786 size
= min (size
, XM_SB_RANGE
);
7787 size
= max (size
, 1);
7789 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7790 value
= top
* XM_SB_RANGE
;
7791 value
= min (value
, XM_SB_MAX
- size
);
7792 value
= max (value
, XM_SB_MIN
);
7794 /* LessTif: Calling XmScrollBarSetValues after an increment or
7795 decrement turns off auto-repeat LessTif-internally. This can
7796 be seen in ScrollBar.c which resets Arrow1Selected and
7797 Arrow2Selected. It also sets internal flags so that LessTif
7798 believes the mouse is in the slider. We either have to change
7799 our code, or work around that by accessing private data. */
7801 sb
= (XmScrollBarWidget
) widget
;
7802 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
7803 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
7804 flags
= sb
->scrollBar
.flags
;
7806 if (NILP (bar
->dragging
))
7807 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
7808 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7809 /* This has the negative side effect that the slider value is
7810 not what it would be if we scrolled here using line-wise or
7811 page-wise movement. */
7812 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
7815 /* If currently dragging, only update the slider size.
7816 This reduces flicker effects. */
7817 int old_value
, old_size
, increment
, page_increment
;
7819 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
7820 &increment
, &page_increment
);
7821 XmScrollBarSetValues (widget
, old_value
,
7822 min (size
, XM_SB_RANGE
- old_value
),
7826 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
7827 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
7828 sb
->scrollBar
.flags
= flags
;
7830 #else /* !USE_MOTIF i.e. use Xaw */
7832 float old_top
, old_shown
;
7834 XtVaGetValues (widget
,
7835 XtNtopOfThumb
, &old_top
,
7836 XtNshown
, &old_shown
,
7840 /* Massage the top+shown values. */
7841 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
7842 top
= max (0, min (1, top
));
7845 /* Keep two pixels available for moving the thumb down. */
7846 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
7848 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
7849 check that your system's configuration file contains a define
7850 for `NARROWPROTO'. See s/freebsd.h for an example. */
7851 if (top
!= old_top
|| shown
!= old_shown
)
7853 if (NILP (bar
->dragging
))
7854 XawScrollbarSetThumb (widget
, top
, shown
);
7858 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
7861 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
7862 if (xaw3d_arrow_scroll
)
7864 /* Xaw3d stupidly ignores resize requests while dragging
7865 so we have to make it believe it's not in dragging mode. */
7866 scroll_mode
= sb
->scrollbar
.scroll_mode
;
7867 if (scroll_mode
== 2)
7868 sb
->scrollbar
.scroll_mode
= 0;
7871 /* Try to make the scrolling a tad smoother. */
7872 if (!xaw3d_pick_top
)
7873 shown
= min (shown
, old_shown
);
7875 XawScrollbarSetThumb (widget
, top
, shown
);
7878 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
7879 sb
->scrollbar
.scroll_mode
= scroll_mode
;
7884 #endif /* !USE_MOTIF */
7889 #endif /* USE_TOOLKIT_SCROLL_BARS */
7893 /************************************************************************
7894 Scroll bars, general
7895 ************************************************************************/
7897 /* Create a scroll bar and return the scroll bar vector for it. W is
7898 the Emacs window on which to create the scroll bar. TOP, LEFT,
7899 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7902 static struct scroll_bar
*
7903 x_scroll_bar_create (w
, top
, left
, width
, height
)
7905 int top
, left
, width
, height
;
7907 struct frame
*f
= XFRAME (w
->frame
);
7908 struct scroll_bar
*bar
7909 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7913 #if USE_TOOLKIT_SCROLL_BARS
7914 x_create_toolkit_scroll_bar (f
, bar
);
7915 #else /* not USE_TOOLKIT_SCROLL_BARS */
7917 XSetWindowAttributes a
;
7921 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7922 if (a
.background_pixel
== -1)
7923 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
7925 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
7926 | ButtonMotionMask
| PointerMotionHintMask
7928 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
7930 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
7932 /* Clear the area of W that will serve as a scroll bar. This is
7933 for the case that a window has been split horizontally. In
7934 this case, no clear_frame is generated to reduce flickering. */
7935 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7937 window_box_height (w
), False
);
7939 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7940 /* Position and size of scroll bar. */
7941 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7943 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7945 /* Border width, depth, class, and visual. */
7952 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
7954 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7956 XSETWINDOW (bar
->window
, w
);
7957 XSETINT (bar
->top
, top
);
7958 XSETINT (bar
->left
, left
);
7959 XSETINT (bar
->width
, width
);
7960 XSETINT (bar
->height
, height
);
7961 XSETINT (bar
->start
, 0);
7962 XSETINT (bar
->end
, 0);
7963 bar
->dragging
= Qnil
;
7965 /* Add bar to its frame's list of scroll bars. */
7966 bar
->next
= FRAME_SCROLL_BARS (f
);
7968 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7969 if (!NILP (bar
->next
))
7970 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7972 /* Map the window/widget. */
7973 #if USE_TOOLKIT_SCROLL_BARS
7974 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
7975 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
7976 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7978 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7980 #else /* not USE_TOOLKIT_SCROLL_BARS */
7981 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7982 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7989 /* Draw BAR's handle in the proper position.
7991 If the handle is already drawn from START to END, don't bother
7992 redrawing it, unless REBUILD is non-zero; in that case, always
7993 redraw it. (REBUILD is handy for drawing the handle after expose
7996 Normally, we want to constrain the start and end of the handle to
7997 fit inside its rectangle, but if the user is dragging the scroll
7998 bar handle, we want to let them drag it down all the way, so that
7999 the bar's top is as far down as it goes; otherwise, there's no way
8000 to move to the very end of the buffer. */
8002 #ifndef USE_TOOLKIT_SCROLL_BARS
8005 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8006 struct scroll_bar
*bar
;
8010 int dragging
= ! NILP (bar
->dragging
);
8011 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8012 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8013 GC gc
= f
->output_data
.x
->normal_gc
;
8015 /* If the display is already accurate, do nothing. */
8017 && start
== XINT (bar
->start
)
8018 && end
== XINT (bar
->end
))
8024 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8025 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8026 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8028 /* Make sure the values are reasonable, and try to preserve
8029 the distance between start and end. */
8031 int length
= end
- start
;
8035 else if (start
> top_range
)
8037 end
= start
+ length
;
8041 else if (end
> top_range
&& ! dragging
)
8045 /* Store the adjusted setting in the scroll bar. */
8046 XSETINT (bar
->start
, start
);
8047 XSETINT (bar
->end
, end
);
8049 /* Clip the end position, just for display. */
8050 if (end
> top_range
)
8053 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8054 below top positions, to make sure the handle is always at least
8055 that many pixels tall. */
8056 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8058 /* Draw the empty space above the handle. Note that we can't clear
8059 zero-height areas; that means "clear to end of window." */
8061 XClearArea (FRAME_X_DISPLAY (f
), w
,
8063 /* x, y, width, height, and exposures. */
8064 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8065 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8066 inside_width
, start
,
8069 /* Change to proper foreground color if one is specified. */
8070 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8071 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8072 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8074 /* Draw the handle itself. */
8075 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8077 /* x, y, width, height */
8078 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8079 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8080 inside_width
, end
- start
);
8082 /* Restore the foreground color of the GC if we changed it above. */
8083 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8084 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8085 f
->output_data
.x
->foreground_pixel
);
8087 /* Draw the empty space below the handle. Note that we can't
8088 clear zero-height areas; that means "clear to end of window." */
8089 if (end
< inside_height
)
8090 XClearArea (FRAME_X_DISPLAY (f
), w
,
8092 /* x, y, width, height, and exposures. */
8093 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8094 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8095 inside_width
, inside_height
- end
,
8103 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8105 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8109 x_scroll_bar_remove (bar
)
8110 struct scroll_bar
*bar
;
8114 #if USE_TOOLKIT_SCROLL_BARS
8115 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
8116 #else /* not USE_TOOLKIT_SCROLL_BARS */
8118 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8119 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8121 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8123 /* Disassociate this scroll bar from its window. */
8124 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8130 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8131 that we are displaying PORTION characters out of a total of WHOLE
8132 characters, starting at POSITION. If WINDOW has no scroll bar,
8136 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8138 int portion
, whole
, position
;
8140 struct frame
*f
= XFRAME (w
->frame
);
8141 struct scroll_bar
*bar
;
8142 int top
, height
, left
, sb_left
, width
, sb_width
;
8143 int window_x
, window_y
, window_width
, window_height
;
8145 /* Get window dimensions. */
8146 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8148 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8149 height
= window_height
;
8151 /* Compute the left edge of the scroll bar area. */
8152 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8153 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8155 left
= XFASTINT (w
->left
);
8156 left
*= CANON_X_UNIT (f
);
8157 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8159 /* Compute the width of the scroll bar which might be less than
8160 the width of the area reserved for the scroll bar. */
8161 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8162 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8166 /* Compute the left edge of the scroll bar. */
8167 #ifdef USE_TOOLKIT_SCROLL_BARS
8168 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8169 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8171 sb_left
= left
+ (width
- sb_width
) / 2;
8173 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8174 sb_left
= left
+ width
- sb_width
;
8179 /* Does the scroll bar exist yet? */
8180 if (NILP (w
->vertical_scroll_bar
))
8183 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8184 left
, top
, width
, height
, False
);
8186 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8190 /* It may just need to be moved and resized. */
8191 unsigned int mask
= 0;
8193 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8197 if (sb_left
!= XINT (bar
->left
))
8199 if (top
!= XINT (bar
->top
))
8201 if (sb_width
!= XINT (bar
->width
))
8203 if (height
!= XINT (bar
->height
))
8206 #ifdef USE_TOOLKIT_SCROLL_BARS
8208 /* Since toolkit scroll bars are smaller than the space reserved
8209 for them on the frame, we have to clear "under" them. */
8210 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8211 left
, top
, width
, height
, False
);
8213 /* Move/size the scroll bar widget. */
8215 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8216 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8218 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8221 #else /* not USE_TOOLKIT_SCROLL_BARS */
8223 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8225 /* Clear areas not covered by the scroll bar. This makes sure a
8226 previous mode line display is cleared after C-x 2 C-x 1, for
8227 example. Non-toolkit scroll bars are as wide as the area
8228 reserved for scroll bars - trim at both sides. */
8229 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8230 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8232 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8233 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8234 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8238 /* Move/size the scroll bar window. */
8243 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8245 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8247 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8251 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8253 /* Remember new settings. */
8254 XSETINT (bar
->left
, sb_left
);
8255 XSETINT (bar
->top
, top
);
8256 XSETINT (bar
->width
, sb_width
);
8257 XSETINT (bar
->height
, height
);
8262 #if USE_TOOLKIT_SCROLL_BARS
8263 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8264 #else /* not USE_TOOLKIT_SCROLL_BARS */
8265 /* Set the scroll bar's current state, unless we're currently being
8267 if (NILP (bar
->dragging
))
8269 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8272 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8275 int start
= ((double) position
* top_range
) / whole
;
8276 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8277 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8280 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8282 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8286 /* The following three hooks are used when we're doing a thorough
8287 redisplay of the frame. We don't explicitly know which scroll bars
8288 are going to be deleted, because keeping track of when windows go
8289 away is a real pain - "Can you say set-window-configuration, boys
8290 and girls?" Instead, we just assert at the beginning of redisplay
8291 that *all* scroll bars are to be removed, and then save a scroll bar
8292 from the fiery pit when we actually redisplay its window. */
8294 /* Arrange for all scroll bars on FRAME to be removed at the next call
8295 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8296 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8299 XTcondemn_scroll_bars (frame
)
8302 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8303 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8306 bar
= FRAME_SCROLL_BARS (frame
);
8307 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8308 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8309 XSCROLL_BAR (bar
)->prev
= Qnil
;
8310 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8311 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8312 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8316 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8317 Note that WINDOW isn't necessarily condemned at all. */
8319 XTredeem_scroll_bar (window
)
8320 struct window
*window
;
8322 struct scroll_bar
*bar
;
8324 /* We can't redeem this window's scroll bar if it doesn't have one. */
8325 if (NILP (window
->vertical_scroll_bar
))
8328 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8330 /* Unlink it from the condemned list. */
8332 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8334 if (NILP (bar
->prev
))
8336 /* If the prev pointer is nil, it must be the first in one of
8338 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8339 /* It's not condemned. Everything's fine. */
8341 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8342 window
->vertical_scroll_bar
))
8343 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8345 /* If its prev pointer is nil, it must be at the front of
8346 one or the other! */
8350 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8352 if (! NILP (bar
->next
))
8353 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8355 bar
->next
= FRAME_SCROLL_BARS (f
);
8357 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8358 if (! NILP (bar
->next
))
8359 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8363 /* Remove all scroll bars on FRAME that haven't been saved since the
8364 last call to `*condemn_scroll_bars_hook'. */
8367 XTjudge_scroll_bars (f
)
8370 Lisp_Object bar
, next
;
8372 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8374 /* Clear out the condemned list now so we won't try to process any
8375 more events on the hapless scroll bars. */
8376 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8378 for (; ! NILP (bar
); bar
= next
)
8380 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8382 x_scroll_bar_remove (b
);
8385 b
->next
= b
->prev
= Qnil
;
8388 /* Now there should be no references to the condemned scroll bars,
8389 and they should get garbage-collected. */
8393 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8394 is a no-op when using toolkit scroll bars.
8396 This may be called from a signal handler, so we have to ignore GC
8400 x_scroll_bar_expose (bar
, event
)
8401 struct scroll_bar
*bar
;
8404 #ifndef USE_TOOLKIT_SCROLL_BARS
8406 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8407 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8408 GC gc
= f
->output_data
.x
->normal_gc
;
8409 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8413 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8415 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8416 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8418 /* x, y, width, height */
8420 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8421 XINT (bar
->height
) - 1);
8425 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8428 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8429 is set to something other than no_event, it is enqueued.
8431 This may be called from a signal handler, so we have to ignore GC
8434 #ifndef USE_TOOLKIT_SCROLL_BARS
8437 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8438 struct scroll_bar
*bar
;
8440 struct input_event
*emacs_event
;
8442 if (! GC_WINDOWP (bar
->window
))
8445 emacs_event
->kind
= scroll_bar_click
;
8446 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8447 emacs_event
->modifiers
8448 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8449 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8450 event
->xbutton
.state
)
8451 | (event
->type
== ButtonRelease
8454 emacs_event
->frame_or_window
= bar
->window
;
8455 emacs_event
->timestamp
= event
->xbutton
.time
;
8458 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8460 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8463 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8464 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8467 if (y
> top_range
) y
= top_range
;
8469 if (y
< XINT (bar
->start
))
8470 emacs_event
->part
= scroll_bar_above_handle
;
8471 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8472 emacs_event
->part
= scroll_bar_handle
;
8474 emacs_event
->part
= scroll_bar_below_handle
;
8476 /* Just because the user has clicked on the handle doesn't mean
8477 they want to drag it. Lisp code needs to be able to decide
8478 whether or not we're dragging. */
8480 /* If the user has just clicked on the handle, record where they're
8482 if (event
->type
== ButtonPress
8483 && emacs_event
->part
== scroll_bar_handle
)
8484 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8487 /* If the user has released the handle, set it to its final position. */
8488 if (event
->type
== ButtonRelease
8489 && ! NILP (bar
->dragging
))
8491 int new_start
= y
- XINT (bar
->dragging
);
8492 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8494 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8495 bar
->dragging
= Qnil
;
8498 /* Same deal here as the other #if 0. */
8500 /* Clicks on the handle are always reported as occurring at the top of
8502 if (emacs_event
->part
== scroll_bar_handle
)
8503 emacs_event
->x
= bar
->start
;
8505 XSETINT (emacs_event
->x
, y
);
8507 XSETINT (emacs_event
->x
, y
);
8510 XSETINT (emacs_event
->y
, top_range
);
8514 /* Handle some mouse motion while someone is dragging the scroll bar.
8516 This may be called from a signal handler, so we have to ignore GC
8520 x_scroll_bar_note_movement (bar
, event
)
8521 struct scroll_bar
*bar
;
8524 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8526 last_mouse_movement_time
= event
->xmotion
.time
;
8529 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8531 /* If we're dragging the bar, display it. */
8532 if (! GC_NILP (bar
->dragging
))
8534 /* Where should the handle be now? */
8535 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8537 if (new_start
!= XINT (bar
->start
))
8539 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8541 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8546 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8548 /* Return information to the user about the current position of the mouse
8549 on the scroll bar. */
8552 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8554 Lisp_Object
*bar_window
;
8555 enum scroll_bar_part
*part
;
8557 unsigned long *time
;
8559 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8560 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8561 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8563 Window dummy_window
;
8565 unsigned int dummy_mask
;
8569 /* Get the mouse's position relative to the scroll bar window, and
8571 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8573 /* Root, child, root x and root y. */
8574 &dummy_window
, &dummy_window
,
8575 &dummy_coord
, &dummy_coord
,
8577 /* Position relative to scroll bar. */
8580 /* Mouse buttons and modifier keys. */
8587 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8590 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8592 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8594 if (! NILP (bar
->dragging
))
8595 win_y
-= XINT (bar
->dragging
);
8599 if (win_y
> top_range
)
8603 *bar_window
= bar
->window
;
8605 if (! NILP (bar
->dragging
))
8606 *part
= scroll_bar_handle
;
8607 else if (win_y
< XINT (bar
->start
))
8608 *part
= scroll_bar_above_handle
;
8609 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8610 *part
= scroll_bar_handle
;
8612 *part
= scroll_bar_below_handle
;
8614 XSETINT (*x
, win_y
);
8615 XSETINT (*y
, top_range
);
8618 last_mouse_scroll_bar
= Qnil
;
8621 *time
= last_mouse_movement_time
;
8627 /* The screen has been cleared so we may have changed foreground or
8628 background colors, and the scroll bars may need to be redrawn.
8629 Clear out the scroll bars, and ask for expose events, so we can
8633 x_scroll_bar_clear (f
)
8636 #ifndef USE_TOOLKIT_SCROLL_BARS
8639 /* We can have scroll bars even if this is 0,
8640 if we just turned off scroll bar mode.
8641 But in that case we should not clear them. */
8642 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8643 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8644 bar
= XSCROLL_BAR (bar
)->next
)
8645 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8647 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8650 /* This processes Expose events from the menu-bar specific X event
8651 loop in xmenu.c. This allows to redisplay the frame if necessary
8652 when handling menu-bar or pop-up items. */
8655 process_expose_from_menu (event
)
8659 struct x_display_info
*dpyinfo
;
8660 int frame_exposed_p
= 0;
8664 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8665 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8668 if (f
->async_visible
== 0)
8670 f
->async_visible
= 1;
8671 f
->async_iconified
= 0;
8672 f
->output_data
.x
->has_been_visible
= 1;
8673 SET_FRAME_GARBAGED (f
);
8677 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8678 event
.xexpose
.x
, event
.xexpose
.y
,
8679 event
.xexpose
.width
, event
.xexpose
.height
);
8680 frame_exposed_p
= 1;
8685 struct scroll_bar
*bar
8686 = x_window_to_scroll_bar (event
.xexpose
.window
);
8689 x_scroll_bar_expose (bar
, &event
);
8693 return frame_exposed_p
;
8696 /* Define a queue to save up SelectionRequest events for later handling. */
8698 struct selection_event_queue
8701 struct selection_event_queue
*next
;
8704 static struct selection_event_queue
*queue
;
8706 /* Nonzero means queue up certain events--don't process them yet. */
8708 static int x_queue_selection_requests
;
8710 /* Queue up an X event *EVENT, to be processed later. */
8713 x_queue_event (f
, event
)
8717 struct selection_event_queue
*queue_tmp
8718 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8720 if (queue_tmp
!= NULL
)
8722 queue_tmp
->event
= *event
;
8723 queue_tmp
->next
= queue
;
8728 /* Take all the queued events and put them back
8729 so that they get processed afresh. */
8732 x_unqueue_events (display
)
8735 while (queue
!= NULL
)
8737 struct selection_event_queue
*queue_tmp
= queue
;
8738 XPutBackEvent (display
, &queue_tmp
->event
);
8739 queue
= queue_tmp
->next
;
8740 xfree ((char *)queue_tmp
);
8744 /* Start queuing SelectionRequest events. */
8747 x_start_queuing_selection_requests (display
)
8750 x_queue_selection_requests
++;
8753 /* Stop queuing SelectionRequest events. */
8756 x_stop_queuing_selection_requests (display
)
8759 x_queue_selection_requests
--;
8760 x_unqueue_events (display
);
8763 /* The main X event-reading loop - XTread_socket. */
8765 /* Time stamp of enter window event. This is only used by XTread_socket,
8766 but we have to put it out here, since static variables within functions
8767 sometimes don't work. */
8769 static Time enter_timestamp
;
8771 /* This holds the state XLookupString needs to implement dead keys
8772 and other tricks known as "compose processing". _X Window System_
8773 says that a portable program can't use this, but Stephen Gildea assures
8774 me that letting the compiler initialize it to zeros will work okay.
8776 This must be defined outside of XTread_socket, for the same reasons
8777 given for enter_time stamp, above. */
8779 static XComposeStatus compose_status
;
8781 /* Record the last 100 characters stored
8782 to help debug the loss-of-chars-during-GC problem. */
8784 static int temp_index
;
8785 static short temp_buffer
[100];
8787 /* Set this to nonzero to fake an "X I/O error"
8788 on a particular display. */
8790 struct x_display_info
*XTread_socket_fake_io_error
;
8792 /* When we find no input here, we occasionally do a no-op command
8793 to verify that the X server is still running and we can still talk with it.
8794 We try all the open displays, one by one.
8795 This variable is used for cycling thru the displays. */
8797 static struct x_display_info
*next_noop_dpyinfo
;
8799 #define SET_SAVED_MENU_EVENT(size) \
8802 if (f->output_data.x->saved_menu_event == 0) \
8803 f->output_data.x->saved_menu_event \
8804 = (XEvent *) xmalloc (sizeof (XEvent)); \
8805 bcopy (&event, f->output_data.x->saved_menu_event, size); \
8806 if (numchars >= 1) \
8808 bufp->kind = menu_bar_activate_event; \
8809 XSETFRAME (bufp->frame_or_window, f); \
8817 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
8818 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
8820 /* Read events coming from the X server.
8821 This routine is called by the SIGIO handler.
8822 We return as soon as there are no more events to be read.
8824 Events representing keys are stored in buffer BUFP,
8825 which can hold up to NUMCHARS characters.
8826 We return the number of characters stored into the buffer,
8827 thus pretending to be `read'.
8829 EXPECTED is nonzero if the caller knows input is available. */
8832 XTread_socket (sd
, bufp
, numchars
, expected
)
8834 /* register */ struct input_event
*bufp
;
8835 /* register */ int numchars
;
8842 int event_found
= 0;
8843 struct x_display_info
*dpyinfo
;
8845 if (interrupt_input_blocked
)
8847 interrupt_input_pending
= 1;
8851 interrupt_input_pending
= 0;
8854 /* So people can tell when we have read the available input. */
8855 input_signal_count
++;
8858 abort (); /* Don't think this happens. */
8860 /* Find the display we are supposed to read input for.
8861 It's the one communicating on descriptor SD. */
8862 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
8864 #if 0 /* This ought to be unnecessary; let's verify it. */
8866 /* If available, Xlib uses FIOSNBIO to make the socket
8867 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
8868 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
8869 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
8870 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
8871 #endif /* ! defined (FIOSNBIO) */
8874 #if 0 /* This code can't be made to work, with multiple displays,
8875 and appears not to be used on any system any more.
8876 Also keyboard.c doesn't turn O_NDELAY on and off
8877 for X connections. */
8880 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
8882 extern int read_alarm_should_throw
;
8883 read_alarm_should_throw
= 1;
8884 XPeekEvent (dpyinfo
->display
, &event
);
8885 read_alarm_should_throw
= 0;
8887 #endif /* HAVE_SELECT */
8891 /* For debugging, this gives a way to fake an I/O error. */
8892 if (dpyinfo
== XTread_socket_fake_io_error
)
8894 XTread_socket_fake_io_error
= 0;
8895 x_io_error_quitter (dpyinfo
->display
);
8898 while (XPending (dpyinfo
->display
))
8900 XNextEvent (dpyinfo
->display
, &event
);
8904 /* Filter events for the current X input method.
8905 XFilterEvent returns non-zero if the input method has
8906 consumed the event. We pass the frame's X window to
8907 XFilterEvent because that's the one for which the IC
8909 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
8910 event
.xclient
.window
);
8911 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
8921 if (event
.xclient
.message_type
8922 == dpyinfo
->Xatom_wm_protocols
8923 && event
.xclient
.format
== 32)
8925 if (event
.xclient
.data
.l
[0]
8926 == dpyinfo
->Xatom_wm_take_focus
)
8928 /* Use x_any_window_to_frame because this
8929 could be the shell widget window
8930 if the frame has no title bar. */
8931 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
8933 /* Not quite sure this is needed -pd */
8934 if (f
&& FRAME_XIC (f
))
8935 XSetICFocus (FRAME_XIC (f
));
8937 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
8938 instructs the WM to set the input focus automatically for
8939 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
8940 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
8941 it has set the focus. So, XSetInputFocus below is not
8944 The call to XSetInputFocus below has also caused trouble. In
8945 cases where the XSetInputFocus done by the WM and the one
8946 below are temporally close (on a fast machine), the call
8947 below can generate additional FocusIn events which confuse
8950 /* Since we set WM_TAKE_FOCUS, we must call
8951 XSetInputFocus explicitly. But not if f is null,
8952 since that might be an event for a deleted frame. */
8955 Display
*d
= event
.xclient
.display
;
8956 /* Catch and ignore errors, in case window has been
8957 iconified by a window manager such as GWM. */
8958 int count
= x_catch_errors (d
);
8959 XSetInputFocus (d
, event
.xclient
.window
,
8960 /* The ICCCM says this is
8961 the only valid choice. */
8963 event
.xclient
.data
.l
[1]);
8964 /* This is needed to detect the error
8965 if there is an error. */
8967 x_uncatch_errors (d
, count
);
8969 /* Not certain about handling scroll bars here */
8972 else if (event
.xclient
.data
.l
[0]
8973 == dpyinfo
->Xatom_wm_save_yourself
)
8975 /* Save state modify the WM_COMMAND property to
8976 something which can reinstate us. This notifies
8977 the session manager, who's looking for such a
8978 PropertyNotify. Can restart processing when
8979 a keyboard or mouse event arrives. */
8982 f
= x_top_window_to_frame (dpyinfo
,
8983 event
.xclient
.window
);
8985 /* This is just so we only give real data once
8986 for a single Emacs process. */
8987 if (f
== SELECTED_FRAME ())
8988 XSetCommand (FRAME_X_DISPLAY (f
),
8989 event
.xclient
.window
,
8990 initial_argv
, initial_argc
);
8992 XSetCommand (FRAME_X_DISPLAY (f
),
8993 event
.xclient
.window
,
8997 else if (event
.xclient
.data
.l
[0]
8998 == dpyinfo
->Xatom_wm_delete_window
)
9001 = x_any_window_to_frame (dpyinfo
,
9002 event
.xclient
.window
);
9009 bufp
->kind
= delete_window_event
;
9010 XSETFRAME (bufp
->frame_or_window
, f
);
9018 else if (event
.xclient
.message_type
9019 == dpyinfo
->Xatom_wm_configure_denied
)
9022 else if (event
.xclient
.message_type
9023 == dpyinfo
->Xatom_wm_window_moved
)
9027 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9029 new_x
= event
.xclient
.data
.s
[0];
9030 new_y
= event
.xclient
.data
.s
[1];
9034 f
->output_data
.x
->left_pos
= new_x
;
9035 f
->output_data
.x
->top_pos
= new_y
;
9039 else if (event
.xclient
.message_type
9040 == dpyinfo
->Xatom_editres
)
9043 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9044 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9047 #endif /* HACK_EDITRES */
9048 else if ((event
.xclient
.message_type
9049 == dpyinfo
->Xatom_DONE
)
9050 || (event
.xclient
.message_type
9051 == dpyinfo
->Xatom_PAGE
))
9053 /* Ghostview job completed. Kill it. We could
9054 reply with "Next" if we received "Page", but we
9055 currently never do because we are interested in
9056 images, only, which should have 1 page. */
9057 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9059 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9060 x_kill_gs_process (pixmap
, f
);
9061 expose_frame (f
, 0, 0, 0, 0);
9063 #ifdef USE_TOOLKIT_SCROLL_BARS
9064 /* Scroll bar callbacks send a ClientMessage from which
9065 we construct an input_event. */
9066 else if (event
.xclient
.message_type
9067 == dpyinfo
->Xatom_Scrollbar
)
9069 x_scroll_bar_to_input_event (&event
, bufp
);
9070 ++bufp
, ++count
, --numchars
;
9073 #endif /* USE_TOOLKIT_SCROLL_BARS */
9079 case SelectionNotify
:
9080 #ifdef USE_X_TOOLKIT
9081 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9083 #endif /* not USE_X_TOOLKIT */
9084 x_handle_selection_notify (&event
.xselection
);
9087 case SelectionClear
: /* Someone has grabbed ownership. */
9088 #ifdef USE_X_TOOLKIT
9089 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9091 #endif /* USE_X_TOOLKIT */
9093 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9098 bufp
->kind
= selection_clear_event
;
9099 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9100 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9101 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9102 bufp
->frame_or_window
= Qnil
;
9110 case SelectionRequest
: /* Someone wants our selection. */
9111 #ifdef USE_X_TOOLKIT
9112 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9114 #endif /* USE_X_TOOLKIT */
9115 if (x_queue_selection_requests
)
9116 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9120 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9125 bufp
->kind
= selection_request_event
;
9126 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9127 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9128 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9129 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9130 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9131 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9132 bufp
->frame_or_window
= Qnil
;
9140 case PropertyNotify
:
9141 #ifdef USE_X_TOOLKIT
9142 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9144 #endif /* not USE_X_TOOLKIT */
9145 x_handle_property_notify (&event
.xproperty
);
9148 case ReparentNotify
:
9149 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9153 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9154 x_real_positions (f
, &x
, &y
);
9155 f
->output_data
.x
->left_pos
= x
;
9156 f
->output_data
.x
->top_pos
= y
;
9161 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9164 if (f
->async_visible
== 0)
9166 f
->async_visible
= 1;
9167 f
->async_iconified
= 0;
9168 f
->output_data
.x
->has_been_visible
= 1;
9169 SET_FRAME_GARBAGED (f
);
9172 expose_frame (x_window_to_frame (dpyinfo
,
9173 event
.xexpose
.window
),
9174 event
.xexpose
.x
, event
.xexpose
.y
,
9175 event
.xexpose
.width
, event
.xexpose
.height
);
9179 #ifdef USE_TOOLKIT_SCROLL_BARS
9180 /* Dispatch event to the widget. */
9182 #else /* not USE_TOOLKIT_SCROLL_BARS */
9183 struct scroll_bar
*bar
9184 = x_window_to_scroll_bar (event
.xexpose
.window
);
9187 x_scroll_bar_expose (bar
, &event
);
9188 #ifdef USE_X_TOOLKIT
9191 #endif /* USE_X_TOOLKIT */
9192 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9196 case GraphicsExpose
: /* This occurs when an XCopyArea's
9197 source area was obscured or not
9199 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9203 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9204 event
.xgraphicsexpose
.width
,
9205 event
.xgraphicsexpose
.height
);
9207 #ifdef USE_X_TOOLKIT
9210 #endif /* USE_X_TOOLKIT */
9213 case NoExpose
: /* This occurs when an XCopyArea's
9214 source area was completely
9219 /* Redo the mouse-highlight after the tooltip has gone. */
9220 if (event
.xmap
.window
== tip_window
)
9223 redo_mouse_highlight ();
9226 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9227 if (f
) /* F may no longer exist if
9228 the frame was deleted. */
9230 /* While a frame is unmapped, display generation is
9231 disabled; you don't want to spend time updating a
9232 display that won't ever be seen. */
9233 f
->async_visible
= 0;
9234 /* We can't distinguish, from the event, whether the window
9235 has become iconified or invisible. So assume, if it
9236 was previously visible, than now it is iconified.
9237 But x_make_frame_invisible clears both
9238 the visible flag and the iconified flag;
9239 and that way, we know the window is not iconified now. */
9240 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9242 f
->async_iconified
= 1;
9244 bufp
->kind
= iconify_event
;
9245 XSETFRAME (bufp
->frame_or_window
, f
);
9254 if (event
.xmap
.window
== tip_window
)
9255 /* The tooltip has been drawn already. Avoid
9256 the SET_FRAME_GARBAGED below. */
9259 /* We use x_top_window_to_frame because map events can
9260 come for sub-windows and they don't mean that the
9261 frame is visible. */
9262 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9265 f
->async_visible
= 1;
9266 f
->async_iconified
= 0;
9267 f
->output_data
.x
->has_been_visible
= 1;
9269 /* wait_reading_process_input will notice this and update
9270 the frame's display structures. */
9271 SET_FRAME_GARBAGED (f
);
9275 bufp
->kind
= deiconify_event
;
9276 XSETFRAME (bufp
->frame_or_window
, f
);
9281 else if (! NILP (Vframe_list
)
9282 && ! NILP (XCDR (Vframe_list
)))
9283 /* Force a redisplay sooner or later
9284 to update the frame titles
9285 in case this is the second frame. */
9286 record_asynch_buffer_change ();
9291 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9294 /* I couldn't find a way to prevent LessTif scroll bars
9295 from consuming key events. */
9298 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9300 if (widget
&& XmIsScrollBar (widget
))
9302 widget
= XtParent (widget
);
9303 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9306 #endif /* USE_MOTIF */
9310 KeySym keysym
, orig_keysym
;
9311 /* al%imercury@uunet.uu.net says that making this 81 instead of
9312 80 fixed a bug whereby meta chars made his Emacs hang. */
9313 unsigned char copy_buffer
[81];
9317 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9318 extra_keyboard_modifiers
);
9319 modifiers
= event
.xkey
.state
;
9321 /* This will have to go some day... */
9323 /* make_lispy_event turns chars into control chars.
9324 Don't do it here because XLookupString is too eager. */
9325 event
.xkey
.state
&= ~ControlMask
;
9326 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9327 | dpyinfo
->super_mod_mask
9328 | dpyinfo
->hyper_mod_mask
9329 | dpyinfo
->alt_mod_mask
);
9331 /* In case Meta is ComposeCharacter,
9332 clear its status. According to Markus Ehrnsperger
9333 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9334 this enables ComposeCharacter to work whether or
9335 not it is combined with Meta. */
9336 if (modifiers
& dpyinfo
->meta_mod_mask
)
9337 bzero (&compose_status
, sizeof (compose_status
));
9342 unsigned char *copy_bufptr
= copy_buffer
;
9343 int copy_bufsiz
= sizeof (copy_buffer
);
9344 Status status_return
;
9346 nbytes
= XmbLookupString (FRAME_XIC (f
),
9347 &event
.xkey
, copy_bufptr
,
9348 copy_bufsiz
, &keysym
,
9350 if (status_return
== XBufferOverflow
)
9352 copy_bufsiz
= nbytes
+ 1;
9353 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9354 nbytes
= XmbLookupString (FRAME_XIC (f
),
9355 &event
.xkey
, copy_bufptr
,
9356 copy_bufsiz
, &keysym
,
9360 if (status_return
== XLookupNone
)
9362 else if (status_return
== XLookupChars
)
9364 else if (status_return
!= XLookupKeySym
9365 && status_return
!= XLookupBoth
)
9369 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9370 80, &keysym
, &compose_status
);
9372 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9373 80, &keysym
, &compose_status
);
9376 orig_keysym
= keysym
;
9380 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9381 || keysym
== XK_Delete
9382 #ifdef XK_ISO_Left_Tab
9383 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9385 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9386 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9387 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9389 /* This recognizes the "extended function keys".
9390 It seems there's no cleaner way.
9391 Test IsModifierKey to avoid handling mode_switch
9393 || ((unsigned) (keysym
) >= XK_Select
9394 && (unsigned)(keysym
) < XK_KP_Space
)
9396 #ifdef XK_dead_circumflex
9397 || orig_keysym
== XK_dead_circumflex
9399 #ifdef XK_dead_grave
9400 || orig_keysym
== XK_dead_grave
9402 #ifdef XK_dead_tilde
9403 || orig_keysym
== XK_dead_tilde
9405 #ifdef XK_dead_diaeresis
9406 || orig_keysym
== XK_dead_diaeresis
9408 #ifdef XK_dead_macron
9409 || orig_keysym
== XK_dead_macron
9411 #ifdef XK_dead_degree
9412 || orig_keysym
== XK_dead_degree
9414 #ifdef XK_dead_acute
9415 || orig_keysym
== XK_dead_acute
9417 #ifdef XK_dead_cedilla
9418 || orig_keysym
== XK_dead_cedilla
9420 #ifdef XK_dead_breve
9421 || orig_keysym
== XK_dead_breve
9423 #ifdef XK_dead_ogonek
9424 || orig_keysym
== XK_dead_ogonek
9426 #ifdef XK_dead_caron
9427 || orig_keysym
== XK_dead_caron
9429 #ifdef XK_dead_doubleacute
9430 || orig_keysym
== XK_dead_doubleacute
9432 #ifdef XK_dead_abovedot
9433 || orig_keysym
== XK_dead_abovedot
9435 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9436 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9437 /* Any "vendor-specific" key is ok. */
9438 || (orig_keysym
& (1 << 28)))
9439 && ! (IsModifierKey (orig_keysym
)
9441 #ifdef XK_Mode_switch
9442 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9445 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9447 #endif /* not HAVE_X11R5 */
9450 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9452 temp_buffer
[temp_index
++] = keysym
;
9453 bufp
->kind
= non_ascii_keystroke
;
9454 bufp
->code
= keysym
;
9455 XSETFRAME (bufp
->frame_or_window
, f
);
9457 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9459 bufp
->timestamp
= event
.xkey
.time
;
9464 else if (numchars
> nbytes
)
9468 for (i
= 0; i
< nbytes
; i
++)
9470 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9472 temp_buffer
[temp_index
++] = copy_buffer
[i
];
9473 bufp
->kind
= ascii_keystroke
;
9474 bufp
->code
= copy_buffer
[i
];
9475 XSETFRAME (bufp
->frame_or_window
, f
);
9477 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9479 bufp
->timestamp
= event
.xkey
.time
;
9486 if (keysym
== NoSymbol
)
9496 /* Don't dispatch this event since XtDispatchEvent calls
9497 XFilterEvent, and two calls in a row may freeze the
9506 /* Don't dispatch this event since XtDispatchEvent calls
9507 XFilterEvent, and two calls in a row may freeze the
9514 /* Here's a possible interpretation of the whole
9515 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9516 you get a FocusIn event, you have to get a FocusOut
9517 event before you relinquish the focus. If you
9518 haven't received a FocusIn event, then a mere
9519 LeaveNotify is enough to free you. */
9523 int from_menu_bar_p
= 0;
9525 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9527 #ifdef LESSTIF_VERSION
9528 /* When clicking outside of a menu bar popup to close
9529 it, we get a FocusIn/ EnterNotify sequence of
9530 events. The flag event.xcrossing.focus is not set
9531 in the EnterNotify event of that sequence because
9532 the focus is in the menu bar,
9533 event.xcrossing.window is the frame's X window.
9534 Unconditionally setting the focus frame to null in
9535 this case is not the right thing, because no event
9536 follows that could set the focus frame to the right
9539 This could be a LessTif bug, but I wasn't able to
9540 reproduce the behavior in a simple test program.
9542 (gerd, LessTif 0.88.1). */
9544 if (!event
.xcrossing
.focus
9546 && f
->output_data
.x
->menubar_widget
)
9551 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9552 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9553 from_menu_bar_p
= 1;
9555 #endif /* LESSTIF_VERSION */
9557 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9559 /* Avoid nasty pop/raise loops. */
9560 if (f
&& (!(f
->auto_raise
)
9562 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9564 x_new_focus_frame (dpyinfo
, f
);
9565 enter_timestamp
= event
.xcrossing
.time
;
9568 else if (f
== dpyinfo
->x_focus_frame
)
9569 x_new_focus_frame (dpyinfo
, 0);
9571 /* EnterNotify counts as mouse movement,
9572 so update things that depend on mouse position. */
9573 if (f
&& !f
->output_data
.x
->busy_p
)
9574 note_mouse_movement (f
, &event
.xmotion
);
9579 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9580 if (event
.xfocus
.detail
!= NotifyPointer
)
9581 dpyinfo
->x_focus_event_frame
= f
;
9583 x_new_focus_frame (dpyinfo
, f
);
9586 if (f
&& FRAME_XIC (f
))
9587 XSetICFocus (FRAME_XIC (f
));
9593 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9597 int from_menu_bar_p
= 0;
9599 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9601 /* If we move outside the frame, then we're
9602 certainly no longer on any text in the frame. */
9603 clear_mouse_face (dpyinfo
);
9604 dpyinfo
->mouse_face_mouse_frame
= 0;
9607 /* Generate a nil HELP_EVENT to cancel a help-echo.
9608 Do it only if there's something to cancel.
9609 Otherwise, the startup message is cleared when
9610 the mouse leaves the frame. */
9611 if (any_help_event_p
)
9613 XSETFRAME (frame
, f
);
9614 bufp
->kind
= HELP_EVENT
;
9615 bufp
->frame_or_window
= Fcons (frame
, Qnil
);
9616 ++bufp
, ++count
, --numchars
;
9619 #ifdef LESSTIF_VERSION
9620 /* Please see the comment at the start of the
9621 EnterNotify case. */
9622 if (!event
.xcrossing
.focus
9623 && f
->output_data
.x
->menubar_widget
)
9627 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9628 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9629 from_menu_bar_p
= 1;
9631 #endif /* LESSTIF_VERSION */
9633 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9634 x_mouse_leave (dpyinfo
);
9637 if (f
== dpyinfo
->x_focus_event_frame
)
9638 dpyinfo
->x_focus_event_frame
= 0;
9639 if (f
== dpyinfo
->x_focus_frame
)
9640 x_new_focus_frame (dpyinfo
, 0);
9646 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9647 if (event
.xfocus
.detail
!= NotifyPointer
9648 && f
== dpyinfo
->x_focus_event_frame
)
9649 dpyinfo
->x_focus_event_frame
= 0;
9650 if (f
&& f
== dpyinfo
->x_focus_frame
)
9651 x_new_focus_frame (dpyinfo
, 0);
9654 if (f
&& FRAME_XIC (f
))
9655 XUnsetICFocus (FRAME_XIC (f
));
9662 previous_help_echo
= help_echo
;
9665 if (dpyinfo
->grabbed
&& last_mouse_frame
9666 && FRAME_LIVE_P (last_mouse_frame
))
9667 f
= last_mouse_frame
;
9669 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9672 note_mouse_movement (f
, &event
.xmotion
);
9675 #ifndef USE_TOOLKIT_SCROLL_BARS
9676 struct scroll_bar
*bar
9677 = x_window_to_scroll_bar (event
.xmotion
.window
);
9680 x_scroll_bar_note_movement (bar
, &event
);
9681 #endif /* USE_TOOLKIT_SCROLL_BARS */
9683 /* If we move outside the frame, then we're
9684 certainly no longer on any text in the frame. */
9685 clear_mouse_face (dpyinfo
);
9688 /* If the contents of the global variable help_echo
9689 has changed, generate a HELP_EVENT. */
9690 if (STRINGP (help_echo
)
9691 || STRINGP (previous_help_echo
))
9696 XSETFRAME (frame
, f
);
9700 any_help_event_p
= 1;
9701 bufp
->kind
= HELP_EVENT
;
9702 bufp
->frame_or_window
= Fcons (frame
, help_echo
);
9703 ++bufp
, ++count
, --numchars
;
9709 case ConfigureNotify
:
9710 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
9713 #ifndef USE_X_TOOLKIT
9714 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
9715 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
9717 /* In the toolkit version, change_frame_size
9718 is called by the code that handles resizing
9719 of the EmacsFrame widget. */
9721 /* Even if the number of character rows and columns has
9722 not changed, the font size may have changed, so we need
9723 to check the pixel dimensions as well. */
9724 if (columns
!= f
->width
9725 || rows
!= f
->height
9726 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
9727 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
9729 change_frame_size (f
, rows
, columns
, 0, 1, 0);
9730 SET_FRAME_GARBAGED (f
);
9731 cancel_mouse_face (f
);
9735 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
9736 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
9738 /* What we have now is the position of Emacs's own window.
9739 Convert that to the position of the window manager window. */
9740 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
9741 &f
->output_data
.x
->top_pos
);
9744 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
9745 xic_set_statusarea (f
);
9748 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
9750 /* Since the WM decorations come below top_pos now,
9751 we must put them below top_pos in the future. */
9752 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
9753 x_wm_set_size_hint (f
, (long) 0, 0);
9756 /* Some window managers pass (0,0) as the location of
9757 the window, and the Motif event handler stores it
9758 in the emacs widget, which messes up Motif menus. */
9759 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
9761 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
9762 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
9764 #endif /* USE_MOTIF */
9771 /* If we decide we want to generate an event to be seen
9772 by the rest of Emacs, we put it here. */
9773 struct input_event emacs_event
;
9776 emacs_event
.kind
= no_event
;
9777 bzero (&compose_status
, sizeof (compose_status
));
9779 if (dpyinfo
->grabbed
9781 && FRAME_LIVE_P (last_mouse_frame
))
9782 f
= last_mouse_frame
;
9784 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9788 /* Is this in the tool-bar? */
9789 if (WINDOWP (f
->tool_bar_window
)
9790 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
9795 x
= event
.xbutton
.x
;
9796 y
= event
.xbutton
.y
;
9799 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
9800 if (EQ (window
, f
->tool_bar_window
))
9802 x_handle_tool_bar_click (f
, &event
.xbutton
);
9808 if (!dpyinfo
->x_focus_frame
9809 || f
== dpyinfo
->x_focus_frame
)
9810 construct_mouse_click (&emacs_event
, &event
, f
);
9814 #ifndef USE_TOOLKIT_SCROLL_BARS
9815 struct scroll_bar
*bar
9816 = x_window_to_scroll_bar (event
.xbutton
.window
);
9819 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
9820 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9823 if (event
.type
== ButtonPress
)
9825 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
9826 last_mouse_frame
= f
;
9827 /* Ignore any mouse motion that happened
9828 before this event; any subsequent mouse-movement
9829 Emacs events should reflect only motion after
9835 last_tool_bar_item
= -1;
9839 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
9842 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
9844 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
9850 #ifdef USE_X_TOOLKIT
9851 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9852 /* For a down-event in the menu bar,
9853 don't pass it to Xt right now.
9854 Instead, save it away
9855 and we will pass it to Xt from kbd_buffer_get_event.
9856 That way, we can run some Lisp code first. */
9857 if (f
&& event
.type
== ButtonPress
9858 /* Verify the event is really within the menu bar
9859 and not just sent to it due to grabbing. */
9860 && event
.xbutton
.x
>= 0
9861 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
9862 && event
.xbutton
.y
>= 0
9863 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
9864 && event
.xbutton
.same_screen
)
9866 SET_SAVED_BUTTON_EVENT
;
9867 XSETFRAME (last_mouse_press_frame
, f
);
9869 else if (event
.type
== ButtonPress
)
9871 last_mouse_press_frame
= Qnil
;
9875 #ifdef USE_MOTIF /* This should do not harm for Lucid,
9876 but I am trying to be cautious. */
9877 else if (event
.type
== ButtonRelease
)
9879 if (!NILP (last_mouse_press_frame
))
9881 f
= XFRAME (last_mouse_press_frame
);
9882 if (f
->output_data
.x
)
9883 SET_SAVED_BUTTON_EVENT
;
9888 #endif /* USE_MOTIF */
9891 #endif /* USE_X_TOOLKIT */
9895 case CirculateNotify
:
9898 case CirculateRequest
:
9901 case VisibilityNotify
:
9905 /* Someone has changed the keyboard mapping - update the
9907 switch (event
.xmapping
.request
)
9909 case MappingModifier
:
9910 x_find_modifier_meanings (dpyinfo
);
9911 /* This is meant to fall through. */
9912 case MappingKeyboard
:
9913 XRefreshKeyboardMapping (&event
.xmapping
);
9919 #ifdef USE_X_TOOLKIT
9921 XtDispatchEvent (&event
);
9923 #endif /* USE_X_TOOLKIT */
9931 /* On some systems, an X bug causes Emacs to get no more events
9932 when the window is destroyed. Detect that. (1994.) */
9935 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
9936 One XNOOP in 100 loops will make Emacs terminate.
9937 B. Bretthauer, 1994 */
9939 if (x_noop_count
>= 100)
9943 if (next_noop_dpyinfo
== 0)
9944 next_noop_dpyinfo
= x_display_list
;
9946 XNoOp (next_noop_dpyinfo
->display
);
9948 /* Each time we get here, cycle through the displays now open. */
9949 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
9953 /* If the focus was just given to an auto-raising frame,
9955 /* ??? This ought to be able to handle more than one such frame. */
9956 if (pending_autoraise_frame
)
9958 x_raise_frame (pending_autoraise_frame
);
9959 pending_autoraise_frame
= 0;
9969 /***********************************************************************
9971 ***********************************************************************/
9973 /* Note if the text cursor of window W has been overwritten by a
9974 drawing operation that outputs N glyphs starting at HPOS in the
9975 line given by output_cursor.vpos. N < 0 means all the rest of the
9976 line after HPOS has been written. */
9979 note_overwritten_text_cursor (w
, hpos
, n
)
9983 if (updated_area
== TEXT_AREA
9984 && output_cursor
.vpos
== w
->phys_cursor
.vpos
9985 && hpos
<= w
->phys_cursor
.hpos
9987 || hpos
+ n
> w
->phys_cursor
.hpos
))
9988 w
->phys_cursor_on_p
= 0;
9992 /* Set clipping for output in glyph row ROW. W is the window in which
9993 we operate. GC is the graphics context to set clipping in.
9994 WHOLE_LINE_P non-zero means include the areas used for truncation
9995 mark display and alike in the clipping rectangle.
9997 ROW may be a text row or, e.g., a mode line. Text rows must be
9998 clipped to the interior of the window dedicated to text display,
9999 mode lines must be clipped to the whole window. */
10002 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10004 struct glyph_row
*row
;
10008 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10009 XRectangle clip_rect
;
10010 int window_x
, window_y
, window_width
, window_height
;
10012 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10014 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10015 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10016 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10017 clip_rect
.width
= window_width
;
10018 clip_rect
.height
= row
->visible_height
;
10020 /* If clipping to the whole line, including trunc marks, extend
10021 the rectangle to the left and increase its width. */
10024 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10025 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10028 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10032 /* Draw a hollow box cursor on window W in glyph row ROW. */
10035 x_draw_hollow_cursor (w
, row
)
10037 struct glyph_row
*row
;
10039 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10040 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10041 Display
*dpy
= FRAME_X_DISPLAY (f
);
10044 struct glyph
*cursor_glyph
;
10047 /* Compute frame-relative coordinates from window-relative
10049 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10050 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10051 + row
->ascent
- w
->phys_cursor_ascent
);
10052 h
= row
->height
- 1;
10054 /* Get the glyph the cursor is on. If we can't tell because
10055 the current matrix is invalid or such, give up. */
10056 cursor_glyph
= get_phys_cursor_glyph (w
);
10057 if (cursor_glyph
== NULL
)
10060 /* Compute the width of the rectangle to draw. If on a stretch
10061 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10062 rectangle as wide as the glyph, but use a canonical character
10064 wd
= cursor_glyph
->pixel_width
- 1;
10065 if (cursor_glyph
->type
== STRETCH_GLYPH
10066 && !x_stretch_cursor_p
)
10067 wd
= min (CANON_X_UNIT (f
), wd
);
10069 /* The foreground of cursor_gc is typically the same as the normal
10070 background color, which can cause the cursor box to be invisible. */
10071 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10072 if (dpyinfo
->scratch_cursor_gc
)
10073 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10075 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10076 GCForeground
, &xgcv
);
10077 gc
= dpyinfo
->scratch_cursor_gc
;
10079 /* Set clipping, draw the rectangle, and reset clipping again. */
10080 x_clip_to_row (w
, row
, gc
, 0);
10081 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10082 XSetClipMask (dpy
, gc
, None
);
10086 /* Draw a bar cursor on window W in glyph row ROW.
10088 Implementation note: One would like to draw a bar cursor with an
10089 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10090 Unfortunately, I didn't find a font yet that has this property set.
10094 x_draw_bar_cursor (w
, row
, width
)
10096 struct glyph_row
*row
;
10099 /* If cursor hpos is out of bounds, don't draw garbage. This can
10100 happen in mini-buffer windows when switching between echo area
10101 glyphs and mini-buffer. */
10102 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10104 struct frame
*f
= XFRAME (w
->frame
);
10105 struct glyph
*cursor_glyph
;
10108 unsigned long mask
;
10113 cursor_glyph
= get_phys_cursor_glyph (w
);
10114 if (cursor_glyph
== NULL
)
10117 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10118 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10119 xgcv
.graphics_exposures
= 0;
10120 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10121 dpy
= FRAME_X_DISPLAY (f
);
10122 window
= FRAME_X_WINDOW (f
);
10123 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10126 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10129 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10130 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10134 width
= f
->output_data
.x
->cursor_width
;
10136 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10137 x_clip_to_row (w
, row
, gc
, 0);
10138 XFillRectangle (dpy
, window
, gc
,
10140 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10141 min (cursor_glyph
->pixel_width
, width
),
10143 XSetClipMask (dpy
, gc
, None
);
10148 /* Clear the cursor of window W to background color, and mark the
10149 cursor as not shown. This is used when the text where the cursor
10150 is is about to be rewritten. */
10156 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10157 x_update_window_cursor (w
, 0);
10161 /* Draw the cursor glyph of window W in glyph row ROW. See the
10162 comment of x_draw_glyphs for the meaning of HL. */
10165 x_draw_phys_cursor_glyph (w
, row
, hl
)
10167 struct glyph_row
*row
;
10168 enum draw_glyphs_face hl
;
10170 /* If cursor hpos is out of bounds, don't draw garbage. This can
10171 happen in mini-buffer windows when switching between echo area
10172 glyphs and mini-buffer. */
10173 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10175 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10176 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10179 /* When we erase the cursor, and ROW is overlapped by other
10180 rows, make sure that these overlapping parts of other rows
10182 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10184 if (row
> w
->current_matrix
->rows
10185 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10186 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10188 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10189 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10190 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10196 /* Erase the image of a cursor of window W from the screen. */
10199 x_erase_phys_cursor (w
)
10202 struct frame
*f
= XFRAME (w
->frame
);
10203 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10204 int hpos
= w
->phys_cursor
.hpos
;
10205 int vpos
= w
->phys_cursor
.vpos
;
10206 int mouse_face_here_p
= 0;
10207 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10208 struct glyph_row
*cursor_row
;
10209 struct glyph
*cursor_glyph
;
10210 enum draw_glyphs_face hl
;
10212 /* No cursor displayed or row invalidated => nothing to do on the
10214 if (w
->phys_cursor_type
== NO_CURSOR
)
10215 goto mark_cursor_off
;
10217 /* VPOS >= active_glyphs->nrows means that window has been resized.
10218 Don't bother to erase the cursor. */
10219 if (vpos
>= active_glyphs
->nrows
)
10220 goto mark_cursor_off
;
10222 /* If row containing cursor is marked invalid, there is nothing we
10224 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10225 if (!cursor_row
->enabled_p
)
10226 goto mark_cursor_off
;
10228 /* This can happen when the new row is shorter than the old one.
10229 In this case, either x_draw_glyphs or clear_end_of_line
10230 should have cleared the cursor. Note that we wouldn't be
10231 able to erase the cursor in this case because we don't have a
10232 cursor glyph at hand. */
10233 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10234 goto mark_cursor_off
;
10236 /* If the cursor is in the mouse face area, redisplay that when
10237 we clear the cursor. */
10238 if (! NILP (dpyinfo
->mouse_face_window
)
10239 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10240 && (vpos
> dpyinfo
->mouse_face_beg_row
10241 || (vpos
== dpyinfo
->mouse_face_beg_row
10242 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10243 && (vpos
< dpyinfo
->mouse_face_end_row
10244 || (vpos
== dpyinfo
->mouse_face_end_row
10245 && hpos
< dpyinfo
->mouse_face_end_col
))
10246 /* Don't redraw the cursor's spot in mouse face if it is at the
10247 end of a line (on a newline). The cursor appears there, but
10248 mouse highlighting does not. */
10249 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10250 mouse_face_here_p
= 1;
10252 /* Maybe clear the display under the cursor. */
10253 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10256 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10258 cursor_glyph
= get_phys_cursor_glyph (w
);
10259 if (cursor_glyph
== NULL
)
10260 goto mark_cursor_off
;
10262 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10264 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10266 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10268 cursor_glyph
->pixel_width
,
10269 cursor_row
->visible_height
,
10273 /* Erase the cursor by redrawing the character underneath it. */
10274 if (mouse_face_here_p
)
10275 hl
= DRAW_MOUSE_FACE
;
10276 else if (cursor_row
->inverse_p
)
10277 hl
= DRAW_INVERSE_VIDEO
;
10279 hl
= DRAW_NORMAL_TEXT
;
10280 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10283 w
->phys_cursor_on_p
= 0;
10284 w
->phys_cursor_type
= NO_CURSOR
;
10288 /* Display or clear cursor of window W. If ON is zero, clear the
10289 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10290 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10293 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10295 int on
, hpos
, vpos
, x
, y
;
10297 struct frame
*f
= XFRAME (w
->frame
);
10298 int new_cursor_type
;
10299 int new_cursor_width
;
10300 struct glyph_matrix
*current_glyphs
;
10301 struct glyph_row
*glyph_row
;
10302 struct glyph
*glyph
;
10304 /* This is pointless on invisible frames, and dangerous on garbaged
10305 windows and frames; in the latter case, the frame or window may
10306 be in the midst of changing its size, and x and y may be off the
10308 if (! FRAME_VISIBLE_P (f
)
10309 || FRAME_GARBAGED_P (f
)
10310 || vpos
>= w
->current_matrix
->nrows
10311 || hpos
>= w
->current_matrix
->matrix_w
)
10314 /* If cursor is off and we want it off, return quickly. */
10315 if (!on
&& !w
->phys_cursor_on_p
)
10318 current_glyphs
= w
->current_matrix
;
10319 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10320 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10322 /* If cursor row is not enabled, we don't really know where to
10323 display the cursor. */
10324 if (!glyph_row
->enabled_p
)
10326 w
->phys_cursor_on_p
= 0;
10330 xassert (interrupt_input_blocked
);
10332 /* Set new_cursor_type to the cursor we want to be displayed. In a
10333 mini-buffer window, we want the cursor only to appear if we are
10334 reading input from this window. For the selected window, we want
10335 the cursor type given by the frame parameter. If explicitly
10336 marked off, draw no cursor. In all other cases, we want a hollow
10338 new_cursor_width
= -1;
10339 if (cursor_in_echo_area
10340 && FRAME_HAS_MINIBUF_P (f
)
10341 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10343 if (w
== XWINDOW (echo_area_window
))
10344 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10346 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10350 if (w
!= XWINDOW (selected_window
)
10351 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10353 extern int cursor_in_non_selected_windows
;
10355 if (MINI_WINDOW_P (w
) || !cursor_in_non_selected_windows
)
10356 new_cursor_type
= NO_CURSOR
;
10358 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10360 else if (w
->cursor_off_p
)
10361 new_cursor_type
= NO_CURSOR
;
10364 struct buffer
*b
= XBUFFER (w
->buffer
);
10366 if (EQ (b
->cursor_type
, Qt
))
10367 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10369 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10370 &new_cursor_width
);
10374 /* If cursor is currently being shown and we don't want it to be or
10375 it is in the wrong place, or the cursor type is not what we want,
10377 if (w
->phys_cursor_on_p
10379 || w
->phys_cursor
.x
!= x
10380 || w
->phys_cursor
.y
!= y
10381 || new_cursor_type
!= w
->phys_cursor_type
))
10382 x_erase_phys_cursor (w
);
10384 /* If the cursor is now invisible and we want it to be visible,
10386 if (on
&& !w
->phys_cursor_on_p
)
10388 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10389 w
->phys_cursor_height
= glyph_row
->height
;
10391 /* Set phys_cursor_.* before x_draw_.* is called because some
10392 of them may need the information. */
10393 w
->phys_cursor
.x
= x
;
10394 w
->phys_cursor
.y
= glyph_row
->y
;
10395 w
->phys_cursor
.hpos
= hpos
;
10396 w
->phys_cursor
.vpos
= vpos
;
10397 w
->phys_cursor_type
= new_cursor_type
;
10398 w
->phys_cursor_on_p
= 1;
10400 switch (new_cursor_type
)
10402 case HOLLOW_BOX_CURSOR
:
10403 x_draw_hollow_cursor (w
, glyph_row
);
10406 case FILLED_BOX_CURSOR
:
10407 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10411 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10422 if (w
== XWINDOW (f
->selected_window
))
10423 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10424 xic_set_preeditarea (w
, x
, y
);
10429 if (updating_frame
!= f
)
10430 XFlush (FRAME_X_DISPLAY (f
));
10435 /* Display the cursor on window W, or clear it. X and Y are window
10436 relative pixel coordinates. HPOS and VPOS are glyph matrix
10437 positions. If W is not the selected window, display a hollow
10438 cursor. ON non-zero means display the cursor at X, Y which
10439 correspond to HPOS, VPOS, otherwise it is cleared. */
10442 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10444 int on
, hpos
, vpos
, x
, y
;
10447 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10452 /* Display the cursor on window W, or clear it, according to ON_P.
10453 Don't change the cursor's position. */
10456 x_update_cursor (f
, on_p
)
10459 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10463 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10464 in the window tree rooted at W. */
10467 x_update_cursor_in_window_tree (w
, on_p
)
10473 if (!NILP (w
->hchild
))
10474 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10475 else if (!NILP (w
->vchild
))
10476 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10478 x_update_window_cursor (w
, on_p
);
10480 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10485 /* Switch the display of W's cursor on or off, according to the value
10489 x_update_window_cursor (w
, on
)
10493 /* Don't update cursor in windows whose frame is in the process
10494 of being deleted. */
10495 if (w
->current_matrix
)
10498 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10499 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10509 /* Refresh bitmap kitchen sink icon for frame F
10510 when we get an expose event for it. */
10516 /* Normally, the window manager handles this function. */
10519 /* Make the x-window of frame F use the gnu icon bitmap. */
10522 x_bitmap_icon (f
, file
)
10528 if (FRAME_X_WINDOW (f
) == 0)
10531 /* Free up our existing icon bitmap if any. */
10532 if (f
->output_data
.x
->icon_bitmap
> 0)
10533 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10534 f
->output_data
.x
->icon_bitmap
= 0;
10536 if (STRINGP (file
))
10537 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10540 /* Create the GNU bitmap if necessary. */
10541 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10542 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10543 = x_create_bitmap_from_data (f
, gnu_bits
,
10544 gnu_width
, gnu_height
);
10546 /* The first time we create the GNU bitmap,
10547 this increments the ref-count one extra time.
10548 As a result, the GNU bitmap is never freed.
10549 That way, we don't have to worry about allocating it again. */
10550 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10552 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10555 x_wm_set_icon_pixmap (f
, bitmap_id
);
10556 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10562 /* Make the x-window of frame F use a rectangle with text.
10563 Use ICON_NAME as the text. */
10566 x_text_icon (f
, icon_name
)
10570 if (FRAME_X_WINDOW (f
) == 0)
10575 XTextProperty text
;
10576 text
.value
= (unsigned char *) icon_name
;
10577 text
.encoding
= XA_STRING
;
10579 text
.nitems
= strlen (icon_name
);
10580 #ifdef USE_X_TOOLKIT
10581 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10583 #else /* not USE_X_TOOLKIT */
10584 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10585 #endif /* not USE_X_TOOLKIT */
10587 #else /* not HAVE_X11R4 */
10588 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10589 #endif /* not HAVE_X11R4 */
10591 if (f
->output_data
.x
->icon_bitmap
> 0)
10592 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10593 f
->output_data
.x
->icon_bitmap
= 0;
10594 x_wm_set_icon_pixmap (f
, 0);
10599 #define X_ERROR_MESSAGE_SIZE 200
10601 /* If non-nil, this should be a string.
10602 It means catch X errors and store the error message in this string. */
10604 static Lisp_Object x_error_message_string
;
10606 /* An X error handler which stores the error message in
10607 x_error_message_string. This is called from x_error_handler if
10608 x_catch_errors is in effect. */
10611 x_error_catcher (display
, error
)
10613 XErrorEvent
*error
;
10615 XGetErrorText (display
, error
->error_code
,
10616 XSTRING (x_error_message_string
)->data
,
10617 X_ERROR_MESSAGE_SIZE
);
10620 /* Begin trapping X errors for display DPY. Actually we trap X errors
10621 for all displays, but DPY should be the display you are actually
10624 After calling this function, X protocol errors no longer cause
10625 Emacs to exit; instead, they are recorded in the string
10626 stored in x_error_message_string.
10628 Calling x_check_errors signals an Emacs error if an X error has
10629 occurred since the last call to x_catch_errors or x_check_errors.
10631 Calling x_uncatch_errors resumes the normal error handling. */
10633 void x_check_errors ();
10634 static Lisp_Object
x_catch_errors_unwind ();
10637 x_catch_errors (dpy
)
10640 int count
= specpdl_ptr
- specpdl
;
10642 /* Make sure any errors from previous requests have been dealt with. */
10643 XSync (dpy
, False
);
10645 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10647 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10648 XSTRING (x_error_message_string
)->data
[0] = 0;
10653 /* Unbind the binding that we made to check for X errors. */
10656 x_catch_errors_unwind (old_val
)
10657 Lisp_Object old_val
;
10659 x_error_message_string
= old_val
;
10663 /* If any X protocol errors have arrived since the last call to
10664 x_catch_errors or x_check_errors, signal an Emacs error using
10665 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10668 x_check_errors (dpy
, format
)
10672 /* Make sure to catch any errors incurred so far. */
10673 XSync (dpy
, False
);
10675 if (XSTRING (x_error_message_string
)->data
[0])
10676 error (format
, XSTRING (x_error_message_string
)->data
);
10679 /* Nonzero if we had any X protocol errors
10680 since we did x_catch_errors on DPY. */
10683 x_had_errors_p (dpy
)
10686 /* Make sure to catch any errors incurred so far. */
10687 XSync (dpy
, False
);
10689 return XSTRING (x_error_message_string
)->data
[0] != 0;
10692 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
10695 x_clear_errors (dpy
)
10698 XSTRING (x_error_message_string
)->data
[0] = 0;
10701 /* Stop catching X protocol errors and let them make Emacs die.
10702 DPY should be the display that was passed to x_catch_errors.
10703 COUNT should be the value that was returned by
10704 the corresponding call to x_catch_errors. */
10707 x_uncatch_errors (dpy
, count
)
10711 unbind_to (count
, Qnil
);
10715 static unsigned int x_wire_count
;
10718 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
10723 /* Handle SIGPIPE, which can happen when the connection to a server
10724 simply goes away. SIGPIPE is handled by x_connection_signal.
10725 Don't need to do anything, because the write which caused the
10726 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
10727 which will do the appropriate cleanup for us. */
10730 x_connection_signal (signalnum
) /* If we don't have an argument, */
10731 int signalnum
; /* some compilers complain in signal calls. */
10734 /* USG systems forget handlers when they are used;
10735 must reestablish each time */
10736 signal (signalnum
, x_connection_signal
);
10740 /* Handling X errors. */
10742 /* Handle the loss of connection to display DISPLAY. */
10745 x_connection_closed (display
, error_message
)
10747 char *error_message
;
10749 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
10750 Lisp_Object frame
, tail
;
10752 /* Indicate that this display is dead. */
10754 #if 0 /* Closing the display caused a bus error on OpenWindows. */
10755 #ifdef USE_X_TOOLKIT
10756 XtCloseDisplay (display
);
10760 dpyinfo
->display
= 0;
10762 /* First delete frames whose mini-buffers are on frames
10763 that are on the dead display. */
10764 FOR_EACH_FRAME (tail
, frame
)
10766 Lisp_Object minibuf_frame
;
10768 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
10769 if (FRAME_X_P (XFRAME (frame
))
10770 && FRAME_X_P (XFRAME (minibuf_frame
))
10771 && ! EQ (frame
, minibuf_frame
)
10772 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
10773 Fdelete_frame (frame
, Qt
);
10776 /* Now delete all remaining frames on the dead display.
10777 We are now sure none of these is used as the mini-buffer
10778 for another frame that we need to delete. */
10779 FOR_EACH_FRAME (tail
, frame
)
10780 if (FRAME_X_P (XFRAME (frame
))
10781 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
10783 /* Set this to t so that Fdelete_frame won't get confused
10784 trying to find a replacement. */
10785 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
10786 Fdelete_frame (frame
, Qt
);
10790 x_delete_display (dpyinfo
);
10792 if (x_display_list
== 0)
10794 fprintf (stderr
, "%s\n", error_message
);
10795 shut_down_emacs (0, 0, Qnil
);
10799 /* Ordinary stack unwind doesn't deal with these. */
10801 sigunblock (sigmask (SIGIO
));
10803 sigunblock (sigmask (SIGALRM
));
10804 TOTALLY_UNBLOCK_INPUT
;
10806 clear_waiting_for_input ();
10807 error ("%s", error_message
);
10810 /* This is the usual handler for X protocol errors.
10811 It kills all frames on the display that we got the error for.
10812 If that was the only one, it prints an error message and kills Emacs. */
10815 x_error_quitter (display
, error
)
10817 XErrorEvent
*error
;
10819 char buf
[256], buf1
[356];
10821 /* Note that there is no real way portable across R3/R4 to get the
10822 original error handler. */
10824 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
10825 sprintf (buf1
, "X protocol error: %s on protocol request %d",
10826 buf
, error
->request_code
);
10827 x_connection_closed (display
, buf1
);
10830 /* This is the first-level handler for X protocol errors.
10831 It calls x_error_quitter or x_error_catcher. */
10834 x_error_handler (display
, error
)
10836 XErrorEvent
*error
;
10838 if (! NILP (x_error_message_string
))
10839 x_error_catcher (display
, error
);
10841 x_error_quitter (display
, error
);
10845 /* This is the handler for X IO errors, always.
10846 It kills all frames on the display that we lost touch with.
10847 If that was the only one, it prints an error message and kills Emacs. */
10850 x_io_error_quitter (display
)
10855 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
10856 x_connection_closed (display
, buf
);
10860 /* Changing the font of the frame. */
10862 /* Give frame F the font named FONTNAME as its default font, and
10863 return the full name of that font. FONTNAME may be a wildcard
10864 pattern; in that case, we choose some font that fits the pattern.
10865 The return value shows which font we chose. */
10868 x_new_font (f
, fontname
)
10870 register char *fontname
;
10872 struct font_info
*fontp
10873 = FS_LOAD_FONT (f
, 0, fontname
, -1);
10878 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
10879 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
10880 f
->output_data
.x
->fontset
= -1;
10882 /* Compute the scroll bar width in character columns. */
10883 if (f
->scroll_bar_pixel_width
> 0)
10885 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10886 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
10890 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10891 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
10894 /* Now make the frame display the given font. */
10895 if (FRAME_X_WINDOW (f
) != 0)
10897 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
10898 f
->output_data
.x
->font
->fid
);
10899 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
10900 f
->output_data
.x
->font
->fid
);
10901 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
10902 f
->output_data
.x
->font
->fid
);
10904 frame_update_line_height (f
);
10905 x_set_window_size (f
, 0, f
->width
, f
->height
);
10908 /* If we are setting a new frame's font for the first time,
10909 there are no faces yet, so this font's height is the line height. */
10910 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
10912 return build_string (fontp
->full_name
);
10915 /* Give frame F the fontset named FONTSETNAME as its default font, and
10916 return the full name of that fontset. FONTSETNAME may be a wildcard
10917 pattern; in that case, we choose some fontset that fits the pattern.
10918 The return value shows which fontset we chose. */
10921 x_new_fontset (f
, fontsetname
)
10925 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
10926 Lisp_Object result
;
10932 if (f
->output_data
.x
->fontset
== fontset
)
10933 /* This fontset is already set in frame F. There's nothing more
10935 return fontset_name (fontset
);
10937 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
10939 if (!STRINGP (result
))
10940 /* Can't load ASCII font. */
10943 /* Since x_new_font doesn't update any fontset information, do it now. */
10944 f
->output_data
.x
->fontset
= fontset
;
10948 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
10949 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
10952 return build_string (fontsetname
);
10956 /***********************************************************************
10958 ***********************************************************************/
10964 /* XIM destroy callback function, which is called whenever the
10965 connection to input method XIM dies. CLIENT_DATA contains a
10966 pointer to the x_display_info structure corresponding to XIM. */
10969 xim_destroy_callback (xim
, client_data
, call_data
)
10971 XPointer client_data
;
10972 XPointer call_data
;
10974 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
10975 Lisp_Object frame
, tail
;
10979 /* No need to call XDestroyIC.. */
10980 FOR_EACH_FRAME (tail
, frame
)
10982 struct frame
*f
= XFRAME (frame
);
10983 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
10985 FRAME_XIC (f
) = NULL
;
10986 if (FRAME_XIC_FONTSET (f
))
10988 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
10989 FRAME_XIC_FONTSET (f
) = NULL
;
10994 /* No need to call XCloseIM. */
10995 dpyinfo
->xim
= NULL
;
10996 XFree (dpyinfo
->xim_styles
);
11000 #endif /* HAVE_X11R6 */
11002 /* Open the connection to the XIM server on display DPYINFO.
11003 RESOURCE_NAME is the resource name Emacs uses. */
11006 xim_open_dpy (dpyinfo
, resource_name
)
11007 struct x_display_info
*dpyinfo
;
11008 char *resource_name
;
11012 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11013 dpyinfo
->xim
= xim
;
11018 XIMCallback destroy
;
11021 /* Get supported styles and XIM values. */
11022 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11025 destroy
.callback
= xim_destroy_callback
;
11026 destroy
.client_data
= (XPointer
)dpyinfo
;
11027 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11033 #ifdef HAVE_X11R6_XIM
11037 struct x_display_info
*dpyinfo
;
11038 char *resource_name
;
11041 /* XIM instantiate callback function, which is called whenever an XIM
11042 server is available. DISPLAY is teh display of the XIM.
11043 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11044 when the callback was registered. */
11047 xim_instantiate_callback (display
, client_data
, call_data
)
11049 XPointer client_data
;
11050 XPointer call_data
;
11052 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11053 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11055 /* We don't support multiple XIM connections. */
11059 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11061 /* Create XIC for the existing frames on the same display, as long
11062 as they have no XIC. */
11063 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11065 Lisp_Object tail
, frame
;
11068 FOR_EACH_FRAME (tail
, frame
)
11070 struct frame
*f
= XFRAME (frame
);
11072 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11073 if (FRAME_XIC (f
) == NULL
)
11075 create_frame_xic (f
);
11076 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11077 xic_set_statusarea (f
);
11078 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11080 struct window
*w
= XWINDOW (f
->selected_window
);
11081 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11090 #endif /* HAVE_X11R6_XIM */
11093 /* Open a connection to the XIM server on display DPYINFO.
11094 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11095 connection only at the first time. On X11R6, open the connection
11096 in the XIM instantiate callback function. */
11099 xim_initialize (dpyinfo
, resource_name
)
11100 struct x_display_info
*dpyinfo
;
11101 char *resource_name
;
11103 #ifdef HAVE_X11R6_XIM
11104 struct xim_inst_t
*xim_inst
;
11107 dpyinfo
->xim
= NULL
;
11108 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11109 xim_inst
->dpyinfo
= dpyinfo
;
11110 len
= strlen (resource_name
);
11111 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11112 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11113 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11114 resource_name
, EMACS_CLASS
,
11115 xim_instantiate_callback
,
11116 (XPointer
)xim_inst
);
11117 #else /* not HAVE_X11R6_XIM */
11118 dpyinfo
->xim
= NULL
;
11119 xim_open_dpy (dpyinfo
, resource_name
);
11120 #endif /* not HAVE_X11R6_XIM */
11124 /* Close the connection to the XIM server on display DPYINFO. */
11127 xim_close_dpy (dpyinfo
)
11128 struct x_display_info
*dpyinfo
;
11130 #ifdef HAVE_X11R6_XIM
11131 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11133 xim_instantiate_callback
, NULL
);
11134 #endif /* not HAVE_X11R6_XIM */
11135 XCloseIM (dpyinfo
->xim
);
11136 dpyinfo
->xim
= NULL
;
11137 XFree (dpyinfo
->xim_styles
);
11140 #endif /* not HAVE_X11R6_XIM */
11144 /* Calculate the absolute position in frame F
11145 from its current recorded position values and gravity. */
11148 x_calc_absolute_position (f
)
11152 int win_x
= 0, win_y
= 0;
11153 int flags
= f
->output_data
.x
->size_hint_flags
;
11156 /* We have nothing to do if the current position
11157 is already for the top-left corner. */
11158 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11161 #ifdef USE_X_TOOLKIT
11162 this_window
= XtWindow (f
->output_data
.x
->widget
);
11164 this_window
= FRAME_X_WINDOW (f
);
11167 /* Find the position of the outside upper-left corner of
11168 the inner window, with respect to the outer window.
11169 But do this only if we will need the results. */
11170 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11175 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11178 x_clear_errors (FRAME_X_DISPLAY (f
));
11179 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11181 /* From-window, to-window. */
11183 f
->output_data
.x
->parent_desc
,
11185 /* From-position, to-position. */
11186 0, 0, &win_x
, &win_y
,
11188 /* Child of win. */
11190 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11192 Window newroot
, newparent
= 0xdeadbeef;
11193 Window
*newchildren
;
11196 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11197 &newparent
, &newchildren
, &nchildren
))
11200 XFree ((char *) newchildren
);
11202 f
->output_data
.x
->parent_desc
= newparent
;
11208 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11212 /* Treat negative positions as relative to the leftmost bottommost
11213 position that fits on the screen. */
11214 if (flags
& XNegative
)
11215 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11216 - 2 * f
->output_data
.x
->border_width
- win_x
11218 + f
->output_data
.x
->left_pos
);
11220 if (flags
& YNegative
)
11222 int menubar_height
= 0;
11224 #ifdef USE_X_TOOLKIT
11225 if (f
->output_data
.x
->menubar_widget
)
11227 = (f
->output_data
.x
->menubar_widget
->core
.height
11228 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
11231 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11232 - 2 * f
->output_data
.x
->border_width
11236 + f
->output_data
.x
->top_pos
);
11239 /* The left_pos and top_pos
11240 are now relative to the top and left screen edges,
11241 so the flags should correspond. */
11242 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11245 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11246 to really change the position, and 0 when calling from
11247 x_make_frame_visible (in that case, XOFF and YOFF are the current
11248 position values). It is -1 when calling from x_set_frame_parameters,
11249 which means, do adjust for borders but don't change the gravity. */
11252 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11254 register int xoff
, yoff
;
11255 int change_gravity
;
11257 int modified_top
, modified_left
;
11259 if (change_gravity
> 0)
11261 f
->output_data
.x
->top_pos
= yoff
;
11262 f
->output_data
.x
->left_pos
= xoff
;
11263 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11265 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11267 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11268 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11270 x_calc_absolute_position (f
);
11273 x_wm_set_size_hint (f
, (long) 0, 0);
11275 modified_left
= f
->output_data
.x
->left_pos
;
11276 modified_top
= f
->output_data
.x
->top_pos
;
11277 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11278 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11279 /* It is a mystery why we need to add the border_width here
11280 when the frame is already visible, but experiment says we do. */
11281 if (change_gravity
!= 0)
11283 modified_left
+= f
->output_data
.x
->border_width
;
11284 modified_top
+= f
->output_data
.x
->border_width
;
11288 #ifdef USE_X_TOOLKIT
11289 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11290 modified_left
, modified_top
);
11291 #else /* not USE_X_TOOLKIT */
11292 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11293 modified_left
, modified_top
);
11294 #endif /* not USE_X_TOOLKIT */
11298 /* Call this to change the size of frame F's x-window.
11299 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11300 for this size change and subsequent size changes.
11301 Otherwise we leave the window gravity unchanged. */
11304 x_set_window_size (f
, change_gravity
, cols
, rows
)
11306 int change_gravity
;
11309 #ifndef USE_X_TOOLKIT
11310 int pixelwidth
, pixelheight
;
11315 #ifdef USE_X_TOOLKIT
11317 /* The x and y position of the widget is clobbered by the
11318 call to XtSetValues within EmacsFrameSetCharSize.
11319 This is a real kludge, but I don't understand Xt so I can't
11320 figure out a correct fix. Can anyone else tell me? -- rms. */
11321 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11322 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11323 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11324 f
->output_data
.x
->widget
->core
.x
= xpos
;
11325 f
->output_data
.x
->widget
->core
.y
= ypos
;
11328 #else /* not USE_X_TOOLKIT */
11330 check_frame_size (f
, &rows
, &cols
);
11331 f
->output_data
.x
->vertical_scroll_bar_extra
11332 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11334 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11335 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11336 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11337 f
->output_data
.x
->flags_areas_extra
11338 = FRAME_FLAGS_AREA_WIDTH (f
);
11339 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11340 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11342 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11343 x_wm_set_size_hint (f
, (long) 0, 0);
11345 XSync (FRAME_X_DISPLAY (f
), False
);
11346 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11347 pixelwidth
, pixelheight
);
11349 /* Now, strictly speaking, we can't be sure that this is accurate,
11350 but the window manager will get around to dealing with the size
11351 change request eventually, and we'll hear how it went when the
11352 ConfigureNotify event gets here.
11354 We could just not bother storing any of this information here,
11355 and let the ConfigureNotify event set everything up, but that
11356 might be kind of confusing to the Lisp code, since size changes
11357 wouldn't be reported in the frame parameters until some random
11358 point in the future when the ConfigureNotify event arrives.
11360 We pass 1 for DELAY since we can't run Lisp code inside of
11362 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11363 PIXEL_WIDTH (f
) = pixelwidth
;
11364 PIXEL_HEIGHT (f
) = pixelheight
;
11366 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11367 receive in the ConfigureNotify event; if we get what we asked
11368 for, then the event won't cause the screen to become garbaged, so
11369 we have to make sure to do it here. */
11370 SET_FRAME_GARBAGED (f
);
11372 XFlush (FRAME_X_DISPLAY (f
));
11374 #endif /* not USE_X_TOOLKIT */
11376 /* If cursor was outside the new size, mark it as off. */
11377 mark_window_cursors_off (XWINDOW (f
->root_window
));
11379 /* Clear out any recollection of where the mouse highlighting was,
11380 since it might be in a place that's outside the new frame size.
11381 Actually checking whether it is outside is a pain in the neck,
11382 so don't try--just let the highlighting be done afresh with new size. */
11383 cancel_mouse_face (f
);
11388 /* Mouse warping. */
11391 x_set_mouse_position (f
, x
, y
)
11397 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11398 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11400 if (pix_x
< 0) pix_x
= 0;
11401 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11403 if (pix_y
< 0) pix_y
= 0;
11404 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11408 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11409 0, 0, 0, 0, pix_x
, pix_y
);
11413 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11416 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11422 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11423 0, 0, 0, 0, pix_x
, pix_y
);
11427 /* focus shifting, raising and lowering. */
11430 x_focus_on_frame (f
)
11433 #if 0 /* This proves to be unpleasant. */
11437 /* I don't think that the ICCCM allows programs to do things like this
11438 without the interaction of the window manager. Whatever you end up
11439 doing with this code, do it to x_unfocus_frame too. */
11440 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11441 RevertToPointerRoot
, CurrentTime
);
11446 x_unfocus_frame (f
)
11450 /* Look at the remarks in x_focus_on_frame. */
11451 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11452 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11453 RevertToPointerRoot
, CurrentTime
);
11457 /* Raise frame F. */
11463 if (f
->async_visible
)
11466 #ifdef USE_X_TOOLKIT
11467 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11468 #else /* not USE_X_TOOLKIT */
11469 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11470 #endif /* not USE_X_TOOLKIT */
11471 XFlush (FRAME_X_DISPLAY (f
));
11476 /* Lower frame F. */
11482 if (f
->async_visible
)
11485 #ifdef USE_X_TOOLKIT
11486 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11487 #else /* not USE_X_TOOLKIT */
11488 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11489 #endif /* not USE_X_TOOLKIT */
11490 XFlush (FRAME_X_DISPLAY (f
));
11496 XTframe_raise_lower (f
, raise_flag
)
11506 /* Change of visibility. */
11508 /* This tries to wait until the frame is really visible.
11509 However, if the window manager asks the user where to position
11510 the frame, this will return before the user finishes doing that.
11511 The frame will not actually be visible at that time,
11512 but it will become visible later when the window manager
11513 finishes with it. */
11516 x_make_frame_visible (f
)
11520 int original_top
, original_left
;
11524 type
= x_icon_type (f
);
11526 x_bitmap_icon (f
, type
);
11528 if (! FRAME_VISIBLE_P (f
))
11530 /* We test FRAME_GARBAGED_P here to make sure we don't
11531 call x_set_offset a second time
11532 if we get to x_make_frame_visible a second time
11533 before the window gets really visible. */
11534 if (! FRAME_ICONIFIED_P (f
)
11535 && ! f
->output_data
.x
->asked_for_visible
)
11536 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11538 f
->output_data
.x
->asked_for_visible
= 1;
11540 if (! EQ (Vx_no_window_manager
, Qt
))
11541 x_wm_set_window_state (f
, NormalState
);
11542 #ifdef USE_X_TOOLKIT
11543 /* This was XtPopup, but that did nothing for an iconified frame. */
11544 XtMapWidget (f
->output_data
.x
->widget
);
11545 #else /* not USE_X_TOOLKIT */
11546 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11547 #endif /* not USE_X_TOOLKIT */
11548 #if 0 /* This seems to bring back scroll bars in the wrong places
11549 if the window configuration has changed. They seem
11550 to come back ok without this. */
11551 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11552 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11556 XFlush (FRAME_X_DISPLAY (f
));
11558 /* Synchronize to ensure Emacs knows the frame is visible
11559 before we do anything else. We do this loop with input not blocked
11560 so that incoming events are handled. */
11564 /* This must be before UNBLOCK_INPUT
11565 since events that arrive in response to the actions above
11566 will set it when they are handled. */
11567 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11569 original_left
= f
->output_data
.x
->left_pos
;
11570 original_top
= f
->output_data
.x
->top_pos
;
11572 /* This must come after we set COUNT. */
11575 /* We unblock here so that arriving X events are processed. */
11577 /* Now move the window back to where it was "supposed to be".
11578 But don't do it if the gravity is negative.
11579 When the gravity is negative, this uses a position
11580 that is 3 pixels too low. Perhaps that's really the border width.
11582 Don't do this if the window has never been visible before,
11583 because the window manager may choose the position
11584 and we don't want to override it. */
11586 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11587 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11588 && previously_visible
)
11592 unsigned int width
, height
, border
, depth
;
11596 /* On some window managers (such as FVWM) moving an existing
11597 window, even to the same place, causes the window manager
11598 to introduce an offset. This can cause the window to move
11599 to an unexpected location. Check the geometry (a little
11600 slow here) and then verify that the window is in the right
11601 place. If the window is not in the right place, move it
11602 there, and take the potential window manager hit. */
11603 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11604 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11606 if (original_left
!= x
|| original_top
!= y
)
11607 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11608 original_left
, original_top
);
11613 XSETFRAME (frame
, f
);
11615 /* Wait until the frame is visible. Process X events until a
11616 MapNotify event has been seen, or until we think we won't get a
11617 MapNotify at all.. */
11618 for (count
= input_signal_count
+ 10;
11619 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
11621 /* Force processing of queued events. */
11624 /* Machines that do polling rather than SIGIO have been
11625 observed to go into a busy-wait here. So we'll fake an
11626 alarm signal to let the handler know that there's something
11627 to be read. We used to raise a real alarm, but it seems
11628 that the handler isn't always enabled here. This is
11630 if (input_polling_used ())
11632 /* It could be confusing if a real alarm arrives while
11633 processing the fake one. Turn it off and let the
11634 handler reset it. */
11635 int old_poll_suppress_count
= poll_suppress_count
;
11636 poll_suppress_count
= 1;
11637 poll_for_input_1 ();
11638 poll_suppress_count
= old_poll_suppress_count
;
11641 /* See if a MapNotify event has been processed. */
11642 FRAME_SAMPLE_VISIBILITY (f
);
11647 /* Change from mapped state to withdrawn state. */
11649 /* Make the frame visible (mapped and not iconified). */
11652 x_make_frame_invisible (f
)
11657 #ifdef USE_X_TOOLKIT
11658 /* Use the frame's outermost window, not the one we normally draw on. */
11659 window
= XtWindow (f
->output_data
.x
->widget
);
11660 #else /* not USE_X_TOOLKIT */
11661 window
= FRAME_X_WINDOW (f
);
11662 #endif /* not USE_X_TOOLKIT */
11664 /* Don't keep the highlight on an invisible frame. */
11665 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11666 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11668 #if 0/* This might add unreliability; I don't trust it -- rms. */
11669 if (! f
->async_visible
&& ! f
->async_iconified
)
11675 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11676 that the current position of the window is user-specified, rather than
11677 program-specified, so that when the window is mapped again, it will be
11678 placed at the same location, without forcing the user to position it
11679 by hand again (they have already done that once for this window.) */
11680 x_wm_set_size_hint (f
, (long) 0, 1);
11684 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11685 DefaultScreen (FRAME_X_DISPLAY (f
))))
11687 UNBLOCK_INPUT_RESIGNAL
;
11688 error ("Can't notify window manager of window withdrawal");
11690 #else /* ! defined (HAVE_X11R4) */
11692 /* Tell the window manager what we're going to do. */
11693 if (! EQ (Vx_no_window_manager
, Qt
))
11697 unmap
.xunmap
.type
= UnmapNotify
;
11698 unmap
.xunmap
.window
= window
;
11699 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
11700 unmap
.xunmap
.from_configure
= False
;
11701 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11702 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11704 SubstructureRedirectMaskSubstructureNotifyMask
,
11707 UNBLOCK_INPUT_RESIGNAL
;
11708 error ("Can't notify window manager of withdrawal");
11712 /* Unmap the window ourselves. Cheeky! */
11713 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
11714 #endif /* ! defined (HAVE_X11R4) */
11716 /* We can't distinguish this from iconification
11717 just by the event that we get from the server.
11718 So we can't win using the usual strategy of letting
11719 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11720 and synchronize with the server to make sure we agree. */
11722 FRAME_ICONIFIED_P (f
) = 0;
11723 f
->async_visible
= 0;
11724 f
->async_iconified
= 0;
11731 /* Change window state from mapped to iconified. */
11734 x_iconify_frame (f
)
11740 /* Don't keep the highlight on an invisible frame. */
11741 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11742 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11744 if (f
->async_iconified
)
11749 FRAME_SAMPLE_VISIBILITY (f
);
11751 type
= x_icon_type (f
);
11753 x_bitmap_icon (f
, type
);
11755 #ifdef USE_X_TOOLKIT
11757 if (! FRAME_VISIBLE_P (f
))
11759 if (! EQ (Vx_no_window_manager
, Qt
))
11760 x_wm_set_window_state (f
, IconicState
);
11761 /* This was XtPopup, but that did nothing for an iconified frame. */
11762 XtMapWidget (f
->output_data
.x
->widget
);
11763 /* The server won't give us any event to indicate
11764 that an invisible frame was changed to an icon,
11765 so we have to record it here. */
11768 f
->async_iconified
= 1;
11769 f
->async_visible
= 0;
11774 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11775 XtWindow (f
->output_data
.x
->widget
),
11776 DefaultScreen (FRAME_X_DISPLAY (f
)));
11780 error ("Can't notify window manager of iconification");
11782 f
->async_iconified
= 1;
11783 f
->async_visible
= 0;
11787 XFlush (FRAME_X_DISPLAY (f
));
11789 #else /* not USE_X_TOOLKIT */
11791 /* Make sure the X server knows where the window should be positioned,
11792 in case the user deiconifies with the window manager. */
11793 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
11794 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11796 /* Since we don't know which revision of X we're running, we'll use both
11797 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11799 /* X11R4: send a ClientMessage to the window manager using the
11800 WM_CHANGE_STATE type. */
11804 message
.xclient
.window
= FRAME_X_WINDOW (f
);
11805 message
.xclient
.type
= ClientMessage
;
11806 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11807 message
.xclient
.format
= 32;
11808 message
.xclient
.data
.l
[0] = IconicState
;
11810 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11811 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11813 SubstructureRedirectMask
| SubstructureNotifyMask
,
11816 UNBLOCK_INPUT_RESIGNAL
;
11817 error ("Can't notify window manager of iconification");
11821 /* X11R3: set the initial_state field of the window manager hints to
11823 x_wm_set_window_state (f
, IconicState
);
11825 if (!FRAME_VISIBLE_P (f
))
11827 /* If the frame was withdrawn, before, we must map it. */
11828 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11831 f
->async_iconified
= 1;
11832 f
->async_visible
= 0;
11834 XFlush (FRAME_X_DISPLAY (f
));
11836 #endif /* not USE_X_TOOLKIT */
11839 /* Destroy the X window of frame F. */
11842 x_destroy_window (f
)
11845 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11849 /* If a display connection is dead, don't try sending more
11850 commands to the X server. */
11851 if (dpyinfo
->display
!= 0)
11853 if (f
->output_data
.x
->icon_desc
!= 0)
11854 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
11857 free_frame_xic (f
);
11859 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
11860 #ifdef USE_X_TOOLKIT
11861 if (f
->output_data
.x
->widget
)
11862 XtDestroyWidget (f
->output_data
.x
->widget
);
11863 free_frame_menubar (f
);
11864 #endif /* USE_X_TOOLKIT */
11866 free_frame_faces (f
);
11867 XFlush (FRAME_X_DISPLAY (f
));
11870 if (f
->output_data
.x
->saved_menu_event
)
11871 xfree (f
->output_data
.x
->saved_menu_event
);
11873 xfree (f
->output_data
.x
);
11874 f
->output_data
.x
= 0;
11875 if (f
== dpyinfo
->x_focus_frame
)
11876 dpyinfo
->x_focus_frame
= 0;
11877 if (f
== dpyinfo
->x_focus_event_frame
)
11878 dpyinfo
->x_focus_event_frame
= 0;
11879 if (f
== dpyinfo
->x_highlight_frame
)
11880 dpyinfo
->x_highlight_frame
= 0;
11882 dpyinfo
->reference_count
--;
11884 if (f
== dpyinfo
->mouse_face_mouse_frame
)
11886 dpyinfo
->mouse_face_beg_row
11887 = dpyinfo
->mouse_face_beg_col
= -1;
11888 dpyinfo
->mouse_face_end_row
11889 = dpyinfo
->mouse_face_end_col
= -1;
11890 dpyinfo
->mouse_face_window
= Qnil
;
11891 dpyinfo
->mouse_face_deferred_gc
= 0;
11892 dpyinfo
->mouse_face_mouse_frame
= 0;
11898 /* Setting window manager hints. */
11900 /* Set the normal size hints for the window manager, for frame F.
11901 FLAGS is the flags word to use--or 0 meaning preserve the flags
11902 that the window now has.
11903 If USER_POSITION is nonzero, we set the USPosition
11904 flag (this is useful when FLAGS is 0). */
11907 x_wm_set_size_hint (f
, flags
, user_position
)
11912 XSizeHints size_hints
;
11914 #ifdef USE_X_TOOLKIT
11917 Dimension widget_width
, widget_height
;
11918 Window window
= XtWindow (f
->output_data
.x
->widget
);
11919 #else /* not USE_X_TOOLKIT */
11920 Window window
= FRAME_X_WINDOW (f
);
11921 #endif /* not USE_X_TOOLKIT */
11923 /* Setting PMaxSize caused various problems. */
11924 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
11926 size_hints
.x
= f
->output_data
.x
->left_pos
;
11927 size_hints
.y
= f
->output_data
.x
->top_pos
;
11929 #ifdef USE_X_TOOLKIT
11930 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
11931 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
11932 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
11933 size_hints
.height
= widget_height
;
11934 size_hints
.width
= widget_width
;
11935 #else /* not USE_X_TOOLKIT */
11936 size_hints
.height
= PIXEL_HEIGHT (f
);
11937 size_hints
.width
= PIXEL_WIDTH (f
);
11938 #endif /* not USE_X_TOOLKIT */
11940 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
11941 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
11942 size_hints
.max_width
11943 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
11944 size_hints
.max_height
11945 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
11947 /* Calculate the base and minimum sizes.
11949 (When we use the X toolkit, we don't do it here.
11950 Instead we copy the values that the widgets are using, below.) */
11951 #ifndef USE_X_TOOLKIT
11953 int base_width
, base_height
;
11954 int min_rows
= 0, min_cols
= 0;
11956 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
11957 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
11959 check_frame_size (f
, &min_rows
, &min_cols
);
11961 /* The window manager uses the base width hints to calculate the
11962 current number of rows and columns in the frame while
11963 resizing; min_width and min_height aren't useful for this
11964 purpose, since they might not give the dimensions for a
11965 zero-row, zero-column frame.
11967 We use the base_width and base_height members if we have
11968 them; otherwise, we set the min_width and min_height members
11969 to the size for a zero x zero frame. */
11972 size_hints
.flags
|= PBaseSize
;
11973 size_hints
.base_width
= base_width
;
11974 size_hints
.base_height
= base_height
;
11975 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
11976 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
11978 size_hints
.min_width
= base_width
;
11979 size_hints
.min_height
= base_height
;
11983 /* If we don't need the old flags, we don't need the old hint at all. */
11986 size_hints
.flags
|= flags
;
11989 #endif /* not USE_X_TOOLKIT */
11992 XSizeHints hints
; /* Sometimes I hate X Windows... */
11993 long supplied_return
;
11997 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12000 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12003 #ifdef USE_X_TOOLKIT
12004 size_hints
.base_height
= hints
.base_height
;
12005 size_hints
.base_width
= hints
.base_width
;
12006 size_hints
.min_height
= hints
.min_height
;
12007 size_hints
.min_width
= hints
.min_width
;
12011 size_hints
.flags
|= flags
;
12016 if (hints
.flags
& PSize
)
12017 size_hints
.flags
|= PSize
;
12018 if (hints
.flags
& PPosition
)
12019 size_hints
.flags
|= PPosition
;
12020 if (hints
.flags
& USPosition
)
12021 size_hints
.flags
|= USPosition
;
12022 if (hints
.flags
& USSize
)
12023 size_hints
.flags
|= USSize
;
12027 #ifndef USE_X_TOOLKIT
12032 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12033 size_hints
.flags
|= PWinGravity
;
12037 size_hints
.flags
&= ~ PPosition
;
12038 size_hints
.flags
|= USPosition
;
12040 #endif /* PWinGravity */
12043 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12045 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12049 /* Used for IconicState or NormalState */
12052 x_wm_set_window_state (f
, state
)
12056 #ifdef USE_X_TOOLKIT
12059 XtSetArg (al
[0], XtNinitialState
, state
);
12060 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12061 #else /* not USE_X_TOOLKIT */
12062 Window window
= FRAME_X_WINDOW (f
);
12064 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12065 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12067 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12068 #endif /* not USE_X_TOOLKIT */
12072 x_wm_set_icon_pixmap (f
, pixmap_id
)
12076 Pixmap icon_pixmap
;
12078 #ifndef USE_X_TOOLKIT
12079 Window window
= FRAME_X_WINDOW (f
);
12084 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12085 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12089 /* It seems there is no way to turn off use of an icon pixmap.
12090 The following line does it, only if no icon has yet been created,
12091 for some window managers. But with mwm it crashes.
12092 Some people say it should clear the IconPixmapHint bit in this case,
12093 but that doesn't work, and the X consortium said it isn't the
12094 right thing at all. Since there is no way to win,
12095 best to explicitly give up. */
12097 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12103 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12107 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12108 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12111 #else /* not USE_X_TOOLKIT */
12113 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12114 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12116 #endif /* not USE_X_TOOLKIT */
12120 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12122 int icon_x
, icon_y
;
12124 #ifdef USE_X_TOOLKIT
12125 Window window
= XtWindow (f
->output_data
.x
->widget
);
12127 Window window
= FRAME_X_WINDOW (f
);
12130 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12131 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12132 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12134 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12138 /***********************************************************************
12140 ***********************************************************************/
12142 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12145 x_get_font_info (f
, font_idx
)
12149 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12153 /* Return a list of names of available fonts matching PATTERN on frame
12154 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
12155 to be listed. Frame F NULL means we have not yet created any
12156 frame on X, and consult the first display in x_display_list.
12157 MAXNAMES sets a limit on how many fonts to match. */
12160 x_list_fonts (f
, pattern
, size
, maxnames
)
12162 Lisp_Object pattern
;
12166 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12167 Lisp_Object tem
, second_best
;
12168 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
12169 int try_XLoadQueryFont
= 0;
12172 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12173 if (NILP (patterns
))
12174 patterns
= Fcons (pattern
, Qnil
);
12176 if (maxnames
== 1 && !size
)
12177 /* We can return any single font matching PATTERN. */
12178 try_XLoadQueryFont
= 1;
12180 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12185 pattern
= XCAR (patterns
);
12186 /* See if we cached the result for this particular query.
12187 The cache is an alist of the form:
12188 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
12190 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
12191 key
= Fcons (pattern
, make_number (maxnames
)),
12192 !NILP (list
= Fassoc (key
, tem
))))
12194 list
= Fcdr_safe (list
);
12195 /* We have a cashed list. Don't have to get the list again. */
12199 /* At first, put PATTERN in the cache. */
12202 count
= x_catch_errors (dpy
);
12204 if (try_XLoadQueryFont
)
12207 unsigned long value
;
12209 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12210 if (x_had_errors_p (dpy
))
12212 /* This error is perhaps due to insufficient memory on X
12213 server. Let's just ignore it. */
12215 x_clear_errors (dpy
);
12219 && XGetFontProperty (font
, XA_FONT
, &value
))
12221 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12222 int len
= strlen (name
);
12225 /* If DXPC (a Differential X Protocol Compressor)
12226 Ver.3.7 is running, XGetAtomName will return null
12227 string. We must avoid such a name. */
12229 try_XLoadQueryFont
= 0;
12233 names
= (char **) alloca (sizeof (char *));
12234 /* Some systems only allow alloca assigned to a
12236 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12237 bcopy (name
, names
[0], len
+ 1);
12242 try_XLoadQueryFont
= 0;
12245 XFreeFont (dpy
, font
);
12248 if (!try_XLoadQueryFont
)
12250 /* We try at least 10 fonts because XListFonts will return
12251 auto-scaled fonts at the head. */
12252 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12254 if (x_had_errors_p (dpy
))
12256 /* This error is perhaps due to insufficient memory on X
12257 server. Let's just ignore it. */
12259 x_clear_errors (dpy
);
12263 x_uncatch_errors (dpy
, count
);
12270 /* Make a list of all the fonts we got back.
12271 Store that in the font cache for the display. */
12272 for (i
= 0; i
< num_fonts
; i
++)
12275 char *p
= names
[i
];
12276 int average_width
= -1, dashes
= 0;
12278 /* Count the number of dashes in NAMES[I]. If there are
12279 14 dashes, and the field value following 12th dash
12280 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12281 is usually too ugly to be used for editing. Let's
12287 if (dashes
== 7) /* PIXEL_SIZE field */
12289 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12290 average_width
= atoi (p
);
12292 if (dashes
< 14 || average_width
!= 0)
12294 tem
= build_string (names
[i
]);
12295 if (NILP (Fassoc (tem
, list
)))
12297 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12298 && ((fast_c_string_match_ignore_case
12299 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12301 /* We can set the value of PIXEL_SIZE to the
12302 width of this font. */
12303 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12305 /* For the moment, width is not known. */
12306 list
= Fcons (Fcons (tem
, Qnil
), list
);
12310 if (!try_XLoadQueryFont
)
12311 XFreeFontNames (names
);
12314 /* Now store the result in the cache. */
12316 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
12317 = Fcons (Fcons (key
, list
),
12318 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
12321 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12323 newlist
= second_best
= Qnil
;
12324 /* Make a list of the fonts that have the right width. */
12325 for (; CONSP (list
); list
= XCDR (list
))
12331 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12335 newlist
= Fcons (XCAR (tem
), newlist
);
12339 if (!INTEGERP (XCDR (tem
)))
12341 /* Since we have not yet known the size of this font, we
12342 must try slow function call XLoadQueryFont. */
12343 XFontStruct
*thisinfo
;
12346 count
= x_catch_errors (dpy
);
12347 thisinfo
= XLoadQueryFont (dpy
,
12348 XSTRING (XCAR (tem
))->data
);
12349 if (x_had_errors_p (dpy
))
12351 /* This error is perhaps due to insufficient memory on X
12352 server. Let's just ignore it. */
12354 x_clear_errors (dpy
);
12356 x_uncatch_errors (dpy
, count
);
12362 = (thisinfo
->min_bounds
.width
== 0
12364 : make_number (thisinfo
->max_bounds
.width
));
12365 XFreeFont (dpy
, thisinfo
);
12368 /* For unknown reason, the previous call of XListFont had
12369 returned a font which can't be opened. Record the size
12370 as 0 not to try to open it again. */
12371 XCDR (tem
) = make_number (0);
12374 found_size
= XINT (XCDR (tem
));
12375 if (found_size
== size
)
12376 newlist
= Fcons (XCAR (tem
), newlist
);
12377 else if (found_size
> 0)
12379 if (NILP (second_best
))
12381 else if (found_size
< size
)
12383 if (XINT (XCDR (second_best
)) > size
12384 || XINT (XCDR (second_best
)) < found_size
)
12389 if (XINT (XCDR (second_best
)) > size
12390 && XINT (XCDR (second_best
)) > found_size
)
12395 if (!NILP (newlist
))
12397 else if (!NILP (second_best
))
12399 newlist
= Fcons (XCAR (second_best
), Qnil
);
12410 /* Check that FONT is valid on frame F. It is if it can be found in F's
12414 x_check_font (f
, font
)
12419 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12421 xassert (font
!= NULL
);
12423 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12424 if (dpyinfo
->font_table
[i
].name
12425 && font
== dpyinfo
->font_table
[i
].font
)
12428 xassert (i
< dpyinfo
->n_fonts
);
12431 #endif /* GLYPH_DEBUG != 0 */
12433 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12434 Note: There are (broken) X fonts out there with invalid XFontStruct
12435 min_bounds contents. For example, handa@etl.go.jp reports that
12436 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
12437 have font->min_bounds.width == 0. */
12440 x_font_min_bounds (font
, w
, h
)
12444 *h
= FONT_HEIGHT (font
);
12445 *w
= font
->min_bounds
.width
;
12447 /* Try to handle the case where FONT->min_bounds has invalid
12448 contents. Since the only font known to have invalid min_bounds
12449 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12451 *w
= font
->max_bounds
.width
;
12455 /* Compute the smallest character width and smallest font height over
12456 all fonts available on frame F. Set the members smallest_char_width
12457 and smallest_font_height in F's x_display_info structure to
12458 the values computed. Value is non-zero if smallest_font_height or
12459 smallest_char_width become smaller than they were before. */
12462 x_compute_min_glyph_bounds (f
)
12466 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12468 int old_width
= dpyinfo
->smallest_char_width
;
12469 int old_height
= dpyinfo
->smallest_font_height
;
12471 dpyinfo
->smallest_font_height
= 100000;
12472 dpyinfo
->smallest_char_width
= 100000;
12474 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12475 if (dpyinfo
->font_table
[i
].name
)
12477 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12480 font
= (XFontStruct
*) fontp
->font
;
12481 xassert (font
!= (XFontStruct
*) ~0);
12482 x_font_min_bounds (font
, &w
, &h
);
12484 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12485 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12488 xassert (dpyinfo
->smallest_char_width
> 0
12489 && dpyinfo
->smallest_font_height
> 0);
12491 return (dpyinfo
->n_fonts
== 1
12492 || dpyinfo
->smallest_char_width
< old_width
12493 || dpyinfo
->smallest_font_height
< old_height
);
12497 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12498 pointer to the structure font_info while allocating it dynamically.
12499 If SIZE is 0, load any size of font.
12500 If loading is failed, return NULL. */
12503 x_load_font (f
, fontname
, size
)
12505 register char *fontname
;
12508 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12509 Lisp_Object font_names
;
12512 /* Get a list of all the fonts that match this name. Once we
12513 have a list of matching fonts, we compare them against the fonts
12514 we already have by comparing names. */
12515 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12517 if (!NILP (font_names
))
12522 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12523 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12524 if (dpyinfo
->font_table
[i
].name
12525 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12526 XSTRING (XCAR (tail
))->data
)
12527 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12528 XSTRING (XCAR (tail
))->data
)))
12529 return (dpyinfo
->font_table
+ i
);
12532 /* Load the font and add it to the table. */
12536 struct font_info
*fontp
;
12537 unsigned long value
;
12540 /* If we have found fonts by x_list_font, load one of them. If
12541 not, we still try to load a font by the name given as FONTNAME
12542 because XListFonts (called in x_list_font) of some X server has
12543 a bug of not finding a font even if the font surely exists and
12544 is loadable by XLoadQueryFont. */
12545 if (size
> 0 && !NILP (font_names
))
12546 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12549 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12550 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12551 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12553 /* This error is perhaps due to insufficient memory on X
12554 server. Let's just ignore it. */
12556 x_clear_errors (FRAME_X_DISPLAY (f
));
12558 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12563 /* Find a free slot in the font table. */
12564 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12565 if (dpyinfo
->font_table
[i
].name
== NULL
)
12568 /* If no free slot found, maybe enlarge the font table. */
12569 if (i
== dpyinfo
->n_fonts
12570 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12573 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12574 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12575 dpyinfo
->font_table
12576 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12579 fontp
= dpyinfo
->font_table
+ i
;
12580 if (i
== dpyinfo
->n_fonts
)
12581 ++dpyinfo
->n_fonts
;
12583 /* Now fill in the slots of *FONTP. */
12585 fontp
->font
= font
;
12586 fontp
->font_idx
= i
;
12587 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12588 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12590 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12592 if (XGetFontProperty (font
, XA_FONT
, &value
))
12594 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12598 /* Count the number of dashes in the "full name".
12599 If it is too few, this isn't really the font's full name,
12601 In X11R4, the fonts did not come with their canonical names
12612 full_name
= (char *) xmalloc (p
- name
+ 1);
12613 bcopy (name
, full_name
, p
- name
+ 1);
12619 if (full_name
!= 0)
12620 fontp
->full_name
= full_name
;
12622 fontp
->full_name
= fontp
->name
;
12624 fontp
->size
= font
->max_bounds
.width
;
12625 fontp
->height
= FONT_HEIGHT (font
);
12627 /* For some font, ascent and descent in max_bounds field is
12628 larger than the above value. */
12629 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12630 if (max_height
> fontp
->height
)
12631 fontp
->height
= max_height
;
12634 if (NILP (font_names
))
12636 /* We come here because of a bug of XListFonts mentioned at
12637 the head of this block. Let's store this information in
12638 the cache for x_list_fonts. */
12639 Lisp_Object lispy_name
= build_string (fontname
);
12640 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12642 XCDR (dpyinfo
->name_list_element
)
12643 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
12644 Fcons (Fcons (lispy_full_name
,
12645 make_number (fontp
->size
)),
12647 XCDR (dpyinfo
->name_list_element
));
12649 XCDR (dpyinfo
->name_list_element
)
12650 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
12651 Fcons (Fcons (lispy_full_name
,
12652 make_number (fontp
->size
)),
12654 XCDR (dpyinfo
->name_list_element
));
12657 /* The slot `encoding' specifies how to map a character
12658 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
12659 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
12660 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
12661 2:0xA020..0xFF7F). For the moment, we don't know which charset
12662 uses this font. So, we set information in fontp->encoding[1]
12663 which is never used by any charset. If mapping can't be
12664 decided, set FONT_ENCODING_NOT_DECIDED. */
12666 = (font
->max_byte1
== 0
12668 ? (font
->min_char_or_byte2
< 0x80
12669 ? (font
->max_char_or_byte2
< 0x80
12670 ? 0 /* 0x20..0x7F */
12671 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
12672 : 1) /* 0xA0..0xFF */
12674 : (font
->min_byte1
< 0x80
12675 ? (font
->max_byte1
< 0x80
12676 ? (font
->min_char_or_byte2
< 0x80
12677 ? (font
->max_char_or_byte2
< 0x80
12678 ? 0 /* 0x2020..0x7F7F */
12679 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
12680 : 3) /* 0x20A0..0x7FFF */
12681 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
12682 : (font
->min_char_or_byte2
< 0x80
12683 ? (font
->max_char_or_byte2
< 0x80
12684 ? 2 /* 0xA020..0xFF7F */
12685 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
12686 : 1))); /* 0xA0A0..0xFFFF */
12688 fontp
->baseline_offset
12689 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
12690 ? (long) value
: 0);
12691 fontp
->relative_compose
12692 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
12693 ? (long) value
: 0);
12694 fontp
->default_ascent
12695 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
12696 ? (long) value
: 0);
12698 /* Set global flag fonts_changed_p to non-zero if the font loaded
12699 has a character with a smaller width than any other character
12700 before, or if the font loaded has a smalle>r height than any
12701 other font loaded before. If this happens, it will make a
12702 glyph matrix reallocation necessary. */
12703 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
12710 /* Return a pointer to struct font_info of a font named FONTNAME for
12711 frame F. If no such font is loaded, return NULL. */
12714 x_query_font (f
, fontname
)
12716 register char *fontname
;
12718 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12721 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12722 if (dpyinfo
->font_table
[i
].name
12723 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
12724 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
12725 return (dpyinfo
->font_table
+ i
);
12730 /* Find a CCL program for a font specified by FONTP, and set the member
12731 `encoder' of the structure. */
12734 x_find_ccl_program (fontp
)
12735 struct font_info
*fontp
;
12737 Lisp_Object list
, elt
;
12739 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
12743 && STRINGP (XCAR (elt
))
12744 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
12750 struct ccl_program
*ccl
12751 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
12753 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
12756 fontp
->font_encoder
= ccl
;
12762 /***********************************************************************
12764 ***********************************************************************/
12766 #ifdef USE_X_TOOLKIT
12767 static XrmOptionDescRec emacs_options
[] = {
12768 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
12769 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
12771 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
12772 XrmoptionSepArg
, NULL
},
12773 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
12775 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12776 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12777 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12778 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12779 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12780 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
12781 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
12783 #endif /* USE_X_TOOLKIT */
12785 static int x_initialized
;
12787 #ifdef MULTI_KBOARD
12788 /* Test whether two display-name strings agree up to the dot that separates
12789 the screen number from the server number. */
12791 same_x_server (name1
, name2
)
12792 char *name1
, *name2
;
12794 int seen_colon
= 0;
12795 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
12796 int system_name_length
= strlen (system_name
);
12797 int length_until_period
= 0;
12799 while (system_name
[length_until_period
] != 0
12800 && system_name
[length_until_period
] != '.')
12801 length_until_period
++;
12803 /* Treat `unix' like an empty host name. */
12804 if (! strncmp (name1
, "unix:", 5))
12806 if (! strncmp (name2
, "unix:", 5))
12808 /* Treat this host's name like an empty host name. */
12809 if (! strncmp (name1
, system_name
, system_name_length
)
12810 && name1
[system_name_length
] == ':')
12811 name1
+= system_name_length
;
12812 if (! strncmp (name2
, system_name
, system_name_length
)
12813 && name2
[system_name_length
] == ':')
12814 name2
+= system_name_length
;
12815 /* Treat this host's domainless name like an empty host name. */
12816 if (! strncmp (name1
, system_name
, length_until_period
)
12817 && name1
[length_until_period
] == ':')
12818 name1
+= length_until_period
;
12819 if (! strncmp (name2
, system_name
, length_until_period
)
12820 && name2
[length_until_period
] == ':')
12821 name2
+= length_until_period
;
12823 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
12827 if (seen_colon
&& *name1
== '.')
12831 && (*name1
== '.' || *name1
== '\0')
12832 && (*name2
== '.' || *name2
== '\0'));
12836 struct x_display_info
*
12837 x_term_init (display_name
, xrm_option
, resource_name
)
12838 Lisp_Object display_name
;
12840 char *resource_name
;
12844 struct x_display_info
*dpyinfo
;
12849 if (!x_initialized
)
12855 #ifdef USE_X_TOOLKIT
12856 /* weiner@footloose.sps.mot.com reports that this causes
12858 X protocol error: BadAtom (invalid Atom parameter)
12859 on protocol request 18skiloaf.
12860 So let's not use it until R6. */
12861 #ifdef HAVE_X11XTR6
12862 XtSetLanguageProc (NULL
, NULL
, NULL
);
12873 argv
[argc
++] = "-xrm";
12874 argv
[argc
++] = xrm_option
;
12876 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
12877 resource_name
, EMACS_CLASS
,
12878 emacs_options
, XtNumber (emacs_options
),
12881 #ifdef HAVE_X11XTR6
12882 /* I think this is to compensate for XtSetLanguageProc. */
12887 #else /* not USE_X_TOOLKIT */
12889 XSetLocaleModifiers ("");
12891 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
12892 #endif /* not USE_X_TOOLKIT */
12894 /* Detect failure. */
12901 /* We have definitely succeeded. Record the new connection. */
12903 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
12905 #ifdef MULTI_KBOARD
12907 struct x_display_info
*share
;
12910 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
12911 share
= share
->next
, tail
= XCDR (tail
))
12912 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
12913 XSTRING (display_name
)->data
))
12916 dpyinfo
->kboard
= share
->kboard
;
12919 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
12920 init_kboard (dpyinfo
->kboard
);
12921 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
12923 char *vendor
= ServerVendor (dpy
);
12925 dpyinfo
->kboard
->Vsystem_key_alist
12926 = call1 (Qvendor_specific_keysyms
,
12927 build_string (vendor
? vendor
: ""));
12931 dpyinfo
->kboard
->next_kboard
= all_kboards
;
12932 all_kboards
= dpyinfo
->kboard
;
12933 /* Don't let the initial kboard remain current longer than necessary.
12934 That would cause problems if a file loaded on startup tries to
12935 prompt in the mini-buffer. */
12936 if (current_kboard
== initial_kboard
)
12937 current_kboard
= dpyinfo
->kboard
;
12939 dpyinfo
->kboard
->reference_count
++;
12943 /* Put this display on the chain. */
12944 dpyinfo
->next
= x_display_list
;
12945 x_display_list
= dpyinfo
;
12947 /* Put it on x_display_name_list as well, to keep them parallel. */
12948 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
12949 x_display_name_list
);
12950 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
12952 dpyinfo
->display
= dpy
;
12955 XSetAfterFunction (x_current_display
, x_trace_wire
);
12959 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
12960 + STRING_BYTES (XSTRING (Vsystem_name
))
12962 sprintf (dpyinfo
->x_id_name
, "%s@%s",
12963 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
12965 /* Figure out which modifier bits mean what. */
12966 x_find_modifier_meanings (dpyinfo
);
12968 /* Get the scroll bar cursor. */
12969 dpyinfo
->vertical_scroll_bar_cursor
12970 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
12972 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
12973 resource_name
, EMACS_CLASS
);
12974 #ifdef HAVE_XRMSETDATABASE
12975 XrmSetDatabase (dpyinfo
->display
, xrdb
);
12977 dpyinfo
->display
->db
= xrdb
;
12979 /* Put the rdb where we can find it in a way that works on
12981 dpyinfo
->xrdb
= xrdb
;
12983 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
12984 DefaultScreen (dpyinfo
->display
));
12985 select_visual (dpyinfo
);
12986 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
12987 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
12988 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
12989 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
12990 dpyinfo
->grabbed
= 0;
12991 dpyinfo
->reference_count
= 0;
12992 dpyinfo
->icon_bitmap_id
= -1;
12993 dpyinfo
->font_table
= NULL
;
12994 dpyinfo
->n_fonts
= 0;
12995 dpyinfo
->font_table_size
= 0;
12996 dpyinfo
->bitmaps
= 0;
12997 dpyinfo
->bitmaps_size
= 0;
12998 dpyinfo
->bitmaps_last
= 0;
12999 dpyinfo
->scratch_cursor_gc
= 0;
13000 dpyinfo
->mouse_face_mouse_frame
= 0;
13001 dpyinfo
->mouse_face_deferred_gc
= 0;
13002 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13003 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13004 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13005 dpyinfo
->mouse_face_window
= Qnil
;
13006 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13007 dpyinfo
->mouse_face_defer
= 0;
13008 dpyinfo
->x_focus_frame
= 0;
13009 dpyinfo
->x_focus_event_frame
= 0;
13010 dpyinfo
->x_highlight_frame
= 0;
13011 dpyinfo
->image_cache
= make_image_cache ();
13013 /* See if a private colormap is requested. */
13014 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13016 if (dpyinfo
->visual
->class == PseudoColor
)
13019 value
= display_x_get_resource (dpyinfo
,
13020 build_string ("privateColormap"),
13021 build_string ("PrivateColormap"),
13023 if (STRINGP (value
)
13024 && (!strcmp (XSTRING (value
)->data
, "true")
13025 || !strcmp (XSTRING (value
)->data
, "on")))
13026 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13030 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13031 dpyinfo
->visual
, AllocNone
);
13034 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13035 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13036 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13037 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13038 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13039 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13040 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13043 dpyinfo
->Xatom_wm_protocols
13044 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13045 dpyinfo
->Xatom_wm_take_focus
13046 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13047 dpyinfo
->Xatom_wm_save_yourself
13048 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13049 dpyinfo
->Xatom_wm_delete_window
13050 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13051 dpyinfo
->Xatom_wm_change_state
13052 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13053 dpyinfo
->Xatom_wm_configure_denied
13054 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13055 dpyinfo
->Xatom_wm_window_moved
13056 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13057 dpyinfo
->Xatom_editres
13058 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13059 dpyinfo
->Xatom_CLIPBOARD
13060 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13061 dpyinfo
->Xatom_TIMESTAMP
13062 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13063 dpyinfo
->Xatom_TEXT
13064 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13065 dpyinfo
->Xatom_COMPOUND_TEXT
13066 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13067 dpyinfo
->Xatom_DELETE
13068 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13069 dpyinfo
->Xatom_MULTIPLE
13070 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13071 dpyinfo
->Xatom_INCR
13072 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13073 dpyinfo
->Xatom_EMACS_TMP
13074 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13075 dpyinfo
->Xatom_TARGETS
13076 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13077 dpyinfo
->Xatom_NULL
13078 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13079 dpyinfo
->Xatom_ATOM_PAIR
13080 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13081 /* For properties of font. */
13082 dpyinfo
->Xatom_PIXEL_SIZE
13083 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13084 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13085 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13086 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13087 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13088 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13089 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13091 /* Ghostscript support. */
13092 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13093 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13095 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13098 dpyinfo
->cut_buffers_initialized
= 0;
13100 connection
= ConnectionNumber (dpyinfo
->display
);
13101 dpyinfo
->connection
= connection
;
13106 null_bits
[0] = 0x00;
13108 dpyinfo
->null_pixel
13109 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13110 null_bits
, 1, 1, (long) 0, (long) 0,
13115 extern int gray_bitmap_width
, gray_bitmap_height
;
13116 extern unsigned char *gray_bitmap_bits
;
13118 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13120 gray_bitmap_width
, gray_bitmap_height
,
13121 (unsigned long) 1, (unsigned long) 0, 1);
13125 xim_initialize (dpyinfo
, resource_name
);
13128 #ifdef subprocesses
13129 /* This is only needed for distinguishing keyboard and process input. */
13130 if (connection
!= 0)
13131 add_keyboard_wait_descriptor (connection
);
13134 #ifndef F_SETOWN_BUG
13136 #ifdef F_SETOWN_SOCK_NEG
13137 /* stdin is a socket here */
13138 fcntl (connection
, F_SETOWN
, -getpid ());
13139 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13140 fcntl (connection
, F_SETOWN
, getpid ());
13141 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13142 #endif /* ! defined (F_SETOWN) */
13143 #endif /* F_SETOWN_BUG */
13146 if (interrupt_input
)
13147 init_sigio (connection
);
13148 #endif /* ! defined (SIGIO) */
13151 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13152 /* Make sure that we have a valid font for dialog boxes
13153 so that Xt does not crash. */
13155 Display
*dpy
= dpyinfo
->display
;
13156 XrmValue d
, fr
, to
;
13160 d
.addr
= (XPointer
)&dpy
;
13161 d
.size
= sizeof (Display
*);
13162 fr
.addr
= XtDefaultFont
;
13163 fr
.size
= sizeof (XtDefaultFont
);
13164 to
.size
= sizeof (Font
*);
13165 to
.addr
= (XPointer
)&font
;
13166 count
= x_catch_errors (dpy
);
13167 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13169 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13170 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13171 x_uncatch_errors (dpy
, count
);
13176 /* See if we should run in synchronous mode. This is useful
13177 for debugging X code. */
13180 value
= display_x_get_resource (dpyinfo
,
13181 build_string ("synchronous"),
13182 build_string ("Synchronous"),
13184 if (STRINGP (value
)
13185 && (!strcmp (XSTRING (value
)->data
, "true")
13186 || !strcmp (XSTRING (value
)->data
, "on")))
13187 XSynchronize (dpyinfo
->display
, True
);
13195 /* Get rid of display DPYINFO, assuming all frames are already gone,
13196 and without sending any more commands to the X server. */
13199 x_delete_display (dpyinfo
)
13200 struct x_display_info
*dpyinfo
;
13202 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13204 /* Discard this display from x_display_name_list and x_display_list.
13205 We can't use Fdelq because that can quit. */
13206 if (! NILP (x_display_name_list
)
13207 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13208 x_display_name_list
= XCDR (x_display_name_list
);
13213 tail
= x_display_name_list
;
13214 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13216 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13218 XCDR (tail
) = XCDR (XCDR (tail
));
13221 tail
= XCDR (tail
);
13225 if (next_noop_dpyinfo
== dpyinfo
)
13226 next_noop_dpyinfo
= dpyinfo
->next
;
13228 if (x_display_list
== dpyinfo
)
13229 x_display_list
= dpyinfo
->next
;
13232 struct x_display_info
*tail
;
13234 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13235 if (tail
->next
== dpyinfo
)
13236 tail
->next
= tail
->next
->next
;
13239 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13240 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13241 XrmDestroyDatabase (dpyinfo
->xrdb
);
13244 #ifdef MULTI_KBOARD
13245 if (--dpyinfo
->kboard
->reference_count
== 0)
13246 delete_kboard (dpyinfo
->kboard
);
13250 xim_close_dpy (dpyinfo
);
13253 xfree (dpyinfo
->font_table
);
13254 xfree (dpyinfo
->x_id_name
);
13258 /* Set up use of X before we make the first connection. */
13260 static struct redisplay_interface x_redisplay_interface
=
13265 x_clear_end_of_line
,
13267 x_after_update_window_line
,
13268 x_update_window_begin
,
13269 x_update_window_end
,
13272 x_get_glyph_overhangs
,
13273 x_fix_overlapping_area
13279 rif
= &x_redisplay_interface
;
13281 clear_frame_hook
= x_clear_frame
;
13282 ins_del_lines_hook
= x_ins_del_lines
;
13283 change_line_highlight_hook
= x_change_line_highlight
;
13284 delete_glyphs_hook
= x_delete_glyphs
;
13285 ring_bell_hook
= XTring_bell
;
13286 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13287 set_terminal_modes_hook
= XTset_terminal_modes
;
13288 update_begin_hook
= x_update_begin
;
13289 update_end_hook
= x_update_end
;
13290 set_terminal_window_hook
= XTset_terminal_window
;
13291 read_socket_hook
= XTread_socket
;
13292 frame_up_to_date_hook
= XTframe_up_to_date
;
13293 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13294 mouse_position_hook
= XTmouse_position
;
13295 frame_rehighlight_hook
= XTframe_rehighlight
;
13296 frame_raise_lower_hook
= XTframe_raise_lower
;
13297 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13298 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13299 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13300 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13301 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13303 scroll_region_ok
= 1; /* we'll scroll partial frames */
13304 char_ins_del_ok
= 0; /* just as fast to write the line */
13305 line_ins_del_ok
= 1; /* we'll just blt 'em */
13306 fast_clear_end_of_line
= 1; /* X does this well */
13307 memory_below_frame
= 0; /* we don't remember what scrolls
13312 last_tool_bar_item
= -1;
13313 any_help_event_p
= 0;
13315 /* Try to use interrupt input; if we can't, then start polling. */
13316 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13318 #ifdef USE_X_TOOLKIT
13319 XtToolkitInitialize ();
13320 Xt_app_con
= XtCreateApplicationContext ();
13321 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13323 /* Install an asynchronous timer that processes Xt timeout events
13324 every 0.1s. This is necessary because some widget sets use
13325 timeouts internally, for example the LessTif menu bar, or the
13326 Xaw3d scroll bar. When Xt timouts aren't processed, these
13327 widgets don't behave normally. */
13329 EMACS_TIME interval
;
13330 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13331 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13335 #if USE_TOOLKIT_SCROLL_BARS
13336 xaw3d_arrow_scroll
= False
;
13337 xaw3d_pick_top
= True
;
13340 /* Note that there is no real way portable across R3/R4 to get the
13341 original error handler. */
13342 XSetErrorHandler (x_error_handler
);
13343 XSetIOErrorHandler (x_io_error_quitter
);
13345 /* Disable Window Change signals; they are handled by X events. */
13347 signal (SIGWINCH
, SIG_DFL
);
13348 #endif /* ! defined (SIGWINCH) */
13350 signal (SIGPIPE
, x_connection_signal
);
13357 staticpro (&x_error_message_string
);
13358 x_error_message_string
= Qnil
;
13360 staticpro (&x_display_name_list
);
13361 x_display_name_list
= Qnil
;
13363 staticpro (&last_mouse_scroll_bar
);
13364 last_mouse_scroll_bar
= Qnil
;
13366 staticpro (&Qvendor_specific_keysyms
);
13367 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13369 staticpro (&last_mouse_press_frame
);
13370 last_mouse_press_frame
= Qnil
;
13372 staticpro (&help_echo
);
13374 staticpro (&previous_help_echo
);
13375 previous_help_echo
= Qnil
;
13377 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13378 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
13379 For example, if a block cursor is over a tab, it will be drawn as\n\
13380 wide as that tab on the display.");
13381 x_stretch_cursor_p
= 0;
13383 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
13384 "If not nil, Emacs uses toolkit scroll bars.");
13385 #if USE_TOOLKIT_SCROLL_BARS
13386 x_toolkit_scroll_bars_p
= 1;
13388 x_toolkit_scroll_bars_p
= 0;
13391 staticpro (&last_mouse_motion_frame
);
13392 last_mouse_motion_frame
= Qnil
;
13395 #endif /* not HAVE_X_WINDOWS */