1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
25 /* On 4.3 these lose if they come after xterm.h. */
26 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
27 /* Putting these at the beginning seems to be standard for other .c files. */
40 #include "blockinput.h"
42 /* Need syssignal.h for various externs and definitions that may be required
43 by some configurations for calls to signal later in this source file. */
44 #include "syssignal.h"
46 /* This may include sys/types.h, and that somehow loses
47 if this is not done before the other system files. */
49 #include <X11/cursorfont.h>
52 /* Load sys/types.h if not already loaded.
53 In some systems loading it twice is suicidal. */
55 #include <sys/types.h>
60 #include <sys/ioctl.h>
61 #endif /* ! defined (BSD_SYSTEM) */
66 #ifndef INCLUDED_FCNTL
73 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
74 /* #include <sys/param.h> */
80 #include "dispextern.h"
81 #include "termhooks.h"
93 #include "intervals.h"
97 #include <X11/Shell.h>
100 #include <sys/types.h>
101 #ifdef HAVE_SYS_TIME_H
102 #include <sys/time.h>
110 extern void free_frame_menubar ();
111 extern FRAME_PTR
x_menubar_window_to_frame ();
113 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
115 extern void _XEditResCheckMessages ();
116 #endif /* not NO_EDITRES */
118 /* Include toolkit specific headers for the scroll bar widget. */
120 #ifdef USE_TOOLKIT_SCROLL_BARS
121 #if defined USE_MOTIF
122 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
123 #include <Xm/ScrollBar.h>
124 #include <Xm/ScrollBarP.h>
125 #elif defined HAVE_XAW3D
126 #include <X11/Xaw3d/Simple.h>
127 #include <X11/Xaw3d/ThreeD.h>
128 #include <X11/Xaw3d/Scrollbar.h>
129 #define ARROW_SCROLLBAR
130 #include <X11/Xaw3d/ScrollbarP.h>
131 #endif /* HAVE_XAW3D */
132 #endif /* USE_TOOLKIT_SCROLL_BARS */
134 #endif /* USE_X_TOOLKIT */
136 #ifndef USE_X_TOOLKIT
137 #define x_any_window_to_frame x_window_to_frame
138 #define x_top_window_to_frame x_window_to_frame
143 #ifndef XtNinitialState
144 #define XtNinitialState "initialState"
148 #ifdef HAVE_SETLOCALE
149 /* So we can do setlocale. */
154 /* memmove will be defined as a macro in Xfuncs.h unless
155 <string.h> is included beforehand. The declaration for memmove in
156 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
161 #define min(a,b) ((a) < (b) ? (a) : (b))
164 #define max(a,b) ((a) > (b) ? (a) : (b))
167 #define abs(x) ((x) < 0 ? -(x) : (x))
169 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
172 /* Bitmaps for truncated lines. */
177 LEFT_TRUNCATION_BITMAP
,
178 RIGHT_TRUNCATION_BITMAP
,
179 OVERLAY_ARROW_BITMAP
,
180 CONTINUED_LINE_BITMAP
,
181 CONTINUATION_LINE_BITMAP
,
185 /* Bitmap drawn to indicate lines not displaying text if
186 `indicate-empty-lines' is non-nil. */
190 static unsigned char zv_bits
[] = {
191 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
193 /* An arrow like this: `<-'. */
196 #define left_height 8
197 static unsigned char left_bits
[] = {
198 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
200 /* Right truncation arrow bitmap `->'. */
202 #define right_width 8
203 #define right_height 8
204 static unsigned char right_bits
[] = {
205 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
207 /* Marker for continued lines. */
209 #define continued_width 8
210 #define continued_height 8
211 static unsigned char continued_bits
[] = {
212 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
214 /* Marker for continuation lines. */
216 #define continuation_width 8
217 #define continuation_height 8
218 static unsigned char continuation_bits
[] = {
219 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
221 /* Overlay arrow bitmap. */
227 static unsigned char ov_bits
[] = {
228 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
230 /* A triangular arrow. */
233 static unsigned char ov_bits
[] = {
234 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
238 extern Lisp_Object Qhelp_echo
;
241 /* Non-zero means Emacs uses toolkit scroll bars. */
243 int x_toolkit_scroll_bars_p
;
245 /* If a string, XTread_socket generates an event to display that string.
246 (The display is done in read_char.) */
248 static Lisp_Object help_echo
;
250 /* Temporary variable for XTread_socket. */
252 static Lisp_Object previous_help_echo
;
254 /* Non-zero means that a HELP_EVENT has been generated since Emacs
257 static int any_help_event_p
;
259 /* Non-zero means draw block and hollow cursor as wide as the glyph
260 under it. For example, if a block cursor is over a tab, it will be
261 drawn as wide as that tab on the display. */
263 int x_stretch_cursor_p
;
265 /* This is a chain of structures for all the X displays currently in
268 struct x_display_info
*x_display_list
;
270 /* This is a list of cons cells, each of the form (NAME
271 . FONT-LIST-CACHE), one for each element of x_display_list and in
272 the same order. NAME is the name of the frame. FONT-LIST-CACHE
273 records previous values returned by x-list-fonts. */
275 Lisp_Object x_display_name_list
;
277 /* Frame being updated by update_frame. This is declared in term.c.
278 This is set by update_begin and looked at by all the XT functions.
279 It is zero while not inside an update. In that case, the XT
280 functions assume that `selected_frame' is the frame to apply to. */
282 extern struct frame
*updating_frame
;
284 extern int waiting_for_input
;
286 /* This is a frame waiting to be auto-raised, within XTread_socket. */
288 struct frame
*pending_autoraise_frame
;
291 /* The application context for Xt use. */
292 XtAppContext Xt_app_con
;
293 static String Xt_default_resources
[] = {0};
294 #endif /* USE_X_TOOLKIT */
296 /* Nominal cursor position -- where to draw output.
297 HPOS and VPOS are window relative glyph matrix coordinates.
298 X and Y are window relative pixel coordinates. */
300 struct cursor_pos output_cursor
;
305 Formerly, we used PointerMotionHintMask (in standard_event_mask)
306 so that we would have to call XQueryPointer after each MotionNotify
307 event to ask for another such event. However, this made mouse tracking
308 slow, and there was a bug that made it eventually stop.
310 Simply asking for MotionNotify all the time seems to work better.
312 In order to avoid asking for motion events and then throwing most
313 of them away or busy-polling the server for mouse positions, we ask
314 the server for pointer motion hints. This means that we get only
315 one event per group of mouse movements. "Groups" are delimited by
316 other kinds of events (focus changes and button clicks, for
317 example), or by XQueryPointer calls; when one of these happens, we
318 get another MotionNotify event the next time the mouse moves. This
319 is at least as efficient as getting motion events when mouse
320 tracking is on, and I suspect only negligibly worse when tracking
323 /* Where the mouse was last time we reported a mouse event. */
325 FRAME_PTR last_mouse_frame
;
326 static XRectangle last_mouse_glyph
;
327 static Lisp_Object last_mouse_press_frame
;
329 /* The scroll bar in which the last X motion event occurred.
331 If the last X motion event occurred in a scroll bar, we set this so
332 XTmouse_position can know whether to report a scroll bar motion or
335 If the last X motion event didn't occur in a scroll bar, we set
336 this to Qnil, to tell XTmouse_position to return an ordinary motion
339 static Lisp_Object last_mouse_scroll_bar
;
341 /* This is a hack. We would really prefer that XTmouse_position would
342 return the time associated with the position it returns, but there
343 doesn't seem to be any way to wrest the time-stamp from the server
344 along with the position query. So, we just keep track of the time
345 of the last movement we received, and return that in hopes that
346 it's somewhat accurate. */
348 static Time last_mouse_movement_time
;
350 /* Incremented by XTread_socket whenever it really tries to read
354 static int volatile input_signal_count
;
356 static int input_signal_count
;
359 /* Used locally within XTread_socket. */
361 static int x_noop_count
;
363 /* Initial values of argv and argc. */
365 extern char **initial_argv
;
366 extern int initial_argc
;
368 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
370 /* Tells if a window manager is present or not. */
372 extern Lisp_Object Vx_no_window_manager
;
374 extern Lisp_Object Qface
, Qmouse_face
;
378 /* A mask of extra modifier bits to put into every keyboard char. */
380 extern int extra_keyboard_modifiers
;
382 static Lisp_Object Qvendor_specific_keysyms
;
384 extern XrmDatabase
x_load_resources ();
385 extern Lisp_Object
x_icon_type ();
388 /* Enumeration for overriding/changing the face to use for drawing
389 glyphs in x_draw_glyphs. */
391 enum draw_glyphs_face
401 static void x_update_window_end
P_ ((struct window
*, int));
402 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
403 void x_delete_display
P_ ((struct x_display_info
*));
404 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
406 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
408 static void set_output_cursor
P_ ((struct cursor_pos
*));
409 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
410 int *, int *, int *));
411 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
412 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
413 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
414 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
415 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
416 static void show_mouse_face
P_ ((struct x_display_info
*,
417 enum draw_glyphs_face
));
418 static int x_io_error_quitter
P_ ((Display
*));
419 int x_catch_errors
P_ ((Display
*));
420 void x_uncatch_errors
P_ ((Display
*, int));
421 void x_lower_frame
P_ ((struct frame
*));
422 void x_scroll_bar_clear
P_ ((struct frame
*));
423 int x_had_errors_p
P_ ((Display
*));
424 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
425 void x_raise_frame
P_ ((struct frame
*));
426 void x_set_window_size
P_ ((struct frame
*, int, int, int));
427 void x_wm_set_window_state
P_ ((struct frame
*, int));
428 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
429 void x_initialize
P_ ((void));
430 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
431 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
432 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
434 enum draw_glyphs_face
));
435 static void x_update_end
P_ ((struct frame
*));
436 static void XTframe_up_to_date
P_ ((struct frame
*));
437 static void XTreassert_line_highlight
P_ ((int, int));
438 static void x_change_line_highlight
P_ ((int, int, int, int));
439 static void XTset_terminal_modes
P_ ((void));
440 static void XTreset_terminal_modes
P_ ((void));
441 static void XTcursor_to
P_ ((int, int, int, int));
442 static void x_write_glyphs
P_ ((struct glyph
*, int));
443 static void x_clear_end_of_line
P_ ((int));
444 static void x_clear_frame
P_ ((void));
445 static void x_clear_cursor
P_ ((struct window
*));
446 static void frame_highlight
P_ ((struct frame
*));
447 static void frame_unhighlight
P_ ((struct frame
*));
448 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
449 static void XTframe_rehighlight
P_ ((struct frame
*));
450 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
451 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
452 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*));
453 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
455 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
456 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
457 static void expose_window
P_ ((struct window
*, XRectangle
*));
458 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
459 XRectangle
*, enum glyph_row_area
));
460 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
462 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
463 static void x_update_window_cursor
P_ ((struct window
*, int));
464 static void x_erase_phys_cursor
P_ ((struct window
*));
465 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
466 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
469 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
471 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
472 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
473 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
474 static void x_flush
P_ ((struct frame
*f
));
477 /* Flush display of frame F, or of all frames if F is null. */
486 Lisp_Object rest
, frame
;
487 FOR_EACH_FRAME (rest
, frame
)
488 x_flush (XFRAME (frame
));
490 else if (FRAME_X_P (f
))
491 XFlush (FRAME_X_DISPLAY (f
));
496 /* Remove calls to XFlush by defining XFlush to an empty replacement.
497 Calls to XFlush should be unnecessary because the X output buffer
498 is flushed automatically as needed by calls to XPending,
499 XNextEvent, or XWindowEvent according to the XFlush man page.
500 XTread_socket calls XPending. Removing XFlush improves
503 #define XFlush(DISPLAY) (void) 0
506 /***********************************************************************
508 ***********************************************************************/
512 /* This is a function useful for recording debugging information about
513 the sequence of occurrences in this file. */
521 struct record event_record
[100];
523 int event_record_index
;
525 record_event (locus
, type
)
529 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
530 event_record_index
= 0;
532 event_record
[event_record_index
].locus
= locus
;
533 event_record
[event_record_index
].type
= type
;
534 event_record_index
++;
541 /* Return the struct x_display_info corresponding to DPY. */
543 struct x_display_info
*
544 x_display_info_for_display (dpy
)
547 struct x_display_info
*dpyinfo
;
549 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
550 if (dpyinfo
->display
== dpy
)
558 /***********************************************************************
559 Starting and ending an update
560 ***********************************************************************/
562 /* Start an update of frame F. This function is installed as a hook
563 for update_begin, i.e. it is called when update_begin is called.
564 This function is called prior to calls to x_update_window_begin for
565 each window being updated. Currently, there is nothing to do here
566 because all interesting stuff is done on a window basis. */
576 /* Start update of window W. Set the global variable updated_window
577 to the window being updated and set output_cursor to the cursor
581 x_update_window_begin (w
)
584 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
585 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
588 set_output_cursor (&w
->cursor
);
592 if (f
== display_info
->mouse_face_mouse_frame
)
594 /* Don't do highlighting for mouse motion during the update. */
595 display_info
->mouse_face_defer
= 1;
597 /* If F needs to be redrawn, simply forget about any prior mouse
599 if (FRAME_GARBAGED_P (f
))
600 display_info
->mouse_face_window
= Qnil
;
602 /* Can we tell that this update does not affect the window
603 where the mouse highlight is? If so, no need to turn off.
604 Likewise, don't do anything if the frame is garbaged;
605 in that case, the frame's current matrix that we would use
606 is all wrong, and we will redisplay that line anyway. */
607 if (!NILP (display_info
->mouse_face_window
)
608 && w
== XWINDOW (display_info
->mouse_face_window
))
612 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
613 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
616 if (i
< w
->desired_matrix
->nrows
)
617 clear_mouse_face (display_info
);
625 /* Draw a vertical window border to the right of window W if W doesn't
626 have vertical scroll bars. */
629 x_draw_vertical_border (w
)
632 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
634 /* Redraw borders between horizontally adjacent windows. Don't
635 do it for frames with vertical scroll bars because either the
636 right scroll bar of a window, or the left scroll bar of its
637 neighbor will suffice as a border. */
638 if (!WINDOW_RIGHTMOST_P (w
)
639 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
643 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
644 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
647 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
648 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
653 /* End update of window W (which is equal to updated_window). Draw
654 vertical borders between horizontally adjacent windows, and display
655 W's cursor if CURSOR_ON_P is non-zero. W may be a menu bar
656 pseudo-window in case we don't have X toolkit support. Such
657 windows don't have a cursor, so don't display it here. */
660 x_update_window_end (w
, cursor_on_p
)
664 if (!w
->pseudo_window_p
)
668 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
670 output_cursor
.x
, output_cursor
.y
);
671 x_draw_vertical_border (w
);
675 updated_window
= NULL
;
679 /* End update of frame F. This function is installed as a hook in
686 /* Mouse highlight may be displayed again. */
687 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
690 XFlush (FRAME_X_DISPLAY (f
));
695 /* This function is called from various places in xdisp.c whenever a
696 complete update has been performed. The global variable
697 updated_window is not available here. */
700 XTframe_up_to_date (f
)
705 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
706 if (dpyinfo
->mouse_face_deferred_gc
707 || f
== dpyinfo
->mouse_face_mouse_frame
)
710 if (dpyinfo
->mouse_face_mouse_frame
)
711 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
712 dpyinfo
->mouse_face_mouse_x
,
713 dpyinfo
->mouse_face_mouse_y
);
714 dpyinfo
->mouse_face_deferred_gc
= 0;
721 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
722 arrow bitmaps, or clear the areas where they would be displayed
723 before DESIRED_ROW is made current. The window being updated is
724 found in updated_window. This function It is called from
725 update_window_line only if it is known that there are differences
726 between bitmaps to be drawn between current row and DESIRED_ROW. */
729 x_after_update_window_line (desired_row
)
730 struct glyph_row
*desired_row
;
732 struct window
*w
= updated_window
;
736 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
739 x_draw_row_bitmaps (w
, desired_row
);
741 /* When a window has disappeared, make sure that no rest of
742 full-width rows stays visible in the internal border. */
743 if (windows_or_buffers_changed
)
745 struct frame
*f
= XFRAME (w
->frame
);
746 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
747 int height
= desired_row
->visible_height
;
748 int x
= (window_box_right (w
, -1)
749 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
750 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
752 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
753 x
, y
, width
, height
, False
);
761 /* Draw the bitmap WHICH in one of the areas to the left or right of
762 window W. ROW is the glyph row for which to display the bitmap; it
763 determines the vertical position at which the bitmap has to be
767 x_draw_bitmap (w
, row
, which
)
769 struct glyph_row
*row
;
770 enum bitmap_type which
;
772 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
773 Display
*display
= FRAME_X_DISPLAY (f
);
774 Window window
= FRAME_X_WINDOW (f
);
778 GC gc
= f
->output_data
.x
->normal_gc
;
780 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
782 /* Must clip because of partially visible lines. */
783 x_clip_to_row (w
, row
, gc
, 1);
787 case LEFT_TRUNCATION_BITMAP
:
791 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
793 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
796 case OVERLAY_ARROW_BITMAP
:
800 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
802 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
805 case RIGHT_TRUNCATION_BITMAP
:
809 x
= window_box_right (w
, -1);
810 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
813 case CONTINUED_LINE_BITMAP
:
816 bits
= continued_bits
;
817 x
= window_box_right (w
, -1);
818 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
821 case CONTINUATION_LINE_BITMAP
:
822 wd
= continuation_width
;
823 h
= continuation_height
;
824 bits
= continuation_bits
;
825 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
827 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
834 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
836 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
843 /* Convert to frame coordinates. Set dy to the offset in the row to
844 start drawing the bitmap. */
845 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
846 dy
= (row
->height
- h
) / 2;
848 /* Draw the bitmap. I believe these small pixmaps can be cached
850 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
851 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
853 face
->background
, depth
);
854 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
855 XFreePixmap (display
, pixmap
);
856 XSetClipMask (display
, gc
, None
);
860 /* Draw flags bitmaps for glyph row ROW on window W. Call this
861 function with input blocked. */
864 x_draw_row_bitmaps (w
, row
)
866 struct glyph_row
*row
;
868 struct frame
*f
= XFRAME (w
->frame
);
869 enum bitmap_type bitmap
;
871 int header_line_height
= -1;
873 xassert (interrupt_input_blocked
);
875 /* If row is completely invisible, because of vscrolling, we
876 don't have to draw anything. */
877 if (row
->visible_height
<= 0)
880 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
881 PREPARE_FACE_FOR_DISPLAY (f
, face
);
883 /* Decide which bitmap to draw at the left side. */
884 if (row
->overlay_arrow_p
)
885 bitmap
= OVERLAY_ARROW_BITMAP
;
886 else if (row
->truncated_on_left_p
)
887 bitmap
= LEFT_TRUNCATION_BITMAP
;
888 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
889 bitmap
= CONTINUATION_LINE_BITMAP
;
890 else if (row
->indicate_empty_line_p
)
891 bitmap
= ZV_LINE_BITMAP
;
895 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
897 if (bitmap
== NO_BITMAP
898 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
899 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
901 /* If W has a vertical border to its left, don't draw over it. */
902 int border
= ((XFASTINT (w
->left
) > 0
903 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
905 int left
= window_box_left (w
, -1);
907 if (header_line_height
< 0)
908 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
910 /* In case the same realized face is used for bitmap areas and
911 for something displayed in the text (e.g. face `region' on
912 mono-displays, the fill style may have been changed to
913 FillSolid in x_draw_glyph_string_background. */
915 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
917 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
919 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
922 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
924 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
926 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
927 row
->visible_height
);
929 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
932 /* Draw the left bitmap. */
933 if (bitmap
!= NO_BITMAP
)
934 x_draw_bitmap (w
, row
, bitmap
);
936 /* Decide which bitmap to draw at the right side. */
937 if (row
->truncated_on_right_p
)
938 bitmap
= RIGHT_TRUNCATION_BITMAP
;
939 else if (row
->continued_p
)
940 bitmap
= CONTINUED_LINE_BITMAP
;
944 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
946 if (bitmap
== NO_BITMAP
947 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
948 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
950 int right
= window_box_right (w
, -1);
952 if (header_line_height
< 0)
953 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
955 /* In case the same realized face is used for bitmap areas and
956 for something displayed in the text (e.g. face `region' on
957 mono-displays, the fill style may have been changed to
958 FillSolid in x_draw_glyph_string_background. */
960 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
962 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
963 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
966 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
968 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
969 row
->visible_height
);
971 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
974 /* Draw the right bitmap. */
975 if (bitmap
!= NO_BITMAP
)
976 x_draw_bitmap (w
, row
, bitmap
);
980 /***********************************************************************
982 ***********************************************************************/
984 /* External interface to control of standout mode. Not used for X
985 frames. Aborts when called. */
988 XTreassert_line_highlight (new, vpos
)
995 /* Call this when about to modify line at position VPOS and change
996 whether it is highlighted. Not used for X frames. Aborts when
1000 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1001 int new_highlight
, vpos
, y
, first_unused_hpos
;
1007 /* This is called when starting Emacs and when restarting after
1008 suspend. When starting Emacs, no X window is mapped. And nothing
1009 must be done to Emacs's own window if it is suspended (though that
1013 XTset_terminal_modes ()
1017 /* This is called when exiting or suspending Emacs. Exiting will make
1018 the X-windows go away, and suspending requires no action. */
1021 XTreset_terminal_modes ()
1027 /***********************************************************************
1029 ***********************************************************************/
1031 /* Set the global variable output_cursor to CURSOR. All cursor
1032 positions are relative to updated_window. */
1035 set_output_cursor (cursor
)
1036 struct cursor_pos
*cursor
;
1038 output_cursor
.hpos
= cursor
->hpos
;
1039 output_cursor
.vpos
= cursor
->vpos
;
1040 output_cursor
.x
= cursor
->x
;
1041 output_cursor
.y
= cursor
->y
;
1045 /* Set a nominal cursor position.
1047 HPOS and VPOS are column/row positions in a window glyph matrix. X
1048 and Y are window text area relative pixel positions.
1050 If this is done during an update, updated_window will contain the
1051 window that is being updated and the position is the future output
1052 cursor position for that window. If updated_window is null, use
1053 selected_window and display the cursor at the given position. */
1056 XTcursor_to (vpos
, hpos
, y
, x
)
1057 int vpos
, hpos
, y
, x
;
1061 /* If updated_window is not set, work on selected_window. */
1065 w
= XWINDOW (selected_window
);
1067 /* Set the output cursor. */
1068 output_cursor
.hpos
= hpos
;
1069 output_cursor
.vpos
= vpos
;
1070 output_cursor
.x
= x
;
1071 output_cursor
.y
= y
;
1073 /* If not called as part of an update, really display the cursor.
1074 This will also set the cursor position of W. */
1075 if (updated_window
== NULL
)
1078 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1079 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1086 /***********************************************************************
1088 ***********************************************************************/
1090 /* Function prototypes of this page. */
1092 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1095 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1096 int, XChar2b
*, int));
1097 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1098 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1099 static void x_append_glyph
P_ ((struct it
*));
1100 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1102 static void x_produce_glyphs
P_ ((struct it
*));
1103 static void x_produce_image_glyph
P_ ((struct it
*it
));
1106 /* Return a pointer to per-char metric information in FONT of a
1107 character pointed by B which is a pointer to an XChar2b. */
1109 #define PER_CHAR_METRIC(font, b) \
1111 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1112 + (((font)->min_byte1 || (font)->max_byte1) \
1113 ? (((b)->byte1 - (font)->min_byte1) \
1114 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1116 : &((font)->max_bounds))
1119 /* Get metrics of character CHAR2B in FONT. Value is always non-null.
1120 If CHAR2B is not contained in FONT, the font's default character
1121 metric is returned. */
1123 static INLINE XCharStruct
*
1124 x_per_char_metric (font
, char2b
)
1128 /* The result metric information. */
1129 XCharStruct
*pcm
= NULL
;
1131 xassert (font
&& char2b
);
1133 if (font
->per_char
!= NULL
)
1135 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1137 /* min_char_or_byte2 specifies the linear character index
1138 corresponding to the first element of the per_char array,
1139 max_char_or_byte2 is the index of the last character. A
1140 character with non-zero CHAR2B->byte1 is not in the font.
1141 A character with byte2 less than min_char_or_byte2 or
1142 greater max_char_or_byte2 is not in the font. */
1143 if (char2b
->byte1
== 0
1144 && char2b
->byte2
>= font
->min_char_or_byte2
1145 && char2b
->byte2
<= font
->max_char_or_byte2
)
1146 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1150 /* If either min_byte1 or max_byte1 are nonzero, both
1151 min_char_or_byte2 and max_char_or_byte2 are less than
1152 256, and the 2-byte character index values corresponding
1153 to the per_char array element N (counting from 0) are:
1155 byte1 = N/D + min_byte1
1156 byte2 = N\D + min_char_or_byte2
1160 D = max_char_or_byte2 - min_char_or_byte2 + 1
1161 / = integer division
1162 \ = integer modulus */
1163 if (char2b
->byte1
>= font
->min_byte1
1164 && char2b
->byte1
<= font
->max_byte1
1165 && char2b
->byte2
>= font
->min_char_or_byte2
1166 && char2b
->byte2
<= font
->max_char_or_byte2
)
1168 pcm
= (font
->per_char
1169 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1170 * (char2b
->byte1
- font
->min_byte1
))
1171 + (char2b
->byte2
- font
->min_char_or_byte2
));
1177 /* If the per_char pointer is null, all glyphs between the first
1178 and last character indexes inclusive have the same
1179 information, as given by both min_bounds and max_bounds. */
1180 if (char2b
->byte2
>= font
->min_char_or_byte2
1181 && char2b
->byte2
<= font
->max_char_or_byte2
)
1182 pcm
= &font
->max_bounds
;
1186 if (pcm
== NULL
|| pcm
->width
== 0)
1188 /* Character not contained in the font. FONT->default_char
1189 gives the character that will be printed. FONT->default_char
1190 is a 16-bit character code with byte1 in the most significant
1191 byte and byte2 in the least significant byte. */
1192 XChar2b default_char
;
1193 default_char
.byte1
= (font
->default_char
>> BITS_PER_CHAR
) & 0xff;
1194 default_char
.byte2
= font
->default_char
& 0xff;
1196 /* Avoid an endless recursion if FONT->default_char itself
1197 hasn't per char metrics. handa@etl.go.jp reports that some
1198 fonts have this problem. */
1199 if (default_char
.byte1
!= char2b
->byte1
1200 || default_char
.byte2
!= char2b
->byte2
)
1201 pcm
= x_per_char_metric (font
, &default_char
);
1203 pcm
= &font
->max_bounds
;
1210 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1211 the two-byte form of C. Encoding is returned in *CHAR2B. */
1214 x_encode_char (c
, char2b
, font_info
)
1217 struct font_info
*font_info
;
1219 int charset
= CHAR_CHARSET (c
);
1220 XFontStruct
*font
= font_info
->font
;
1222 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1223 This may be either a program in a special encoder language or a
1225 if (font_info
->font_encoder
)
1227 /* It's a program. */
1228 struct ccl_program
*ccl
= font_info
->font_encoder
;
1230 if (CHARSET_DIMENSION (charset
) == 1)
1232 ccl
->reg
[0] = charset
;
1233 ccl
->reg
[1] = char2b
->byte2
;
1237 ccl
->reg
[0] = charset
;
1238 ccl
->reg
[1] = char2b
->byte1
;
1239 ccl
->reg
[2] = char2b
->byte2
;
1242 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1244 /* We assume that MSBs are appropriately set/reset by CCL
1246 if (font
->max_byte1
== 0) /* 1-byte font */
1247 char2b
->byte2
= ccl
->reg
[1];
1249 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1251 else if (font_info
->encoding
[charset
])
1253 /* Fixed encoding scheme. See fontset.h for the meaning of the
1254 encoding numbers. */
1255 int enc
= font_info
->encoding
[charset
];
1257 if ((enc
== 1 || enc
== 2)
1258 && CHARSET_DIMENSION (charset
) == 2)
1259 char2b
->byte1
|= 0x80;
1261 if (enc
== 1 || enc
== 3)
1262 char2b
->byte2
|= 0x80;
1267 /* Get face and two-byte form of character C in face FACE_ID on frame
1268 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1269 means we want to display multibyte text. Value is a pointer to a
1270 realized face that is ready for display. */
1272 static INLINE
struct face
*
1273 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1279 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1283 /* Unibyte case. We don't have to encode, but we have to make
1284 sure to use a face suitable for unibyte. */
1288 if (!FACE_SUITABLE_FOR_CHARSET_P (face
, -1))
1290 face_id
= FACE_FOR_CHARSET (f
, face_id
, -1);
1291 face
= FACE_FROM_ID (f
, face_id
);
1294 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1296 /* Case of ASCII in a face known to fit ASCII. */
1302 int c1
, c2
, charset
;
1304 /* Split characters into bytes. If c2 is -1 afterwards, C is
1305 really a one-byte character so that byte1 is zero. */
1306 SPLIT_CHAR (c
, charset
, c1
, c2
);
1308 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1310 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1312 /* Get the face for displaying C. If `face' is not suitable for
1313 charset, get the one that fits. (This can happen for the
1314 translations of composite characters where the glyph
1315 specifies a face for ASCII, but translations have a different
1317 if (!FACE_SUITABLE_FOR_CHARSET_P (face
, charset
))
1319 face_id
= FACE_FOR_CHARSET (f
, face_id
, charset
);
1320 face
= FACE_FROM_ID (f
, face_id
);
1323 /* Maybe encode the character in *CHAR2B. */
1324 if (charset
!= CHARSET_ASCII
)
1326 struct font_info
*font_info
1327 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1330 x_encode_char (c
, char2b
, font_info
);
1331 if (charset
== charset_latin_iso8859_1
)
1333 xassert (((XFontStruct
*) font_info
->font
)->max_char_or_byte2
1335 char2b
->byte2
|= 0x80;
1341 /* Make sure X resources of the face are allocated. */
1342 xassert (face
!= NULL
);
1343 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1349 /* Get face and two-byte form of character glyph GLYPH on frame F.
1350 The encoding of GLYPH->u.ch.code is returned in *CHAR2B. Value is
1351 a pointer to a realized face that is ready for display. */
1353 static INLINE
struct face
*
1354 x_get_glyph_face_and_encoding (f
, glyph
, char2b
)
1356 struct glyph
*glyph
;
1361 xassert (glyph
->type
== CHAR_GLYPH
);
1362 face
= FACE_FROM_ID (f
, glyph
->u
.ch
.face_id
);
1364 if (!glyph
->multibyte_p
)
1366 /* Unibyte case. We don't have to encode, but we have to make
1367 sure to use a face suitable for unibyte. */
1369 char2b
->byte2
= glyph
->u
.ch
.code
;
1371 else if (glyph
->u
.ch
.code
< 128
1372 && glyph
->u
.ch
.face_id
< BASIC_FACE_ID_SENTINEL
)
1374 /* Case of ASCII in a face known to fit ASCII. */
1376 char2b
->byte2
= glyph
->u
.ch
.code
;
1380 int c1
, c2
, charset
;
1382 /* Split characters into bytes. If c2 is -1 afterwards, C is
1383 really a one-byte character so that byte1 is zero. */
1384 SPLIT_CHAR (glyph
->u
.ch
.code
, charset
, c1
, c2
);
1386 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1388 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1390 /* Maybe encode the character in *CHAR2B. */
1391 if (charset
!= CHARSET_ASCII
)
1393 struct font_info
*font_info
1394 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1397 x_encode_char (glyph
->u
.ch
.code
, char2b
, font_info
);
1398 if (charset
== charset_latin_iso8859_1
)
1399 char2b
->byte2
|= 0x80;
1404 /* Make sure X resources of the face are allocated. */
1405 xassert (face
!= NULL
);
1406 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1411 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1412 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1418 struct glyph
*glyph
;
1419 enum glyph_row_area area
= it
->area
;
1421 xassert (it
->glyph_row
);
1422 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1424 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1425 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1427 /* Play it safe. If sub-structures of the glyph are not all the
1428 same size, it otherwise be that some bits stay set. This
1429 would prevent a comparison with GLYPH_EQUAL_P. */
1432 glyph
->type
= CHAR_GLYPH
;
1433 glyph
->pixel_width
= it
->pixel_width
;
1434 glyph
->u
.ch
.code
= it
->char_to_display
;
1435 glyph
->u
.ch
.face_id
= it
->face_id
;
1436 glyph
->charpos
= CHARPOS (it
->position
);
1437 glyph
->object
= it
->object
;
1438 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1439 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1440 glyph
->voffset
= it
->voffset
;
1441 glyph
->multibyte_p
= it
->multibyte_p
;
1442 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1443 || it
->phys_descent
> it
->descent
);
1444 ++it
->glyph_row
->used
[area
];
1449 /* Change IT->ascent and IT->height according to the setting of
1453 take_vertical_position_into_account (it
)
1458 if (it
->voffset
< 0)
1459 /* Increase the ascent so that we can display the text higher
1461 it
->ascent
+= abs (it
->voffset
);
1463 /* Increase the descent so that we can display the text lower
1465 it
->descent
+= it
->voffset
;
1470 /* Produce glyphs/get display metrics for the image IT is loaded with.
1471 See the description of struct display_iterator in dispextern.h for
1472 an overview of struct display_iterator. */
1475 x_produce_image_glyph (it
)
1481 xassert (it
->what
== IT_IMAGE
);
1483 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1484 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1487 /* Make sure X resources of the face and image are loaded. */
1488 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1489 prepare_image_for_display (it
->f
, img
);
1491 it
->ascent
= it
->phys_ascent
= IMAGE_ASCENT (img
);
1492 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->margin
- it
->ascent
;
1493 it
->pixel_width
= img
->width
+ 2 * img
->margin
;
1497 if (face
->box
!= FACE_NO_BOX
)
1499 it
->ascent
+= face
->box_line_width
;
1500 it
->descent
+= face
->box_line_width
;
1502 if (it
->start_of_box_run_p
)
1503 it
->pixel_width
+= face
->box_line_width
;
1504 if (it
->end_of_box_run_p
)
1505 it
->pixel_width
+= face
->box_line_width
;
1508 take_vertical_position_into_account (it
);
1512 struct glyph
*glyph
;
1513 enum glyph_row_area area
= it
->area
;
1515 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1516 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1518 glyph
->type
= IMAGE_GLYPH
;
1519 glyph
->u
.img
.id
= img
->id
;
1520 glyph
->u
.img
.face_id
= it
->face_id
;
1521 glyph
->pixel_width
= it
->pixel_width
;
1522 glyph
->charpos
= CHARPOS (it
->position
);
1523 glyph
->object
= it
->object
;
1524 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1525 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1526 glyph
->voffset
= it
->voffset
;
1527 glyph
->multibyte_p
= it
->multibyte_p
;
1528 ++it
->glyph_row
->used
[area
];
1534 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1535 of the glyph, WIDTH and HEIGHT are the width and height of the
1536 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1537 ascent of the glyph (0 <= ASCENT <= 1). */
1540 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1546 struct glyph
*glyph
;
1547 enum glyph_row_area area
= it
->area
;
1549 xassert (ascent
>= 0 && ascent
<= 1);
1551 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1552 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1554 glyph
->type
= STRETCH_GLYPH
;
1555 glyph
->u
.stretch
.ascent
= height
* ascent
;
1556 glyph
->u
.stretch
.height
= height
;
1557 glyph
->u
.stretch
.face_id
= it
->face_id
;
1558 glyph
->pixel_width
= width
;
1559 glyph
->charpos
= CHARPOS (it
->position
);
1560 glyph
->object
= object
;
1561 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1562 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1563 glyph
->voffset
= it
->voffset
;
1564 glyph
->multibyte_p
= it
->multibyte_p
;
1565 ++it
->glyph_row
->used
[area
];
1570 /* Produce a stretch glyph for iterator IT. IT->object is the value
1571 of the glyph property displayed. The value must be a list
1572 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1575 1. `:width WIDTH' specifies that the space should be WIDTH *
1576 canonical char width wide. WIDTH may be an integer or floating
1579 2. `:relative-width FACTOR' specifies that the width of the stretch
1580 should be computed from the width of the first character having the
1581 `glyph' property, and should be FACTOR times that width.
1583 3. `:align-to HPOS' specifies that the space should be wide enough
1584 to reach HPOS, a value in canonical character units.
1586 Exactly one of the above pairs must be present.
1588 4. `:height HEIGHT' specifies that the height of the stretch produced
1589 should be HEIGHT, measured in canonical character units.
1591 5. `:relative-height FACTOR' specifies that the height of the the
1592 stretch should be FACTOR times the height of the characters having
1595 Either none or exactly one of 4 or 5 must be present.
1597 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1598 of the stretch should be used for the ascent of the stretch.
1599 ASCENT must be in the range 0 <= ASCENT <= 100. */
1602 ((INTEGERP (X) || FLOATP (X)) \
1608 x_produce_stretch_glyph (it
)
1611 /* (space :width WIDTH :height HEIGHT. */
1612 extern Lisp_Object QCwidth
, QCheight
, QCascent
, Qspace
;
1613 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1614 extern Lisp_Object QCalign_to
;
1615 Lisp_Object prop
, plist
;
1616 double width
= 0, height
= 0, ascent
= 0;
1617 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1618 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1620 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1622 /* List should start with `space'. */
1623 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1624 plist
= XCDR (it
->object
);
1626 /* Compute the width of the stretch. */
1627 if (prop
= Fplist_get (plist
, QCwidth
),
1629 /* Absolute width `:width WIDTH' specified and valid. */
1630 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1631 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1634 /* Relative width `:relative-width FACTOR' specified and valid.
1635 Compute the width of the characters having the `glyph'
1638 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1641 if (it
->multibyte_p
)
1643 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1644 - IT_BYTEPOS (*it
));
1645 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1648 it2
.c
= *p
, it2
.len
= 1;
1650 it2
.glyph_row
= NULL
;
1651 it2
.what
= IT_CHARACTER
;
1652 x_produce_glyphs (&it2
);
1653 width
= NUMVAL (prop
) * it2
.pixel_width
;
1655 else if (prop
= Fplist_get (plist
, QCalign_to
),
1657 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1659 /* Nothing specified -> width defaults to canonical char width. */
1660 width
= CANON_X_UNIT (it
->f
);
1662 /* Compute height. */
1663 if (prop
= Fplist_get (plist
, QCheight
),
1665 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1666 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1668 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1670 height
= FONT_HEIGHT (font
);
1672 /* Compute percentage of height used for ascent. If
1673 `:ascent ASCENT' is present and valid, use that. Otherwise,
1674 derive the ascent from the font in use. */
1675 if (prop
= Fplist_get (plist
, QCascent
),
1676 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1677 ascent
= NUMVAL (prop
) / 100.0;
1679 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1688 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1689 if (!STRINGP (object
))
1690 object
= it
->w
->buffer
;
1691 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1694 it
->pixel_width
= width
;
1695 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1696 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1699 if (face
->box
!= FACE_NO_BOX
)
1701 it
->ascent
+= face
->box_line_width
;
1702 it
->descent
+= face
->box_line_width
;
1704 if (it
->start_of_box_run_p
)
1705 it
->pixel_width
+= face
->box_line_width
;
1706 if (it
->end_of_box_run_p
)
1707 it
->pixel_width
+= face
->box_line_width
;
1710 take_vertical_position_into_account (it
);
1714 /* Produce glyphs/get display metrics for the display element IT is
1715 loaded with. See the description of struct display_iterator in
1716 dispextern.h for an overview of struct display_iterator. */
1719 x_produce_glyphs (it
)
1722 if (it
->what
== IT_CHARACTER
)
1728 int font_not_found_p
;
1730 /* Maybe translate single-byte characters to multibyte. */
1731 it
->char_to_display
= it
->c
;
1732 if (unibyte_display_via_language_environment
1733 && SINGLE_BYTE_CHAR_P (it
->c
)
1736 && !NILP (Vnonascii_translation_table
))))
1738 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1739 it
->charset
= CHAR_CHARSET (it
->char_to_display
);
1742 /* Get face and font to use. Encode IT->char_to_display. */
1743 face
= x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1744 it
->face_id
, &char2b
,
1748 /* When no suitable font found, use the default font. */
1749 font_not_found_p
= font
== NULL
;
1750 if (font_not_found_p
)
1751 font
= FRAME_FONT (it
->f
);
1753 if (it
->char_to_display
>= ' '
1754 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1756 /* Either unibyte or ASCII. */
1761 pcm
= x_per_char_metric (font
, &char2b
);
1762 it
->ascent
= font
->ascent
;
1763 it
->descent
= font
->descent
;
1764 it
->phys_ascent
= pcm
->ascent
;
1765 it
->phys_descent
= pcm
->descent
;
1766 it
->pixel_width
= pcm
->width
;
1768 /* If this is a space inside a region of text with
1769 `space-width' property, change its width. */
1770 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1772 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1774 /* If face has a box, add the box thickness to the character
1775 height. If character has a box line to the left and/or
1776 right, add the box line width to the character's width. */
1777 if (face
->box
!= FACE_NO_BOX
)
1779 int thick
= face
->box_line_width
;
1781 it
->ascent
+= thick
;
1782 it
->descent
+= thick
;
1784 if (it
->start_of_box_run_p
)
1785 it
->pixel_width
+= thick
;
1786 if (it
->end_of_box_run_p
)
1787 it
->pixel_width
+= thick
;
1790 /* If face has an overline, add the height of the overline
1791 (1 pixel) and a 1 pixel margin to the character height. */
1792 if (face
->overline_p
)
1795 take_vertical_position_into_account (it
);
1797 /* If we have to actually produce glyphs, do it. */
1802 /* Translate a space with a `space-width' property
1803 into a stretch glyph. */
1804 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1805 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1806 it
->ascent
+ it
->descent
, ascent
);
1809 x_append_glyph (it
);
1811 /* If characters with lbearing or rbearing are displayed
1812 in this line, record that fact in a flag of the
1813 glyph row. This is used to optimize X output code. */
1814 if (pcm
->lbearing
< 0
1815 || pcm
->rbearing
> pcm
->width
)
1816 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1819 else if (it
->char_to_display
== '\n')
1821 /* A newline has no width but we need the height of the line. */
1822 it
->pixel_width
= 0;
1824 it
->ascent
= it
->phys_ascent
= font
->ascent
;
1825 it
->descent
= it
->phys_descent
= font
->descent
;
1827 if (face
->box
!= FACE_NO_BOX
)
1829 int thick
= face
->box_line_width
;
1830 it
->ascent
+= thick
;
1831 it
->descent
+= thick
;
1834 else if (it
->char_to_display
== '\t')
1836 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1837 int x
= (it
->current_x
1839 + it
->continuation_lines_width
);
1840 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1842 it
->pixel_width
= next_tab_x
- x
;
1844 it
->ascent
= it
->phys_ascent
= font
->ascent
;
1845 it
->descent
= it
->phys_descent
= font
->descent
;
1849 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1850 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1851 it
->ascent
+ it
->descent
, ascent
);
1856 /* A multi-byte character. Assume that the display width of the
1857 character is the width of the character multiplied by the
1858 width of the font. There has to be better support for
1859 variable sizes in cmpchar_info to do anything better than
1862 Note: composite characters are represented as one glyph in
1863 the glyph matrix. There are no padding glyphs. */
1864 if (it
->charset
== CHARSET_COMPOSITION
)
1866 struct cmpchar_info
*cmpcharp
;
1869 idx
= COMPOSITE_CHAR_ID (it
->char_to_display
);
1870 cmpcharp
= cmpchar_table
[idx
];
1871 it
->pixel_width
= font
->max_bounds
.width
* cmpcharp
->width
;
1873 /* There are no padding glyphs, so there is only one glyph
1874 to produce for the composite char. Important is that
1875 pixel_width, ascent and descent are the values of what is
1876 drawn by draw_glyphs. */
1879 /* These settings may not be correct. We must have more
1880 information in cmpcharp to do the correct setting. */
1881 it
->ascent
= font
->ascent
;
1882 it
->descent
= font
->descent
;
1883 it
->phys_ascent
= font
->max_bounds
.ascent
;
1884 it
->phys_descent
= font
->max_bounds
.descent
;
1888 /* If we found a font, this font should give us the right
1889 metrics. If we didn't find a font, use the frame's
1890 default font and calculate the width of the character
1891 from the charset width; this is what old redisplay code
1893 pcm
= x_per_char_metric (font
, &char2b
);
1894 it
->pixel_width
= pcm
->width
;
1895 if (font_not_found_p
)
1896 it
->pixel_width
*= CHARSET_WIDTH (it
->charset
);
1898 it
->ascent
= font
->ascent
;
1899 it
->descent
= font
->descent
;
1900 it
->phys_ascent
= pcm
->ascent
;
1901 it
->phys_descent
= pcm
->descent
;
1903 && (pcm
->lbearing
< 0
1904 || pcm
->rbearing
> pcm
->width
))
1905 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1908 if (face
->box
!= FACE_NO_BOX
)
1910 int thick
= face
->box_line_width
;
1911 it
->ascent
+= thick
;
1912 it
->descent
+= thick
;
1914 if (it
->start_of_box_run_p
)
1915 it
->pixel_width
+= thick
;
1916 if (it
->end_of_box_run_p
)
1917 it
->pixel_width
+= thick
;
1920 /* If face has an overline, add the height of the overline
1921 (1 pixel) and a 1 pixel margin to the character height. */
1922 if (face
->overline_p
)
1925 take_vertical_position_into_account (it
);
1928 x_append_glyph (it
);
1931 else if (it
->what
== IT_IMAGE
)
1932 x_produce_image_glyph (it
);
1933 else if (it
->what
== IT_STRETCH
)
1934 x_produce_stretch_glyph (it
);
1936 /* Accumulate dimensions. */
1937 xassert (it
->ascent
>= 0 && it
->descent
> 0);
1938 if (it
->area
== TEXT_AREA
)
1939 it
->current_x
+= it
->pixel_width
;
1941 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
1942 it
->max_descent
= max (it
->max_descent
, it
->descent
);
1943 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
1944 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
1948 /* Estimate the pixel height of the mode or top line on frame F.
1949 FACE_ID specifies what line's height to estimate. */
1952 x_estimate_mode_line_height (f
, face_id
)
1954 enum face_id face_id
;
1958 /* This function is called so early when Emacs starts that the face
1959 cache and mode line face are not yet initialized. */
1960 if (FRAME_FACE_CACHE (f
))
1962 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1964 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
1971 /***********************************************************************
1973 ***********************************************************************/
1975 /* A sequence of glyphs to be drawn in the same face.
1977 This data structure is not really completely X specific, so it
1978 could possibly, at least partially, be useful for other systems. It
1979 is currently not part of the external redisplay interface because
1980 it's not clear what other systems will need. */
1984 /* X-origin of the string. */
1987 /* Y-origin and y-position of the base line of this string. */
1990 /* The width of the string, not including a face extension. */
1993 /* The width of the string, including a face extension. */
1994 int background_width
;
1996 /* The height of this string. This is the height of the line this
1997 string is drawn in, and can be different from the height of the
1998 font the string is drawn in. */
2001 /* Number of pixels this string overwrites in front of its x-origin.
2002 This number is zero if the string has an lbearing >= 0; it is
2003 -lbearing, if the string has an lbearing < 0. */
2006 /* Number of pixels this string overwrites past its right-most
2007 nominal x-position, i.e. x + width. Zero if the string's
2008 rbearing is <= its nominal width, rbearing - width otherwise. */
2011 /* The frame on which the glyph string is drawn. */
2014 /* The window on which the glyph string is drawn. */
2017 /* X display and window for convenience. */
2021 /* The glyph row for which this string was built. It determines the
2022 y-origin and height of the string. */
2023 struct glyph_row
*row
;
2025 /* The area within row. */
2026 enum glyph_row_area area
;
2028 /* Characters to be drawn, and number of characters. */
2032 /* Character set of this glyph string. */
2035 /* A face-override for drawing cursors, mouse face and similar. */
2036 enum draw_glyphs_face hl
;
2038 /* Face in which this string is to be drawn. */
2041 /* Font in which this string is to be drawn. */
2044 /* Font info for this string. */
2045 struct font_info
*font_info
;
2047 /* Non-null means this string describes (part of) a composite
2048 character. All characters from char2b are drawn at the same
2049 x-origin in that case. */
2050 struct cmpchar_info
*cmpcharp
;
2052 /* Index of this glyph string's first character in the glyph
2053 definition of cmpcharp. If this is zero, this glyph string
2054 describes the first character of a composite character. */
2057 /* 1 means this glyph strings face has to be drawn to the right end
2058 of the window's drawing area. */
2059 unsigned extends_to_end_of_line_p
: 1;
2061 /* 1 means the background of this string has been drawn. */
2062 unsigned background_filled_p
: 1;
2064 /* 1 means glyph string must be drawn with 16-bit functions. */
2065 unsigned two_byte_p
: 1;
2067 /* 1 means that the original font determined for drawing this glyph
2068 string could not be loaded. The member `font' has been set to
2069 the frame's default font in this case. */
2070 unsigned font_not_found_p
: 1;
2072 /* 1 means that the face in which this glyph string is drawn has a
2074 unsigned stippled_p
: 1;
2076 /* 1 means only the foreground of this glyph string must be drawn,
2077 and we should use the physical height of the line this glyph
2078 string appears in as clip rect. */
2079 unsigned for_overlaps_p
: 1;
2081 /* The GC to use for drawing this glyph string. */
2084 /* A pointer to the first glyph in the string. This glyph
2085 corresponds to char2b[0]. Needed to draw rectangles if
2086 font_not_found_p is 1. */
2087 struct glyph
*first_glyph
;
2089 /* Image, if any. */
2092 struct glyph_string
*next
, *prev
;
2099 x_dump_glyph_string (s
)
2100 struct glyph_string
*s
;
2102 fprintf (stderr
, "glyph string\n");
2103 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2104 s
->x
, s
->y
, s
->width
, s
->height
);
2105 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2106 fprintf (stderr
, " hl = %d\n", s
->hl
);
2107 fprintf (stderr
, " left overhang = %d, right = %d\n",
2108 s
->left_overhang
, s
->right_overhang
);
2109 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2110 fprintf (stderr
, " extends to end of line = %d\n",
2111 s
->extends_to_end_of_line_p
);
2112 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2113 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2116 #endif /* GLYPH_DEBUG */
2120 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2121 struct glyph_string
**,
2122 struct glyph_string
*,
2123 struct glyph_string
*));
2124 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2125 struct glyph_string
**,
2126 struct glyph_string
*,
2127 struct glyph_string
*));
2128 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2129 struct glyph_string
**,
2130 struct glyph_string
*));
2131 static int x_left_overwritten
P_ ((struct glyph_string
*));
2132 static int x_left_overwriting
P_ ((struct glyph_string
*));
2133 static int x_right_overwritten
P_ ((struct glyph_string
*));
2134 static int x_right_overwriting
P_ ((struct glyph_string
*));
2135 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2137 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2138 XChar2b
*, struct window
*,
2140 enum glyph_row_area
, int,
2141 enum draw_glyphs_face
));
2142 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2143 enum glyph_row_area
, int, int,
2144 enum draw_glyphs_face
, int *, int *, int));
2145 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2146 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2147 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2149 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2150 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2151 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2152 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2153 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2154 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2155 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2156 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2158 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2159 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2160 unsigned long *, float, int));
2161 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2162 float, int, unsigned long));
2163 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2164 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2165 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2166 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2167 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2168 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2169 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2171 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2172 int, int, int, int, XRectangle
*));
2173 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2174 int, int, int, XRectangle
*));
2175 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2176 enum glyph_row_area
));
2179 /* Append the list of glyph strings with head H and tail T to the list
2180 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2183 x_append_glyph_string_lists (head
, tail
, h
, t
)
2184 struct glyph_string
**head
, **tail
;
2185 struct glyph_string
*h
, *t
;
2199 /* Prepend the list of glyph strings with head H and tail T to the
2200 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2204 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2205 struct glyph_string
**head
, **tail
;
2206 struct glyph_string
*h
, *t
;
2220 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2221 Set *HEAD and *TAIL to the resulting list. */
2224 x_append_glyph_string (head
, tail
, s
)
2225 struct glyph_string
**head
, **tail
;
2226 struct glyph_string
*s
;
2228 s
->next
= s
->prev
= NULL
;
2229 x_append_glyph_string_lists (head
, tail
, s
, s
);
2233 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2238 struct glyph_string
*s
;
2240 if (s
->font
== FRAME_FONT (s
->f
)
2241 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2242 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2244 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2247 /* Cursor on non-default face: must merge. */
2251 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2252 xgcv
.foreground
= s
->face
->background
;
2254 /* If the glyph would be invisible, try a different foreground. */
2255 if (xgcv
.foreground
== xgcv
.background
)
2256 xgcv
.foreground
= s
->face
->foreground
;
2257 if (xgcv
.foreground
== xgcv
.background
)
2258 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2259 if (xgcv
.foreground
== xgcv
.background
)
2260 xgcv
.foreground
= s
->face
->foreground
;
2262 /* Make sure the cursor is distinct from text in this face. */
2263 if (xgcv
.background
== s
->face
->background
2264 && xgcv
.foreground
== s
->face
->foreground
)
2266 xgcv
.background
= s
->face
->foreground
;
2267 xgcv
.foreground
= s
->face
->background
;
2270 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2271 xgcv
.font
= s
->font
->fid
;
2272 xgcv
.graphics_exposures
= False
;
2273 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2275 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2276 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2279 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2280 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2282 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2287 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2290 x_set_mouse_face_gc (s
)
2291 struct glyph_string
*s
;
2295 /* What face has to be used for the mouse face? */
2296 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2297 face_id
= FACE_FOR_CHARSET (s
->f
, face_id
, s
->charset
);
2298 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2299 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2301 /* If font in this face is same as S->font, use it. */
2302 if (s
->font
== s
->face
->font
)
2303 s
->gc
= s
->face
->gc
;
2306 /* Otherwise construct scratch_cursor_gc with values from FACE
2311 xgcv
.background
= s
->face
->background
;
2312 xgcv
.foreground
= s
->face
->foreground
;
2313 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2314 xgcv
.font
= s
->font
->fid
;
2315 xgcv
.graphics_exposures
= False
;
2316 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2318 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2319 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2322 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2323 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2325 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2328 xassert (s
->gc
!= 0);
2332 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2333 Faces to use in the mode line have already been computed when the
2334 matrix was built, so there isn't much to do, here. */
2337 x_set_mode_line_face_gc (s
)
2338 struct glyph_string
*s
;
2340 s
->gc
= s
->face
->gc
;
2341 xassert (s
->gc
!= 0);
2345 /* Set S->gc of glyph string S for drawing that glyph string. Set
2346 S->stippled_p to a non-zero value if the face of S has a stipple
2350 x_set_glyph_string_gc (s
)
2351 struct glyph_string
*s
;
2353 if (s
->hl
== DRAW_NORMAL_TEXT
)
2355 s
->gc
= s
->face
->gc
;
2356 s
->stippled_p
= s
->face
->stipple
!= 0;
2358 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2360 x_set_mode_line_face_gc (s
);
2361 s
->stippled_p
= s
->face
->stipple
!= 0;
2363 else if (s
->hl
== DRAW_CURSOR
)
2365 x_set_cursor_gc (s
);
2368 else if (s
->hl
== DRAW_MOUSE_FACE
)
2370 x_set_mouse_face_gc (s
);
2371 s
->stippled_p
= s
->face
->stipple
!= 0;
2373 else if (s
->hl
== DRAW_IMAGE_RAISED
2374 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2376 s
->gc
= s
->face
->gc
;
2377 s
->stippled_p
= s
->face
->stipple
!= 0;
2381 s
->gc
= s
->face
->gc
;
2382 s
->stippled_p
= s
->face
->stipple
!= 0;
2385 /* GC must have been set. */
2386 xassert (s
->gc
!= 0);
2390 /* Return in *R the clipping rectangle for glyph string S. */
2393 x_get_glyph_string_clip_rect (s
, r
)
2394 struct glyph_string
*s
;
2397 if (s
->row
->full_width_p
)
2399 /* Draw full-width. X coordinates are relative to S->w->left. */
2400 int canon_x
= CANON_X_UNIT (s
->f
);
2402 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2403 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2405 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2407 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2408 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2412 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2414 /* Unless displaying a mode or menu bar line, which are always
2415 fully visible, clip to the visible part of the row. */
2416 if (s
->w
->pseudo_window_p
)
2417 r
->height
= s
->row
->visible_height
;
2419 r
->height
= s
->height
;
2423 /* This is a text line that may be partially visible. */
2424 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2425 r
->width
= window_box_width (s
->w
, s
->area
);
2426 r
->height
= s
->row
->visible_height
;
2429 /* Don't use S->y for clipping because it doesn't take partially
2430 visible lines into account. For example, it can be negative for
2431 partially visible lines at the top of a window. */
2432 if (!s
->row
->full_width_p
2433 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2434 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2436 r
->y
= max (0, s
->row
->y
);
2438 /* If drawing a tool-bar window, draw it over the internal border
2439 at the top of the window. */
2440 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2441 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2443 /* If S draws overlapping rows, it's sufficient to use the top and
2444 bottom of the window for clipping because this glyph string
2445 intentionally draws over other lines. */
2446 if (s
->for_overlaps_p
)
2448 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2449 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2452 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2456 /* Set clipping for output of glyph string S. S may be part of a mode
2457 line or menu if we don't have X toolkit support. */
2460 x_set_glyph_string_clipping (s
)
2461 struct glyph_string
*s
;
2464 x_get_glyph_string_clip_rect (s
, &r
);
2465 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2469 /* Compute left and right overhang of glyph string S. If S is a glyph
2470 string for a composite character, assume overhangs don't exist. */
2473 x_compute_glyph_string_overhangs (s
)
2474 struct glyph_string
*s
;
2476 if (s
->cmpcharp
== NULL
2477 && s
->first_glyph
->type
== CHAR_GLYPH
)
2480 int direction
, font_ascent
, font_descent
;
2481 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2482 &font_ascent
, &font_descent
, &cs
);
2483 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2484 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2489 /* Compute overhangs and x-positions for glyph string S and its
2490 predecessors, or successors. X is the starting x-position for S.
2491 BACKWARD_P non-zero means process predecessors. */
2494 x_compute_overhangs_and_x (s
, x
, backward_p
)
2495 struct glyph_string
*s
;
2503 x_compute_glyph_string_overhangs (s
);
2513 x_compute_glyph_string_overhangs (s
);
2522 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2523 frame F. Overhangs of glyphs other than type CHAR_GLYPH or of
2524 character glyphs for composite characters are assumed to be zero. */
2527 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2528 struct glyph
*glyph
;
2536 if (glyph
->type
== CHAR_GLYPH
2537 && (c
= glyph
->u
.ch
.code
,
2538 CHAR_CHARSET (c
) != CHARSET_COMPOSITION
))
2542 struct font_info
*font_info
;
2545 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
);
2547 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2550 XCharStruct
*pcm
= x_per_char_metric (font
, &char2b
);
2552 if (pcm
->rbearing
> pcm
->width
)
2553 *right
= pcm
->rbearing
- pcm
->width
;
2554 if (pcm
->lbearing
< 0)
2555 *left
= -pcm
->lbearing
;
2561 /* Return the index of the first glyph preceding glyph string S that
2562 is overwritten by S because of S's left overhang. Value is -1
2563 if no glyphs are overwritten. */
2566 x_left_overwritten (s
)
2567 struct glyph_string
*s
;
2571 if (s
->left_overhang
)
2574 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2575 int first
= s
->first_glyph
- glyphs
;
2577 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2578 x
-= glyphs
[i
].pixel_width
;
2589 /* Return the index of the first glyph preceding glyph string S that
2590 is overwriting S because of its right overhang. Value is -1 if no
2591 glyph in front of S overwrites S. */
2594 x_left_overwriting (s
)
2595 struct glyph_string
*s
;
2598 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2599 int first
= s
->first_glyph
- glyphs
;
2603 for (i
= first
- 1; i
>= 0; --i
)
2606 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2609 x
-= glyphs
[i
].pixel_width
;
2616 /* Return the index of the last glyph following glyph string S that is
2617 not overwritten by S because of S's right overhang. Value is -1 if
2618 no such glyph is found. */
2621 x_right_overwritten (s
)
2622 struct glyph_string
*s
;
2626 if (s
->right_overhang
)
2629 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2630 int first
= (s
->first_glyph
- glyphs
) + (s
->cmpcharp
? 1 : s
->nchars
);
2631 int end
= s
->row
->used
[s
->area
];
2633 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
2634 x
+= glyphs
[i
].pixel_width
;
2643 /* Return the index of the last glyph following glyph string S that
2644 overwrites S because of its left overhang. Value is negative
2645 if no such glyph is found. */
2648 x_right_overwriting (s
)
2649 struct glyph_string
*s
;
2652 int end
= s
->row
->used
[s
->area
];
2653 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2654 int first
= (s
->first_glyph
- glyphs
) + (s
->cmpcharp
? 1 : s
->nchars
);
2658 for (i
= first
; i
< end
; ++i
)
2661 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2664 x
+= glyphs
[i
].pixel_width
;
2671 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2674 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2675 struct glyph_string
*s
;
2679 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
2680 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2681 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2682 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2686 /* Draw the background of glyph_string S. If S->background_filled_p
2687 is non-zero don't draw it. FORCE_P non-zero means draw the
2688 background even if it wouldn't be drawn normally. This is used
2689 when a string preceding S draws into the background of S. */
2692 x_draw_glyph_string_background (s
, force_p
)
2693 struct glyph_string
*s
;
2696 /* Nothing to do if background has already been drawn or if it
2697 shouldn't be drawn in the first place. */
2698 if (!s
->background_filled_p
)
2702 && !s
->font_not_found_p
2703 && !s
->extends_to_end_of_line_p
)
2705 /* Don't draw background for glyphs of a composite
2706 characters, except for the first one. */
2707 s
->background_filled_p
= 1;
2709 else if (s
->stippled_p
)
2711 /* Fill background with a stipple pattern. */
2712 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2713 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2714 s
->y
+ s
->face
->box_line_width
,
2715 s
->background_width
,
2716 s
->height
- 2 * s
->face
->box_line_width
);
2717 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2718 s
->background_filled_p
= 1;
2720 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
2721 || s
->font_not_found_p
2722 || s
->extends_to_end_of_line_p
2726 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
2727 s
->background_width
,
2728 s
->height
- 2 * s
->face
->box_line_width
);
2729 s
->background_filled_p
= 1;
2735 /* Draw the foreground of glyph string S. */
2738 x_draw_glyph_string_foreground (s
)
2739 struct glyph_string
*s
;
2743 /* If first glyph of S has a left box line, start drawing the text
2744 of S to the right of that box line. */
2745 if (s
->face
->box
!= FACE_NO_BOX
2746 && s
->first_glyph
->left_box_line_p
)
2747 x
= s
->x
+ s
->face
->box_line_width
;
2751 if (s
->cmpcharp
== NULL
)
2753 /* Not a composite character. Draw characters of S as
2754 rectangles if S's font could not be loaded. */
2755 if (s
->font_not_found_p
)
2757 for (i
= 0; i
< s
->nchars
; ++i
)
2759 struct glyph
*g
= s
->first_glyph
+ i
;
2760 XDrawRectangle (s
->display
, s
->window
,
2761 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
2763 x
+= g
->pixel_width
;
2768 char *char1b
= (char *) s
->char2b
;
2770 /* If we can use 8-bit functions, condense S->char2b. */
2772 for (i
= 0; i
< s
->nchars
; ++i
)
2773 char1b
[i
] = s
->char2b
[i
].byte2
;
2775 /* Draw text with XDrawString if background has already been
2776 filled. Otherwise, use XDrawImageString. (Note that
2777 XDrawImageString is usually faster than XDrawString.)
2778 Always use XDrawImageString when drawing the cursor so
2779 that there is no chance that characters under a box
2780 cursor are invisible. */
2781 if (s
->for_overlaps_p
2782 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
2784 /* Draw characters with 16-bit or 8-bit functions. */
2786 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
, s
->ybase
,
2787 s
->char2b
, s
->nchars
);
2789 XDrawString (s
->display
, s
->window
, s
->gc
, x
, s
->ybase
,
2795 XDrawImageString16 (s
->display
, s
->window
, s
->gc
,
2796 x
, s
->ybase
, s
->char2b
, s
->nchars
);
2798 XDrawImageString (s
->display
, s
->window
, s
->gc
,
2799 x
, s
->ybase
, char1b
, s
->nchars
);
2805 /* S is a glyph string for a composite character. S->gidx is the
2806 index of the first character drawn in the vector
2807 S->cmpcharp->glyph. S->gidx == 0 means we are drawing the
2808 very first component character of a composite char. */
2810 /* Draw a single rectangle for the composite character if S's
2811 font could not be loaded. */
2812 if (s
->font_not_found_p
&& s
->gidx
== 0)
2813 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
2814 s
->width
- 1, s
->height
- 1);
2818 int relative_compose
, default_ascent
, i
;
2819 int highest
= 0, lowest
= 0;
2821 /* The value of font_info my be null if we couldn't find it
2822 in x_get_char_face_and_encoding. */
2823 if (s
->cmpcharp
->cmp_rule
== NULL
&& s
->font_info
)
2825 relative_compose
= s
->font_info
->relative_compose
;
2826 default_ascent
= s
->font_info
->default_ascent
;
2829 relative_compose
= default_ascent
= 0;
2831 if ((s
->cmpcharp
->cmp_rule
|| relative_compose
)
2834 /* This is the first character. Initialize variables.
2835 Highest is the highest position of glyphs ever
2836 written, lowest the lowest position. */
2838 int first_ch
= s
->first_glyph
->u
.ch
.code
;
2841 && CHAR_TABLE_P (Vuse_default_ascent
)
2842 && !NILP (Faref (Vuse_default_ascent
, first_ch
)))
2844 highest
= default_ascent
;
2849 pcm
= PER_CHAR_METRIC (s
->font
, s
->char2b
);
2850 highest
= pcm
->ascent
+ 1;
2851 lowest
= - pcm
->descent
;
2854 if (s
->cmpcharp
->cmp_rule
)
2855 x_offset
= (s
->cmpcharp
->col_offset
[0]
2856 * FONT_WIDTH (s
->f
->output_data
.x
->font
));
2858 /* Draw the first character at the normal position. */
2859 XDrawString16 (s
->display
, s
->window
, s
->gc
,
2861 s
->ybase
, s
->char2b
, 1);
2868 for (; i
< s
->nchars
; i
++, ++s
->gidx
)
2870 int x_offset
= 0, y_offset
= 0;
2872 if (relative_compose
)
2874 pcm
= PER_CHAR_METRIC (s
->font
, s
->char2b
+ i
);
2875 if (NILP (Vignore_relative_composition
)
2876 || NILP (Faref (Vignore_relative_composition
,
2877 make_number (s
->cmpcharp
->glyph
[s
->gidx
]))))
2879 if (- pcm
->descent
>= relative_compose
)
2881 /* Draw above the current glyphs. */
2882 y_offset
= highest
+ pcm
->descent
;
2883 highest
+= pcm
->ascent
+ pcm
->descent
;
2885 else if (pcm
->ascent
<= 0)
2887 /* Draw beneath the current glyphs. */
2888 y_offset
= lowest
- pcm
->ascent
;
2889 lowest
-= pcm
->ascent
+ pcm
->descent
;
2894 /* Draw the glyph at normal position. If
2895 it sticks out of HIGHEST or LOWEST,
2896 update them appropriately. */
2897 if (pcm
->ascent
> highest
)
2898 highest
= pcm
->ascent
;
2899 else if (- pcm
->descent
< lowest
)
2900 lowest
= - pcm
->descent
;
2903 else if (s
->cmpcharp
->cmp_rule
)
2905 int gref
= (s
->cmpcharp
->cmp_rule
[s
->gidx
] - 0xA0) / 9;
2906 int nref
= (s
->cmpcharp
->cmp_rule
[s
->gidx
] - 0xA0) % 9;
2909 /* Re-encode GREF and NREF so that they specify
2910 only Y-axis information:
2911 0:top, 1:base, 2:bottom, 3:center */
2912 gref
= gref
/ 3 + (gref
== 4) * 2;
2913 nref
= nref
/ 3 + (nref
== 4) * 2;
2915 pcm
= PER_CHAR_METRIC (s
->font
, s
->char2b
+ i
);
2916 bottom
= ((gref
== 0 ? highest
: gref
== 1 ? 0
2917 : gref
== 2 ? lowest
2918 : (highest
+ lowest
) / 2)
2919 - (nref
== 0 ? pcm
->ascent
+ pcm
->descent
2920 : nref
== 1 ? pcm
->descent
: nref
== 2 ? 0
2921 : (pcm
->ascent
+ pcm
->descent
) / 2));
2922 top
= bottom
+ (pcm
->ascent
+ pcm
->descent
);
2925 if (bottom
< lowest
)
2927 y_offset
= bottom
+ pcm
->descent
;
2928 x_offset
= (s
->cmpcharp
->col_offset
[s
->gidx
]
2929 * FONT_WIDTH (FRAME_FONT (s
->f
)));
2932 XDrawString16 (s
->display
, s
->window
, s
->gc
,
2933 x
+ x_offset
, s
->ybase
- y_offset
,
2941 #ifdef USE_X_TOOLKIT
2943 /* Allocate the color COLOR->pixel on the screen and display of
2944 widget WIDGET in colormap CMAP. If an exact match cannot be
2945 allocated, try the nearest color available. Value is non-zero
2946 if successful. This is called from lwlib. */
2949 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
2955 struct x_display_info
*dpyinfo
;
2958 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
2960 /* Find the top-level shell of the widget. Note that this function
2961 can be called when the widget is not yet realized, so XtWindow
2962 (widget) == 0. That's the reason we can't simply use
2963 x_any_window_to_frame. */
2964 while (!XtIsTopLevelShell (widget
))
2965 widget
= XtParent (widget
);
2967 /* Look for a frame with that top-level widget. Allocate the color
2968 on that frame to get the right gamma correction value. */
2969 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
2970 if (GC_FRAMEP (XCAR (tail
))
2971 && (f
= XFRAME (XCAR (tail
)),
2972 (f
->output_data
.nothing
!= 1
2973 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
2974 && f
->output_data
.x
->widget
== widget
)
2975 return x_alloc_nearest_color (f
, cmap
, color
);
2980 #endif /* USE_X_TOOLKIT */
2983 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
2984 CMAP. If an exact match can't be allocated, try the nearest color
2985 available. Value is non-zero if successful. Set *COLOR to the
2989 x_alloc_nearest_color (f
, cmap
, color
)
2994 Display
*display
= FRAME_X_DISPLAY (f
);
2995 Screen
*screen
= FRAME_X_SCREEN (f
);
2998 gamma_correct (f
, color
);
2999 rc
= XAllocColor (display
, cmap
, color
);
3002 /* If we got to this point, the colormap is full, so we're going
3003 to try to get the next closest color. The algorithm used is
3004 a least-squares matching, which is what X uses for closest
3005 color matching with StaticColor visuals. */
3007 unsigned long nearest_delta
= ~0;
3008 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3009 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3011 for (i
= 0; i
< ncells
; ++i
)
3013 XQueryColors (display
, cmap
, cells
, ncells
);
3015 for (nearest
= i
= 0; i
< ncells
; ++i
)
3017 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3018 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3019 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3020 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3022 if (delta
< nearest_delta
)
3025 nearest_delta
= delta
;
3029 color
->red
= cells
[nearest
].red
;
3030 color
->green
= cells
[nearest
].green
;
3031 color
->blue
= cells
[nearest
].blue
;
3032 rc
= XAllocColor (display
, cmap
, color
);
3039 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3040 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3041 If this produces the same color as PIXEL, try a color where all RGB
3042 values have DELTA added. Return the allocated color in *PIXEL.
3043 DISPLAY is the X display, CMAP is the colormap to operate on.
3044 Value is non-zero if successful. */
3047 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3051 unsigned long *pixel
;
3058 /* Get RGB color values. */
3059 color
.pixel
= *pixel
;
3060 XQueryColor (display
, cmap
, &color
);
3062 /* Change RGB values by specified FACTOR. Avoid overflow! */
3063 xassert (factor
>= 0);
3064 new.red
= min (0xffff, factor
* color
.red
);
3065 new.green
= min (0xffff, factor
* color
.green
);
3066 new.blue
= min (0xffff, factor
* color
.blue
);
3068 /* Try to allocate the color. */
3069 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3072 if (new.pixel
== *pixel
)
3074 /* If we end up with the same color as before, try adding
3075 delta to the RGB values. */
3076 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
3078 /* If display has an immutable color map, freeing colors is
3079 not necessary and some servers don't allow it. So don't
3081 if (class != StaticColor
3082 && class != StaticGray
3083 && class != TrueColor
)
3084 XFreeColors (display
, cmap
, &new.pixel
, 1, 0);
3086 new.red
= min (0xffff, delta
+ color
.red
);
3087 new.green
= min (0xffff, delta
+ color
.green
);
3088 new.blue
= min (0xffff, delta
+ color
.blue
);
3089 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3100 /* Set up the foreground color for drawing relief lines of glyph
3101 string S. RELIEF is a pointer to a struct relief containing the GC
3102 with which lines will be drawn. Use a color that is FACTOR or
3103 DELTA lighter or darker than the relief's background which is found
3104 in S->f->output_data.x->relief_background. If such a color cannot
3105 be allocated, use DEFAULT_PIXEL, instead. */
3108 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3110 struct relief
*relief
;
3113 unsigned long default_pixel
;
3116 struct x_output
*di
= f
->output_data
.x
;
3117 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3118 unsigned long pixel
;
3119 unsigned long background
= di
->relief_background
;
3120 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
3121 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3122 Display
*dpy
= FRAME_X_DISPLAY (f
);
3124 xgcv
.graphics_exposures
= False
;
3125 xgcv
.line_width
= 1;
3127 /* Free previously allocated color. The color cell will be reused
3128 when it has been freed as many times as it was allocated, so this
3129 doesn't affect faces using the same colors. */
3131 && relief
->allocated_p
)
3133 /* If display has an immutable color map, freeing colors is not
3134 necessary and some servers don't allow it. So don't do it. */
3135 int class = dpyinfo
->visual
->class;
3136 if (class != StaticColor
3137 && class != StaticGray
3138 && class != TrueColor
)
3139 XFreeColors (dpy
, cmap
, &relief
->pixel
, 1, 0);
3140 relief
->allocated_p
= 0;
3143 /* Allocate new color. */
3144 xgcv
.foreground
= default_pixel
;
3146 if (dpyinfo
->n_planes
!= 1
3147 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3149 relief
->allocated_p
= 1;
3150 xgcv
.foreground
= relief
->pixel
= pixel
;
3153 if (relief
->gc
== 0)
3155 xgcv
.stipple
= dpyinfo
->gray
;
3157 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3160 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3164 /* Set up colors for the relief lines around glyph string S. */
3167 x_setup_relief_colors (s
)
3168 struct glyph_string
*s
;
3170 struct x_output
*di
= s
->f
->output_data
.x
;
3171 unsigned long color
;
3173 if (s
->face
->use_box_color_for_shadows_p
)
3174 color
= s
->face
->box_color
;
3179 /* Get the background color of the face. */
3180 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3181 color
= xgcv
.background
;
3184 if (di
->white_relief
.gc
== 0
3185 || color
!= di
->relief_background
)
3187 di
->relief_background
= color
;
3188 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3189 WHITE_PIX_DEFAULT (s
->f
));
3190 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3191 BLACK_PIX_DEFAULT (s
->f
));
3196 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3197 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3198 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3199 relief. LEFT_P non-zero means draw a relief on the left side of
3200 the rectangle. RIGHT_P non-zero means draw a relief on the right
3201 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3205 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3206 raised_p
, left_p
, right_p
, clip_rect
)
3208 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3209 XRectangle
*clip_rect
;
3215 gc
= f
->output_data
.x
->white_relief
.gc
;
3217 gc
= f
->output_data
.x
->black_relief
.gc
;
3218 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3221 for (i
= 0; i
< width
; ++i
)
3222 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3223 left_x
+ i
* left_p
, top_y
+ i
,
3224 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3228 for (i
= 0; i
< width
; ++i
)
3229 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3230 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3232 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3234 gc
= f
->output_data
.x
->black_relief
.gc
;
3236 gc
= f
->output_data
.x
->white_relief
.gc
;
3237 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3240 for (i
= 0; i
< width
; ++i
)
3241 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3242 left_x
+ i
* left_p
, bottom_y
- i
,
3243 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3247 for (i
= 0; i
< width
; ++i
)
3248 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3249 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3251 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3255 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3256 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3257 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3258 left side of the rectangle. RIGHT_P non-zero means draw a line
3259 on the right side of the rectangle. CLIP_RECT is the clipping
3260 rectangle to use when drawing. */
3263 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3264 left_p
, right_p
, clip_rect
)
3265 struct glyph_string
*s
;
3266 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3267 XRectangle
*clip_rect
;
3271 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3272 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3273 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3276 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3277 left_x
, top_y
, right_x
- left_x
, width
);
3281 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3282 left_x
, top_y
, width
, bottom_y
- top_y
);
3285 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3286 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3290 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3291 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3293 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3294 XSetClipMask (s
->display
, s
->gc
, None
);
3298 /* Draw a box around glyph string S. */
3301 x_draw_glyph_string_box (s
)
3302 struct glyph_string
*s
;
3304 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3305 int left_p
, right_p
;
3306 struct glyph
*last_glyph
;
3307 XRectangle clip_rect
;
3309 last_x
= window_box_right (s
->w
, s
->area
);
3310 if (s
->row
->full_width_p
3311 && !s
->w
->pseudo_window_p
)
3313 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3314 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3315 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3318 /* The glyph that may have a right box line. */
3319 last_glyph
= (s
->cmpcharp
|| s
->img
3321 : s
->first_glyph
+ s
->nchars
- 1);
3323 width
= s
->face
->box_line_width
;
3324 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3326 right_x
= ((s
->row
->full_width_p
3328 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3330 bottom_y
= top_y
+ s
->height
- 1;
3332 left_p
= (s
->first_glyph
->left_box_line_p
3333 || (s
->hl
== DRAW_MOUSE_FACE
3335 || s
->prev
->hl
!= s
->hl
)));
3336 right_p
= (last_glyph
->right_box_line_p
3337 || (s
->hl
== DRAW_MOUSE_FACE
3339 || s
->next
->hl
!= s
->hl
)));
3341 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3343 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3344 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3345 left_p
, right_p
, &clip_rect
);
3348 x_setup_relief_colors (s
);
3349 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3350 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3355 /* Draw foreground of image glyph string S. */
3358 x_draw_image_foreground (s
)
3359 struct glyph_string
*s
;
3362 int y
= s
->ybase
- IMAGE_ASCENT (s
->img
);
3364 /* If first glyph of S has a left box line, start drawing it to the
3365 right of that line. */
3366 if (s
->face
->box
!= FACE_NO_BOX
3367 && s
->first_glyph
->left_box_line_p
)
3368 x
= s
->x
+ s
->face
->box_line_width
;
3372 /* If there is a margin around the image, adjust x- and y-position
3376 x
+= s
->img
->margin
;
3377 y
+= s
->img
->margin
;
3384 /* We can't set both a clip mask and use XSetClipRectangles
3385 because the latter also sets a clip mask. We also can't
3386 trust on the shape extension to be available
3387 (XShapeCombineRegion). So, compute the rectangle to draw
3389 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3392 XRectangle clip_rect
, image_rect
, r
;
3394 xgcv
.clip_mask
= s
->img
->mask
;
3395 xgcv
.clip_x_origin
= x
;
3396 xgcv
.clip_y_origin
= y
;
3397 xgcv
.function
= GXcopy
;
3398 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3400 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3403 image_rect
.width
= s
->img
->width
;
3404 image_rect
.height
= s
->img
->height
;
3405 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3406 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3407 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3411 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3412 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3414 /* When the image has a mask, we can expect that at
3415 least part of a mouse highlight or a block cursor will
3416 be visible. If the image doesn't have a mask, make
3417 a block cursor visible by drawing a rectangle around
3418 the image. I believe it's looking better if we do
3419 nothing here for mouse-face. */
3420 if (s
->hl
== DRAW_CURSOR
)
3421 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3422 s
->img
->width
- 1, s
->img
->height
- 1);
3426 /* Draw a rectangle if image could not be loaded. */
3427 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3428 s
->img
->width
- 1, s
->img
->height
- 1);
3432 /* Draw a relief around the image glyph string S. */
3435 x_draw_image_relief (s
)
3436 struct glyph_string
*s
;
3438 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3441 int y
= s
->ybase
- IMAGE_ASCENT (s
->img
);
3443 /* If first glyph of S has a left box line, start drawing it to the
3444 right of that line. */
3445 if (s
->face
->box
!= FACE_NO_BOX
3446 && s
->first_glyph
->left_box_line_p
)
3447 x
= s
->x
+ s
->face
->box_line_width
;
3451 /* If there is a margin around the image, adjust x- and y-position
3455 x
+= s
->img
->margin
;
3456 y
+= s
->img
->margin
;
3459 if (s
->hl
== DRAW_IMAGE_SUNKEN
3460 || s
->hl
== DRAW_IMAGE_RAISED
)
3462 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3463 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3467 thick
= abs (s
->img
->relief
);
3468 raised_p
= s
->img
->relief
> 0;
3473 x1
= x
+ s
->img
->width
+ thick
- 1;
3474 y1
= y
+ s
->img
->height
+ thick
- 1;
3476 x_setup_relief_colors (s
);
3477 x_get_glyph_string_clip_rect (s
, &r
);
3478 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3482 /* Draw the foreground of image glyph string S to PIXMAP. */
3485 x_draw_image_foreground_1 (s
, pixmap
)
3486 struct glyph_string
*s
;
3490 int y
= s
->ybase
- s
->y
- IMAGE_ASCENT (s
->img
);
3492 /* If first glyph of S has a left box line, start drawing it to the
3493 right of that line. */
3494 if (s
->face
->box
!= FACE_NO_BOX
3495 && s
->first_glyph
->left_box_line_p
)
3496 x
= s
->face
->box_line_width
;
3500 /* If there is a margin around the image, adjust x- and y-position
3504 x
+= s
->img
->margin
;
3505 y
+= s
->img
->margin
;
3512 /* We can't set both a clip mask and use XSetClipRectangles
3513 because the latter also sets a clip mask. We also can't
3514 trust on the shape extension to be available
3515 (XShapeCombineRegion). So, compute the rectangle to draw
3517 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3521 xgcv
.clip_mask
= s
->img
->mask
;
3522 xgcv
.clip_x_origin
= x
;
3523 xgcv
.clip_y_origin
= y
;
3524 xgcv
.function
= GXcopy
;
3525 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3527 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3528 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3529 XSetClipMask (s
->display
, s
->gc
, None
);
3533 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3534 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3536 /* When the image has a mask, we can expect that at
3537 least part of a mouse highlight or a block cursor will
3538 be visible. If the image doesn't have a mask, make
3539 a block cursor visible by drawing a rectangle around
3540 the image. I believe it's looking better if we do
3541 nothing here for mouse-face. */
3542 if (s
->hl
== DRAW_CURSOR
)
3543 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3544 s
->img
->width
- 1, s
->img
->height
- 1);
3548 /* Draw a rectangle if image could not be loaded. */
3549 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3550 s
->img
->width
- 1, s
->img
->height
- 1);
3554 /* Draw part of the background of glyph string S. X, Y, W, and H
3555 give the rectangle to draw. */
3558 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3559 struct glyph_string
*s
;
3564 /* Fill background with a stipple pattern. */
3565 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3566 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3567 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3570 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3574 /* Draw image glyph string S.
3577 s->x +-------------------------
3580 | +-------------------------
3583 | | +-------------------
3589 x_draw_image_glyph_string (s
)
3590 struct glyph_string
*s
;
3593 int box_line_width
= s
->face
->box_line_width
;
3594 int margin
= s
->img
->margin
;
3596 Pixmap pixmap
= None
;
3598 height
= s
->height
- 2 * box_line_width
;
3600 /* Fill background with face under the image. Do it only if row is
3601 taller than image or if image has a clip mask to reduce
3603 s
->stippled_p
= s
->face
->stipple
!= 0;
3604 if (height
> s
->img
->height
3607 || s
->img
->pixmap
== 0
3608 || s
->width
!= s
->background_width
)
3610 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3611 x
= s
->x
+ box_line_width
;
3615 y
= s
->y
+ box_line_width
;
3619 /* Create a pixmap as large as the glyph string Fill it with
3620 the background color. Copy the image to it, using its
3621 mask. Copy the temporary pixmap to the display. */
3622 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3623 int depth
= DefaultDepthOfScreen (screen
);
3625 /* Create a pixmap as large as the glyph string. */
3626 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3627 s
->background_width
,
3630 /* Don't clip in the following because we're working on the
3632 XSetClipMask (s
->display
, s
->gc
, None
);
3634 /* Fill the pixmap with the background color/stipple. */
3637 /* Fill background with a stipple pattern. */
3638 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3639 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3640 0, 0, s
->background_width
, s
->height
);
3641 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3646 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3648 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3649 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3650 0, 0, s
->background_width
, s
->height
);
3651 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3655 /* Implementation idea: Is it possible to construct a mask?
3656 We could look at the color at the margins of the image, and
3657 say that this color is probably the background color of the
3659 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3661 s
->background_filled_p
= 1;
3664 /* Draw the foreground. */
3667 x_draw_image_foreground_1 (s
, pixmap
);
3668 x_set_glyph_string_clipping (s
);
3669 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
3670 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3671 XFreePixmap (s
->display
, pixmap
);
3674 x_draw_image_foreground (s
);
3676 /* If we must draw a relief around the image, do it. */
3678 || s
->hl
== DRAW_IMAGE_RAISED
3679 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3680 x_draw_image_relief (s
);
3684 /* Draw stretch glyph string S. */
3687 x_draw_stretch_glyph_string (s
)
3688 struct glyph_string
*s
;
3690 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3691 s
->stippled_p
= s
->face
->stipple
!= 0;
3693 if (s
->hl
== DRAW_CURSOR
3694 && !x_stretch_cursor_p
)
3696 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3697 as wide as the stretch glyph. */
3698 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
3701 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3703 /* Clear rest using the GC of the original non-cursor face. */
3704 if (width
< s
->background_width
)
3706 GC gc
= s
->face
->gc
;
3707 int x
= s
->x
+ width
, y
= s
->y
;
3708 int w
= s
->background_width
- width
, h
= s
->height
;
3711 x_get_glyph_string_clip_rect (s
, &r
);
3712 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
3714 if (s
->face
->stipple
)
3716 /* Fill background with a stipple pattern. */
3717 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3718 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3719 XSetFillStyle (s
->display
, gc
, FillSolid
);
3724 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
3725 XSetForeground (s
->display
, gc
, xgcv
.background
);
3726 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3727 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
3732 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
3735 s
->background_filled_p
= 1;
3739 /* Draw glyph string S. */
3742 x_draw_glyph_string (s
)
3743 struct glyph_string
*s
;
3745 /* If S draws into the background of its successor, draw the
3746 background of the successor first so that S can draw into it.
3747 This makes S->next use XDrawString instead of XDrawImageString. */
3748 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
3750 xassert (s
->next
->img
== NULL
);
3751 x_set_glyph_string_gc (s
->next
);
3752 x_set_glyph_string_clipping (s
->next
);
3753 x_draw_glyph_string_background (s
->next
, 1);
3756 /* Set up S->gc, set clipping and draw S. */
3757 x_set_glyph_string_gc (s
);
3758 x_set_glyph_string_clipping (s
);
3760 switch (s
->first_glyph
->type
)
3763 x_draw_image_glyph_string (s
);
3767 x_draw_stretch_glyph_string (s
);
3771 if (s
->for_overlaps_p
)
3772 s
->background_filled_p
= 1;
3774 x_draw_glyph_string_background (s
, 0);
3775 x_draw_glyph_string_foreground (s
);
3782 if (!s
->for_overlaps_p
)
3784 /* Draw underline. */
3785 if (s
->face
->underline_p
)
3787 unsigned long dy
, h
;
3789 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
3791 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
3794 if (s
->face
->underline_defaulted_p
)
3795 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3800 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3801 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3802 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3804 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3808 /* Draw overline. */
3809 if (s
->face
->overline_p
)
3811 unsigned long dy
= 0, h
= 1;
3813 if (s
->face
->overline_color_defaulted_p
)
3814 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3819 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3820 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3821 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3823 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3827 /* Draw strike-through. */
3828 if (s
->face
->strike_through_p
)
3830 unsigned long h
= 1;
3831 unsigned long dy
= (s
->height
- h
) / 2;
3833 if (s
->face
->strike_through_color_defaulted_p
)
3834 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3839 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3840 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3841 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3843 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3848 if (s
->face
->box
!= FACE_NO_BOX
)
3849 x_draw_glyph_string_box (s
);
3852 /* Reset clipping. */
3853 XSetClipMask (s
->display
, s
->gc
, None
);
3857 /* A work-list entry used during the construction of glyph_string
3858 structures for a composite character. */
3862 /* Pointer to composite char info defining has the composite
3863 character is drawn. */
3864 struct cmpchar_info
*cmpcharp
;
3866 /* Start index in compcharp->glyph[]. */
3869 /* Next in stack. */
3874 static void x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
3875 int, struct work
**,
3876 struct work
**, int));
3879 /* Load glyph string S with information from the top of *STACK for a
3880 composite character. FACE_ID is the id of the face in which S is
3881 drawn. *NEW is a pointer to a struct work not on the stack, that
3882 can be used if this function needs to push a new structure on the
3883 stack. If it uses it, *NEW is set to null. OVERLAPS_P non-zero
3884 means S should draw the foreground only, and use its lines physical
3885 height for clipping. */
3888 x_fill_composite_glyph_string (s
, face_id
, stack
, new, overlaps_p
)
3889 struct glyph_string
*s
;
3891 struct work
**stack
, **new;
3897 xassert (s
&& *new && *stack
);
3899 s
->for_overlaps_p
= 1;
3901 /* Pop the work stack. */
3903 *stack
= work
->next
;
3905 /* For all glyphs of cmpcharp->glyph, starting at the offset
3906 work->offset, until we reach the end of the definition or
3907 encounter another composite char, get the font and face to use,
3909 for (i
= work
->gidx
; i
< work
->cmpcharp
->glyph_len
; ++i
)
3911 c
= FAST_GLYPH_CHAR (work
->cmpcharp
->glyph
[i
]);
3912 if (CHAR_CHARSET (c
) == CHARSET_COMPOSITION
)
3914 s
->face
= x_get_char_face_and_encoding (s
->f
, c
, face_id
,
3915 s
->char2b
+ s
->nchars
, 1);
3916 s
->font
= s
->face
->font
;
3917 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
3921 /* If we find another composite char in the glyph definition of
3922 work->cmpcharp, put back the rest of the glyphs on the work
3923 stack, and make a new entry for the composite char. */
3924 if (i
< work
->cmpcharp
->glyph_len
)
3926 /* Push back an unprocessed rest of this glyph spec. */
3927 if (i
< work
->cmpcharp
->glyph_len
- 1)
3930 work
->next
= *stack
;
3936 /* Make an entry for the composite char on the work stack. */
3937 work
->cmpcharp
= cmpchar_table
[COMPOSITE_CHAR_ID (c
)];
3939 work
->next
= *stack
;
3943 /* The width of this glyph string equals the width of the first
3944 glyph. All characters are drawn at the same x-position. */
3945 s
->width
= s
->first_glyph
->pixel_width
;
3947 /* If the specified font could not be loaded, use the frame's
3948 default font, but record the fact that we couldn't load it in
3949 the glyph string so that we can draw rectangles for the
3950 characters of the glyph string. */
3951 if (s
->font
== NULL
)
3953 s
->font_not_found_p
= 1;
3954 s
->font
= FRAME_FONT (s
->f
);
3957 /* Adjust base line for subscript/superscript text. */
3958 s
->ybase
+= s
->first_glyph
->voffset
;
3960 xassert (s
->face
&& s
->face
->gc
);
3962 /* This glyph string must always be drawn with 16-bit functions. */
3967 /* Load glyph string S with a sequence of non-composite characters.
3968 FACE_ID is the face id of the string. START is the index of the
3969 first glyph to consider, END is the index of the last + 1.
3970 OVERLAPS_P non-zero means S should draw the foreground only, and
3971 use its lines physical height for clipping.
3973 Value is the index of the first glyph not in S. */
3976 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
3977 struct glyph_string
*s
;
3979 int start
, end
, overlaps_p
;
3981 struct glyph
*glyph
, *last
;
3984 xassert (s
->charset
!= CHARSET_COMPOSITION
);
3985 xassert (s
->f
== XFRAME (s
->w
->frame
));
3986 xassert (s
->nchars
== 0);
3987 xassert (start
>= 0 && end
> start
);
3989 s
->for_overlaps_p
= overlaps_p
,
3990 glyph
= s
->row
->glyphs
[s
->area
] + start
;
3991 last
= s
->row
->glyphs
[s
->area
] + end
;
3992 voffset
= glyph
->voffset
;
3995 && glyph
->type
== CHAR_GLYPH
3996 && glyph
->voffset
== voffset
3997 /* Same face id implies same charset, nowadays. */
3998 && glyph
->u
.ch
.face_id
== face_id
)
4000 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4001 s
->char2b
+ s
->nchars
);
4002 if (s
->char2b
[s
->nchars
].byte2
!= 0)
4006 xassert (s
->nchars
<= end
- start
);
4007 s
->width
+= glyph
->pixel_width
;
4011 s
->font
= s
->face
->font
;
4012 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4014 /* If the specified font could not be loaded, use the frame's font,
4015 but record the fact that we couldn't load it in
4016 S->font_not_found_p so that we can draw rectangles for the
4017 characters of the glyph string. */
4018 if (s
->font
== NULL
)
4020 s
->font_not_found_p
= 1;
4021 s
->font
= FRAME_FONT (s
->f
);
4024 /* Adjust base line for subscript/superscript text. */
4025 s
->ybase
+= voffset
;
4027 xassert (s
->face
&& s
->face
->gc
);
4028 return glyph
- s
->row
->glyphs
[s
->area
];
4032 /* Fill glyph string S from image glyph S->first_glyph. */
4035 x_fill_image_glyph_string (s
)
4036 struct glyph_string
*s
;
4038 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4039 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img
.id
);
4041 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->u
.img
.face_id
);
4042 s
->font
= s
->face
->font
;
4043 s
->width
= s
->first_glyph
->pixel_width
;
4045 /* Adjust base line for subscript/superscript text. */
4046 s
->ybase
+= s
->first_glyph
->voffset
;
4050 /* Fill glyph string S from stretch glyph S->first_glyph. */
4053 x_fill_stretch_glyph_string (s
)
4054 struct glyph_string
*s
;
4056 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4057 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->u
.stretch
.face_id
);
4058 s
->font
= s
->face
->font
;
4059 s
->width
= s
->first_glyph
->pixel_width
;
4061 /* Adjust base line for subscript/superscript text. */
4062 s
->ybase
+= s
->first_glyph
->voffset
;
4066 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4067 of XChar2b structures for S; it can't be allocated in
4068 x_init_glyph_string because it must be allocated via `alloca'. W
4069 is the window on which S is drawn. ROW and AREA are the glyph row
4070 and area within the row from which S is constructed. START is the
4071 index of the first glyph structure covered by S. HL is a
4072 face-override for drawing S. */
4075 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4076 struct glyph_string
*s
;
4079 struct glyph_row
*row
;
4080 enum glyph_row_area area
;
4082 enum draw_glyphs_face hl
;
4084 bzero (s
, sizeof *s
);
4086 s
->f
= XFRAME (w
->frame
);
4087 s
->display
= FRAME_X_DISPLAY (s
->f
);
4088 s
->window
= FRAME_X_WINDOW (s
->f
);
4093 s
->first_glyph
= row
->glyphs
[area
] + start
;
4094 s
->height
= row
->height
;
4095 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4097 /* Display the internal border below the tool-bar window. */
4098 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4099 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4101 s
->ybase
= s
->y
+ row
->ascent
;
4105 /* Set background width of glyph string S. START is the index of the
4106 first glyph following S. LAST_X is the right-most x-position + 1
4107 in the drawing area. */
4110 x_set_glyph_string_background_width (s
, start
, last_x
)
4111 struct glyph_string
*s
;
4115 /* If the face of this glyph string has to be drawn to the end of
4116 the drawing area, set S->extends_to_end_of_line_p. */
4117 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4119 if (start
== s
->row
->used
[s
->area
]
4120 && s
->hl
== DRAW_NORMAL_TEXT
4121 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4122 || s
->face
->background
!= default_face
->background
4123 || s
->face
->stipple
!= default_face
->stipple
))
4124 s
->extends_to_end_of_line_p
= 1;
4126 /* If S extends its face to the end of the line, set its
4127 background_width to the distance to the right edge of the drawing
4129 if (s
->extends_to_end_of_line_p
)
4130 s
->background_width
= last_x
- s
->x
+ 1;
4132 s
->background_width
= s
->width
;
4136 /* Add a glyph string for a stretch glyph to the list of strings
4137 between HEAD and TAIL. START is the index of the stretch glyph in
4138 row area AREA of glyph row ROW. END is the index of the last glyph
4139 in that glyph row area. X is the current output position assigned
4140 to the new glyph string constructed. HL overrides that face of the
4141 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4142 is the right-most x-position of the drawing area. */
4144 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4145 and below -- keep them on one line. */
4146 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4149 s = (struct glyph_string *) alloca (sizeof *s); \
4150 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4151 x_fill_stretch_glyph_string (s); \
4152 x_append_glyph_string (&HEAD, &TAIL, s); \
4159 /* Add a glyph string for an image glyph to the list of strings
4160 between HEAD and TAIL. START is the index of the image glyph in
4161 row area AREA of glyph row ROW. END is the index of the last glyph
4162 in that glyph row area. X is the current output position assigned
4163 to the new glyph string constructed. HL overrides that face of the
4164 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4165 is the right-most x-position of the drawing area. */
4167 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4170 s = (struct glyph_string *) alloca (sizeof *s); \
4171 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4172 x_fill_image_glyph_string (s); \
4173 x_append_glyph_string (&HEAD, &TAIL, s); \
4180 /* Add a glyph string for a sequence of character glyphs to the list
4181 of strings between HEAD and TAIL. START is the index of the first
4182 glyph in row area AREA of glyph row ROW that is part of the new
4183 glyph string. END is the index of the last glyph in that glyph row
4184 area. X is the current output position assigned to the new glyph
4185 string constructed. HL overrides that face of the glyph; e.g. it
4186 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4187 right-most x-position of the drawing area. */
4189 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4192 int c, charset, face_id; \
4195 c = (ROW)->glyphs[AREA][START].u.ch.code; \
4196 charset = CHAR_CHARSET (c); \
4197 face_id = (ROW)->glyphs[AREA][START].u.ch.face_id; \
4199 if (charset == CHARSET_COMPOSITION) \
4201 struct work *stack, *work, *new = NULL; \
4203 struct glyph_string *first_s = NULL; \
4205 /* Push an initial entry for character c on the stack. */ \
4207 work = (struct work *) alloca (sizeof *work); \
4208 work->cmpcharp = cmpchar_table[COMPOSITE_CHAR_ID (c)]; \
4210 work->next = stack; \
4213 /* While the stack is not empty, append glyph_strings \
4214 to head/tail for glyphs to draw. */ \
4217 s = (struct glyph_string *) alloca (sizeof *s); \
4218 char2b = (XChar2b *) alloca (stack->cmpcharp->glyph_len \
4219 * sizeof (XChar2b)); \
4220 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4221 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4222 s->cmpcharp = stack->cmpcharp; \
4223 s->gidx = stack->gidx; \
4224 s->charset = charset; \
4229 /* Don't draw the background except for the \
4230 first glyph string. */ \
4231 s->background_filled_p = n > 0; \
4237 new = (struct work *) alloca (sizeof *new); \
4238 x_fill_composite_glyph_string (s, face_id, &stack, \
4239 &new, OVERLAPS_P); \
4247 s = (struct glyph_string *) alloca (sizeof *s); \
4248 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4249 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4250 x_append_glyph_string (&HEAD, &TAIL, s); \
4251 s->charset = charset; \
4253 START = x_fill_glyph_string (s, face_id, START, END, \
4260 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4261 of AREA of glyph row ROW on window W between indices START and END.
4262 HL overrides the face for drawing glyph strings, e.g. it is
4263 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4264 x-positions of the drawing area.
4266 This is an ugly monster macro construct because we must use alloca
4267 to allocate glyph strings (because x_draw_glyphs can be called
4270 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4273 HEAD = TAIL = NULL; \
4274 while (START < END) \
4276 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4277 switch (first_glyph->type) \
4280 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4281 TAIL, HL, X, LAST_X, \
4285 case STRETCH_GLYPH: \
4286 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4287 HEAD, TAIL, HL, X, LAST_X); \
4291 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4292 TAIL, HL, X, LAST_X); \
4299 x_set_glyph_string_background_width (s, START, LAST_X); \
4306 /* Draw glyphs between START and END in AREA of ROW on window W,
4307 starting at x-position X. X is relative to AREA in W. HL is a
4308 face-override with the following meaning:
4310 DRAW_NORMAL_TEXT draw normally
4311 DRAW_CURSOR draw in cursor face
4312 DRAW_MOUSE_FACE draw in mouse face.
4313 DRAW_INVERSE_VIDEO draw in mode line face
4314 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4315 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4317 If REAL_START is non-null, return in *REAL_START the real starting
4318 position for display. This can be different from START in case
4319 overlapping glyphs must be displayed. If REAL_END is non-null,
4320 return in *REAL_END the real end position for display. This can be
4321 different from END in case overlapping glyphs must be displayed.
4323 If OVERLAPS_P is non-zero, draw only the foreground of characters
4324 and clip to the physical height of ROW.
4326 Value is the x-position reached, relative to AREA of W. */
4329 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4333 struct glyph_row
*row
;
4334 enum glyph_row_area area
;
4336 enum draw_glyphs_face hl
;
4337 int *real_start
, *real_end
;
4340 struct glyph_string
*head
, *tail
;
4341 struct glyph_string
*s
;
4342 int last_x
, area_width
;
4346 /* Let's rather be paranoid than getting a SEGV. */
4347 start
= max (0, start
);
4348 end
= min (end
, row
->used
[area
]);
4350 *real_start
= start
;
4354 /* Translate X to frame coordinates. Set last_x to the right
4355 end of the drawing area. */
4356 if (row
->full_width_p
)
4358 /* X is relative to the left edge of W, without scroll bars
4360 struct frame
*f
= XFRAME (w
->frame
);
4361 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4362 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4365 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4366 last_x
= window_left_x
+ area_width
;
4368 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4370 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4371 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4377 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4378 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4382 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4383 area_width
= window_box_width (w
, area
);
4384 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4387 /* Build a doubly-linked list of glyph_string structures between
4388 head and tail from what we have to draw. Note that the macro
4389 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4390 the reason we use a separate variable `i'. */
4392 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4395 x_reached
= tail
->x
+ tail
->background_width
;
4399 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4400 the row, redraw some glyphs in front or following the glyph
4401 strings built above. */
4402 if (!overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4405 struct glyph_string
*h
, *t
;
4407 /* Compute overhangs for all glyph strings. */
4408 for (s
= head
; s
; s
= s
->next
)
4409 x_compute_glyph_string_overhangs (s
);
4411 /* Prepend glyph strings for glyphs in front of the first glyph
4412 string that are overwritten because of the first glyph
4413 string's left overhang. The background of all strings
4414 prepended must be drawn because the first glyph string
4416 i
= x_left_overwritten (head
);
4420 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4421 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4425 *real_start
= start
;
4426 x_compute_overhangs_and_x (t
, head
->x
, 1);
4427 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4430 /* Prepend glyph strings for glyphs in front of the first glyph
4431 string that overwrite that glyph string because of their
4432 right overhang. For these strings, only the foreground must
4433 be drawn, because it draws over the glyph string at `head'.
4434 The background must not be drawn because this would overwrite
4435 right overhangs of preceding glyphs for which no glyph
4437 i
= x_left_overwriting (head
);
4440 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4441 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4443 for (s
= h
; s
; s
= s
->next
)
4444 s
->background_filled_p
= 1;
4447 x_compute_overhangs_and_x (t
, head
->x
, 1);
4448 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4451 /* Append glyphs strings for glyphs following the last glyph
4452 string tail that are overwritten by tail. The background of
4453 these strings has to be drawn because tail's foreground draws
4455 i
= x_right_overwritten (tail
);
4458 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4459 DRAW_NORMAL_TEXT
, x
, last_x
,
4461 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4462 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4467 /* Append glyph strings for glyphs following the last glyph
4468 string tail that overwrite tail. The foreground of such
4469 glyphs has to be drawn because it writes into the background
4470 of tail. The background must not be drawn because it could
4471 paint over the foreground of following glyphs. */
4472 i
= x_right_overwriting (tail
);
4475 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4476 DRAW_NORMAL_TEXT
, x
, last_x
,
4478 for (s
= h
; s
; s
= s
->next
)
4479 s
->background_filled_p
= 1;
4480 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4481 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4487 /* Draw all strings. */
4488 for (s
= head
; s
; s
= s
->next
)
4489 x_draw_glyph_string (s
);
4491 /* Value is the x-position up to which drawn, relative to AREA of W.
4492 This doesn't include parts drawn because of overhangs. */
4493 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4494 if (!row
->full_width_p
)
4496 if (area
> LEFT_MARGIN_AREA
)
4497 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4498 if (area
> TEXT_AREA
)
4499 x_reached
-= window_box_width (w
, TEXT_AREA
);
4505 /* Fix the display of area AREA of overlapping row ROW in window W. */
4508 x_fix_overlapping_area (w
, row
, area
)
4510 struct glyph_row
*row
;
4511 enum glyph_row_area area
;
4517 if (area
== LEFT_MARGIN_AREA
)
4519 else if (area
== TEXT_AREA
)
4520 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4522 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4523 + window_box_width (w
, TEXT_AREA
));
4525 for (i
= 0; i
< row
->used
[area
];)
4527 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4529 int start
= i
, start_x
= x
;
4533 x
+= row
->glyphs
[area
][i
].pixel_width
;
4536 while (i
< row
->used
[area
]
4537 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4539 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4541 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4546 x
+= row
->glyphs
[area
][i
].pixel_width
;
4555 /* Output LEN glyphs starting at START at the nominal cursor position.
4556 Advance the nominal cursor over the text. The global variable
4557 updated_window contains the window being updated, updated_row is
4558 the glyph row being updated, and updated_area is the area of that
4559 row being updated. */
4562 x_write_glyphs (start
, len
)
4563 struct glyph
*start
;
4566 int x
, hpos
, real_start
, real_end
;
4568 xassert (updated_window
&& updated_row
);
4573 hpos
= start
- updated_row
->glyphs
[updated_area
];
4574 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4575 updated_row
, updated_area
,
4577 (updated_row
->inverse_p
4578 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4579 &real_start
, &real_end
, 0);
4581 /* If we drew over the cursor, note that it is not visible any more. */
4582 note_overwritten_text_cursor (updated_window
, real_start
,
4583 real_end
- real_start
);
4587 /* Advance the output cursor. */
4588 output_cursor
.hpos
+= len
;
4589 output_cursor
.x
= x
;
4593 /* Insert LEN glyphs from START at the nominal cursor position. */
4596 x_insert_glyphs (start
, len
)
4597 struct glyph
*start
;
4602 int line_height
, shift_by_width
, shifted_region_width
;
4603 struct glyph_row
*row
;
4604 struct glyph
*glyph
;
4605 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4607 xassert (updated_window
&& updated_row
);
4610 f
= XFRAME (WINDOW_FRAME (w
));
4612 /* Get the height of the line we are in. */
4614 line_height
= row
->height
;
4616 /* Get the width of the glyphs to insert. */
4618 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4619 shift_by_width
+= glyph
->pixel_width
;
4621 /* Get the width of the region to shift right. */
4622 shifted_region_width
= (window_box_width (w
, updated_area
)
4627 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4628 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4629 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4630 f
->output_data
.x
->normal_gc
,
4632 shifted_region_width
, line_height
,
4633 frame_x
+ shift_by_width
, frame_y
);
4635 /* Write the glyphs. */
4636 hpos
= start
- row
->glyphs
[updated_area
];
4637 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4638 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4639 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4641 /* Advance the output cursor. */
4642 output_cursor
.hpos
+= len
;
4643 output_cursor
.x
+= shift_by_width
;
4648 /* Delete N glyphs at the nominal cursor position. Not implemented
4659 /* Erase the current text line from the nominal cursor position
4660 (inclusive) to pixel column TO_X (exclusive). The idea is that
4661 everything from TO_X onward is already erased.
4663 TO_X is a pixel position relative to updated_area of
4664 updated_window. TO_X == -1 means clear to the end of this area. */
4667 x_clear_end_of_line (to_x
)
4671 struct window
*w
= updated_window
;
4672 int max_x
, min_y
, max_y
;
4673 int from_x
, from_y
, to_y
;
4675 xassert (updated_window
&& updated_row
);
4676 f
= XFRAME (w
->frame
);
4678 if (updated_row
->full_width_p
)
4680 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4681 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4682 && !w
->pseudo_window_p
)
4683 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4686 max_x
= window_box_width (w
, updated_area
);
4687 max_y
= window_text_bottom_y (w
);
4689 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
4690 of window. For TO_X > 0, truncate to end of drawing area. */
4696 to_x
= min (to_x
, max_x
);
4698 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
4700 /* Notice if the cursor will be cleared by this operation. */
4701 if (!updated_row
->full_width_p
)
4702 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
4704 from_x
= output_cursor
.x
;
4706 /* Translate to frame coordinates. */
4707 if (updated_row
->full_width_p
)
4709 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
4710 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
4714 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
4715 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
4718 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
4719 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
4720 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
4722 /* Prevent inadvertently clearing to end of the X window. */
4723 if (to_x
> from_x
&& to_y
> from_y
)
4726 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4727 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
4734 /* Clear entire frame. If updating_frame is non-null, clear that
4735 frame. Otherwise clear the selected frame. */
4745 f
= SELECTED_FRAME ();
4747 /* Clearing the frame will erase any cursor, so mark them all as no
4749 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4750 output_cursor
.hpos
= output_cursor
.vpos
= 0;
4751 output_cursor
.x
= -1;
4753 /* We don't set the output cursor here because there will always
4754 follow an explicit cursor_to. */
4756 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
4758 /* We have to clear the scroll bars, too. If we have changed
4759 colors or something like that, then they should be notified. */
4760 x_scroll_bar_clear (f
);
4762 XFlush (FRAME_X_DISPLAY (f
));
4768 /* Invert the middle quarter of the frame for .15 sec. */
4770 /* We use the select system call to do the waiting, so we have to make
4771 sure it's available. If it isn't, we just won't do visual bells. */
4773 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4776 /* Subtract the `struct timeval' values X and Y, storing the result in
4777 *RESULT. Return 1 if the difference is negative, otherwise 0. */
4780 timeval_subtract (result
, x
, y
)
4781 struct timeval
*result
, x
, y
;
4783 /* Perform the carry for the later subtraction by updating y. This
4784 is safer because on some systems the tv_sec member is unsigned. */
4785 if (x
.tv_usec
< y
.tv_usec
)
4787 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
4788 y
.tv_usec
-= 1000000 * nsec
;
4792 if (x
.tv_usec
- y
.tv_usec
> 1000000)
4794 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
4795 y
.tv_usec
+= 1000000 * nsec
;
4799 /* Compute the time remaining to wait. tv_usec is certainly
4801 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
4802 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
4804 /* Return indication of whether the result should be considered
4806 return x
.tv_sec
< y
.tv_sec
;
4818 /* Create a GC that will use the GXxor function to flip foreground
4819 pixels into background pixels. */
4823 values
.function
= GXxor
;
4824 values
.foreground
= (f
->output_data
.x
->foreground_pixel
4825 ^ f
->output_data
.x
->background_pixel
);
4827 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4828 GCFunction
| GCForeground
, &values
);
4832 /* Get the height not including a menu bar widget. */
4833 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
4834 /* Height of each line to flash. */
4835 int flash_height
= FRAME_LINE_HEIGHT (f
);
4836 /* These will be the left and right margins of the rectangles. */
4837 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
4838 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
4842 /* Don't flash the area between a scroll bar and the frame
4843 edge it is next to. */
4844 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
4846 case vertical_scroll_bar_left
:
4847 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
4850 case vertical_scroll_bar_right
:
4851 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
4858 width
= flash_right
- flash_left
;
4860 /* If window is tall, flash top and bottom line. */
4861 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4863 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4865 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4866 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
4867 width
, flash_height
);
4868 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4870 (height
- flash_height
4871 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4872 width
, flash_height
);
4875 /* If it is short, flash it all. */
4876 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4877 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4878 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4883 struct timeval wakeup
;
4885 EMACS_GET_TIME (wakeup
);
4887 /* Compute time to wait until, propagating carry from usecs. */
4888 wakeup
.tv_usec
+= 150000;
4889 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
4890 wakeup
.tv_usec
%= 1000000;
4892 /* Keep waiting until past the time wakeup. */
4895 struct timeval timeout
;
4897 EMACS_GET_TIME (timeout
);
4899 /* In effect, timeout = wakeup - timeout.
4900 Break if result would be negative. */
4901 if (timeval_subtract (&timeout
, wakeup
, timeout
))
4904 /* Try to wait that long--but we might wake up sooner. */
4905 select (0, NULL
, NULL
, NULL
, &timeout
);
4909 /* If window is tall, flash top and bottom line. */
4910 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4912 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4914 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4915 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
4916 width
, flash_height
);
4917 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4919 (height
- flash_height
4920 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4921 width
, flash_height
);
4924 /* If it is short, flash it all. */
4925 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4926 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4927 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4929 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
4937 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
4940 /* Make audible bell. */
4945 struct frame
*f
= SELECTED_FRAME ();
4947 if (FRAME_X_DISPLAY (f
))
4949 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4956 XBell (FRAME_X_DISPLAY (f
), 0);
4957 XFlush (FRAME_X_DISPLAY (f
));
4964 /* Specify how many text lines, from the top of the window,
4965 should be affected by insert-lines and delete-lines operations.
4966 This, and those operations, are used only within an update
4967 that is bounded by calls to x_update_begin and x_update_end. */
4970 XTset_terminal_window (n
)
4973 /* This function intentionally left blank. */
4978 /***********************************************************************
4980 ***********************************************************************/
4982 /* Perform an insert-lines or delete-lines operation, inserting N
4983 lines or deleting -N lines at vertical position VPOS. */
4986 x_ins_del_lines (vpos
, n
)
4993 /* Scroll part of the display as described by RUN. */
4996 x_scroll_run (w
, run
)
5000 struct frame
*f
= XFRAME (w
->frame
);
5001 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5003 /* Get frame-relative bounding box of the text display area of W,
5004 without mode lines. Include in this box the flags areas to the
5005 left and right of W. */
5006 window_box (w
, -1, &x
, &y
, &width
, &height
);
5007 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5008 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5010 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5011 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5012 bottom_y
= y
+ height
;
5016 /* Scrolling up. Make sure we don't copy part of the mode
5017 line at the bottom. */
5018 if (from_y
+ run
->height
> bottom_y
)
5019 height
= bottom_y
- from_y
;
5021 height
= run
->height
;
5025 /* Scolling down. Make sure we don't copy over the mode line.
5027 if (to_y
+ run
->height
> bottom_y
)
5028 height
= bottom_y
- to_y
;
5030 height
= run
->height
;
5035 /* Cursor off. Will be switched on again in x_update_window_end. */
5039 XCopyArea (FRAME_X_DISPLAY (f
),
5040 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5041 f
->output_data
.x
->normal_gc
,
5051 /***********************************************************************
5053 ***********************************************************************/
5055 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5056 corner of the exposed rectangle. W and H are width and height of
5057 the exposed area. All are pixel values. W or H zero means redraw
5058 the entire frame. */
5061 expose_frame (f
, x
, y
, w
, h
)
5067 TRACE ((stderr
, "expose_frame "));
5069 /* No need to redraw if frame will be redrawn soon. */
5070 if (FRAME_GARBAGED_P (f
))
5072 TRACE ((stderr
, " garbaged\n"));
5076 /* If basic faces haven't been realized yet, there is no point in
5077 trying to redraw anything. This can happen when we get an expose
5078 event while Emacs is starting, e.g. by moving another window. */
5079 if (FRAME_FACE_CACHE (f
) == NULL
5080 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5082 TRACE ((stderr
, " no faces\n"));
5086 if (w
== 0 || h
== 0)
5089 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5090 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5100 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5101 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5103 if (WINDOWP (f
->tool_bar_window
))
5105 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5106 XRectangle window_rect
;
5107 XRectangle intersection_rect
;
5108 int window_x
, window_y
, window_width
, window_height
;
5111 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5112 window_rect
.x
= window_x
;
5113 window_rect
.y
= window_y
;
5114 window_rect
.width
= window_width
;
5115 window_rect
.height
= window_height
;
5117 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5118 expose_window (w
, &intersection_rect
);
5121 #ifndef USE_X_TOOLKIT
5122 if (WINDOWP (f
->menu_bar_window
))
5124 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5125 XRectangle window_rect
;
5126 XRectangle intersection_rect
;
5127 int window_x
, window_y
, window_width
, window_height
;
5130 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5131 window_rect
.x
= window_x
;
5132 window_rect
.y
= window_y
;
5133 window_rect
.width
= window_width
;
5134 window_rect
.height
= window_height
;
5136 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5137 expose_window (w
, &intersection_rect
);
5139 #endif /* not USE_X_TOOLKIT */
5143 /* Redraw (parts) of all windows in the window tree rooted at W that
5144 intersect R. R contains frame pixel coordinates. */
5147 expose_window_tree (w
, r
)
5153 if (!NILP (w
->hchild
))
5154 expose_window_tree (XWINDOW (w
->hchild
), r
);
5155 else if (!NILP (w
->vchild
))
5156 expose_window_tree (XWINDOW (w
->vchild
), r
);
5159 XRectangle window_rect
;
5160 XRectangle intersection_rect
;
5161 struct frame
*f
= XFRAME (w
->frame
);
5162 int window_x
, window_y
, window_width
, window_height
;
5164 /* Frame-relative pixel rectangle of W. */
5165 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5169 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5170 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5171 window_rect
.y
= window_y
;
5174 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5175 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5177 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5179 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5180 expose_window (w
, &intersection_rect
);
5183 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5188 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5189 which intersects rectangle R. R is in window-relative coordinates. */
5192 expose_area (w
, row
, r
, area
)
5194 struct glyph_row
*row
;
5196 enum glyph_row_area area
;
5199 struct glyph
*first
= row
->glyphs
[area
];
5200 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5204 /* Set x to the window-relative start position for drawing glyphs of
5205 AREA. The first glyph of the text area can be partially visible.
5206 The first glyphs of other areas cannot. */
5207 if (area
== LEFT_MARGIN_AREA
)
5209 else if (area
== TEXT_AREA
)
5210 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5212 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5213 + window_box_width (w
, TEXT_AREA
));
5215 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5216 /* If row extends face to end of line write the whole line. */
5217 x_draw_glyphs (w
, x
, row
, area
,
5219 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5223 /* Find the first glyph that must be redrawn. */
5225 && x
+ first
->pixel_width
< r
->x
)
5227 x
+= first
->pixel_width
;
5231 /* Find the last one. */
5235 && x
< r
->x
+ r
->width
)
5237 x
+= last
->pixel_width
;
5243 x_draw_glyphs (w
, first_x
, row
, area
,
5244 first
- row
->glyphs
[area
],
5245 last
- row
->glyphs
[area
],
5246 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5252 /* Redraw the parts of the glyph row ROW on window W intersecting
5253 rectangle R. R is in window-relative coordinates. */
5256 expose_line (w
, row
, r
)
5258 struct glyph_row
*row
;
5261 xassert (row
->enabled_p
);
5263 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5264 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5265 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5269 if (row
->used
[LEFT_MARGIN_AREA
])
5270 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5271 if (row
->used
[TEXT_AREA
])
5272 expose_area (w
, row
, r
, TEXT_AREA
);
5273 if (row
->used
[RIGHT_MARGIN_AREA
])
5274 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5275 x_draw_row_bitmaps (w
, row
);
5280 /* Return non-zero if W's cursor intersects rectangle R. */
5283 x_phys_cursor_in_rect_p (w
, r
)
5287 XRectangle cr
, result
;
5288 struct glyph
*cursor_glyph
;
5290 cursor_glyph
= get_phys_cursor_glyph (w
);
5293 cr
.x
= w
->phys_cursor
.x
;
5294 cr
.y
= w
->phys_cursor
.y
;
5295 cr
.width
= cursor_glyph
->pixel_width
;
5296 cr
.height
= w
->phys_cursor_height
;
5297 return x_intersect_rectangles (&cr
, r
, &result
);
5304 /* Redraw a rectangle of window W. R is a rectangle in window
5305 relative coordinates. Call this function with input blocked. */
5308 expose_window (w
, r
)
5312 struct glyph_row
*row
;
5314 int yb
= window_text_bottom_y (w
);
5315 int cursor_cleared_p
;
5317 /* If window is not yet fully initialized, do nothing. This can
5318 happen when toolkit scroll bars are used and a window is split.
5319 Reconfiguring the scroll bar will generate an expose for a newly
5321 if (w
->current_matrix
== NULL
)
5324 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5325 r
->x
, r
->y
, r
->width
, r
->height
));
5327 /* Convert to window coordinates. */
5328 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5329 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5331 /* Turn off the cursor. */
5332 if (!w
->pseudo_window_p
5333 && x_phys_cursor_in_rect_p (w
, r
))
5336 cursor_cleared_p
= 1;
5339 cursor_cleared_p
= 0;
5341 /* Find the first row intersecting the rectangle R. */
5342 row
= w
->current_matrix
->rows
;
5344 while (row
->enabled_p
5346 && y
+ row
->height
< r
->y
)
5352 /* Display the text in the rectangle, one text line at a time. */
5353 while (row
->enabled_p
5355 && y
< r
->y
+ r
->height
)
5357 expose_line (w
, row
, r
);
5362 /* Display the mode line if there is one. */
5363 if (WINDOW_WANTS_MODELINE_P (w
)
5364 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5366 && row
->y
< r
->y
+ r
->height
)
5367 expose_line (w
, row
, r
);
5369 if (!w
->pseudo_window_p
)
5371 /* Draw border between windows. */
5372 x_draw_vertical_border (w
);
5374 /* Turn the cursor on again. */
5375 if (cursor_cleared_p
)
5376 x_update_window_cursor (w
, 1);
5381 /* Determine the intersection of two rectangles R1 and R2. Return
5382 the intersection in *RESULT. Value is non-zero if RESULT is not
5386 x_intersect_rectangles (r1
, r2
, result
)
5387 XRectangle
*r1
, *r2
, *result
;
5389 XRectangle
*left
, *right
;
5390 XRectangle
*upper
, *lower
;
5391 int intersection_p
= 0;
5393 /* Rearrange so that R1 is the left-most rectangle. */
5395 left
= r1
, right
= r2
;
5397 left
= r2
, right
= r1
;
5399 /* X0 of the intersection is right.x0, if this is inside R1,
5400 otherwise there is no intersection. */
5401 if (right
->x
<= left
->x
+ left
->width
)
5403 result
->x
= right
->x
;
5405 /* The right end of the intersection is the minimum of the
5406 the right ends of left and right. */
5407 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5410 /* Same game for Y. */
5412 upper
= r1
, lower
= r2
;
5414 upper
= r2
, lower
= r1
;
5416 /* The upper end of the intersection is lower.y0, if this is inside
5417 of upper. Otherwise, there is no intersection. */
5418 if (lower
->y
<= upper
->y
+ upper
->height
)
5420 result
->y
= lower
->y
;
5422 /* The lower end of the intersection is the minimum of the lower
5423 ends of upper and lower. */
5424 result
->height
= (min (lower
->y
+ lower
->height
,
5425 upper
->y
+ upper
->height
)
5431 return intersection_p
;
5442 /* We used to only do this if Vx_no_window_manager was non-nil, but
5443 the ICCCM (section 4.1.6) says that the window's border pixmap
5444 and border pixel are window attributes which are "private to the
5445 client", so we can always change it to whatever we want. */
5447 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5448 f
->output_data
.x
->border_pixel
);
5450 x_update_cursor (f
, 1);
5454 frame_unhighlight (f
)
5457 /* We used to only do this if Vx_no_window_manager was non-nil, but
5458 the ICCCM (section 4.1.6) says that the window's border pixmap
5459 and border pixel are window attributes which are "private to the
5460 client", so we can always change it to whatever we want. */
5462 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5463 f
->output_data
.x
->border_tile
);
5465 x_update_cursor (f
, 1);
5468 /* The focus has changed. Update the frames as necessary to reflect
5469 the new situation. Note that we can't change the selected frame
5470 here, because the Lisp code we are interrupting might become confused.
5471 Each event gets marked with the frame in which it occurred, so the
5472 Lisp code can tell when the switch took place by examining the events. */
5475 x_new_focus_frame (dpyinfo
, frame
)
5476 struct x_display_info
*dpyinfo
;
5477 struct frame
*frame
;
5479 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5481 if (frame
!= dpyinfo
->x_focus_frame
)
5483 /* Set this before calling other routines, so that they see
5484 the correct value of x_focus_frame. */
5485 dpyinfo
->x_focus_frame
= frame
;
5487 if (old_focus
&& old_focus
->auto_lower
)
5488 x_lower_frame (old_focus
);
5491 selected_frame
= frame
;
5492 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5494 Fselect_window (selected_frame
->selected_window
);
5495 choose_minibuf_frame ();
5498 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5499 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5501 pending_autoraise_frame
= 0;
5504 x_frame_rehighlight (dpyinfo
);
5507 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5510 x_mouse_leave (dpyinfo
)
5511 struct x_display_info
*dpyinfo
;
5513 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5516 /* The focus has changed, or we have redirected a frame's focus to
5517 another frame (this happens when a frame uses a surrogate
5518 mini-buffer frame). Shift the highlight as appropriate.
5520 The FRAME argument doesn't necessarily have anything to do with which
5521 frame is being highlighted or un-highlighted; we only use it to find
5522 the appropriate X display info. */
5525 XTframe_rehighlight (frame
)
5526 struct frame
*frame
;
5528 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5532 x_frame_rehighlight (dpyinfo
)
5533 struct x_display_info
*dpyinfo
;
5535 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5537 if (dpyinfo
->x_focus_frame
)
5539 dpyinfo
->x_highlight_frame
5540 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5541 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5542 : dpyinfo
->x_focus_frame
);
5543 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5545 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5546 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5550 dpyinfo
->x_highlight_frame
= 0;
5552 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5555 frame_unhighlight (old_highlight
);
5556 if (dpyinfo
->x_highlight_frame
)
5557 frame_highlight (dpyinfo
->x_highlight_frame
);
5563 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5565 /* Initialize mode_switch_bit and modifier_meaning. */
5567 x_find_modifier_meanings (dpyinfo
)
5568 struct x_display_info
*dpyinfo
;
5570 int min_code
, max_code
;
5573 XModifierKeymap
*mods
;
5575 dpyinfo
->meta_mod_mask
= 0;
5576 dpyinfo
->shift_lock_mask
= 0;
5577 dpyinfo
->alt_mod_mask
= 0;
5578 dpyinfo
->super_mod_mask
= 0;
5579 dpyinfo
->hyper_mod_mask
= 0;
5582 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5584 min_code
= dpyinfo
->display
->min_keycode
;
5585 max_code
= dpyinfo
->display
->max_keycode
;
5588 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5589 min_code
, max_code
- min_code
+ 1,
5591 mods
= XGetModifierMapping (dpyinfo
->display
);
5593 /* Scan the modifier table to see which modifier bits the Meta and
5594 Alt keysyms are on. */
5596 int row
, col
; /* The row and column in the modifier table. */
5598 for (row
= 3; row
< 8; row
++)
5599 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5602 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5604 /* Zeroes are used for filler. Skip them. */
5608 /* Are any of this keycode's keysyms a meta key? */
5612 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5614 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5620 dpyinfo
->meta_mod_mask
|= (1 << row
);
5625 dpyinfo
->alt_mod_mask
|= (1 << row
);
5630 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5635 dpyinfo
->super_mod_mask
|= (1 << row
);
5639 /* Ignore this if it's not on the lock modifier. */
5640 if ((1 << row
) == LockMask
)
5641 dpyinfo
->shift_lock_mask
= LockMask
;
5649 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5650 if (! dpyinfo
->meta_mod_mask
)
5652 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
5653 dpyinfo
->alt_mod_mask
= 0;
5656 /* If some keys are both alt and meta,
5657 make them just meta, not alt. */
5658 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
5660 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
5663 XFree ((char *) syms
);
5664 XFreeModifiermap (mods
);
5667 /* Convert between the modifier bits X uses and the modifier bits
5671 x_x_to_emacs_modifiers (dpyinfo
, state
)
5672 struct x_display_info
*dpyinfo
;
5675 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
5676 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
5677 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
5678 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
5679 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
5680 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
5684 x_emacs_to_x_modifiers (dpyinfo
, state
)
5685 struct x_display_info
*dpyinfo
;
5688 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
5689 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
5690 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
5691 | ((state
& shift_modifier
) ? ShiftMask
: 0)
5692 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
5693 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
5696 /* Convert a keysym to its name. */
5699 x_get_keysym_name (keysym
)
5705 value
= XKeysymToString (keysym
);
5713 /* Mouse clicks and mouse movement. Rah. */
5715 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
5716 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
5717 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
5718 not force the value into range. */
5721 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
5723 register int pix_x
, pix_y
;
5724 register int *x
, *y
;
5728 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
5729 even for negative values. */
5731 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
5733 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
5735 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
5736 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
5740 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
5741 bounds
->height
= f
->output_data
.x
->line_height
;
5742 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
5743 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
5750 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
5751 pix_x
= FRAME_WINDOW_WIDTH (f
);
5755 else if (pix_y
> f
->height
)
5764 /* Given HPOS/VPOS in the current matrix of W, return corresponding
5765 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
5766 can't tell the positions because W's display is not up to date,
5770 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
5773 int *frame_x
, *frame_y
;
5777 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
5778 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
5780 if (display_completed
)
5782 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
5783 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
5784 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
5790 *frame_x
+= glyph
->pixel_width
;
5798 *frame_y
= *frame_x
= 0;
5802 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
5803 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
5808 /* Prepare a mouse-event in *RESULT for placement in the input queue.
5810 If the event is a button press, then note that we have grabbed
5814 construct_mouse_click (result
, event
, f
)
5815 struct input_event
*result
;
5816 XButtonEvent
*event
;
5819 /* Make the event type no_event; we'll change that when we decide
5821 result
->kind
= mouse_click
;
5822 result
->code
= event
->button
- Button1
;
5823 result
->timestamp
= event
->time
;
5824 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
5826 | (event
->type
== ButtonRelease
5830 XSETINT (result
->x
, event
->x
);
5831 XSETINT (result
->y
, event
->y
);
5832 XSETFRAME (result
->frame_or_window
, f
);
5836 #if 0 /* This function isn't called. --gerd */
5838 /* Prepare a menu-event in *RESULT for placement in the input queue. */
5841 construct_menu_click (result
, event
, f
)
5842 struct input_event
*result
;
5843 XButtonEvent
*event
;
5846 /* Make the event type no_event; we'll change that when we decide
5848 result
->kind
= mouse_click
;
5849 result
->code
= event
->button
- Button1
;
5850 result
->timestamp
= event
->time
;
5851 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
5853 | (event
->type
== ButtonRelease
5857 XSETINT (result
->x
, event
->x
);
5858 XSETINT (result
->y
, -1);
5859 XSETFRAME (result
->frame_or_window
, f
);
5865 /* Function to report a mouse movement to the mainstream Emacs code.
5866 The input handler calls this.
5868 We have received a mouse movement event, which is given in *event.
5869 If the mouse is over a different glyph than it was last time, tell
5870 the mainstream emacs code by setting mouse_moved. If not, ask for
5871 another motion event, so we can check again the next time it moves. */
5873 static XMotionEvent last_mouse_motion_event
;
5874 static Lisp_Object last_mouse_motion_frame
;
5877 note_mouse_movement (frame
, event
)
5879 XMotionEvent
*event
;
5881 last_mouse_movement_time
= event
->time
;
5882 last_mouse_motion_event
= *event
;
5883 XSETFRAME (last_mouse_motion_frame
, frame
);
5885 if (event
->window
!= FRAME_X_WINDOW (frame
))
5887 frame
->mouse_moved
= 1;
5888 last_mouse_scroll_bar
= Qnil
;
5889 note_mouse_highlight (frame
, -1, -1);
5892 /* Has the mouse moved off the glyph it was on at the last sighting? */
5893 else if (event
->x
< last_mouse_glyph
.x
5894 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
5895 || event
->y
< last_mouse_glyph
.y
5896 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
5898 frame
->mouse_moved
= 1;
5899 last_mouse_scroll_bar
= Qnil
;
5900 note_mouse_highlight (frame
, event
->x
, event
->y
);
5904 /* This is used for debugging, to turn off note_mouse_highlight. */
5906 int disable_mouse_highlight
;
5910 /************************************************************************
5912 ************************************************************************/
5914 /* Find the glyph under window-relative coordinates X/Y in window W.
5915 Consider only glyphs from buffer text, i.e. no glyphs from overlay
5916 strings. Return in *HPOS and *VPOS the row and column number of
5917 the glyph found. Return in *AREA the glyph area containing X.
5918 Value is a pointer to the glyph found or null if X/Y is not on
5919 text, or we can't tell because W's current matrix is not up to
5922 static struct glyph
*
5923 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
5926 int *hpos
, *vpos
, *area
;
5928 struct glyph
*glyph
, *end
;
5929 struct glyph_row
*row
;
5930 int x0
, i
, left_area_width
;
5932 /* Find row containing Y. Give up if some row is not enabled. */
5933 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
5935 row
= MATRIX_ROW (w
->current_matrix
, i
);
5936 if (!row
->enabled_p
)
5938 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
5945 /* Give up if Y is not in the window. */
5946 if (i
== w
->current_matrix
->nrows
)
5949 /* Get the glyph area containing X. */
5950 if (w
->pseudo_window_p
)
5957 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5958 if (x
< left_area_width
)
5960 *area
= LEFT_MARGIN_AREA
;
5963 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
5966 x0
= row
->x
+ left_area_width
;
5970 *area
= RIGHT_MARGIN_AREA
;
5971 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
5975 /* Find glyph containing X. */
5976 glyph
= row
->glyphs
[*area
];
5977 end
= glyph
+ row
->used
[*area
];
5980 if (x
< x0
+ glyph
->pixel_width
)
5982 if (w
->pseudo_window_p
)
5984 else if (BUFFERP (glyph
->object
))
5988 x0
+= glyph
->pixel_width
;
5995 *hpos
= glyph
- row
->glyphs
[*area
];
6000 /* Convert frame-relative x/y to coordinates relative to window W.
6001 Takes pseudo-windows into account. */
6004 frame_to_window_pixel_xy (w
, x
, y
)
6008 if (w
->pseudo_window_p
)
6010 /* A pseudo-window is always full-width, and starts at the
6011 left edge of the frame, plus a frame border. */
6012 struct frame
*f
= XFRAME (w
->frame
);
6013 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6014 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6018 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6019 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6024 /* Take proper action when mouse has moved to the mode or top line of
6025 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6026 mode line. X is relative to the start of the text display area of
6027 W, so the width of bitmap areas and scroll bars must be subtracted
6028 to get a position relative to the start of the mode line. */
6031 note_mode_line_highlight (w
, x
, mode_line_p
)
6035 struct frame
*f
= XFRAME (w
->frame
);
6036 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6037 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6038 struct glyph_row
*row
;
6041 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6043 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6047 struct glyph
*glyph
, *end
;
6048 Lisp_Object help
, map
;
6051 /* Find the glyph under X. */
6052 glyph
= row
->glyphs
[TEXT_AREA
];
6053 end
= glyph
+ row
->used
[TEXT_AREA
];
6054 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6055 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6057 && x
>= x0
+ glyph
->pixel_width
)
6059 x0
+= glyph
->pixel_width
;
6064 && STRINGP (glyph
->object
)
6065 && XSTRING (glyph
->object
)->intervals
6066 && glyph
->charpos
>= 0
6067 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6069 /* If we're on a string with `help-echo' text property,
6070 arrange for the help to be displayed. This is done by
6071 setting the global variable help_echo to the help string. */
6072 help
= Fget_text_property (make_number (glyph
->charpos
),
6073 Qhelp_echo
, glyph
->object
);
6077 /* Change the mouse pointer according to what is under X/Y. */
6078 map
= Fget_text_property (make_number (glyph
->charpos
),
6079 Qlocal_map
, glyph
->object
);
6080 if (!NILP (Fkeymapp (map
)))
6081 cursor
= f
->output_data
.x
->nontext_cursor
;
6085 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6089 /* Take proper action when the mouse has moved to position X, Y on
6090 frame F as regards highlighting characters that have mouse-face
6091 properties. Also de-highlighting chars where the mouse was before.
6092 X and Y can be negative or out of range. */
6095 note_mouse_highlight (f
, x
, y
)
6099 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6104 /* When a menu is active, don't highlight because this looks odd. */
6105 #ifdef USE_X_TOOLKIT
6106 if (popup_activated ())
6110 if (disable_mouse_highlight
)
6113 dpyinfo
->mouse_face_mouse_x
= x
;
6114 dpyinfo
->mouse_face_mouse_y
= y
;
6115 dpyinfo
->mouse_face_mouse_frame
= f
;
6117 if (dpyinfo
->mouse_face_defer
)
6122 dpyinfo
->mouse_face_deferred_gc
= 1;
6126 /* Which window is that in? */
6127 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6129 /* If we were displaying active text in another window, clear that. */
6130 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6131 clear_mouse_face (dpyinfo
);
6133 /* Not on a window -> return. */
6134 if (!WINDOWP (window
))
6137 /* Convert to window-relative pixel coordinates. */
6138 w
= XWINDOW (window
);
6139 frame_to_window_pixel_xy (w
, &x
, &y
);
6141 /* Handle tool-bar window differently since it doesn't display a
6143 if (EQ (window
, f
->tool_bar_window
))
6145 note_tool_bar_highlight (f
, x
, y
);
6149 if (portion
== 1 || portion
== 3)
6151 /* Mouse is on the mode or top line. */
6152 note_mode_line_highlight (w
, x
, portion
== 1);
6156 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6157 f
->output_data
.x
->text_cursor
);
6159 /* Are we in a window whose display is up to date?
6160 And verify the buffer's text has not changed. */
6161 if (/* Within text portion of the window. */
6163 && EQ (w
->window_end_valid
, w
->buffer
)
6164 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6165 && (XFASTINT (w
->last_overlay_modified
)
6166 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6168 int hpos
, vpos
, pos
, i
, area
;
6169 struct glyph
*glyph
;
6171 /* Find the glyph under X/Y. */
6172 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6174 /* Clear mouse face if X/Y not over text. */
6176 || area
!= TEXT_AREA
6177 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6179 clear_mouse_face (dpyinfo
);
6183 pos
= glyph
->charpos
;
6184 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6186 /* Check for mouse-face and help-echo. */
6188 Lisp_Object mouse_face
, overlay
, position
;
6189 Lisp_Object
*overlay_vec
;
6191 struct buffer
*obuf
;
6194 /* If we get an out-of-range value, return now; avoid an error. */
6195 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6198 /* Make the window's buffer temporarily current for
6199 overlays_at and compute_char_face. */
6200 obuf
= current_buffer
;
6201 current_buffer
= XBUFFER (w
->buffer
);
6207 /* Is this char mouse-active or does it have help-echo? */
6208 XSETINT (position
, pos
);
6210 /* Put all the overlays we want in a vector in overlay_vec.
6211 Store the length in len. If there are more than 10, make
6212 enough space for all, and try again. */
6214 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6215 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6216 if (noverlays
> len
)
6219 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6220 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
6223 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6225 /* Check mouse-face highlighting. */
6226 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6227 && vpos
>= dpyinfo
->mouse_face_beg_row
6228 && vpos
<= dpyinfo
->mouse_face_end_row
6229 && (vpos
> dpyinfo
->mouse_face_beg_row
6230 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6231 && (vpos
< dpyinfo
->mouse_face_end_row
6232 || hpos
< dpyinfo
->mouse_face_end_col
6233 || dpyinfo
->mouse_face_past_end
)))
6235 /* Clear the display of the old active region, if any. */
6236 clear_mouse_face (dpyinfo
);
6238 /* Find the highest priority overlay that has a mouse-face prop. */
6240 for (i
= 0; i
< noverlays
; i
++)
6242 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6243 if (!NILP (mouse_face
))
6245 overlay
= overlay_vec
[i
];
6250 /* If no overlay applies, get a text property. */
6252 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6254 /* Handle the overlay case. */
6255 if (! NILP (overlay
))
6257 /* Find the range of text around this char that
6258 should be active. */
6259 Lisp_Object before
, after
;
6262 before
= Foverlay_start (overlay
);
6263 after
= Foverlay_end (overlay
);
6264 /* Record this as the current active region. */
6265 fast_find_position (w
, XFASTINT (before
),
6266 &dpyinfo
->mouse_face_beg_col
,
6267 &dpyinfo
->mouse_face_beg_row
,
6268 &dpyinfo
->mouse_face_beg_x
,
6269 &dpyinfo
->mouse_face_beg_y
);
6270 dpyinfo
->mouse_face_past_end
6271 = !fast_find_position (w
, XFASTINT (after
),
6272 &dpyinfo
->mouse_face_end_col
,
6273 &dpyinfo
->mouse_face_end_row
,
6274 &dpyinfo
->mouse_face_end_x
,
6275 &dpyinfo
->mouse_face_end_y
);
6276 dpyinfo
->mouse_face_window
= window
;
6277 dpyinfo
->mouse_face_face_id
6278 = face_at_buffer_position (w
, pos
, 0, 0,
6279 &ignore
, pos
+ 1, 1);
6281 /* Display it as active. */
6282 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6284 /* Handle the text property case. */
6285 else if (! NILP (mouse_face
))
6287 /* Find the range of text around this char that
6288 should be active. */
6289 Lisp_Object before
, after
, beginning
, end
;
6292 beginning
= Fmarker_position (w
->start
);
6293 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6294 - XFASTINT (w
->window_end_pos
)));
6296 = Fprevious_single_property_change (make_number (pos
+ 1),
6298 w
->buffer
, beginning
);
6300 = Fnext_single_property_change (position
, Qmouse_face
,
6302 /* Record this as the current active region. */
6303 fast_find_position (w
, XFASTINT (before
),
6304 &dpyinfo
->mouse_face_beg_col
,
6305 &dpyinfo
->mouse_face_beg_row
,
6306 &dpyinfo
->mouse_face_beg_x
,
6307 &dpyinfo
->mouse_face_beg_y
);
6308 dpyinfo
->mouse_face_past_end
6309 = !fast_find_position (w
, XFASTINT (after
),
6310 &dpyinfo
->mouse_face_end_col
,
6311 &dpyinfo
->mouse_face_end_row
,
6312 &dpyinfo
->mouse_face_end_x
,
6313 &dpyinfo
->mouse_face_end_y
);
6314 dpyinfo
->mouse_face_window
= window
;
6315 dpyinfo
->mouse_face_face_id
6316 = face_at_buffer_position (w
, pos
, 0, 0,
6317 &ignore
, pos
+ 1, 1);
6319 /* Display it as active. */
6320 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6324 /* Look for a `help-echo' property. */
6328 /* Check overlays first. */
6330 for (i
= 0; i
< noverlays
&& !STRINGP (help
); ++i
)
6331 help
= Foverlay_get (overlay_vec
[i
], Qhelp_echo
);
6333 /* Try text properties. */
6335 && ((STRINGP (glyph
->object
)
6336 && glyph
->charpos
>= 0
6337 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6338 || (BUFFERP (glyph
->object
)
6339 && glyph
->charpos
>= BEGV
6340 && glyph
->charpos
< ZV
)))
6341 help
= Fget_text_property (make_number (glyph
->charpos
),
6342 Qhelp_echo
, glyph
->object
);
6350 current_buffer
= obuf
;
6356 redo_mouse_highlight ()
6358 if (!NILP (last_mouse_motion_frame
)
6359 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6360 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6361 last_mouse_motion_event
.x
,
6362 last_mouse_motion_event
.y
);
6367 /***********************************************************************
6369 ***********************************************************************/
6371 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6372 struct glyph
**, int *, int *, int *));
6374 /* Tool-bar item index of the item on which a mouse button was pressed
6377 static int last_tool_bar_item
;
6380 /* Get information about the tool-bar item at position X/Y on frame F.
6381 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6382 the current matrix of the tool-bar window of F, or NULL if not
6383 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6384 item in F->current_tool_bar_items. Value is
6386 -1 if X/Y is not on a tool-bar item
6387 0 if X/Y is on the same item that was highlighted before.
6391 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6394 struct glyph
**glyph
;
6395 int *hpos
, *vpos
, *prop_idx
;
6397 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6398 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6401 /* Find the glyph under X/Y. */
6402 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6406 /* Get the start of this tool-bar item's properties in
6407 f->current_tool_bar_items. */
6408 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6411 /* Is mouse on the highlighted item? */
6412 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6413 && *vpos
>= dpyinfo
->mouse_face_beg_row
6414 && *vpos
<= dpyinfo
->mouse_face_end_row
6415 && (*vpos
> dpyinfo
->mouse_face_beg_row
6416 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6417 && (*vpos
< dpyinfo
->mouse_face_end_row
6418 || *hpos
< dpyinfo
->mouse_face_end_col
6419 || dpyinfo
->mouse_face_past_end
))
6426 /* Handle mouse button event on the tool-bar of frame F, at
6427 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6431 x_handle_tool_bar_click (f
, button_event
)
6433 XButtonEvent
*button_event
;
6435 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6436 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6437 int hpos
, vpos
, prop_idx
;
6438 struct glyph
*glyph
;
6439 Lisp_Object enabled_p
;
6440 int x
= button_event
->x
;
6441 int y
= button_event
->y
;
6443 /* If not on the highlighted tool-bar item, return. */
6444 frame_to_window_pixel_xy (w
, &x
, &y
);
6445 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6448 /* If item is disabled, do nothing. */
6449 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6450 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6451 if (NILP (enabled_p
))
6454 if (button_event
->type
== ButtonPress
)
6456 /* Show item in pressed state. */
6457 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6458 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6459 last_tool_bar_item
= prop_idx
;
6463 Lisp_Object key
, frame
;
6464 struct input_event event
;
6466 /* Show item in released state. */
6467 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6468 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6470 key
= (XVECTOR (f
->current_tool_bar_items
)
6471 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6473 XSETFRAME (frame
, f
);
6474 event
.kind
= TOOL_BAR_EVENT
;
6475 event
.frame_or_window
= Fcons (frame
, Fcons (Qtool_bar
, Qnil
));
6476 kbd_buffer_store_event (&event
);
6478 event
.kind
= TOOL_BAR_EVENT
;
6479 event
.frame_or_window
= Fcons (frame
, key
);
6480 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6481 button_event
->state
);
6482 kbd_buffer_store_event (&event
);
6483 last_tool_bar_item
= -1;
6488 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6489 tool-bar window-relative coordinates X/Y. Called from
6490 note_mouse_highlight. */
6493 note_tool_bar_highlight (f
, x
, y
)
6497 Lisp_Object window
= f
->tool_bar_window
;
6498 struct window
*w
= XWINDOW (window
);
6499 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6501 struct glyph
*glyph
;
6502 struct glyph_row
*row
;
6504 Lisp_Object enabled_p
;
6506 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6507 int mouse_down_p
, rc
;
6509 /* Function note_mouse_highlight is called with negative x(y
6510 values when mouse moves outside of the frame. */
6511 if (x
<= 0 || y
<= 0)
6513 clear_mouse_face (dpyinfo
);
6517 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6520 /* Not on tool-bar item. */
6521 clear_mouse_face (dpyinfo
);
6525 /* On same tool-bar item as before. */
6528 clear_mouse_face (dpyinfo
);
6530 /* Mouse is down, but on different tool-bar item? */
6531 mouse_down_p
= (dpyinfo
->grabbed
6532 && f
== last_mouse_frame
6533 && FRAME_LIVE_P (f
));
6535 && last_tool_bar_item
!= prop_idx
)
6538 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6539 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6541 /* If tool-bar item is not enabled, don't highlight it. */
6542 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6543 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6544 if (!NILP (enabled_p
))
6546 /* Compute the x-position of the glyph. In front and past the
6547 image is a space. We include this is the highlighted area. */
6548 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6549 for (i
= x
= 0; i
< hpos
; ++i
)
6550 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6552 /* Record this as the current active region. */
6553 dpyinfo
->mouse_face_beg_col
= hpos
;
6554 dpyinfo
->mouse_face_beg_row
= vpos
;
6555 dpyinfo
->mouse_face_beg_x
= x
;
6556 dpyinfo
->mouse_face_beg_y
= row
->y
;
6557 dpyinfo
->mouse_face_past_end
= 0;
6559 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6560 dpyinfo
->mouse_face_end_row
= vpos
;
6561 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6562 dpyinfo
->mouse_face_end_y
= row
->y
;
6563 dpyinfo
->mouse_face_window
= window
;
6564 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6566 /* Display it as active. */
6567 show_mouse_face (dpyinfo
, draw
);
6568 dpyinfo
->mouse_face_image_state
= draw
;
6573 /* Set help_echo to a help string.to display for this tool-bar item.
6574 XTread_socket does the rest. */
6575 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6576 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6577 if (!STRINGP (help_echo
))
6578 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6579 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6584 /* Find the glyph matrix position of buffer position POS in window W.
6585 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6586 current glyphs must be up to date. If POS is above window start
6587 return (0, 0, 0, 0). If POS is after end of W, return end of
6591 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6594 int *hpos
, *vpos
, *x
, *y
;
6598 int maybe_next_line_p
= 0;
6599 int line_start_position
;
6600 int yb
= window_text_bottom_y (w
);
6601 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6602 struct glyph_row
*best_row
= row
;
6603 int row_vpos
= 0, best_row_vpos
= 0;
6608 if (row
->used
[TEXT_AREA
])
6609 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6611 line_start_position
= 0;
6613 if (line_start_position
> pos
)
6615 /* If the position sought is the end of the buffer,
6616 don't include the blank lines at the bottom of the window. */
6617 else if (line_start_position
== pos
6618 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6620 maybe_next_line_p
= 1;
6623 else if (line_start_position
> 0)
6626 best_row_vpos
= row_vpos
;
6633 /* Find the right column within BEST_ROW. */
6635 current_x
= best_row
->x
;
6636 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6638 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6641 charpos
= glyph
->charpos
;
6645 *vpos
= best_row_vpos
;
6650 else if (charpos
> pos
)
6652 else if (charpos
> 0)
6655 current_x
+= glyph
->pixel_width
;
6658 /* If we're looking for the end of the buffer,
6659 and we didn't find it in the line we scanned,
6660 use the start of the following line. */
6661 if (maybe_next_line_p
)
6666 current_x
= best_row
->x
;
6669 *vpos
= best_row_vpos
;
6670 *hpos
= lastcol
+ 1;
6677 /* Display the active region described by mouse_face_*
6678 in its mouse-face if HL > 0, in its normal face if HL = 0. */
6681 show_mouse_face (dpyinfo
, draw
)
6682 struct x_display_info
*dpyinfo
;
6683 enum draw_glyphs_face draw
;
6685 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
6686 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6688 int cursor_off_p
= 0;
6689 struct cursor_pos saved_cursor
;
6691 saved_cursor
= output_cursor
;
6693 /* If window is in the process of being destroyed, don't bother
6695 if (w
->current_matrix
== NULL
)
6698 /* Recognize when we are called to operate on rows that don't exist
6699 anymore. This can happen when a window is split. */
6700 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
6703 set_output_cursor (&w
->phys_cursor
);
6705 /* Note that mouse_face_beg_row etc. are window relative. */
6706 for (i
= dpyinfo
->mouse_face_beg_row
;
6707 i
<= dpyinfo
->mouse_face_end_row
;
6710 int start_hpos
, end_hpos
, start_x
;
6711 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
6713 /* Don't do anything if row doesn't have valid contents. */
6714 if (!row
->enabled_p
)
6717 /* For all but the first row, the highlight starts at column 0. */
6718 if (i
== dpyinfo
->mouse_face_beg_row
)
6720 start_hpos
= dpyinfo
->mouse_face_beg_col
;
6721 start_x
= dpyinfo
->mouse_face_beg_x
;
6729 if (i
== dpyinfo
->mouse_face_end_row
)
6730 end_hpos
= dpyinfo
->mouse_face_end_col
;
6732 end_hpos
= row
->used
[TEXT_AREA
];
6734 /* If the cursor's in the text we are about to rewrite, turn the
6736 if (!w
->pseudo_window_p
6737 && i
== output_cursor
.vpos
6738 && output_cursor
.hpos
>= start_hpos
- 1
6739 && output_cursor
.hpos
<= end_hpos
)
6741 x_update_window_cursor (w
, 0);
6745 if (end_hpos
> start_hpos
)
6746 x_draw_glyphs (w
, start_x
, row
, updated_area
,
6747 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
6750 /* If we turned the cursor off, turn it back on. */
6752 x_display_cursor (w
, 1,
6753 output_cursor
.hpos
, output_cursor
.vpos
,
6754 output_cursor
.x
, output_cursor
.y
);
6756 output_cursor
= saved_cursor
;
6760 /* Change the mouse cursor. */
6761 if (draw
== DRAW_NORMAL_TEXT
)
6762 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6763 f
->output_data
.x
->text_cursor
);
6764 else if (draw
== DRAW_MOUSE_FACE
)
6765 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6766 f
->output_data
.x
->cross_cursor
);
6768 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6769 f
->output_data
.x
->nontext_cursor
);
6772 /* Clear out the mouse-highlighted active region.
6773 Redraw it un-highlighted first. */
6776 clear_mouse_face (dpyinfo
)
6777 struct x_display_info
*dpyinfo
;
6782 if (! NILP (dpyinfo
->mouse_face_window
))
6783 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
6785 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6786 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6787 dpyinfo
->mouse_face_window
= Qnil
;
6790 /* Just discard the mouse face information for frame F, if any.
6791 This is used when the size of F is changed. */
6794 cancel_mouse_face (f
)
6798 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6800 window
= dpyinfo
->mouse_face_window
;
6801 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
6803 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6804 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6805 dpyinfo
->mouse_face_window
= Qnil
;
6809 static struct scroll_bar
*x_window_to_scroll_bar ();
6810 static void x_scroll_bar_report_motion ();
6812 /* Return the current position of the mouse.
6813 *fp should be a frame which indicates which display to ask about.
6815 If the mouse movement started in a scroll bar, set *fp, *bar_window,
6816 and *part to the frame, window, and scroll bar part that the mouse
6817 is over. Set *x and *y to the portion and whole of the mouse's
6818 position on the scroll bar.
6820 If the mouse movement started elsewhere, set *fp to the frame the
6821 mouse is on, *bar_window to nil, and *x and *y to the character cell
6824 Set *time to the server time-stamp for the time at which the mouse
6825 was at this position.
6827 Don't store anything if we don't have a valid set of values to report.
6829 This clears the mouse_moved flag, so we can wait for the next mouse
6833 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
6836 Lisp_Object
*bar_window
;
6837 enum scroll_bar_part
*part
;
6839 unsigned long *time
;
6845 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
6846 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
6852 Window dummy_window
;
6855 Lisp_Object frame
, tail
;
6857 /* Clear the mouse-moved flag for every frame on this display. */
6858 FOR_EACH_FRAME (tail
, frame
)
6859 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
6860 XFRAME (frame
)->mouse_moved
= 0;
6862 last_mouse_scroll_bar
= Qnil
;
6864 /* Figure out which root window we're on. */
6865 XQueryPointer (FRAME_X_DISPLAY (*fp
),
6866 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
6868 /* The root window which contains the pointer. */
6871 /* Trash which we can't trust if the pointer is on
6872 a different screen. */
6875 /* The position on that root window. */
6878 /* More trash we can't trust. */
6881 /* Modifier keys and pointer buttons, about which
6883 (unsigned int *) &dummy
);
6885 /* Now we have a position on the root; find the innermost window
6886 containing the pointer. */
6890 int parent_x
= 0, parent_y
= 0;
6895 /* XTranslateCoordinates can get errors if the window
6896 structure is changing at the same time this function
6897 is running. So at least we must not crash from them. */
6899 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
6901 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
6902 && FRAME_LIVE_P (last_mouse_frame
))
6904 /* If mouse was grabbed on a frame, give coords for that frame
6905 even if the mouse is now outside it. */
6906 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
6908 /* From-window, to-window. */
6909 root
, FRAME_X_WINDOW (last_mouse_frame
),
6911 /* From-position, to-position. */
6912 root_x
, root_y
, &win_x
, &win_y
,
6916 f1
= last_mouse_frame
;
6922 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
6924 /* From-window, to-window. */
6927 /* From-position, to-position. */
6928 root_x
, root_y
, &win_x
, &win_y
,
6933 if (child
== None
|| child
== win
)
6941 /* Now we know that:
6942 win is the innermost window containing the pointer
6943 (XTC says it has no child containing the pointer),
6944 win_x and win_y are the pointer's position in it
6945 (XTC did this the last time through), and
6946 parent_x and parent_y are the pointer's position in win's parent.
6947 (They are what win_x and win_y were when win was child.
6948 If win is the root window, it has no parent, and
6949 parent_{x,y} are invalid, but that's okay, because we'll
6950 never use them in that case.) */
6952 /* Is win one of our frames? */
6953 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
6956 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
6959 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
6961 /* If not, is it one of our scroll bars? */
6964 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
6968 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6974 if (f1
== 0 && insist
> 0)
6975 f1
= SELECTED_FRAME ();
6979 /* Ok, we found a frame. Store all the values.
6980 last_mouse_glyph is a rectangle used to reduce the
6981 generation of mouse events. To not miss any motion
6982 events, we must divide the frame into rectangles of the
6983 size of the smallest character that could be displayed
6984 on it, i.e. into the same rectangles that matrices on
6985 the frame are divided into. */
6987 #if OLD_REDISPLAY_CODE
6988 int ignore1
, ignore2
;
6989 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
6991 FRAME_X_DISPLAY_INFO (f1
)->grabbed
6995 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
6996 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7000 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7001 round down even for negative values. */
7007 last_mouse_glyph
.width
= width
;
7008 last_mouse_glyph
.height
= height
;
7009 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7010 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7017 XSETINT (*x
, win_x
);
7018 XSETINT (*y
, win_y
);
7019 *time
= last_mouse_movement_time
;
7028 DEFUN ("xt-process-timeouts", Fxt_process_timeouts
, Sxt_process_timeouts
,
7030 "Arrange for Xt timeout callbacks to be called.")
7033 #ifdef USE_X_TOOLKIT
7035 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7036 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7038 #endif /* USE_X_TOOLKIT */
7045 /* Scroll bar support. */
7047 /* Given an X window ID, find the struct scroll_bar which manages it.
7048 This can be called in GC, so we have to make sure to strip off mark
7050 static struct scroll_bar
*
7051 x_window_to_scroll_bar (window_id
)
7056 for (tail
= Vframe_list
;
7057 XGCTYPE (tail
) == Lisp_Cons
;
7060 Lisp_Object frame
, bar
, condemned
;
7062 frame
= XCAR (tail
);
7063 /* All elements of Vframe_list should be frames. */
7064 if (! GC_FRAMEP (frame
))
7067 /* Scan this frame's scroll bar list for a scroll bar with the
7069 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7070 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7071 /* This trick allows us to search both the ordinary and
7072 condemned scroll bar lists with one loop. */
7073 ! GC_NILP (bar
) || (bar
= condemned
,
7076 bar
= XSCROLL_BAR (bar
)->next
)
7077 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7078 return XSCROLL_BAR (bar
);
7086 /************************************************************************
7088 ************************************************************************/
7090 #if USE_TOOLKIT_SCROLL_BARS
7092 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7093 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7094 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7095 struct scroll_bar
*));
7096 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7100 /* Id of action hook installed for scroll bars. */
7102 static XtActionHookId action_hook_id
;
7104 /* Lisp window being scrolled. Set when starting to interact with
7105 a toolkit scroll bar, reset to nil when ending the interaction. */
7107 static Lisp_Object window_being_scrolled
;
7109 /* Last scroll bar part sent in xm_scroll_callback. */
7111 static int last_scroll_bar_part
;
7114 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7115 bars are used.. The hoos is responsible for detecting when
7116 the user ends an interaction with the scroll bar, and generates
7117 a `end-scroll' scroll_bar_click' event if so. */
7120 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7123 XtPointer client_data
;
7127 Cardinal
*num_params
;
7133 scroll_bar_p
= XmIsScrollBar (widget
);
7134 end_action
= "Release";
7135 #elif defined HAVE_XAW3D
7136 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7137 end_action
= "EndScroll";
7139 #error unknown scroll bar toolkit
7140 #endif /* HAVE_XAW3D */
7142 /* Although LessTif uses XtTimeouts like Xaw3d, the timer hack to
7143 let Xt timeouts be processed doesn't work. */
7145 && strcmp (action_name
, end_action
) == 0
7146 && WINDOWP (window_being_scrolled
))
7150 x_send_scroll_bar_event (window_being_scrolled
,
7151 scroll_bar_end_scroll
, 0, 0);
7152 w
= XWINDOW (window_being_scrolled
);
7153 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7154 window_being_scrolled
= Qnil
;
7155 last_scroll_bar_part
= -1;
7160 /* Send a client message with message type Xatom_Scrollbar for a
7161 scroll action to the frame of WINDOW. PART is a value identifying
7162 the part of the scroll bar that was clicked on. PORTION is the
7163 amount to scroll of a whole of WHOLE. */
7166 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7168 int part
, portion
, whole
;
7171 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7172 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7174 /* Construct a ClientMessage event to send to the frame. */
7175 ev
->type
= ClientMessage
;
7176 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7177 ev
->display
= FRAME_X_DISPLAY (f
);
7178 ev
->window
= FRAME_X_WINDOW (f
);
7180 ev
->data
.l
[0] = (long) window
;
7181 ev
->data
.l
[1] = (long) part
;
7182 ev
->data
.l
[2] = (long) 0;
7183 ev
->data
.l
[3] = (long) portion
;
7184 ev
->data
.l
[4] = (long) whole
;
7186 /* Setting the event mask to zero means that the message will
7187 be sent to the client that created the window, and if that
7188 window no longer exists, no event will be sent. */
7190 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7195 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7199 x_scroll_bar_to_input_event (event
, ievent
)
7201 struct input_event
*ievent
;
7203 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7204 Lisp_Object window
= (Lisp_Object
) ev
->data
.l
[0];
7205 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7207 ievent
->kind
= scroll_bar_click
;
7208 ievent
->frame_or_window
= window
;
7209 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7210 ievent
->part
= ev
->data
.l
[1];
7211 ievent
->code
= ev
->data
.l
[2];
7212 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7213 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7214 ievent
->modifiers
= 0;
7220 /* Minimum and maximum values used for Motif scroll bars. */
7223 #define XM_SB_MAX 10000000
7224 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7227 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7228 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7229 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7232 xm_scroll_callback (widget
, client_data
, call_data
)
7234 XtPointer client_data
, call_data
;
7236 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7237 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7239 int part
= -1, whole
= 0, portion
= 0;
7243 case XmCR_DECREMENT
:
7244 bar
->dragging
= Qnil
;
7245 part
= scroll_bar_up_arrow
;
7248 case XmCR_INCREMENT
:
7249 bar
->dragging
= Qnil
;
7250 part
= scroll_bar_down_arrow
;
7253 case XmCR_PAGE_DECREMENT
:
7254 bar
->dragging
= Qnil
;
7255 part
= scroll_bar_above_handle
;
7258 case XmCR_PAGE_INCREMENT
:
7259 bar
->dragging
= Qnil
;
7260 part
= scroll_bar_below_handle
;
7264 bar
->dragging
= Qnil
;
7265 part
= scroll_bar_to_top
;
7268 case XmCR_TO_BOTTOM
:
7269 bar
->dragging
= Qnil
;
7270 part
= scroll_bar_to_bottom
;
7276 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7277 && XINT (bar
->dragging
) <= cs
->value
);
7279 /* Get the slider size. */
7281 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7284 /* At the max position of the scroll bar, do a line-wise
7285 movement. Without doing anything, the LessTif scroll bar
7286 calls us with the same cs->value again and again. If we
7287 want to make sure that we can reach the end of the buffer,
7288 we have to do something.
7290 Implementation note: setting bar->dragging always to
7291 cs->value gives a smoother movement at the max position.
7292 Setting it to nil when doing line-wise movement gives
7293 a better slider behavior. */
7295 if (cs
->value
+ slider_size
== XM_SB_MAX
7297 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7299 part
= scroll_bar_down_arrow
;
7300 bar
->dragging
= Qnil
;
7304 whole
= XM_SB_RANGE
;
7305 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7306 part
= scroll_bar_handle
;
7307 bar
->dragging
= make_number (cs
->value
);
7312 case XmCR_VALUE_CHANGED
:
7318 window_being_scrolled
= bar
->window
;
7319 last_scroll_bar_part
= part
;
7320 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7325 #else /* not USE_MOTIF, i.e. XAW3D. */
7328 /* Xaw3d scroll bar callback. Invoked when the thumb is dragged.
7329 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7330 scroll bar struct. CALL_DATA is a pointer to a float saying where
7334 xaw3d_jump_callback (widget
, client_data
, call_data
)
7336 XtPointer client_data
, call_data
;
7338 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7339 float top
= *(float *) call_data
;
7342 int dragging_down_p
, part
;
7343 double epsilon
= 0.01;
7345 /* Get the size of the thumb, a value between 0 and 1. */
7347 XtVaGetValues (widget
, XtNshown
, &shown
, NULL
);
7351 portion
= shown
< 1 ? top
* whole
: 0;
7352 dragging_down_p
= (INTEGERP (bar
->dragging
)
7353 && XINT (bar
->dragging
) < portion
);
7356 && (abs (top
+ shown
- 1) < epsilon
7358 && last_scroll_bar_part
== scroll_bar_down_arrow
)))
7359 part
= scroll_bar_down_arrow
;
7361 part
= scroll_bar_handle
;
7363 window_being_scrolled
= bar
->window
;
7364 bar
->dragging
= make_number (portion
);
7365 last_scroll_bar_part
= part
;
7366 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7370 /* Xaw3d scroll bar callback. Invoked for incremental scrolling.,
7371 i.e. line or page up or down. WIDGET is the Xaw3d scroll bar
7372 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7373 the scroll bar. CALL_DATA is an integer specifying the action that
7374 has taken place. It's magnitude is in the range 0..height of the
7375 scroll bar. Negative values mean scroll towards buffer start.
7376 Values < height of scroll bar mean line-wise movement. */
7379 xaw3d_scroll_callback (widget
, client_data
, call_data
)
7381 XtPointer client_data
, call_data
;
7383 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7384 int position
= (int) call_data
;
7388 /* Get the height of the scroll bar. */
7390 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7395 if (abs (position
) < height
)
7396 part
= scroll_bar_up_arrow
;
7398 part
= scroll_bar_above_handle
;
7402 if (abs (position
) < height
)
7403 part
= scroll_bar_down_arrow
;
7405 part
= scroll_bar_below_handle
;
7408 window_being_scrolled
= bar
->window
;
7409 bar
->dragging
= Qnil
;
7410 last_scroll_bar_part
= part
;
7411 x_send_scroll_bar_event (bar
->window
, part
, 0, 0);
7415 #endif /* not USE_MOTIF */
7418 /* Create the widget for scroll bar BAR on frame F. Record the widget
7419 and X window of the scroll bar in BAR. */
7422 x_create_toolkit_scroll_bar (f
, bar
)
7424 struct scroll_bar
*bar
;
7430 char *scroll_bar_name
= "verticalScrollBar";
7431 unsigned long pixel
;
7436 /* LessTif 0.85, problems:
7438 1. When the mouse if over the scroll bar, the scroll bar will
7439 get keyboard events. I didn't find a way to turn this off.
7441 2. Do we have to explicitly set the cursor to get an arrow
7442 cursor (see below)? */
7444 /* Set resources. Create the widget. */
7445 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7446 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7447 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7448 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7449 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7450 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7451 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7453 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7456 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7460 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7463 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7467 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7468 scroll_bar_name
, av
, ac
);
7470 /* Add one callback for everything that can happen. */
7471 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7473 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7475 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7477 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7479 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7481 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7483 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7486 /* Realize the widget. Only after that is the X window created. */
7487 XtRealizeWidget (widget
);
7489 /* Set the cursor to an arrow. I didn't find a resource to do that.
7490 And I'm wondering why it hasn't an arrow cursor by default. */
7491 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7492 f
->output_data
.x
->nontext_cursor
);
7494 #elif defined HAVE_XAW3D
7496 /* Set resources. Create the widget. The background of the
7497 Xaw3d scroll bar widget is a little bit light for my taste.
7498 We don't alter it here to let users change it according
7499 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7500 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7501 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7502 XtSetArg (av
[ac
], XtNcursorName
, "left_ptr"); ++ac
;
7503 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
); ++ac
;
7505 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7508 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7512 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7515 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7519 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7520 f
->output_data
.x
->edit_widget
, av
, ac
);
7522 /* Define callbacks. */
7523 XtAddCallback (widget
, XtNjumpProc
, xaw3d_jump_callback
, (XtPointer
) bar
);
7524 XtAddCallback (widget
, XtNscrollProc
, xaw3d_scroll_callback
,
7527 /* Realize the widget. Only after that is the X window created. */
7528 XtRealizeWidget (widget
);
7530 #endif /* HAVE_XAW3D */
7532 /* Install an action hook that let's us detect when the user
7533 finishes interacting with a scroll bar. */
7534 if (action_hook_id
== 0)
7535 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7537 /* Remember X window and widget in the scroll bar vector. */
7538 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7539 xwindow
= XtWindow (widget
);
7540 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7546 /* Set the thumb size and position of scroll bar BAR. We are currently
7547 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7550 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7551 struct scroll_bar
*bar
;
7552 int portion
, position
, whole
;
7555 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7561 top
= (float) position
/ whole
;
7562 shown
= (float) portion
/ whole
;
7570 Boolean arrow1_selected
, arrow2_selected
;
7571 unsigned char flags
;
7572 XmScrollBarWidget sb
;
7574 /* Slider size. Must be in the range [1 .. MAX - MIN] where NAX
7575 is the scroll bar's maximum and MIN is the scroll bar's minimum
7577 size
= shown
* XM_SB_RANGE
;
7578 size
= min (size
, XM_SB_RANGE
);
7579 size
= max (size
, 1);
7581 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7582 value
= top
* XM_SB_RANGE
;
7583 value
= min (value
, XM_SB_MAX
- size
);
7584 value
= max (value
, XM_SB_MIN
);
7586 /* LessTif: Calling XmScrollBarSetValues after an increment or
7587 decrement turns off auto-repeat LessTif-internally. This can
7588 be seen in ScrollBar.c which resets Arrow1Selected and
7589 Arrow2Selected. It also sets internal flags so that LessTif
7590 believes the mouse is in the slider. We either have to change
7591 our code, or work around that by accessing private data. */
7593 sb
= (XmScrollBarWidget
) widget
;
7594 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
7595 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
7596 flags
= sb
->scrollBar
.flags
;
7598 if (NILP (bar
->dragging
))
7599 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
7600 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7601 /* This has the negative side effect that the slider value is
7602 not would it would be if we scrolled here using line-wise or
7603 page-wise movement. */
7604 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
7607 /* If currently dragging, only update the slider size.
7608 This reduces flicker effects. */
7609 int old_value
, old_size
, increment
, page_increment
;
7611 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
7612 &increment
, &page_increment
);
7613 XmScrollBarSetValues (widget
, old_value
,
7614 min (size
, XM_SB_RANGE
- old_value
),
7618 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
7619 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
7620 sb
->scrollBar
.flags
= flags
;
7622 #elif defined HAVE_XAW3D
7624 /* Restrict to [0 1]. */
7625 top
= max (0, min (1, top
));
7626 shown
= max (0, min (1, shown
));
7628 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
7629 check that your system's configuration file contains a define
7630 for `NARROWPROTO'. See s/freebsd.h for an example. */
7631 if (NILP (bar
->dragging
))
7633 float old_top
, old_shown
;
7634 XtVaGetValues (widget
, XtNtopOfThumb
, &old_top
, XtNshown
, &old_shown
,
7636 if (top
!= old_top
|| shown
!= old_shown
)
7637 XawScrollbarSetThumb (widget
, top
, shown
);
7641 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
7642 int scroll_mode
= sb
->scrollbar
.scroll_mode
;
7644 sb
->scrollbar
.scroll_mode
= 0;
7646 if (last_scroll_bar_part
== scroll_bar_down_arrow
)
7647 XawScrollbarSetThumb (widget
, top
, 1 - top
);
7651 XtVaGetValues (widget
, XtNtopOfThumb
, &old_top
, NULL
);
7652 XawScrollbarSetThumb (widget
, old_top
, min (shown
, 1 - old_top
));
7655 sb
->scrollbar
.scroll_mode
= scroll_mode
;
7658 #endif /* HAVE_XAW3D */
7663 #endif /* USE_TOOLKIT_SCROLL_BARS */
7667 /************************************************************************
7668 Scroll bars, general
7669 ************************************************************************/
7671 /* Create a scroll bar and return the scroll bar vector for it. W is
7672 the Emacs window on which to create the scroll bar. TOP, LEFT,
7673 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
7676 static struct scroll_bar
*
7677 x_scroll_bar_create (w
, top
, left
, width
, height
)
7679 int top
, left
, width
, height
;
7681 struct frame
*f
= XFRAME (w
->frame
);
7682 struct scroll_bar
*bar
7683 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
7687 #if USE_TOOLKIT_SCROLL_BARS
7688 x_create_toolkit_scroll_bar (f
, bar
);
7689 #else /* not USE_TOOLKIT_SCROLL_BARS */
7691 XSetWindowAttributes a
;
7695 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7696 if (a
.background_pixel
== -1)
7697 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
7699 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
7700 | ButtonMotionMask
| PointerMotionHintMask
7702 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
7704 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
7706 /* Clear the area of W that will serve as a scroll bar. This is
7707 for the case that a window has been split horizontally. In
7708 this case, no clear_frame is generated to reduce flickering. */
7709 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7711 window_box_height (w
), False
);
7713 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7714 /* Position and size of scroll bar. */
7715 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7717 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7719 /* Border width, depth, class, and visual. */
7726 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
7728 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7730 XSETWINDOW (bar
->window
, w
);
7731 XSETINT (bar
->top
, top
);
7732 XSETINT (bar
->left
, left
);
7733 XSETINT (bar
->width
, width
);
7734 XSETINT (bar
->height
, height
);
7735 XSETINT (bar
->start
, 0);
7736 XSETINT (bar
->end
, 0);
7737 bar
->dragging
= Qnil
;
7739 /* Add bar to its frame's list of scroll bars. */
7740 bar
->next
= FRAME_SCROLL_BARS (f
);
7742 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7743 if (!NILP (bar
->next
))
7744 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7746 /* Map the window/widget. */
7747 #if USE_TOOLKIT_SCROLL_BARS
7748 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
7749 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
7750 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7752 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7754 #else /* not USE_TOOLKIT_SCROLL_BARS */
7755 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7756 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7763 /* Draw BAR's handle in the proper position.
7765 If the handle is already drawn from START to END, don't bother
7766 redrawing it, unless REBUILD is non-zero; in that case, always
7767 redraw it. (REBUILD is handy for drawing the handle after expose
7770 Normally, we want to constrain the start and end of the handle to
7771 fit inside its rectangle, but if the user is dragging the scroll
7772 bar handle, we want to let them drag it down all the way, so that
7773 the bar's top is as far down as it goes; otherwise, there's no way
7774 to move to the very end of the buffer. */
7776 #ifndef USE_TOOLKIT_SCROLL_BARS
7779 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
7780 struct scroll_bar
*bar
;
7784 int dragging
= ! NILP (bar
->dragging
);
7785 Window w
= SCROLL_BAR_X_WINDOW (bar
);
7786 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7787 GC gc
= f
->output_data
.x
->normal_gc
;
7789 /* If the display is already accurate, do nothing. */
7791 && start
== XINT (bar
->start
)
7792 && end
== XINT (bar
->end
))
7798 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
7799 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
7800 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7802 /* Make sure the values are reasonable, and try to preserve
7803 the distance between start and end. */
7805 int length
= end
- start
;
7809 else if (start
> top_range
)
7811 end
= start
+ length
;
7815 else if (end
> top_range
&& ! dragging
)
7819 /* Store the adjusted setting in the scroll bar. */
7820 XSETINT (bar
->start
, start
);
7821 XSETINT (bar
->end
, end
);
7823 /* Clip the end position, just for display. */
7824 if (end
> top_range
)
7827 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
7828 below top positions, to make sure the handle is always at least
7829 that many pixels tall. */
7830 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7832 /* Draw the empty space above the handle. Note that we can't clear
7833 zero-height areas; that means "clear to end of window." */
7835 XClearArea (FRAME_X_DISPLAY (f
), w
,
7837 /* x, y, width, height, and exposures. */
7838 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7839 VERTICAL_SCROLL_BAR_TOP_BORDER
,
7840 inside_width
, start
,
7843 /* Change to proper foreground color if one is specified. */
7844 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7845 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7846 f
->output_data
.x
->scroll_bar_foreground_pixel
);
7848 /* Draw the handle itself. */
7849 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
7851 /* x, y, width, height */
7852 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7853 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
7854 inside_width
, end
- start
);
7856 /* Restore the foreground color of the GC if we changed it above. */
7857 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7858 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7859 f
->output_data
.x
->foreground_pixel
);
7861 /* Draw the empty space below the handle. Note that we can't
7862 clear zero-height areas; that means "clear to end of window." */
7863 if (end
< inside_height
)
7864 XClearArea (FRAME_X_DISPLAY (f
), w
,
7866 /* x, y, width, height, and exposures. */
7867 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7868 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
7869 inside_width
, inside_height
- end
,
7877 #endif /* !USE_TOOLKIT_SCROLL_BARS */
7879 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
7883 x_scroll_bar_remove (bar
)
7884 struct scroll_bar
*bar
;
7888 #if USE_TOOLKIT_SCROLL_BARS
7889 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
7890 #else /* not USE_TOOLKIT_SCROLL_BARS */
7892 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7893 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7895 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7897 /* Disassociate this scroll bar from its window. */
7898 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
7904 /* Set the handle of the vertical scroll bar for WINDOW to indicate
7905 that we are displaying PORTION characters out of a total of WHOLE
7906 characters, starting at POSITION. If WINDOW has no scroll bar,
7910 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
7912 int portion
, whole
, position
;
7914 struct frame
*f
= XFRAME (w
->frame
);
7915 struct scroll_bar
*bar
;
7916 int top
, height
, left
, sb_left
, width
, sb_width
;
7917 int window_x
, window_y
, window_width
, window_height
;
7919 /* Get window dimensions. */
7920 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7922 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
7923 height
= window_height
;
7925 /* Compute the left edge of the scroll bar area. */
7926 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7927 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
7929 left
= XFASTINT (w
->left
);
7930 left
*= CANON_X_UNIT (f
);
7931 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
7933 /* Compute the width of the scroll bar which might be less than
7934 the width of the area reserved for the scroll bar. */
7935 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
7936 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
7940 /* Compute the left edge of the scroll bar. */
7941 #ifdef USE_TOOLKIT_SCROLL_BARS
7942 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7943 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
7945 sb_left
= left
+ (width
- sb_width
) / 2;
7947 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7948 sb_left
= left
+ width
- sb_width
;
7953 /* Does the scroll bar exist yet? */
7954 if (NILP (w
->vertical_scroll_bar
))
7957 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7958 left
, top
, width
, height
, False
);
7960 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
7964 /* It may just need to be moved and resized. */
7965 unsigned int mask
= 0;
7967 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
7971 if (sb_left
!= XINT (bar
->left
))
7973 if (top
!= XINT (bar
->top
))
7975 if (sb_width
!= XINT (bar
->width
))
7977 if (height
!= XINT (bar
->height
))
7980 #ifdef USE_TOOLKIT_SCROLL_BARS
7982 /* Since toolkit scroll bars are smaller than the space reserved
7983 for them on the frame, we have to clear "under" them. */
7984 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7985 left
, top
, width
, height
, False
);
7987 /* Move/size the scroll bar widget. */
7989 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
7990 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7992 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7995 #else /* not USE_TOOLKIT_SCROLL_BARS */
7997 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
7999 /* Clear areas not covered by the scroll bar. This makes sure a
8000 previous mode line display is cleared after C-x 2 C-x 1, for
8001 example. Non-toolkit scroll bars are as wide as the area
8002 reserved for scroll bars - trim at both sides. */
8003 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8004 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8006 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8007 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8008 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8012 /* Move/size the scroll bar window. */
8017 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8019 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8021 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8025 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8027 /* Remember new settings. */
8028 XSETINT (bar
->left
, sb_left
);
8029 XSETINT (bar
->top
, top
);
8030 XSETINT (bar
->width
, sb_width
);
8031 XSETINT (bar
->height
, height
);
8036 #if USE_TOOLKIT_SCROLL_BARS
8037 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8038 #else /* not USE_TOOLKIT_SCROLL_BARS */
8039 /* Set the scroll bar's current state, unless we're currently being
8041 if (NILP (bar
->dragging
))
8043 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8046 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8049 int start
= ((double) position
* top_range
) / whole
;
8050 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8051 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8054 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8056 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8060 /* The following three hooks are used when we're doing a thorough
8061 redisplay of the frame. We don't explicitly know which scroll bars
8062 are going to be deleted, because keeping track of when windows go
8063 away is a real pain - "Can you say set-window-configuration, boys
8064 and girls?" Instead, we just assert at the beginning of redisplay
8065 that *all* scroll bars are to be removed, and then save a scroll bar
8066 from the fiery pit when we actually redisplay its window. */
8068 /* Arrange for all scroll bars on FRAME to be removed at the next call
8069 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8070 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8073 XTcondemn_scroll_bars (frame
)
8076 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8077 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8080 bar
= FRAME_SCROLL_BARS (frame
);
8081 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8082 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8083 XSCROLL_BAR (bar
)->prev
= Qnil
;
8084 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8085 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8086 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8090 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8091 Note that WINDOW isn't necessarily condemned at all. */
8093 XTredeem_scroll_bar (window
)
8094 struct window
*window
;
8096 struct scroll_bar
*bar
;
8098 /* We can't redeem this window's scroll bar if it doesn't have one. */
8099 if (NILP (window
->vertical_scroll_bar
))
8102 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8104 /* Unlink it from the condemned list. */
8106 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8108 if (NILP (bar
->prev
))
8110 /* If the prev pointer is nil, it must be the first in one of
8112 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8113 /* It's not condemned. Everything's fine. */
8115 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8116 window
->vertical_scroll_bar
))
8117 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8119 /* If its prev pointer is nil, it must be at the front of
8120 one or the other! */
8124 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8126 if (! NILP (bar
->next
))
8127 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8129 bar
->next
= FRAME_SCROLL_BARS (f
);
8131 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8132 if (! NILP (bar
->next
))
8133 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8137 /* Remove all scroll bars on FRAME that haven't been saved since the
8138 last call to `*condemn_scroll_bars_hook'. */
8141 XTjudge_scroll_bars (f
)
8144 Lisp_Object bar
, next
;
8146 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8148 /* Clear out the condemned list now so we won't try to process any
8149 more events on the hapless scroll bars. */
8150 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8152 for (; ! NILP (bar
); bar
= next
)
8154 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8156 x_scroll_bar_remove (b
);
8159 b
->next
= b
->prev
= Qnil
;
8162 /* Now there should be no references to the condemned scroll bars,
8163 and they should get garbage-collected. */
8167 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8168 is a no-op when using toolkit scroll bars.
8170 This may be called from a signal handler, so we have to ignore GC
8174 x_scroll_bar_expose (bar
, event
)
8175 struct scroll_bar
*bar
;
8178 #ifndef USE_TOOLKIT_SCROLL_BARS
8180 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8181 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8182 GC gc
= f
->output_data
.x
->normal_gc
;
8183 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8187 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8189 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8190 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8192 /* x, y, width, height */
8194 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8195 XINT (bar
->height
) - 1);
8199 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8202 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8203 is set to something other than no_event, it is enqueued.
8205 This may be called from a signal handler, so we have to ignore GC
8208 #ifndef USE_TOOLKIT_SCROLL_BARS
8211 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8212 struct scroll_bar
*bar
;
8214 struct input_event
*emacs_event
;
8216 if (! GC_WINDOWP (bar
->window
))
8219 emacs_event
->kind
= scroll_bar_click
;
8220 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8221 emacs_event
->modifiers
8222 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8223 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8224 event
->xbutton
.state
)
8225 | (event
->type
== ButtonRelease
8228 emacs_event
->frame_or_window
= bar
->window
;
8229 emacs_event
->timestamp
= event
->xbutton
.time
;
8232 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8234 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8237 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8238 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8241 if (y
> top_range
) y
= top_range
;
8243 if (y
< XINT (bar
->start
))
8244 emacs_event
->part
= scroll_bar_above_handle
;
8245 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8246 emacs_event
->part
= scroll_bar_handle
;
8248 emacs_event
->part
= scroll_bar_below_handle
;
8250 /* Just because the user has clicked on the handle doesn't mean
8251 they want to drag it. Lisp code needs to be able to decide
8252 whether or not we're dragging. */
8254 /* If the user has just clicked on the handle, record where they're
8256 if (event
->type
== ButtonPress
8257 && emacs_event
->part
== scroll_bar_handle
)
8258 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8261 /* If the user has released the handle, set it to its final position. */
8262 if (event
->type
== ButtonRelease
8263 && ! NILP (bar
->dragging
))
8265 int new_start
= y
- XINT (bar
->dragging
);
8266 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8268 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8269 bar
->dragging
= Qnil
;
8272 /* Same deal here as the other #if 0. */
8274 /* Clicks on the handle are always reported as occurring at the top of
8276 if (emacs_event
->part
== scroll_bar_handle
)
8277 emacs_event
->x
= bar
->start
;
8279 XSETINT (emacs_event
->x
, y
);
8281 XSETINT (emacs_event
->x
, y
);
8284 XSETINT (emacs_event
->y
, top_range
);
8288 /* Handle some mouse motion while someone is dragging the scroll bar.
8290 This may be called from a signal handler, so we have to ignore GC
8294 x_scroll_bar_note_movement (bar
, event
)
8295 struct scroll_bar
*bar
;
8298 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8300 last_mouse_movement_time
= event
->xmotion
.time
;
8303 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8305 /* If we're dragging the bar, display it. */
8306 if (! GC_NILP (bar
->dragging
))
8308 /* Where should the handle be now? */
8309 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8311 if (new_start
!= XINT (bar
->start
))
8313 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8315 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8320 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8322 /* Return information to the user about the current position of the mouse
8323 on the scroll bar. */
8326 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8328 Lisp_Object
*bar_window
;
8329 enum scroll_bar_part
*part
;
8331 unsigned long *time
;
8333 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8334 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8335 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8337 Window dummy_window
;
8339 unsigned int dummy_mask
;
8343 /* Get the mouse's position relative to the scroll bar window, and
8345 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8347 /* Root, child, root x and root y. */
8348 &dummy_window
, &dummy_window
,
8349 &dummy_coord
, &dummy_coord
,
8351 /* Position relative to scroll bar. */
8354 /* Mouse buttons and modifier keys. */
8361 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8364 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8366 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8368 if (! NILP (bar
->dragging
))
8369 win_y
-= XINT (bar
->dragging
);
8373 if (win_y
> top_range
)
8377 *bar_window
= bar
->window
;
8379 if (! NILP (bar
->dragging
))
8380 *part
= scroll_bar_handle
;
8381 else if (win_y
< XINT (bar
->start
))
8382 *part
= scroll_bar_above_handle
;
8383 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8384 *part
= scroll_bar_handle
;
8386 *part
= scroll_bar_below_handle
;
8388 XSETINT (*x
, win_y
);
8389 XSETINT (*y
, top_range
);
8392 last_mouse_scroll_bar
= Qnil
;
8395 *time
= last_mouse_movement_time
;
8401 /* The screen has been cleared so we may have changed foreground or
8402 background colors, and the scroll bars may need to be redrawn.
8403 Clear out the scroll bars, and ask for expose events, so we can
8407 x_scroll_bar_clear (f
)
8410 #ifndef USE_TOOLKIT_SCROLL_BARS
8413 /* We can have scroll bars even if this is 0,
8414 if we just turned off scroll bar mode.
8415 But in that case we should not clear them. */
8416 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8417 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8418 bar
= XSCROLL_BAR (bar
)->next
)
8419 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8421 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8424 /* This processes Expose events from the menu-bar specific X event
8425 loop in xmenu.c. This allows to redisplay the frame if necessary
8426 when handling menu-bar or pop-up items. */
8429 process_expose_from_menu (event
)
8433 struct x_display_info
*dpyinfo
;
8434 int frame_exposed_p
= 0;
8438 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8439 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8442 if (f
->async_visible
== 0)
8444 f
->async_visible
= 1;
8445 f
->async_iconified
= 0;
8446 f
->output_data
.x
->has_been_visible
= 1;
8447 SET_FRAME_GARBAGED (f
);
8451 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8452 event
.xexpose
.x
, event
.xexpose
.y
,
8453 event
.xexpose
.width
, event
.xexpose
.height
);
8454 frame_exposed_p
= 1;
8459 struct scroll_bar
*bar
8460 = x_window_to_scroll_bar (event
.xexpose
.window
);
8463 x_scroll_bar_expose (bar
, &event
);
8467 return frame_exposed_p
;
8470 /* Define a queue to save up SelectionRequest events for later handling. */
8472 struct selection_event_queue
8475 struct selection_event_queue
*next
;
8478 static struct selection_event_queue
*queue
;
8480 /* Nonzero means queue up certain events--don't process them yet. */
8482 static int x_queue_selection_requests
;
8484 /* Queue up an X event *EVENT, to be processed later. */
8487 x_queue_event (f
, event
)
8491 struct selection_event_queue
*queue_tmp
8492 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8494 if (queue_tmp
!= NULL
)
8496 queue_tmp
->event
= *event
;
8497 queue_tmp
->next
= queue
;
8502 /* Take all the queued events and put them back
8503 so that they get processed afresh. */
8506 x_unqueue_events (display
)
8509 while (queue
!= NULL
)
8511 struct selection_event_queue
*queue_tmp
= queue
;
8512 XPutBackEvent (display
, &queue_tmp
->event
);
8513 queue
= queue_tmp
->next
;
8514 xfree ((char *)queue_tmp
);
8518 /* Start queuing SelectionRequest events. */
8521 x_start_queuing_selection_requests (display
)
8524 x_queue_selection_requests
++;
8527 /* Stop queuing SelectionRequest events. */
8530 x_stop_queuing_selection_requests (display
)
8533 x_queue_selection_requests
--;
8534 x_unqueue_events (display
);
8537 /* The main X event-reading loop - XTread_socket. */
8539 /* Time stamp of enter window event. This is only used by XTread_socket,
8540 but we have to put it out here, since static variables within functions
8541 sometimes don't work. */
8543 static Time enter_timestamp
;
8545 /* This holds the state XLookupString needs to implement dead keys
8546 and other tricks known as "compose processing". _X Window System_
8547 says that a portable program can't use this, but Stephen Gildea assures
8548 me that letting the compiler initialize it to zeros will work okay.
8550 This must be defined outside of XTread_socket, for the same reasons
8551 given for enter_time stamp, above. */
8553 static XComposeStatus compose_status
;
8555 /* Record the last 100 characters stored
8556 to help debug the loss-of-chars-during-GC problem. */
8558 static int temp_index
;
8559 static short temp_buffer
[100];
8561 /* Set this to nonzero to fake an "X I/O error"
8562 on a particular display. */
8564 struct x_display_info
*XTread_socket_fake_io_error
;
8566 /* When we find no input here, we occasionally do a no-op command
8567 to verify that the X server is still running and we can still talk with it.
8568 We try all the open displays, one by one.
8569 This variable is used for cycling thru the displays. */
8571 static struct x_display_info
*next_noop_dpyinfo
;
8573 #define SET_SAVED_MENU_EVENT(size) \
8576 if (f->output_data.x->saved_menu_event == 0) \
8577 f->output_data.x->saved_menu_event \
8578 = (XEvent *) xmalloc (sizeof (XEvent)); \
8579 bcopy (&event, f->output_data.x->saved_menu_event, size); \
8580 if (numchars >= 1) \
8582 bufp->kind = menu_bar_activate_event; \
8583 XSETFRAME (bufp->frame_or_window, f); \
8591 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
8592 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
8594 /* Read events coming from the X server.
8595 This routine is called by the SIGIO handler.
8596 We return as soon as there are no more events to be read.
8598 Events representing keys are stored in buffer BUFP,
8599 which can hold up to NUMCHARS characters.
8600 We return the number of characters stored into the buffer,
8601 thus pretending to be `read'.
8603 EXPECTED is nonzero if the caller knows input is available. */
8606 XTread_socket (sd
, bufp
, numchars
, expected
)
8608 /* register */ struct input_event
*bufp
;
8609 /* register */ int numchars
;
8616 int event_found
= 0;
8617 struct x_display_info
*dpyinfo
;
8619 Status status_return
;
8622 if (interrupt_input_blocked
)
8624 interrupt_input_pending
= 1;
8628 interrupt_input_pending
= 0;
8631 /* So people can tell when we have read the available input. */
8632 input_signal_count
++;
8635 abort (); /* Don't think this happens. */
8637 /* Find the display we are supposed to read input for.
8638 It's the one communicating on descriptor SD. */
8639 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
8641 #if 0 /* This ought to be unnecessary; let's verify it. */
8643 /* If available, Xlib uses FIOSNBIO to make the socket
8644 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
8645 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
8646 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
8647 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
8648 #endif /* ! defined (FIOSNBIO) */
8651 #if 0 /* This code can't be made to work, with multiple displays,
8652 and appears not to be used on any system any more.
8653 Also keyboard.c doesn't turn O_NDELAY on and off
8654 for X connections. */
8657 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
8659 extern int read_alarm_should_throw
;
8660 read_alarm_should_throw
= 1;
8661 XPeekEvent (dpyinfo
->display
, &event
);
8662 read_alarm_should_throw
= 0;
8664 #endif /* HAVE_SELECT */
8668 /* For debugging, this gives a way to fake an I/O error. */
8669 if (dpyinfo
== XTread_socket_fake_io_error
)
8671 XTread_socket_fake_io_error
= 0;
8672 x_io_error_quitter (dpyinfo
->display
);
8675 while (XPending (dpyinfo
->display
))
8677 XNextEvent (dpyinfo
->display
, &event
);
8679 if (display_busy_cursor_p
)
8681 /* Setting inhibit_busy_cursor to 2 inhibits busy-cursor
8682 display until the next X event is read and we come
8683 here again. Setting it to 1 inhibits busy-cursor
8684 display for direct commands. */
8685 if (event
.type
== MotionNotify
8686 || event
.type
== EnterNotify
8687 || (dpyinfo
->grabbed
8688 && event
.type
!= ButtonRelease
))
8689 inhibit_busy_cursor
= 2;
8691 inhibit_busy_cursor
= 1;
8696 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
8697 event
.xclient
.window
);
8698 /* The necessity of the following line took me
8699 a full work-day to decipher from the docs!! */
8700 if (f1
!= 0 && FRAME_XIC (f1
) && XFilterEvent (&event
, None
))
8710 if (event
.xclient
.message_type
8711 == dpyinfo
->Xatom_wm_protocols
8712 && event
.xclient
.format
== 32)
8714 if (event
.xclient
.data
.l
[0]
8715 == dpyinfo
->Xatom_wm_take_focus
)
8717 /* Use x_any_window_to_frame because this
8718 could be the shell widget window
8719 if the frame has no title bar. */
8720 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
8722 /* Not quite sure this is needed -pd */
8723 if (f
&& FRAME_XIC (f
))
8724 XSetICFocus (FRAME_XIC (f
));
8726 /* Since we set WM_TAKE_FOCUS, we must call
8727 XSetInputFocus explicitly. But not if f is null,
8728 since that might be an event for a deleted frame. */
8731 Display
*d
= event
.xclient
.display
;
8732 /* Catch and ignore errors, in case window has been
8733 iconified by a window manager such as GWM. */
8734 int count
= x_catch_errors (d
);
8735 XSetInputFocus (d
, event
.xclient
.window
,
8736 /* The ICCCM says this is
8737 the only valid choice. */
8739 event
.xclient
.data
.l
[1]);
8740 /* This is needed to detect the error
8741 if there is an error. */
8743 x_uncatch_errors (d
, count
);
8745 /* Not certain about handling scroll bars here */
8747 else if (event
.xclient
.data
.l
[0]
8748 == dpyinfo
->Xatom_wm_save_yourself
)
8750 /* Save state modify the WM_COMMAND property to
8751 something which can reinstate us. This notifies
8752 the session manager, who's looking for such a
8753 PropertyNotify. Can restart processing when
8754 a keyboard or mouse event arrives. */
8757 f
= x_top_window_to_frame (dpyinfo
,
8758 event
.xclient
.window
);
8760 /* This is just so we only give real data once
8761 for a single Emacs process. */
8762 if (f
== SELECTED_FRAME ())
8763 XSetCommand (FRAME_X_DISPLAY (f
),
8764 event
.xclient
.window
,
8765 initial_argv
, initial_argc
);
8767 XSetCommand (FRAME_X_DISPLAY (f
),
8768 event
.xclient
.window
,
8772 else if (event
.xclient
.data
.l
[0]
8773 == dpyinfo
->Xatom_wm_delete_window
)
8776 = x_any_window_to_frame (dpyinfo
,
8777 event
.xclient
.window
);
8784 bufp
->kind
= delete_window_event
;
8785 XSETFRAME (bufp
->frame_or_window
, f
);
8793 else if (event
.xclient
.message_type
8794 == dpyinfo
->Xatom_wm_configure_denied
)
8797 else if (event
.xclient
.message_type
8798 == dpyinfo
->Xatom_wm_window_moved
)
8802 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
8804 new_x
= event
.xclient
.data
.s
[0];
8805 new_y
= event
.xclient
.data
.s
[1];
8809 f
->output_data
.x
->left_pos
= new_x
;
8810 f
->output_data
.x
->top_pos
= new_y
;
8814 else if (event
.xclient
.message_type
8815 == dpyinfo
->Xatom_editres
)
8818 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
8819 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
8822 #endif /* HACK_EDITRES */
8823 else if ((event
.xclient
.message_type
8824 == dpyinfo
->Xatom_DONE
)
8825 || (event
.xclient
.message_type
8826 == dpyinfo
->Xatom_PAGE
))
8828 /* Ghostview job completed. Kill it. We could
8829 reply with "Next" if we received "Page", but we
8830 currently never do because we are interested in
8831 images, only, which should have 1 page. */
8832 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
8834 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
8835 x_kill_gs_process (pixmap
, f
);
8836 expose_frame (f
, 0, 0, 0, 0);
8838 #ifdef USE_TOOLKIT_SCROLL_BARS
8839 /* Scroll bar callbacks send a ClientMessage from which
8840 we construct an input_event. */
8841 else if (event
.xclient
.message_type
8842 == dpyinfo
->Xatom_Scrollbar
)
8844 x_scroll_bar_to_input_event (&event
, bufp
);
8845 ++bufp
, ++count
, --numchars
;
8848 #endif /* USE_TOOLKIT_SCROLL_BARS */
8854 case SelectionNotify
:
8855 #ifdef USE_X_TOOLKIT
8856 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
8858 #endif /* not USE_X_TOOLKIT */
8859 x_handle_selection_notify (&event
.xselection
);
8862 case SelectionClear
: /* Someone has grabbed ownership. */
8863 #ifdef USE_X_TOOLKIT
8864 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
8866 #endif /* USE_X_TOOLKIT */
8868 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
8873 bufp
->kind
= selection_clear_event
;
8874 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
8875 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
8876 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
8877 bufp
->frame_or_window
= Qnil
;
8885 case SelectionRequest
: /* Someone wants our selection. */
8886 #ifdef USE_X_TOOLKIT
8887 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
8889 #endif /* USE_X_TOOLKIT */
8890 if (x_queue_selection_requests
)
8891 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
8895 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
8900 bufp
->kind
= selection_request_event
;
8901 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
8902 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
8903 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
8904 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
8905 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
8906 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
8907 bufp
->frame_or_window
= Qnil
;
8915 case PropertyNotify
:
8916 #ifdef USE_X_TOOLKIT
8917 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
8919 #endif /* not USE_X_TOOLKIT */
8920 x_handle_property_notify (&event
.xproperty
);
8923 case ReparentNotify
:
8924 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
8928 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
8929 x_real_positions (f
, &x
, &y
);
8930 f
->output_data
.x
->left_pos
= x
;
8931 f
->output_data
.x
->top_pos
= y
;
8936 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8939 if (f
->async_visible
== 0)
8941 f
->async_visible
= 1;
8942 f
->async_iconified
= 0;
8943 f
->output_data
.x
->has_been_visible
= 1;
8944 SET_FRAME_GARBAGED (f
);
8947 expose_frame (x_window_to_frame (dpyinfo
,
8948 event
.xexpose
.window
),
8949 event
.xexpose
.x
, event
.xexpose
.y
,
8950 event
.xexpose
.width
, event
.xexpose
.height
);
8954 #ifdef USE_TOOLKIT_SCROLL_BARS
8955 /* Dispatch event to the widget. */
8957 #else /* not USE_TOOLKIT_SCROLL_BARS */
8958 struct scroll_bar
*bar
8959 = x_window_to_scroll_bar (event
.xexpose
.window
);
8962 x_scroll_bar_expose (bar
, &event
);
8963 #ifdef USE_X_TOOLKIT
8966 #endif /* USE_X_TOOLKIT */
8967 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8971 case GraphicsExpose
: /* This occurs when an XCopyArea's
8972 source area was obscured or not
8974 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
8978 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
8979 event
.xgraphicsexpose
.width
,
8980 event
.xgraphicsexpose
.height
);
8982 #ifdef USE_X_TOOLKIT
8985 #endif /* USE_X_TOOLKIT */
8988 case NoExpose
: /* This occurs when an XCopyArea's
8989 source area was completely
8994 /* Redo the mouse-highlight after the tooltip has gone. */
8995 if (event
.xmap
.window
== tip_window
)
8998 redo_mouse_highlight ();
9001 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9002 if (f
) /* F may no longer exist if
9003 the frame was deleted. */
9005 /* While a frame is unmapped, display generation is
9006 disabled; you don't want to spend time updating a
9007 display that won't ever be seen. */
9008 f
->async_visible
= 0;
9009 /* We can't distinguish, from the event, whether the window
9010 has become iconified or invisible. So assume, if it
9011 was previously visible, than now it is iconified.
9012 But x_make_frame_invisible clears both
9013 the visible flag and the iconified flag;
9014 and that way, we know the window is not iconified now. */
9015 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9017 f
->async_iconified
= 1;
9019 bufp
->kind
= iconify_event
;
9020 XSETFRAME (bufp
->frame_or_window
, f
);
9029 if (event
.xmap
.window
== tip_window
)
9030 /* The tooltip has been drawn already. Avoid
9031 the SET_FRAME_GARBAGED below. */
9034 /* We use x_top_window_to_frame because map events can
9035 come for sub-windows and they don't mean that the
9036 frame is visible. */
9037 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9040 f
->async_visible
= 1;
9041 f
->async_iconified
= 0;
9042 f
->output_data
.x
->has_been_visible
= 1;
9044 /* wait_reading_process_input will notice this and update
9045 the frame's display structures. */
9046 SET_FRAME_GARBAGED (f
);
9050 bufp
->kind
= deiconify_event
;
9051 XSETFRAME (bufp
->frame_or_window
, f
);
9056 else if (! NILP (Vframe_list
)
9057 && ! NILP (XCDR (Vframe_list
)))
9058 /* Force a redisplay sooner or later
9059 to update the frame titles
9060 in case this is the second frame. */
9061 record_asynch_buffer_change ();
9066 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9069 /* I couldn't find a way to prevent LessTif scroll bars
9070 from consuming key events. */
9073 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9075 if (widget
&& XmIsScrollBar (widget
))
9077 widget
= XtParent (widget
);
9078 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9081 #endif /* USE_MOTIF */
9085 KeySym keysym
, orig_keysym
;
9086 /* al%imercury@uunet.uu.net says that making this 81 instead of
9087 80 fixed a bug whereby meta chars made his Emacs hang. */
9088 unsigned char copy_buffer
[81];
9092 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9093 extra_keyboard_modifiers
);
9094 modifiers
= event
.xkey
.state
;
9096 /* This will have to go some day... */
9098 /* make_lispy_event turns chars into control chars.
9099 Don't do it here because XLookupString is too eager. */
9100 event
.xkey
.state
&= ~ControlMask
;
9101 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9102 | dpyinfo
->super_mod_mask
9103 | dpyinfo
->hyper_mod_mask
9104 | dpyinfo
->alt_mod_mask
);
9106 /* In case Meta is ComposeCharacter,
9107 clear its status. According to Markus Ehrnsperger
9108 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9109 this enables ComposeCharacter to work whether or
9110 not it is combined with Meta. */
9111 if (modifiers
& dpyinfo
->meta_mod_mask
)
9112 bzero (&compose_status
, sizeof (compose_status
));
9117 /* The necessity of the following line took me
9118 a full work-day to decipher from the docs!! */
9119 if (XFilterEvent (&event
, None
))
9121 nbytes
= XmbLookupString (FRAME_XIC (f
),
9122 &event
.xkey
, copy_buffer
,
9125 if (status_return
== XLookupNone
)
9127 else if (status_return
== XLookupChars
)
9129 else if (status_return
!= XLookupKeySym
9130 && status_return
!= XLookupBoth
)
9134 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9135 80, &keysym
, &compose_status
);
9137 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
9138 80, &keysym
, &compose_status
);
9141 orig_keysym
= keysym
;
9145 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9146 || keysym
== XK_Delete
9147 #ifdef XK_ISO_Left_Tab
9148 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9150 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9151 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9152 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9154 /* This recognizes the "extended function keys".
9155 It seems there's no cleaner way.
9156 Test IsModifierKey to avoid handling mode_switch
9158 || ((unsigned) (keysym
) >= XK_Select
9159 && (unsigned)(keysym
) < XK_KP_Space
)
9161 #ifdef XK_dead_circumflex
9162 || orig_keysym
== XK_dead_circumflex
9164 #ifdef XK_dead_grave
9165 || orig_keysym
== XK_dead_grave
9167 #ifdef XK_dead_tilde
9168 || orig_keysym
== XK_dead_tilde
9170 #ifdef XK_dead_diaeresis
9171 || orig_keysym
== XK_dead_diaeresis
9173 #ifdef XK_dead_macron
9174 || orig_keysym
== XK_dead_macron
9176 #ifdef XK_dead_degree
9177 || orig_keysym
== XK_dead_degree
9179 #ifdef XK_dead_acute
9180 || orig_keysym
== XK_dead_acute
9182 #ifdef XK_dead_cedilla
9183 || orig_keysym
== XK_dead_cedilla
9185 #ifdef XK_dead_breve
9186 || orig_keysym
== XK_dead_breve
9188 #ifdef XK_dead_ogonek
9189 || orig_keysym
== XK_dead_ogonek
9191 #ifdef XK_dead_caron
9192 || orig_keysym
== XK_dead_caron
9194 #ifdef XK_dead_doubleacute
9195 || orig_keysym
== XK_dead_doubleacute
9197 #ifdef XK_dead_abovedot
9198 || orig_keysym
== XK_dead_abovedot
9200 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9201 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9202 /* Any "vendor-specific" key is ok. */
9203 || (orig_keysym
& (1 << 28)))
9204 && ! (IsModifierKey (orig_keysym
)
9206 #ifdef XK_Mode_switch
9207 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9210 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9212 #endif /* not HAVE_X11R5 */
9215 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9217 temp_buffer
[temp_index
++] = keysym
;
9218 bufp
->kind
= non_ascii_keystroke
;
9219 bufp
->code
= keysym
;
9220 XSETFRAME (bufp
->frame_or_window
, f
);
9222 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9224 bufp
->timestamp
= event
.xkey
.time
;
9229 if (display_busy_cursor_p
)
9230 if (keysym
!= XK_Return
|| minibuf_level
== 0)
9231 inhibit_busy_cursor
= 2;
9233 else if (numchars
> nbytes
)
9237 for (i
= 0; i
< nbytes
; i
++)
9239 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9241 temp_buffer
[temp_index
++] = copy_buffer
[i
];
9242 bufp
->kind
= ascii_keystroke
;
9243 bufp
->code
= copy_buffer
[i
];
9244 XSETFRAME (bufp
->frame_or_window
, f
);
9246 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9248 bufp
->timestamp
= event
.xkey
.time
;
9255 if (keysym
== NoSymbol
)
9266 /* Here's a possible interpretation of the whole
9267 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9268 you get a FocusIn event, you have to get a FocusOut
9269 event before you relinquish the focus. If you
9270 haven't received a FocusIn event, then a mere
9271 LeaveNotify is enough to free you. */
9275 int from_menu_bar_p
= 0;
9277 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9279 #ifdef LESSTIF_VERSION
9280 /* When clicking outside of a menu bar popup to close
9281 it, we get a FocusIn/ EnterNotify sequence of
9282 events. The flag event.xcrossing.focus is not set
9283 in the EnterNotify event of that sequence because
9284 the focus is in the menu bar,
9285 event.xcrossing.window is the frame's X window.
9286 Unconditionally setting the focus frame to null in
9287 this case is not the right thing, because no event
9288 follows that could set the focus frame to the right
9291 This could be a LessTif bug, but I wasn't able to
9292 reproduce the behavior in a simple test program.
9294 (gerd, LessTif 0.88.1). */
9296 if (!event
.xcrossing
.focus
9298 && f
->output_data
.x
->menubar_widget
)
9303 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9304 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9305 from_menu_bar_p
= 1;
9307 #endif /* LESSTIF_VERSION */
9309 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9311 /* Avoid nasty pop/raise loops. */
9312 if (f
&& (!(f
->auto_raise
)
9314 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9316 x_new_focus_frame (dpyinfo
, f
);
9317 enter_timestamp
= event
.xcrossing
.time
;
9320 else if (f
== dpyinfo
->x_focus_frame
)
9321 x_new_focus_frame (dpyinfo
, 0);
9323 /* EnterNotify counts as mouse movement,
9324 so update things that depend on mouse position. */
9325 if (f
&& !f
->output_data
.x
->busy_p
)
9326 note_mouse_movement (f
, &event
.xmotion
);
9331 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9332 if (event
.xfocus
.detail
!= NotifyPointer
)
9333 dpyinfo
->x_focus_event_frame
= f
;
9335 x_new_focus_frame (dpyinfo
, f
);
9338 if (f
&& FRAME_XIC (f
))
9339 XSetICFocus (FRAME_XIC (f
));
9345 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9349 int from_menu_bar_p
= 0;
9351 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9353 /* If we move outside the frame, then we're
9354 certainly no longer on any text in the frame. */
9355 clear_mouse_face (dpyinfo
);
9356 dpyinfo
->mouse_face_mouse_frame
= 0;
9359 /* Generate a nil HELP_EVENT to cancel a help-echo.
9360 Do it only if there's something to cancel.
9361 Otherwise, the startup message is cleared when
9362 the mouse leaves the frame. */
9363 if (any_help_event_p
)
9365 XSETFRAME (frame
, f
);
9366 bufp
->kind
= HELP_EVENT
;
9367 bufp
->frame_or_window
= Fcons (frame
, Qnil
);
9368 ++bufp
, ++count
, --numchars
;
9371 #ifdef LESSTIF_VERSION
9372 /* Please see the comment at the start of the
9373 EnterNotify case. */
9374 if (!event
.xcrossing
.focus
9375 && f
->output_data
.x
->menubar_widget
)
9379 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9380 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9381 from_menu_bar_p
= 1;
9383 #endif /* LESSTIF_VERSION */
9385 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9386 x_mouse_leave (dpyinfo
);
9389 if (f
== dpyinfo
->x_focus_event_frame
)
9390 dpyinfo
->x_focus_event_frame
= 0;
9391 if (f
== dpyinfo
->x_focus_frame
)
9392 x_new_focus_frame (dpyinfo
, 0);
9398 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9399 if (event
.xfocus
.detail
!= NotifyPointer
9400 && f
== dpyinfo
->x_focus_event_frame
)
9401 dpyinfo
->x_focus_event_frame
= 0;
9402 if (f
&& f
== dpyinfo
->x_focus_frame
)
9403 x_new_focus_frame (dpyinfo
, 0);
9406 if (f
&& FRAME_XIC (f
))
9407 XUnsetICFocus (FRAME_XIC (f
));
9414 previous_help_echo
= help_echo
;
9417 if (dpyinfo
->grabbed
&& last_mouse_frame
9418 && FRAME_LIVE_P (last_mouse_frame
))
9419 f
= last_mouse_frame
;
9421 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9424 note_mouse_movement (f
, &event
.xmotion
);
9427 #ifndef USE_X_TOOLKIT
9428 struct scroll_bar
*bar
9429 = x_window_to_scroll_bar (event
.xmotion
.window
);
9432 x_scroll_bar_note_movement (bar
, &event
);
9433 #endif /* USE_X_TOOLKIT */
9435 /* If we move outside the frame, then we're
9436 certainly no longer on any text in the frame. */
9437 clear_mouse_face (dpyinfo
);
9440 /* If the contents of the global variable help_echo
9441 has changed, generate a HELP_EVENT. */
9442 if (STRINGP (help_echo
)
9443 || STRINGP (previous_help_echo
))
9448 XSETFRAME (frame
, f
);
9452 any_help_event_p
= 1;
9453 bufp
->kind
= HELP_EVENT
;
9454 bufp
->frame_or_window
= Fcons (frame
, help_echo
);
9455 ++bufp
, ++count
, --numchars
;
9461 case ConfigureNotify
:
9462 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
9465 #ifndef USE_X_TOOLKIT
9466 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
9467 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
9469 /* In the toolkit version, change_frame_size
9470 is called by the code that handles resizing
9471 of the EmacsFrame widget. */
9473 /* Even if the number of character rows and columns has
9474 not changed, the font size may have changed, so we need
9475 to check the pixel dimensions as well. */
9476 if (columns
!= f
->width
9477 || rows
!= f
->height
9478 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
9479 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
9481 change_frame_size (f
, rows
, columns
, 0, 1, 0);
9482 SET_FRAME_GARBAGED (f
);
9483 cancel_mouse_face (f
);
9487 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
9488 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
9490 /* What we have now is the position of Emacs's own window.
9491 Convert that to the position of the window manager window. */
9492 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
9493 &f
->output_data
.x
->top_pos
);
9495 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
9497 /* Since the WM decorations come below top_pos now,
9498 we must put them below top_pos in the future. */
9499 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
9500 x_wm_set_size_hint (f
, (long) 0, 0);
9503 /* Some window managers pass (0,0) as the location of
9504 the window, and the Motif event handler stores it
9505 in the emacs widget, which messes up Motif menus. */
9506 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
9508 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
9509 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
9511 #endif /* USE_MOTIF */
9518 /* If we decide we want to generate an event to be seen
9519 by the rest of Emacs, we put it here. */
9520 struct input_event emacs_event
;
9523 emacs_event
.kind
= no_event
;
9524 bzero (&compose_status
, sizeof (compose_status
));
9526 if (dpyinfo
->grabbed
9528 && FRAME_LIVE_P (last_mouse_frame
))
9529 f
= last_mouse_frame
;
9531 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9535 /* Is this in the tool-bar? */
9536 if (WINDOWP (f
->tool_bar_window
)
9537 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
9542 x
= event
.xbutton
.x
;
9543 y
= event
.xbutton
.y
;
9546 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
9547 if (EQ (window
, f
->tool_bar_window
))
9549 x_handle_tool_bar_click (f
, &event
.xbutton
);
9555 if (!dpyinfo
->x_focus_frame
9556 || f
== dpyinfo
->x_focus_frame
)
9557 construct_mouse_click (&emacs_event
, &event
, f
);
9561 #ifndef USE_TOOLKIT_SCROLL_BARS
9562 struct scroll_bar
*bar
9563 = x_window_to_scroll_bar (event
.xbutton
.window
);
9566 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
9567 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9570 if (event
.type
== ButtonPress
)
9572 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
9573 last_mouse_frame
= f
;
9574 /* Ignore any mouse motion that happened
9575 before this event; any subsequent mouse-movement
9576 Emacs events should reflect only motion after
9582 last_tool_bar_item
= -1;
9583 if (display_busy_cursor_p
)
9584 inhibit_busy_cursor
= 2;
9588 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
9591 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
9593 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
9599 #ifdef USE_X_TOOLKIT
9600 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9601 /* For a down-event in the menu bar,
9602 don't pass it to Xt right now.
9603 Instead, save it away
9604 and we will pass it to Xt from kbd_buffer_get_event.
9605 That way, we can run some Lisp code first. */
9606 if (f
&& event
.type
== ButtonPress
9607 /* Verify the event is really within the menu bar
9608 and not just sent to it due to grabbing. */
9609 && event
.xbutton
.x
>= 0
9610 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
9611 && event
.xbutton
.y
>= 0
9612 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
9613 && event
.xbutton
.same_screen
)
9615 SET_SAVED_BUTTON_EVENT
;
9616 XSETFRAME (last_mouse_press_frame
, f
);
9618 else if (event
.type
== ButtonPress
)
9620 last_mouse_press_frame
= Qnil
;
9624 #ifdef USE_MOTIF /* This should do not harm for Lucid,
9625 but I am trying to be cautious. */
9626 else if (event
.type
== ButtonRelease
)
9628 if (!NILP (last_mouse_press_frame
))
9630 f
= XFRAME (last_mouse_press_frame
);
9631 if (f
->output_data
.x
)
9632 SET_SAVED_BUTTON_EVENT
;
9637 #endif /* USE_MOTIF */
9640 #endif /* USE_X_TOOLKIT */
9644 case CirculateNotify
:
9647 case CirculateRequest
:
9650 case VisibilityNotify
:
9654 /* Someone has changed the keyboard mapping - update the
9656 switch (event
.xmapping
.request
)
9658 case MappingModifier
:
9659 x_find_modifier_meanings (dpyinfo
);
9660 /* This is meant to fall through. */
9661 case MappingKeyboard
:
9662 XRefreshKeyboardMapping (&event
.xmapping
);
9668 #ifdef USE_X_TOOLKIT
9670 XtDispatchEvent (&event
);
9672 #endif /* USE_X_TOOLKIT */
9680 /* On some systems, an X bug causes Emacs to get no more events
9681 when the window is destroyed. Detect that. (1994.) */
9684 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
9685 One XNOOP in 100 loops will make Emacs terminate.
9686 B. Bretthauer, 1994 */
9688 if (x_noop_count
>= 100)
9692 if (next_noop_dpyinfo
== 0)
9693 next_noop_dpyinfo
= x_display_list
;
9695 XNoOp (next_noop_dpyinfo
->display
);
9697 /* Each time we get here, cycle through the displays now open. */
9698 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
9702 /* If the focus was just given to an auto-raising frame,
9704 /* ??? This ought to be able to handle more than one such frame. */
9705 if (pending_autoraise_frame
)
9707 x_raise_frame (pending_autoraise_frame
);
9708 pending_autoraise_frame
= 0;
9718 /***********************************************************************
9720 ***********************************************************************/
9722 /* Note if the text cursor of window W has been overwritten by a
9723 drawing operation that outputs N glyphs starting at HPOS in the
9724 line given by output_cursor.vpos. N < 0 means all the rest of the
9725 line after HPOS has been written. */
9728 note_overwritten_text_cursor (w
, hpos
, n
)
9732 if (updated_area
== TEXT_AREA
9733 && output_cursor
.vpos
== w
->phys_cursor
.vpos
9734 && hpos
<= w
->phys_cursor
.hpos
9736 || hpos
+ n
> w
->phys_cursor
.hpos
))
9737 w
->phys_cursor_on_p
= 0;
9741 /* Set clipping for output in glyph row ROW. W is the window in which
9742 we operate. GC is the graphics context to set clipping in.
9743 WHOLE_LINE_P non-zero means include the areas used for truncation
9744 mark display and alike in the clipping rectangle.
9746 ROW may be a text row or, e.g., a mode line. Text rows must be
9747 clipped to the interior of the window dedicated to text display,
9748 mode lines must be clipped to the whole window. */
9751 x_clip_to_row (w
, row
, gc
, whole_line_p
)
9753 struct glyph_row
*row
;
9757 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9758 XRectangle clip_rect
;
9759 int window_x
, window_y
, window_width
, window_height
;
9761 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9763 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
9764 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
9765 clip_rect
.y
= max (clip_rect
.y
, window_y
);
9766 clip_rect
.width
= window_width
;
9767 clip_rect
.height
= row
->visible_height
;
9769 /* If clipping to the whole line, including trunc marks, extend
9770 the rectangle to the left and increase its width. */
9773 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
9774 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
9777 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
9781 /* Draw a hollow box cursor on window W in glyph row ROW. */
9784 x_draw_hollow_cursor (w
, row
)
9786 struct glyph_row
*row
;
9788 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9789 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9790 Display
*dpy
= FRAME_X_DISPLAY (f
);
9793 struct glyph
*cursor_glyph
;
9796 /* Compute frame-relative coordinates from window-relative
9798 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9799 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
9800 + row
->ascent
- w
->phys_cursor_ascent
);
9801 h
= row
->height
- 1;
9803 /* Get the glyph the cursor is on. If we can't tell because
9804 the current matrix is invalid or such, give up. */
9805 cursor_glyph
= get_phys_cursor_glyph (w
);
9806 if (cursor_glyph
== NULL
)
9809 /* Compute the width of the rectangle to draw. If on a stretch
9810 glyph, and `x-stretch-block-cursor' is nil, don't draw a
9811 rectangle as wide as the glyph, but use a canonical character
9813 wd
= cursor_glyph
->pixel_width
- 1;
9814 if (cursor_glyph
->type
== STRETCH_GLYPH
9815 && !x_stretch_cursor_p
)
9816 wd
= min (CANON_X_UNIT (f
), wd
);
9818 /* The foreground of cursor_gc is typically the same as the normal
9819 background color, which can cause the cursor box to be invisible. */
9820 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9821 if (dpyinfo
->scratch_cursor_gc
)
9822 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
9824 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
9825 GCForeground
, &xgcv
);
9826 gc
= dpyinfo
->scratch_cursor_gc
;
9828 /* Set clipping, draw the rectangle, and reset clipping again. */
9829 x_clip_to_row (w
, row
, gc
, 0);
9830 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
9831 XSetClipMask (dpy
, gc
, None
);
9835 /* Draw a bar cursor on window W in glyph row ROW.
9837 Implementation note: One would like to draw a bar cursor with an
9838 angle equal to the one given by the font property XA_ITALIC_ANGLE.
9839 Unfortunately, I didn't find a font yet that has this property set.
9843 x_draw_bar_cursor (w
, row
)
9845 struct glyph_row
*row
;
9847 /* If cursor hpos is out of bounds, don't draw garbage. This can
9848 happen in mini-buffer windows when switching between echo area
9849 glyphs and mini-buffer. */
9850 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9852 struct frame
*f
= XFRAME (w
->frame
);
9853 struct glyph
*cursor_glyph
;
9861 cursor_glyph
= get_phys_cursor_glyph (w
);
9862 if (cursor_glyph
== NULL
)
9865 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
9866 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9867 xgcv
.graphics_exposures
= 0;
9868 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
9869 dpy
= FRAME_X_DISPLAY (f
);
9870 window
= FRAME_X_WINDOW (f
);
9871 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
9874 XChangeGC (dpy
, gc
, mask
, &xgcv
);
9877 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
9878 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
9881 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9882 x_clip_to_row (w
, row
, gc
, 0);
9883 XFillRectangle (dpy
, window
, gc
,
9885 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9886 min (cursor_glyph
->pixel_width
,
9887 f
->output_data
.x
->cursor_width
),
9889 XSetClipMask (dpy
, gc
, None
);
9894 /* Clear the cursor of window W to background color, and mark the
9895 cursor as not shown. This is used when the text where the cursor
9896 is is about to be rewritten. */
9902 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
9903 x_update_window_cursor (w
, 0);
9907 /* Draw the cursor glyph of window W in glyph row ROW. See the
9908 comment of x_draw_glyphs for the meaning of HL. */
9911 x_draw_phys_cursor_glyph (w
, row
, hl
)
9913 struct glyph_row
*row
;
9914 enum draw_glyphs_face hl
;
9916 /* If cursor hpos is out of bounds, don't draw garbage. This can
9917 happen in mini-buffer windows when switching between echo area
9918 glyphs and mini-buffer. */
9919 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9921 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
9922 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
9925 /* When we erase the cursor, and ROW is overlapped by other
9926 rows, make sure that these overlapping parts of other rows
9928 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
9930 if (row
> w
->current_matrix
->rows
9931 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
9932 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
9934 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
9935 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
9936 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
9942 /* Erase the image of a cursor of window W from the screen. */
9945 x_erase_phys_cursor (w
)
9948 struct frame
*f
= XFRAME (w
->frame
);
9949 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9950 int hpos
= w
->phys_cursor
.hpos
;
9951 int vpos
= w
->phys_cursor
.vpos
;
9952 int mouse_face_here_p
= 0;
9953 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
9954 struct glyph_row
*cursor_row
;
9955 struct glyph
*cursor_glyph
;
9956 enum draw_glyphs_face hl
;
9958 /* No cursor displayed or row invalidated => nothing to do on the
9960 if (w
->phys_cursor_type
== NO_CURSOR
)
9961 goto mark_cursor_off
;
9963 /* VPOS >= active_glyphs->nrows means that window has been resized.
9964 Don't bother to erase the cursor. */
9965 if (vpos
>= active_glyphs
->nrows
)
9966 goto mark_cursor_off
;
9968 /* If row containing cursor is marked invalid, there is nothing we
9970 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9971 if (!cursor_row
->enabled_p
)
9972 goto mark_cursor_off
;
9974 /* This can happen when the new row is shorter than the old one.
9975 In this case, either x_draw_glyphs or clear_end_of_line
9976 should have cleared the cursor. Note that we wouldn't be
9977 able to erase the cursor in this case because we don't have a
9978 cursor glyph at hand. */
9979 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9980 goto mark_cursor_off
;
9982 /* If the cursor is in the mouse face area, redisplay that when
9983 we clear the cursor. */
9984 if (w
== XWINDOW (dpyinfo
->mouse_face_window
)
9985 && (vpos
> dpyinfo
->mouse_face_beg_row
9986 || (vpos
== dpyinfo
->mouse_face_beg_row
9987 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9988 && (vpos
< dpyinfo
->mouse_face_end_row
9989 || (vpos
== dpyinfo
->mouse_face_end_row
9990 && hpos
< dpyinfo
->mouse_face_end_col
))
9991 /* Don't redraw the cursor's spot in mouse face if it is at the
9992 end of a line (on a newline). The cursor appears there, but
9993 mouse highlighting does not. */
9994 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9995 mouse_face_here_p
= 1;
9997 /* Maybe clear the display under the cursor. */
9998 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10001 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10003 cursor_glyph
= get_phys_cursor_glyph (w
);
10004 if (cursor_glyph
== NULL
)
10005 goto mark_cursor_off
;
10007 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10009 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10011 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10013 cursor_glyph
->pixel_width
,
10014 cursor_row
->visible_height
,
10018 /* Erase the cursor by redrawing the character underneath it. */
10019 if (mouse_face_here_p
)
10020 hl
= DRAW_MOUSE_FACE
;
10021 else if (cursor_row
->inverse_p
)
10022 hl
= DRAW_INVERSE_VIDEO
;
10024 hl
= DRAW_NORMAL_TEXT
;
10025 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10028 w
->phys_cursor_on_p
= 0;
10029 w
->phys_cursor_type
= NO_CURSOR
;
10033 /* Display or clear cursor of window W. If ON is zero, clear the
10034 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10035 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10038 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10040 int on
, hpos
, vpos
, x
, y
;
10042 struct frame
*f
= XFRAME (w
->frame
);
10043 int new_cursor_type
;
10044 struct glyph_matrix
*current_glyphs
;
10045 struct glyph_row
*glyph_row
;
10046 struct glyph
*glyph
;
10048 /* This is pointless on invisible frames, and dangerous on garbaged
10049 windows and frames; in the latter case, the frame or window may
10050 be in the midst of changing its size, and x and y may be off the
10052 if (! FRAME_VISIBLE_P (f
)
10053 || FRAME_GARBAGED_P (f
)
10054 || vpos
>= w
->current_matrix
->nrows
10055 || hpos
>= w
->current_matrix
->matrix_w
)
10058 /* If cursor is off and we want it off, return quickly. */
10059 if (!on
&& !w
->phys_cursor_on_p
)
10062 current_glyphs
= w
->current_matrix
;
10063 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10064 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10066 /* If cursor row is not enabled, we don't really know where to
10067 display the cursor. */
10068 if (!glyph_row
->enabled_p
)
10070 w
->phys_cursor_on_p
= 0;
10074 xassert (interrupt_input_blocked
);
10076 /* Set new_cursor_type to the cursor we want to be displayed. In a
10077 mini-buffer window, we want the cursor only to appear if we are
10078 reading input from this window. For the selected window, we want
10079 the cursor type given by the frame parameter. If explicitly
10080 marked off, draw no cursor. In all other cases, we want a hollow
10082 if (cursor_in_echo_area
10083 && FRAME_HAS_MINIBUF_P (f
)
10084 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10086 if (w
== XWINDOW (echo_area_window
))
10087 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10089 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10093 if (w
!= XWINDOW (selected_window
)
10094 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10096 if (MINI_WINDOW_P (w
))
10097 new_cursor_type
= NO_CURSOR
;
10099 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10101 else if (w
->cursor_off_p
)
10102 new_cursor_type
= NO_CURSOR
;
10104 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10107 /* If cursor is currently being shown and we don't want it to be or
10108 it is in the wrong place, or the cursor type is not what we want,
10110 if (w
->phys_cursor_on_p
10112 || w
->phys_cursor
.x
!= x
10113 || w
->phys_cursor
.y
!= y
10114 || new_cursor_type
!= w
->phys_cursor_type
))
10115 x_erase_phys_cursor (w
);
10117 /* If the cursor is now invisible and we want it to be visible,
10119 if (on
&& !w
->phys_cursor_on_p
)
10121 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10122 w
->phys_cursor_height
= glyph_row
->height
;
10124 /* Set phys_cursor_.* before x_draw_.* is called because some
10125 of them may need the information. */
10126 w
->phys_cursor
.x
= x
;
10127 w
->phys_cursor
.y
= glyph_row
->y
;
10128 w
->phys_cursor
.hpos
= hpos
;
10129 w
->phys_cursor
.vpos
= vpos
;
10130 w
->phys_cursor_type
= new_cursor_type
;
10131 w
->phys_cursor_on_p
= 1;
10133 switch (new_cursor_type
)
10135 case HOLLOW_BOX_CURSOR
:
10136 x_draw_hollow_cursor (w
, glyph_row
);
10139 case FILLED_BOX_CURSOR
:
10140 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10144 x_draw_bar_cursor (w
, glyph_row
);
10156 if (updating_frame
!= f
)
10157 XFlush (FRAME_X_DISPLAY (f
));
10162 /* Display the cursor on window W, or clear it. X and Y are window
10163 relative pixel coordinates. HPOS and VPOS are glyph matrix
10164 positions. If W is not the selected window, display a hollow
10165 cursor. ON non-zero means display the cursor at X, Y which
10166 correspond to HPOS, VPOS, otherwise it is cleared. */
10169 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10171 int on
, hpos
, vpos
, x
, y
;
10174 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10179 /* Display the cursor on window W, or clear it, according to ON_P.
10180 Don't change the cursor's position. */
10183 x_update_cursor (f
, on_p
)
10186 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10190 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10191 in the window tree rooted at W. */
10194 x_update_cursor_in_window_tree (w
, on_p
)
10200 if (!NILP (w
->hchild
))
10201 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10202 else if (!NILP (w
->vchild
))
10203 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10205 x_update_window_cursor (w
, on_p
);
10207 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10212 /* Switch the display of W's cursor on or off, according to the value
10216 x_update_window_cursor (w
, on
)
10221 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10222 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10231 /* Refresh bitmap kitchen sink icon for frame F
10232 when we get an expose event for it. */
10238 /* Normally, the window manager handles this function. */
10241 /* Make the x-window of frame F use the gnu icon bitmap. */
10244 x_bitmap_icon (f
, file
)
10250 if (FRAME_X_WINDOW (f
) == 0)
10253 /* Free up our existing icon bitmap if any. */
10254 if (f
->output_data
.x
->icon_bitmap
> 0)
10255 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10256 f
->output_data
.x
->icon_bitmap
= 0;
10258 if (STRINGP (file
))
10259 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10262 /* Create the GNU bitmap if necessary. */
10263 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10264 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10265 = x_create_bitmap_from_data (f
, gnu_bits
,
10266 gnu_width
, gnu_height
);
10268 /* The first time we create the GNU bitmap,
10269 this increments the ref-count one extra time.
10270 As a result, the GNU bitmap is never freed.
10271 That way, we don't have to worry about allocating it again. */
10272 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10274 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10277 x_wm_set_icon_pixmap (f
, bitmap_id
);
10278 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10284 /* Make the x-window of frame F use a rectangle with text.
10285 Use ICON_NAME as the text. */
10288 x_text_icon (f
, icon_name
)
10292 if (FRAME_X_WINDOW (f
) == 0)
10297 XTextProperty text
;
10298 text
.value
= (unsigned char *) icon_name
;
10299 text
.encoding
= XA_STRING
;
10301 text
.nitems
= strlen (icon_name
);
10302 #ifdef USE_X_TOOLKIT
10303 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10305 #else /* not USE_X_TOOLKIT */
10306 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10307 #endif /* not USE_X_TOOLKIT */
10309 #else /* not HAVE_X11R4 */
10310 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10311 #endif /* not HAVE_X11R4 */
10313 if (f
->output_data
.x
->icon_bitmap
> 0)
10314 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10315 f
->output_data
.x
->icon_bitmap
= 0;
10316 x_wm_set_icon_pixmap (f
, 0);
10321 #define X_ERROR_MESSAGE_SIZE 200
10323 /* If non-nil, this should be a string.
10324 It means catch X errors and store the error message in this string. */
10326 static Lisp_Object x_error_message_string
;
10328 /* An X error handler which stores the error message in
10329 x_error_message_string. This is called from x_error_handler if
10330 x_catch_errors is in effect. */
10333 x_error_catcher (display
, error
)
10335 XErrorEvent
*error
;
10337 XGetErrorText (display
, error
->error_code
,
10338 XSTRING (x_error_message_string
)->data
,
10339 X_ERROR_MESSAGE_SIZE
);
10342 /* Begin trapping X errors for display DPY. Actually we trap X errors
10343 for all displays, but DPY should be the display you are actually
10346 After calling this function, X protocol errors no longer cause
10347 Emacs to exit; instead, they are recorded in the string
10348 stored in x_error_message_string.
10350 Calling x_check_errors signals an Emacs error if an X error has
10351 occurred since the last call to x_catch_errors or x_check_errors.
10353 Calling x_uncatch_errors resumes the normal error handling. */
10355 void x_check_errors ();
10356 static Lisp_Object
x_catch_errors_unwind ();
10359 x_catch_errors (dpy
)
10362 int count
= specpdl_ptr
- specpdl
;
10364 /* Make sure any errors from previous requests have been dealt with. */
10365 XSync (dpy
, False
);
10367 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10369 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10370 XSTRING (x_error_message_string
)->data
[0] = 0;
10375 /* Unbind the binding that we made to check for X errors. */
10378 x_catch_errors_unwind (old_val
)
10379 Lisp_Object old_val
;
10381 x_error_message_string
= old_val
;
10385 /* If any X protocol errors have arrived since the last call to
10386 x_catch_errors or x_check_errors, signal an Emacs error using
10387 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10390 x_check_errors (dpy
, format
)
10394 /* Make sure to catch any errors incurred so far. */
10395 XSync (dpy
, False
);
10397 if (XSTRING (x_error_message_string
)->data
[0])
10398 error (format
, XSTRING (x_error_message_string
)->data
);
10401 /* Nonzero if we had any X protocol errors
10402 since we did x_catch_errors on DPY. */
10405 x_had_errors_p (dpy
)
10408 /* Make sure to catch any errors incurred so far. */
10409 XSync (dpy
, False
);
10411 return XSTRING (x_error_message_string
)->data
[0] != 0;
10414 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
10417 x_clear_errors (dpy
)
10420 XSTRING (x_error_message_string
)->data
[0] = 0;
10423 /* Stop catching X protocol errors and let them make Emacs die.
10424 DPY should be the display that was passed to x_catch_errors.
10425 COUNT should be the value that was returned by
10426 the corresponding call to x_catch_errors. */
10429 x_uncatch_errors (dpy
, count
)
10433 unbind_to (count
, Qnil
);
10437 static unsigned int x_wire_count
;
10440 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
10445 /* Handle SIGPIPE, which can happen when the connection to a server
10446 simply goes away. SIGPIPE is handled by x_connection_signal.
10447 Don't need to do anything, because the write which caused the
10448 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
10449 which will do the appropriate cleanup for us. */
10452 x_connection_signal (signalnum
) /* If we don't have an argument, */
10453 int signalnum
; /* some compilers complain in signal calls. */
10456 /* USG systems forget handlers when they are used;
10457 must reestablish each time */
10458 signal (signalnum
, x_connection_signal
);
10462 /* Handling X errors. */
10464 /* Handle the loss of connection to display DISPLAY. */
10467 x_connection_closed (display
, error_message
)
10469 char *error_message
;
10471 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
10472 Lisp_Object frame
, tail
;
10474 /* Indicate that this display is dead. */
10476 #ifdef USE_X_TOOLKIT
10477 XtCloseDisplay (display
);
10480 dpyinfo
->display
= 0;
10482 /* First delete frames whose mini-buffers are on frames
10483 that are on the dead display. */
10484 FOR_EACH_FRAME (tail
, frame
)
10486 Lisp_Object minibuf_frame
;
10488 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
10489 if (FRAME_X_P (XFRAME (frame
))
10490 && FRAME_X_P (XFRAME (minibuf_frame
))
10491 && ! EQ (frame
, minibuf_frame
)
10492 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
10493 Fdelete_frame (frame
, Qt
);
10496 /* Now delete all remaining frames on the dead display.
10497 We are now sure none of these is used as the mini-buffer
10498 for another frame that we need to delete. */
10499 FOR_EACH_FRAME (tail
, frame
)
10500 if (FRAME_X_P (XFRAME (frame
))
10501 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
10503 /* Set this to t so that Fdelete_frame won't get confused
10504 trying to find a replacement. */
10505 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
10506 Fdelete_frame (frame
, Qt
);
10510 x_delete_display (dpyinfo
);
10512 if (x_display_list
== 0)
10514 fprintf (stderr
, "%s\n", error_message
);
10515 shut_down_emacs (0, 0, Qnil
);
10519 /* Ordinary stack unwind doesn't deal with these. */
10521 sigunblock (sigmask (SIGIO
));
10523 sigunblock (sigmask (SIGALRM
));
10524 TOTALLY_UNBLOCK_INPUT
;
10526 clear_waiting_for_input ();
10527 error ("%s", error_message
);
10530 /* This is the usual handler for X protocol errors.
10531 It kills all frames on the display that we got the error for.
10532 If that was the only one, it prints an error message and kills Emacs. */
10535 x_error_quitter (display
, error
)
10537 XErrorEvent
*error
;
10539 char buf
[256], buf1
[356];
10541 /* Note that there is no real way portable across R3/R4 to get the
10542 original error handler. */
10544 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
10545 sprintf (buf1
, "X protocol error: %s on protocol request %d",
10546 buf
, error
->request_code
);
10547 x_connection_closed (display
, buf1
);
10550 /* This is the first-level handler for X protocol errors.
10551 It calls x_error_quitter or x_error_catcher. */
10554 x_error_handler (display
, error
)
10556 XErrorEvent
*error
;
10558 if (! NILP (x_error_message_string
))
10559 x_error_catcher (display
, error
);
10561 x_error_quitter (display
, error
);
10565 /* This is the handler for X IO errors, always.
10566 It kills all frames on the display that we lost touch with.
10567 If that was the only one, it prints an error message and kills Emacs. */
10570 x_io_error_quitter (display
)
10575 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
10576 x_connection_closed (display
, buf
);
10580 /* Changing the font of the frame. */
10582 /* Give frame F the font named FONTNAME as its default font, and
10583 return the full name of that font. FONTNAME may be a wildcard
10584 pattern; in that case, we choose some font that fits the pattern.
10585 The return value shows which font we chose. */
10588 x_new_font (f
, fontname
)
10590 register char *fontname
;
10592 struct font_info
*fontp
10593 = fs_load_font (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
, fontname
, -1);
10598 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
10599 f
->output_data
.x
->font_baseline
10600 = (f
->output_data
.x
->font
->ascent
+ fontp
->baseline_offset
);
10601 f
->output_data
.x
->fontset
= -1;
10603 /* Compute the scroll bar width in character columns. */
10604 if (f
->scroll_bar_pixel_width
> 0)
10606 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10607 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
10611 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10612 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
10615 /* Now make the frame display the given font. */
10616 if (FRAME_X_WINDOW (f
) != 0)
10618 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
10619 f
->output_data
.x
->font
->fid
);
10620 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
10621 f
->output_data
.x
->font
->fid
);
10622 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
10623 f
->output_data
.x
->font
->fid
);
10625 frame_update_line_height (f
);
10626 x_set_window_size (f
, 0, f
->width
, f
->height
);
10629 /* If we are setting a new frame's font for the first time,
10630 there are no faces yet, so this font's height is the line height. */
10631 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
10633 return build_string (fontp
->full_name
);
10636 /* Give frame F the fontset named FONTSETNAME as its default font, and
10637 return the full name of that fontset. FONTSETNAME may be a wildcard
10638 pattern; in that case, we choose some fontset that fits the pattern.
10639 The return value shows which fontset we chose. */
10642 x_new_fontset (f
, fontsetname
)
10646 int fontset
= fs_query_fontset (f
, fontsetname
);
10647 struct fontset_info
*fontsetp
;
10648 Lisp_Object result
;
10653 if (f
->output_data
.x
->fontset
== fontset
)
10654 /* This fontset is already set in frame F. There's nothing more
10656 return build_string (fontsetname
);
10658 fontsetp
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
10660 if (!fontsetp
->fontname
[CHARSET_ASCII
])
10661 /* This fontset doesn't contain ASCII font. */
10664 result
= x_new_font (f
, fontsetp
->fontname
[CHARSET_ASCII
]);
10666 if (!STRINGP (result
))
10667 /* Can't load ASCII font. */
10670 /* Since x_new_font doesn't update any fontset information, do it now. */
10671 f
->output_data
.x
->fontset
= fontset
;
10672 FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
),
10673 CHARSET_ASCII
, fontsetp
->fontname
[CHARSET_ASCII
], fontset
);
10675 return build_string (fontsetname
);
10678 /* Calculate the absolute position in frame F
10679 from its current recorded position values and gravity. */
10682 x_calc_absolute_position (f
)
10686 int win_x
= 0, win_y
= 0;
10687 int flags
= f
->output_data
.x
->size_hint_flags
;
10690 /* We have nothing to do if the current position
10691 is already for the top-left corner. */
10692 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
10695 #ifdef USE_X_TOOLKIT
10696 this_window
= XtWindow (f
->output_data
.x
->widget
);
10698 this_window
= FRAME_X_WINDOW (f
);
10701 /* Find the position of the outside upper-left corner of
10702 the inner window, with respect to the outer window.
10703 But do this only if we will need the results. */
10704 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10709 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
10712 x_clear_errors (FRAME_X_DISPLAY (f
));
10713 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
10715 /* From-window, to-window. */
10717 f
->output_data
.x
->parent_desc
,
10719 /* From-position, to-position. */
10720 0, 0, &win_x
, &win_y
,
10722 /* Child of win. */
10724 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
10726 Window newroot
, newparent
= 0xdeadbeef;
10727 Window
*newchildren
;
10730 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
10731 &newparent
, &newchildren
, &nchildren
))
10734 XFree ((char *) newchildren
);
10736 f
->output_data
.x
->parent_desc
= newparent
;
10742 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
10746 /* Treat negative positions as relative to the leftmost bottommost
10747 position that fits on the screen. */
10748 if (flags
& XNegative
)
10749 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
10750 - 2 * f
->output_data
.x
->border_width
- win_x
10752 + f
->output_data
.x
->left_pos
);
10754 if (flags
& YNegative
)
10756 int menubar_height
= 0;
10758 #ifdef USE_X_TOOLKIT
10759 if (f
->output_data
.x
->menubar_widget
)
10761 = (f
->output_data
.x
->menubar_widget
->core
.height
10762 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
10765 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
10766 - 2 * f
->output_data
.x
->border_width
10770 + f
->output_data
.x
->top_pos
);
10773 /* The left_pos and top_pos
10774 are now relative to the top and left screen edges,
10775 so the flags should correspond. */
10776 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10779 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
10780 to really change the position, and 0 when calling from
10781 x_make_frame_visible (in that case, XOFF and YOFF are the current
10782 position values). It is -1 when calling from x_set_frame_parameters,
10783 which means, do adjust for borders but don't change the gravity. */
10786 x_set_offset (f
, xoff
, yoff
, change_gravity
)
10788 register int xoff
, yoff
;
10789 int change_gravity
;
10791 int modified_top
, modified_left
;
10793 if (change_gravity
> 0)
10795 f
->output_data
.x
->top_pos
= yoff
;
10796 f
->output_data
.x
->left_pos
= xoff
;
10797 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10799 f
->output_data
.x
->size_hint_flags
|= XNegative
;
10801 f
->output_data
.x
->size_hint_flags
|= YNegative
;
10802 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10804 x_calc_absolute_position (f
);
10807 x_wm_set_size_hint (f
, (long) 0, 0);
10809 modified_left
= f
->output_data
.x
->left_pos
;
10810 modified_top
= f
->output_data
.x
->top_pos
;
10811 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
10812 this seems to be unnecessary and incorrect. rms, 4/17/97. */
10813 /* It is a mystery why we need to add the border_width here
10814 when the frame is already visible, but experiment says we do. */
10815 if (change_gravity
!= 0)
10817 modified_left
+= f
->output_data
.x
->border_width
;
10818 modified_top
+= f
->output_data
.x
->border_width
;
10822 #ifdef USE_X_TOOLKIT
10823 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10824 modified_left
, modified_top
);
10825 #else /* not USE_X_TOOLKIT */
10826 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10827 modified_left
, modified_top
);
10828 #endif /* not USE_X_TOOLKIT */
10832 /* Call this to change the size of frame F's x-window.
10833 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
10834 for this size change and subsequent size changes.
10835 Otherwise we leave the window gravity unchanged. */
10838 x_set_window_size (f
, change_gravity
, cols
, rows
)
10840 int change_gravity
;
10843 #ifndef USE_X_TOOLKIT
10844 int pixelwidth
, pixelheight
;
10849 #ifdef USE_X_TOOLKIT
10851 /* The x and y position of the widget is clobbered by the
10852 call to XtSetValues within EmacsFrameSetCharSize.
10853 This is a real kludge, but I don't understand Xt so I can't
10854 figure out a correct fix. Can anyone else tell me? -- rms. */
10855 int xpos
= f
->output_data
.x
->widget
->core
.x
;
10856 int ypos
= f
->output_data
.x
->widget
->core
.y
;
10857 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
10858 f
->output_data
.x
->widget
->core
.x
= xpos
;
10859 f
->output_data
.x
->widget
->core
.y
= ypos
;
10862 #else /* not USE_X_TOOLKIT */
10864 check_frame_size (f
, &rows
, &cols
);
10865 f
->output_data
.x
->vertical_scroll_bar_extra
10866 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
10868 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
10869 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
10870 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
10871 f
->output_data
.x
->flags_areas_extra
10872 = FRAME_FLAGS_AREA_WIDTH (f
);
10873 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
10874 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
10876 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10877 x_wm_set_size_hint (f
, (long) 0, 0);
10879 XSync (FRAME_X_DISPLAY (f
), False
);
10880 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10881 pixelwidth
, pixelheight
);
10883 /* Now, strictly speaking, we can't be sure that this is accurate,
10884 but the window manager will get around to dealing with the size
10885 change request eventually, and we'll hear how it went when the
10886 ConfigureNotify event gets here.
10888 We could just not bother storing any of this information here,
10889 and let the ConfigureNotify event set everything up, but that
10890 might be kind of confusing to the Lisp code, since size changes
10891 wouldn't be reported in the frame parameters until some random
10892 point in the future when the ConfigureNotify event arrives.
10894 We pass 1 for DELAY since we can't run Lisp code inside of
10896 change_frame_size (f
, rows
, cols
, 0, 1, 0);
10897 PIXEL_WIDTH (f
) = pixelwidth
;
10898 PIXEL_HEIGHT (f
) = pixelheight
;
10900 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
10901 receive in the ConfigureNotify event; if we get what we asked
10902 for, then the event won't cause the screen to become garbaged, so
10903 we have to make sure to do it here. */
10904 SET_FRAME_GARBAGED (f
);
10906 XFlush (FRAME_X_DISPLAY (f
));
10908 #endif /* not USE_X_TOOLKIT */
10910 /* If cursor was outside the new size, mark it as off. */
10911 mark_window_cursors_off (XWINDOW (f
->root_window
));
10913 /* Clear out any recollection of where the mouse highlighting was,
10914 since it might be in a place that's outside the new frame size.
10915 Actually checking whether it is outside is a pain in the neck,
10916 so don't try--just let the highlighting be done afresh with new size. */
10917 cancel_mouse_face (f
);
10922 /* Mouse warping. */
10925 x_set_mouse_position (f
, x
, y
)
10931 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
10932 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
10934 if (pix_x
< 0) pix_x
= 0;
10935 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
10937 if (pix_y
< 0) pix_y
= 0;
10938 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
10942 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
10943 0, 0, 0, 0, pix_x
, pix_y
);
10947 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
10950 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
10956 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
10957 0, 0, 0, 0, pix_x
, pix_y
);
10961 /* focus shifting, raising and lowering. */
10964 x_focus_on_frame (f
)
10967 #if 0 /* This proves to be unpleasant. */
10971 /* I don't think that the ICCCM allows programs to do things like this
10972 without the interaction of the window manager. Whatever you end up
10973 doing with this code, do it to x_unfocus_frame too. */
10974 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10975 RevertToPointerRoot
, CurrentTime
);
10980 x_unfocus_frame (f
)
10984 /* Look at the remarks in x_focus_on_frame. */
10985 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
10986 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
10987 RevertToPointerRoot
, CurrentTime
);
10991 /* Raise frame F. */
10997 if (f
->async_visible
)
11000 #ifdef USE_X_TOOLKIT
11001 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11002 #else /* not USE_X_TOOLKIT */
11003 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11004 #endif /* not USE_X_TOOLKIT */
11005 XFlush (FRAME_X_DISPLAY (f
));
11010 /* Lower frame F. */
11016 if (f
->async_visible
)
11019 #ifdef USE_X_TOOLKIT
11020 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11021 #else /* not USE_X_TOOLKIT */
11022 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11023 #endif /* not USE_X_TOOLKIT */
11024 XFlush (FRAME_X_DISPLAY (f
));
11030 XTframe_raise_lower (f
, raise_flag
)
11040 /* Change of visibility. */
11042 /* This tries to wait until the frame is really visible.
11043 However, if the window manager asks the user where to position
11044 the frame, this will return before the user finishes doing that.
11045 The frame will not actually be visible at that time,
11046 but it will become visible later when the window manager
11047 finishes with it. */
11050 x_make_frame_visible (f
)
11054 int original_top
, original_left
;
11058 type
= x_icon_type (f
);
11060 x_bitmap_icon (f
, type
);
11062 if (! FRAME_VISIBLE_P (f
))
11064 /* We test FRAME_GARBAGED_P here to make sure we don't
11065 call x_set_offset a second time
11066 if we get to x_make_frame_visible a second time
11067 before the window gets really visible. */
11068 if (! FRAME_ICONIFIED_P (f
)
11069 && ! f
->output_data
.x
->asked_for_visible
)
11070 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11072 f
->output_data
.x
->asked_for_visible
= 1;
11074 if (! EQ (Vx_no_window_manager
, Qt
))
11075 x_wm_set_window_state (f
, NormalState
);
11076 #ifdef USE_X_TOOLKIT
11077 /* This was XtPopup, but that did nothing for an iconified frame. */
11078 XtMapWidget (f
->output_data
.x
->widget
);
11079 #else /* not USE_X_TOOLKIT */
11080 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11081 #endif /* not USE_X_TOOLKIT */
11082 #if 0 /* This seems to bring back scroll bars in the wrong places
11083 if the window configuration has changed. They seem
11084 to come back ok without this. */
11085 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11086 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11090 XFlush (FRAME_X_DISPLAY (f
));
11092 /* Synchronize to ensure Emacs knows the frame is visible
11093 before we do anything else. We do this loop with input not blocked
11094 so that incoming events are handled. */
11097 int count
= input_signal_count
;
11098 /* This must be before UNBLOCK_INPUT
11099 since events that arrive in response to the actions above
11100 will set it when they are handled. */
11101 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11103 original_left
= f
->output_data
.x
->left_pos
;
11104 original_top
= f
->output_data
.x
->top_pos
;
11106 /* This must come after we set COUNT. */
11109 /* We unblock here so that arriving X events are processed. */
11111 /* Now move the window back to where it was "supposed to be".
11112 But don't do it if the gravity is negative.
11113 When the gravity is negative, this uses a position
11114 that is 3 pixels too low. Perhaps that's really the border width.
11116 Don't do this if the window has never been visible before,
11117 because the window manager may choose the position
11118 and we don't want to override it. */
11120 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11121 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11122 && previously_visible
)
11126 unsigned int width
, height
, border
, depth
;
11130 /* On some window managers (such as FVWM) moving an existing
11131 window, even to the same place, causes the window manager
11132 to introduce an offset. This can cause the window to move
11133 to an unexpected location. Check the geometry (a little
11134 slow here) and then verify that the window is in the right
11135 place. If the window is not in the right place, move it
11136 there, and take the potential window manager hit. */
11137 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11138 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11140 if (original_left
!= x
|| original_top
!= y
)
11141 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11142 original_left
, original_top
);
11147 XSETFRAME (frame
, f
);
11152 /* Once we have handled input events,
11153 we should have received the MapNotify if one is coming.
11154 So if we have not got it yet, stop looping.
11155 Some window managers make their own decisions
11156 about visibility. */
11157 if (input_signal_count
!= count
)
11159 /* Machines that do polling rather than SIGIO have been observed
11160 to go into a busy-wait here. So we'll fake an alarm signal
11161 to let the handler know that there's something to be read.
11162 We used to raise a real alarm, but it seems that the handler
11163 isn't always enabled here. This is probably a bug. */
11164 if (input_polling_used ())
11166 /* It could be confusing if a real alarm arrives while processing
11167 the fake one. Turn it off and let the handler reset it. */
11169 input_poll_signal (0);
11171 /* Once we have handled input events,
11172 we should have received the MapNotify if one is coming.
11173 So if we have not got it yet, stop looping.
11174 Some window managers make their own decisions
11175 about visibility. */
11176 if (input_signal_count
!= count
)
11179 FRAME_SAMPLE_VISIBILITY (f
);
11183 /* Change from mapped state to withdrawn state. */
11185 /* Make the frame visible (mapped and not iconified). */
11188 x_make_frame_invisible (f
)
11193 #ifdef USE_X_TOOLKIT
11194 /* Use the frame's outermost window, not the one we normally draw on. */
11195 window
= XtWindow (f
->output_data
.x
->widget
);
11196 #else /* not USE_X_TOOLKIT */
11197 window
= FRAME_X_WINDOW (f
);
11198 #endif /* not USE_X_TOOLKIT */
11200 /* Don't keep the highlight on an invisible frame. */
11201 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11202 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11204 #if 0/* This might add unreliability; I don't trust it -- rms. */
11205 if (! f
->async_visible
&& ! f
->async_iconified
)
11211 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11212 that the current position of the window is user-specified, rather than
11213 program-specified, so that when the window is mapped again, it will be
11214 placed at the same location, without forcing the user to position it
11215 by hand again (they have already done that once for this window.) */
11216 x_wm_set_size_hint (f
, (long) 0, 1);
11220 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11221 DefaultScreen (FRAME_X_DISPLAY (f
))))
11223 UNBLOCK_INPUT_RESIGNAL
;
11224 error ("Can't notify window manager of window withdrawal");
11226 #else /* ! defined (HAVE_X11R4) */
11228 /* Tell the window manager what we're going to do. */
11229 if (! EQ (Vx_no_window_manager
, Qt
))
11233 unmap
.xunmap
.type
= UnmapNotify
;
11234 unmap
.xunmap
.window
= window
;
11235 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
11236 unmap
.xunmap
.from_configure
= False
;
11237 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11238 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11240 SubstructureRedirectMaskSubstructureNotifyMask
,
11243 UNBLOCK_INPUT_RESIGNAL
;
11244 error ("Can't notify window manager of withdrawal");
11248 /* Unmap the window ourselves. Cheeky! */
11249 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
11250 #endif /* ! defined (HAVE_X11R4) */
11252 /* We can't distinguish this from iconification
11253 just by the event that we get from the server.
11254 So we can't win using the usual strategy of letting
11255 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11256 and synchronize with the server to make sure we agree. */
11258 FRAME_ICONIFIED_P (f
) = 0;
11259 f
->async_visible
= 0;
11260 f
->async_iconified
= 0;
11267 /* Change window state from mapped to iconified. */
11270 x_iconify_frame (f
)
11276 /* Don't keep the highlight on an invisible frame. */
11277 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11278 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11280 if (f
->async_iconified
)
11285 FRAME_SAMPLE_VISIBILITY (f
);
11287 type
= x_icon_type (f
);
11289 x_bitmap_icon (f
, type
);
11291 #ifdef USE_X_TOOLKIT
11293 if (! FRAME_VISIBLE_P (f
))
11295 if (! EQ (Vx_no_window_manager
, Qt
))
11296 x_wm_set_window_state (f
, IconicState
);
11297 /* This was XtPopup, but that did nothing for an iconified frame. */
11298 XtMapWidget (f
->output_data
.x
->widget
);
11299 /* The server won't give us any event to indicate
11300 that an invisible frame was changed to an icon,
11301 so we have to record it here. */
11304 f
->async_iconified
= 1;
11305 f
->async_visible
= 0;
11310 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11311 XtWindow (f
->output_data
.x
->widget
),
11312 DefaultScreen (FRAME_X_DISPLAY (f
)));
11316 error ("Can't notify window manager of iconification");
11318 f
->async_iconified
= 1;
11319 f
->async_visible
= 0;
11323 XFlush (FRAME_X_DISPLAY (f
));
11325 #else /* not USE_X_TOOLKIT */
11327 /* Make sure the X server knows where the window should be positioned,
11328 in case the user deiconifies with the window manager. */
11329 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
11330 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11332 /* Since we don't know which revision of X we're running, we'll use both
11333 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11335 /* X11R4: send a ClientMessage to the window manager using the
11336 WM_CHANGE_STATE type. */
11340 message
.xclient
.window
= FRAME_X_WINDOW (f
);
11341 message
.xclient
.type
= ClientMessage
;
11342 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11343 message
.xclient
.format
= 32;
11344 message
.xclient
.data
.l
[0] = IconicState
;
11346 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11347 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11349 SubstructureRedirectMask
| SubstructureNotifyMask
,
11352 UNBLOCK_INPUT_RESIGNAL
;
11353 error ("Can't notify window manager of iconification");
11357 /* X11R3: set the initial_state field of the window manager hints to
11359 x_wm_set_window_state (f
, IconicState
);
11361 if (!FRAME_VISIBLE_P (f
))
11363 /* If the frame was withdrawn, before, we must map it. */
11364 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11367 f
->async_iconified
= 1;
11368 f
->async_visible
= 0;
11370 XFlush (FRAME_X_DISPLAY (f
));
11372 #endif /* not USE_X_TOOLKIT */
11375 /* Destroy the X window of frame F. */
11378 x_destroy_window (f
)
11381 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11385 /* If a display connection is dead, don't try sending more
11386 commands to the X server. */
11387 if (dpyinfo
->display
!= 0)
11389 if (f
->output_data
.x
->icon_desc
!= 0)
11390 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
11394 XDestroyIC (FRAME_XIC (f
));
11395 #if ! defined (SOLARIS2) || defined (HAVE_X11R6)
11396 /* This line causes crashes on Solaris with Openwin,
11397 due to an apparent bug in XCloseIM.
11398 X11R6 seems not to have the bug. */
11399 XCloseIM (FRAME_XIM (f
));
11403 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
11404 #ifdef USE_X_TOOLKIT
11405 if (f
->output_data
.x
->widget
)
11406 XtDestroyWidget (f
->output_data
.x
->widget
);
11407 free_frame_menubar (f
);
11408 #endif /* USE_X_TOOLKIT */
11410 free_frame_faces (f
);
11411 XFlush (FRAME_X_DISPLAY (f
));
11414 if (f
->output_data
.x
->saved_menu_event
)
11415 xfree (f
->output_data
.x
->saved_menu_event
);
11417 xfree (f
->output_data
.x
);
11418 f
->output_data
.x
= 0;
11419 if (f
== dpyinfo
->x_focus_frame
)
11420 dpyinfo
->x_focus_frame
= 0;
11421 if (f
== dpyinfo
->x_focus_event_frame
)
11422 dpyinfo
->x_focus_event_frame
= 0;
11423 if (f
== dpyinfo
->x_highlight_frame
)
11424 dpyinfo
->x_highlight_frame
= 0;
11426 dpyinfo
->reference_count
--;
11428 if (f
== dpyinfo
->mouse_face_mouse_frame
)
11430 dpyinfo
->mouse_face_beg_row
11431 = dpyinfo
->mouse_face_beg_col
= -1;
11432 dpyinfo
->mouse_face_end_row
11433 = dpyinfo
->mouse_face_end_col
= -1;
11434 dpyinfo
->mouse_face_window
= Qnil
;
11435 dpyinfo
->mouse_face_deferred_gc
= 0;
11436 dpyinfo
->mouse_face_mouse_frame
= 0;
11442 /* Setting window manager hints. */
11444 /* Set the normal size hints for the window manager, for frame F.
11445 FLAGS is the flags word to use--or 0 meaning preserve the flags
11446 that the window now has.
11447 If USER_POSITION is nonzero, we set the USPosition
11448 flag (this is useful when FLAGS is 0). */
11451 x_wm_set_size_hint (f
, flags
, user_position
)
11456 XSizeHints size_hints
;
11458 #ifdef USE_X_TOOLKIT
11461 Dimension widget_width
, widget_height
;
11462 Window window
= XtWindow (f
->output_data
.x
->widget
);
11463 #else /* not USE_X_TOOLKIT */
11464 Window window
= FRAME_X_WINDOW (f
);
11465 #endif /* not USE_X_TOOLKIT */
11467 /* Setting PMaxSize caused various problems. */
11468 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
11470 size_hints
.x
= f
->output_data
.x
->left_pos
;
11471 size_hints
.y
= f
->output_data
.x
->top_pos
;
11473 #ifdef USE_X_TOOLKIT
11474 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
11475 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
11476 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
11477 size_hints
.height
= widget_height
;
11478 size_hints
.width
= widget_width
;
11479 #else /* not USE_X_TOOLKIT */
11480 size_hints
.height
= PIXEL_HEIGHT (f
);
11481 size_hints
.width
= PIXEL_WIDTH (f
);
11482 #endif /* not USE_X_TOOLKIT */
11484 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
11485 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
11486 size_hints
.max_width
11487 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
11488 size_hints
.max_height
11489 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
11491 /* Calculate the base and minimum sizes.
11493 (When we use the X toolkit, we don't do it here.
11494 Instead we copy the values that the widgets are using, below.) */
11495 #ifndef USE_X_TOOLKIT
11497 int base_width
, base_height
;
11498 int min_rows
= 0, min_cols
= 0;
11500 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
11501 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
11503 check_frame_size (f
, &min_rows
, &min_cols
);
11505 /* The window manager uses the base width hints to calculate the
11506 current number of rows and columns in the frame while
11507 resizing; min_width and min_height aren't useful for this
11508 purpose, since they might not give the dimensions for a
11509 zero-row, zero-column frame.
11511 We use the base_width and base_height members if we have
11512 them; otherwise, we set the min_width and min_height members
11513 to the size for a zero x zero frame. */
11516 size_hints
.flags
|= PBaseSize
;
11517 size_hints
.base_width
= base_width
;
11518 size_hints
.base_height
= base_height
;
11519 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
11520 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
11522 size_hints
.min_width
= base_width
;
11523 size_hints
.min_height
= base_height
;
11527 /* If we don't need the old flags, we don't need the old hint at all. */
11530 size_hints
.flags
|= flags
;
11533 #endif /* not USE_X_TOOLKIT */
11536 XSizeHints hints
; /* Sometimes I hate X Windows... */
11537 long supplied_return
;
11541 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
11544 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
11547 #ifdef USE_X_TOOLKIT
11548 size_hints
.base_height
= hints
.base_height
;
11549 size_hints
.base_width
= hints
.base_width
;
11550 size_hints
.min_height
= hints
.min_height
;
11551 size_hints
.min_width
= hints
.min_width
;
11555 size_hints
.flags
|= flags
;
11560 if (hints
.flags
& PSize
)
11561 size_hints
.flags
|= PSize
;
11562 if (hints
.flags
& PPosition
)
11563 size_hints
.flags
|= PPosition
;
11564 if (hints
.flags
& USPosition
)
11565 size_hints
.flags
|= USPosition
;
11566 if (hints
.flags
& USSize
)
11567 size_hints
.flags
|= USSize
;
11571 #ifndef USE_X_TOOLKIT
11576 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
11577 size_hints
.flags
|= PWinGravity
;
11581 size_hints
.flags
&= ~ PPosition
;
11582 size_hints
.flags
|= USPosition
;
11584 #endif /* PWinGravity */
11587 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11589 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11593 /* Used for IconicState or NormalState */
11596 x_wm_set_window_state (f
, state
)
11600 #ifdef USE_X_TOOLKIT
11603 XtSetArg (al
[0], XtNinitialState
, state
);
11604 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11605 #else /* not USE_X_TOOLKIT */
11606 Window window
= FRAME_X_WINDOW (f
);
11608 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
11609 f
->output_data
.x
->wm_hints
.initial_state
= state
;
11611 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11612 #endif /* not USE_X_TOOLKIT */
11616 x_wm_set_icon_pixmap (f
, pixmap_id
)
11620 Pixmap icon_pixmap
;
11622 #ifndef USE_X_TOOLKIT
11623 Window window
= FRAME_X_WINDOW (f
);
11628 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
11629 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
11633 /* It seems there is no way to turn off use of an icon pixmap.
11634 The following line does it, only if no icon has yet been created,
11635 for some window managers. But with mwm it crashes.
11636 Some people say it should clear the IconPixmapHint bit in this case,
11637 but that doesn't work, and the X consortium said it isn't the
11638 right thing at all. Since there is no way to win,
11639 best to explicitly give up. */
11641 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
11647 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
11651 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
11652 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11655 #else /* not USE_X_TOOLKIT */
11657 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
11658 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11660 #endif /* not USE_X_TOOLKIT */
11664 x_wm_set_icon_position (f
, icon_x
, icon_y
)
11666 int icon_x
, icon_y
;
11668 #ifdef USE_X_TOOLKIT
11669 Window window
= XtWindow (f
->output_data
.x
->widget
);
11671 Window window
= FRAME_X_WINDOW (f
);
11674 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
11675 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
11676 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
11678 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11682 /***********************************************************************
11684 ***********************************************************************/
11686 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
11689 x_get_font_info (f
, font_idx
)
11693 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
11697 /* Return a list of names of available fonts matching PATTERN on frame
11698 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
11699 to be listed. Frame F NULL means we have not yet created any
11700 frame on X, and consult the first display in x_display_list.
11701 MAXNAMES sets a limit on how many fonts to match. */
11704 x_list_fonts (f
, pattern
, size
, maxnames
)
11706 Lisp_Object pattern
;
11710 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
11711 Lisp_Object tem
, second_best
;
11712 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
11713 int try_XLoadQueryFont
= 0;
11716 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
11717 if (NILP (patterns
))
11718 patterns
= Fcons (pattern
, Qnil
);
11720 if (maxnames
== 1 && !size
)
11721 /* We can return any single font matching PATTERN. */
11722 try_XLoadQueryFont
= 1;
11724 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
11729 pattern
= XCAR (patterns
);
11730 /* See if we cached the result for this particular query.
11731 The cache is an alist of the form:
11732 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
11734 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
11735 key
= Fcons (pattern
, make_number (maxnames
)),
11736 !NILP (list
= Fassoc (key
, tem
))))
11738 list
= Fcdr_safe (list
);
11739 /* We have a cashed list. Don't have to get the list again. */
11743 /* At first, put PATTERN in the cache. */
11746 count
= x_catch_errors (dpy
);
11748 if (try_XLoadQueryFont
)
11751 unsigned long value
;
11753 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
11754 if (x_had_errors_p (dpy
))
11756 /* This error is perhaps due to insufficient memory on X
11757 server. Let's just ignore it. */
11759 x_clear_errors (dpy
);
11763 && XGetFontProperty (font
, XA_FONT
, &value
))
11765 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
11766 int len
= strlen (name
);
11769 /* If DXPC (a Differential X Protocol Compressor)
11770 Ver.3.7 is running, XGetAtomName will return null
11771 string. We must avoid such a name. */
11773 try_XLoadQueryFont
= 0;
11777 names
= (char **) alloca (sizeof (char *));
11778 /* Some systems only allow alloca assigned to a
11780 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
11781 bcopy (name
, names
[0], len
+ 1);
11786 try_XLoadQueryFont
= 0;
11789 XFreeFont (dpy
, font
);
11792 if (!try_XLoadQueryFont
)
11794 /* We try at least 10 fonts because XListFonts will return
11795 auto-scaled fonts at the head. */
11796 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
11798 if (x_had_errors_p (dpy
))
11800 /* This error is perhaps due to insufficient memory on X
11801 server. Let's just ignore it. */
11803 x_clear_errors (dpy
);
11807 x_uncatch_errors (dpy
, count
);
11814 /* Make a list of all the fonts we got back.
11815 Store that in the font cache for the display. */
11816 for (i
= 0; i
< num_fonts
; i
++)
11819 char *p
= names
[i
];
11820 int average_width
= -1, dashes
= 0;
11822 /* Count the number of dashes in NAMES[I]. If there are
11823 14 dashes, and the field value following 12th dash
11824 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
11825 is usually too ugly to be used for editing. Let's
11831 if (dashes
== 7) /* PIXEL_SIZE field */
11833 else if (dashes
== 12) /* AVERAGE_WIDTH field */
11834 average_width
= atoi (p
);
11836 if (dashes
< 14 || average_width
!= 0)
11838 tem
= build_string (names
[i
]);
11839 if (NILP (Fassoc (tem
, list
)))
11841 if (STRINGP (Vx_pixel_size_width_font_regexp
)
11842 && ((fast_c_string_match_ignore_case
11843 (Vx_pixel_size_width_font_regexp
, names
[i
]))
11845 /* We can set the value of PIXEL_SIZE to the
11846 width of this font. */
11847 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
11849 /* For the moment, width is not known. */
11850 list
= Fcons (Fcons (tem
, Qnil
), list
);
11854 if (!try_XLoadQueryFont
)
11855 XFreeFontNames (names
);
11858 /* Now store the result in the cache. */
11860 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
11861 = Fcons (Fcons (key
, list
),
11862 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
11865 if (NILP (list
)) continue; /* Try the remaining alternatives. */
11867 newlist
= second_best
= Qnil
;
11868 /* Make a list of the fonts that have the right width. */
11869 for (; CONSP (list
); list
= XCDR (list
))
11875 if (!CONSP (tem
) || NILP (XCAR (tem
)))
11879 newlist
= Fcons (XCAR (tem
), newlist
);
11883 if (!INTEGERP (XCDR (tem
)))
11885 /* Since we have not yet known the size of this font, we
11886 must try slow function call XLoadQueryFont. */
11887 XFontStruct
*thisinfo
;
11890 count
= x_catch_errors (dpy
);
11891 thisinfo
= XLoadQueryFont (dpy
,
11892 XSTRING (XCAR (tem
))->data
);
11893 if (x_had_errors_p (dpy
))
11895 /* This error is perhaps due to insufficient memory on X
11896 server. Let's just ignore it. */
11898 x_clear_errors (dpy
);
11900 x_uncatch_errors (dpy
, count
);
11906 = (thisinfo
->min_bounds
.width
== 0
11908 : make_number (thisinfo
->max_bounds
.width
));
11909 XFreeFont (dpy
, thisinfo
);
11912 /* For unknown reason, the previous call of XListFont had
11913 returned a font which can't be opened. Record the size
11914 as 0 not to try to open it again. */
11915 XCDR (tem
) = make_number (0);
11918 found_size
= XINT (XCDR (tem
));
11919 if (found_size
== size
)
11920 newlist
= Fcons (XCAR (tem
), newlist
);
11921 else if (found_size
> 0)
11923 if (NILP (second_best
))
11925 else if (found_size
< size
)
11927 if (XINT (XCDR (second_best
)) > size
11928 || XINT (XCDR (second_best
)) < found_size
)
11933 if (XINT (XCDR (second_best
)) > size
11934 && XINT (XCDR (second_best
)) > found_size
)
11939 if (!NILP (newlist
))
11941 else if (!NILP (second_best
))
11943 newlist
= Fcons (XCAR (second_best
), Qnil
);
11954 /* Check that FONT is valid on frame F. It is if it can be found in F's
11958 x_check_font (f
, font
)
11963 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11965 xassert (font
!= NULL
);
11967 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11968 if (dpyinfo
->font_table
[i
].name
11969 && font
== dpyinfo
->font_table
[i
].font
)
11972 xassert (i
< dpyinfo
->n_fonts
);
11975 #endif /* GLYPH_DEBUG != 0 */
11977 /* Set *W to the minimum width, *H to the minimum font height of FONT.
11978 Note: There are (broken) X fonts out there with invalid XFontStruct
11979 min_bounds contents. For example, handa@etl.go.jp reports that
11980 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
11981 have font->min_bounds.width == 0. */
11984 x_font_min_bounds (font
, w
, h
)
11988 *h
= FONT_HEIGHT (font
);
11989 *w
= font
->min_bounds
.width
;
11991 /* Try to handle the case where FONT->min_bounds has invalid
11992 contents. Since the only font known to have invalid min_bounds
11993 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
11995 *w
= font
->max_bounds
.width
;
11999 /* Compute the smallest character width and smallest font height over
12000 all fonts available on frame F. Set the members smallest_char_width
12001 and smallest_font_height in F's x_display_info structure to
12002 the values computed. Value is non-zero if smallest_font_height or
12003 smallest_char_width become smaller than they were before. */
12006 x_compute_min_glyph_bounds (f
)
12010 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12012 int old_width
= dpyinfo
->smallest_char_width
;
12013 int old_height
= dpyinfo
->smallest_font_height
;
12015 dpyinfo
->smallest_font_height
= 100000;
12016 dpyinfo
->smallest_char_width
= 100000;
12018 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12019 if (dpyinfo
->font_table
[i
].name
)
12021 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12024 font
= (XFontStruct
*) fontp
->font
;
12025 xassert (font
!= (XFontStruct
*) ~0);
12026 x_font_min_bounds (font
, &w
, &h
);
12028 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12029 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12032 xassert (dpyinfo
->smallest_char_width
> 0
12033 && dpyinfo
->smallest_font_height
> 0);
12035 return (dpyinfo
->n_fonts
== 1
12036 || dpyinfo
->smallest_char_width
< old_width
12037 || dpyinfo
->smallest_font_height
< old_height
);
12041 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12042 pointer to the structure font_info while allocating it dynamically.
12043 If SIZE is 0, load any size of font.
12044 If loading is failed, return NULL. */
12047 x_load_font (f
, fontname
, size
)
12049 register char *fontname
;
12052 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12053 Lisp_Object font_names
;
12056 /* Get a list of all the fonts that match this name. Once we
12057 have a list of matching fonts, we compare them against the fonts
12058 we already have by comparing names. */
12059 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12061 if (!NILP (font_names
))
12066 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12067 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12068 if (dpyinfo
->font_table
[i
].name
12069 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12070 XSTRING (XCAR (tail
))->data
)
12071 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12072 XSTRING (XCAR (tail
))->data
)))
12073 return (dpyinfo
->font_table
+ i
);
12076 /* Load the font and add it to the table. */
12080 struct font_info
*fontp
;
12081 unsigned long value
;
12084 /* If we have found fonts by x_list_font, load one of them. If
12085 not, we still try to load a font by the name given as FONTNAME
12086 because XListFonts (called in x_list_font) of some X server has
12087 a bug of not finding a font even if the font surely exists and
12088 is loadable by XLoadQueryFont. */
12089 if (size
> 0 && !NILP (font_names
))
12090 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12093 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12094 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12095 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12097 /* This error is perhaps due to insufficient memory on X
12098 server. Let's just ignore it. */
12100 x_clear_errors (FRAME_X_DISPLAY (f
));
12102 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12107 /* Find a free slot in the font table. */
12108 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12109 if (dpyinfo
->font_table
[i
].name
== NULL
)
12112 /* If no free slot found, maybe enlarge the font table. */
12113 if (i
== dpyinfo
->n_fonts
12114 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12117 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12118 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12119 dpyinfo
->font_table
12120 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12123 fontp
= dpyinfo
->font_table
+ i
;
12124 if (i
== dpyinfo
->n_fonts
)
12125 ++dpyinfo
->n_fonts
;
12127 /* Now fill in the slots of *FONTP. */
12129 fontp
->font
= font
;
12130 fontp
->font_idx
= i
;
12131 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12132 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12134 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12136 if (XGetFontProperty (font
, XA_FONT
, &value
))
12138 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12142 /* Count the number of dashes in the "full name".
12143 If it is too few, this isn't really the font's full name,
12145 In X11R4, the fonts did not come with their canonical names
12156 full_name
= (char *) xmalloc (p
- name
+ 1);
12157 bcopy (name
, full_name
, p
- name
+ 1);
12163 if (full_name
!= 0)
12164 fontp
->full_name
= full_name
;
12166 fontp
->full_name
= fontp
->name
;
12168 fontp
->size
= font
->max_bounds
.width
;
12169 fontp
->height
= FONT_HEIGHT (font
);
12171 /* For some font, ascent and descent in max_bounds field is
12172 larger than the above value. */
12173 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12174 if (max_height
> fontp
->height
)
12175 fontp
->height
= max_height
;
12178 if (NILP (font_names
))
12180 /* We come here because of a bug of XListFonts mentioned at
12181 the head of this block. Let's store this information in
12182 the cache for x_list_fonts. */
12183 Lisp_Object lispy_name
= build_string (fontname
);
12184 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12186 XCDR (dpyinfo
->name_list_element
)
12187 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
12188 Fcons (Fcons (lispy_full_name
,
12189 make_number (fontp
->size
)),
12191 XCDR (dpyinfo
->name_list_element
));
12193 XCDR (dpyinfo
->name_list_element
)
12194 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
12195 Fcons (Fcons (lispy_full_name
,
12196 make_number (fontp
->size
)),
12198 XCDR (dpyinfo
->name_list_element
));
12201 /* The slot `encoding' specifies how to map a character
12202 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
12203 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
12204 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
12205 0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
12206 2:0xA020..0xFF7F). For the moment, we don't know which charset
12207 uses this font. So, we set information in fontp->encoding[1]
12208 which is never used by any charset. If mapping can't be
12209 decided, set FONT_ENCODING_NOT_DECIDED. */
12211 = (font
->max_byte1
== 0
12213 ? (font
->min_char_or_byte2
< 0x80
12214 ? (font
->max_char_or_byte2
< 0x80
12215 ? 0 /* 0x20..0x7F */
12216 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
12217 : 1) /* 0xA0..0xFF */
12219 : (font
->min_byte1
< 0x80
12220 ? (font
->max_byte1
< 0x80
12221 ? (font
->min_char_or_byte2
< 0x80
12222 ? (font
->max_char_or_byte2
< 0x80
12223 ? 0 /* 0x2020..0x7F7F */
12224 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
12225 : 3) /* 0x20A0..0x7FFF */
12226 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
12227 : (font
->min_char_or_byte2
< 0x80
12228 ? (font
->max_char_or_byte2
< 0x80
12229 ? 2 /* 0xA020..0xFF7F */
12230 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
12231 : 1))); /* 0xA0A0..0xFFFF */
12233 fontp
->baseline_offset
12234 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
12235 ? (long) value
: 0);
12236 fontp
->relative_compose
12237 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
12238 ? (long) value
: 0);
12239 fontp
->default_ascent
12240 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
12241 ? (long) value
: 0);
12243 /* Set global flag fonts_changed_p to non-zero if the font loaded
12244 has a character with a smaller width than any other character
12245 before, or if the font loaded has a smalle>r height than any
12246 other font loaded before. If this happens, it will make a
12247 glyph matrix reallocation necessary. */
12248 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
12255 /* Return a pointer to struct font_info of a font named FONTNAME for
12256 frame F. If no such font is loaded, return NULL. */
12259 x_query_font (f
, fontname
)
12261 register char *fontname
;
12263 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12266 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12267 if (dpyinfo
->font_table
[i
].name
12268 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
12269 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
12270 return (dpyinfo
->font_table
+ i
);
12275 /* Find a CCL program for a font specified by FONTP, and set the member
12276 `encoder' of the structure. */
12279 x_find_ccl_program (fontp
)
12280 struct font_info
*fontp
;
12282 Lisp_Object list
, elt
;
12284 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
12288 && STRINGP (XCAR (elt
))
12289 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
12295 struct ccl_program
*ccl
12296 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
12298 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
12301 fontp
->font_encoder
= ccl
;
12307 /***********************************************************************
12309 ***********************************************************************/
12311 #ifdef USE_X_TOOLKIT
12312 static XrmOptionDescRec emacs_options
[] = {
12313 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
12314 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
12316 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
12317 XrmoptionSepArg
, NULL
},
12318 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
12320 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12321 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12322 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12323 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12324 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12325 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
12326 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
12328 #endif /* USE_X_TOOLKIT */
12330 static int x_initialized
;
12332 #ifdef MULTI_KBOARD
12333 /* Test whether two display-name strings agree up to the dot that separates
12334 the screen number from the server number. */
12336 same_x_server (name1
, name2
)
12337 char *name1
, *name2
;
12339 int seen_colon
= 0;
12340 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
12341 int system_name_length
= strlen (system_name
);
12342 int length_until_period
= 0;
12344 while (system_name
[length_until_period
] != 0
12345 && system_name
[length_until_period
] != '.')
12346 length_until_period
++;
12348 /* Treat `unix' like an empty host name. */
12349 if (! strncmp (name1
, "unix:", 5))
12351 if (! strncmp (name2
, "unix:", 5))
12353 /* Treat this host's name like an empty host name. */
12354 if (! strncmp (name1
, system_name
, system_name_length
)
12355 && name1
[system_name_length
] == ':')
12356 name1
+= system_name_length
;
12357 if (! strncmp (name2
, system_name
, system_name_length
)
12358 && name2
[system_name_length
] == ':')
12359 name2
+= system_name_length
;
12360 /* Treat this host's domainless name like an empty host name. */
12361 if (! strncmp (name1
, system_name
, length_until_period
)
12362 && name1
[length_until_period
] == ':')
12363 name1
+= length_until_period
;
12364 if (! strncmp (name2
, system_name
, length_until_period
)
12365 && name2
[length_until_period
] == ':')
12366 name2
+= length_until_period
;
12368 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
12372 if (seen_colon
&& *name1
== '.')
12376 && (*name1
== '.' || *name1
== '\0')
12377 && (*name2
== '.' || *name2
== '\0'));
12381 #if defined (HAVE_X_I18N) || (defined (USE_X_TOOLKIT) && defined (HAVE_X11XTR6))
12382 /* Recover from setlocale (LC_ALL, ""). */
12386 /* Currently we require strerror to use the "C" locale,
12387 since we don't yet support decoding its string result. */
12389 setlocale (LC_MESSAGES
, "C");
12392 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
12393 so that numbers are read and printed properly for Emacs Lisp. */
12394 setlocale (LC_NUMERIC
, "C");
12396 /* Currently we require strftime to use the "C" locale,
12397 since we don't yet support encoding its format argument,
12398 or decoding its string result. */
12399 setlocale (LC_TIME
, "C");
12403 struct x_display_info
*
12404 x_term_init (display_name
, xrm_option
, resource_name
)
12405 Lisp_Object display_name
;
12407 char *resource_name
;
12411 struct x_display_info
*dpyinfo
;
12416 if (!x_initialized
)
12423 setlocale (LC_ALL
, "");
12427 #ifdef USE_X_TOOLKIT
12428 /* weiner@footloose.sps.mot.com reports that this causes
12430 X protocol error: BadAtom (invalid Atom parameter)
12431 on protocol request 18skiloaf.
12432 So let's not use it until R6. */
12433 #ifdef HAVE_X11XTR6
12434 XtSetLanguageProc (NULL
, NULL
, NULL
);
12445 argv
[argc
++] = "-xrm";
12446 argv
[argc
++] = xrm_option
;
12448 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
12449 resource_name
, EMACS_CLASS
,
12450 emacs_options
, XtNumber (emacs_options
),
12453 #ifdef HAVE_X11XTR6
12454 /* I think this is to compensate for XtSetLanguageProc. */
12459 #else /* not USE_X_TOOLKIT */
12461 XSetLocaleModifiers ("");
12463 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
12464 #endif /* not USE_X_TOOLKIT */
12466 /* Detect failure. */
12473 /* We have definitely succeeded. Record the new connection. */
12475 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
12477 #ifdef MULTI_KBOARD
12479 struct x_display_info
*share
;
12482 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
12483 share
= share
->next
, tail
= XCDR (tail
))
12484 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
12485 XSTRING (display_name
)->data
))
12488 dpyinfo
->kboard
= share
->kboard
;
12491 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
12492 init_kboard (dpyinfo
->kboard
);
12493 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
12495 char *vendor
= ServerVendor (dpy
);
12496 dpyinfo
->kboard
->Vsystem_key_alist
12497 = call1 (Qvendor_specific_keysyms
,
12498 build_string (vendor
? vendor
: ""));
12501 dpyinfo
->kboard
->next_kboard
= all_kboards
;
12502 all_kboards
= dpyinfo
->kboard
;
12503 /* Don't let the initial kboard remain current longer than necessary.
12504 That would cause problems if a file loaded on startup tries to
12505 prompt in the mini-buffer. */
12506 if (current_kboard
== initial_kboard
)
12507 current_kboard
= dpyinfo
->kboard
;
12509 dpyinfo
->kboard
->reference_count
++;
12513 /* Put this display on the chain. */
12514 dpyinfo
->next
= x_display_list
;
12515 x_display_list
= dpyinfo
;
12517 /* Put it on x_display_name_list as well, to keep them parallel. */
12518 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
12519 x_display_name_list
);
12520 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
12522 dpyinfo
->display
= dpy
;
12525 XSetAfterFunction (x_current_display
, x_trace_wire
);
12529 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
12530 + STRING_BYTES (XSTRING (Vsystem_name
))
12532 sprintf (dpyinfo
->x_id_name
, "%s@%s",
12533 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
12535 /* Figure out which modifier bits mean what. */
12536 x_find_modifier_meanings (dpyinfo
);
12538 /* Get the scroll bar cursor. */
12539 dpyinfo
->vertical_scroll_bar_cursor
12540 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
12542 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
12543 resource_name
, EMACS_CLASS
);
12544 #ifdef HAVE_XRMSETDATABASE
12545 XrmSetDatabase (dpyinfo
->display
, xrdb
);
12547 dpyinfo
->display
->db
= xrdb
;
12549 /* Put the rdb where we can find it in a way that works on
12551 dpyinfo
->xrdb
= xrdb
;
12553 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
12554 DefaultScreen (dpyinfo
->display
));
12555 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
12556 &dpyinfo
->n_planes
);
12557 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
12558 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
12559 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
12560 dpyinfo
->grabbed
= 0;
12561 dpyinfo
->reference_count
= 0;
12562 dpyinfo
->icon_bitmap_id
= -1;
12563 dpyinfo
->font_table
= NULL
;
12564 dpyinfo
->n_fonts
= 0;
12565 dpyinfo
->font_table_size
= 0;
12566 dpyinfo
->bitmaps
= 0;
12567 dpyinfo
->bitmaps_size
= 0;
12568 dpyinfo
->bitmaps_last
= 0;
12569 dpyinfo
->scratch_cursor_gc
= 0;
12570 dpyinfo
->mouse_face_mouse_frame
= 0;
12571 dpyinfo
->mouse_face_deferred_gc
= 0;
12572 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
12573 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
12574 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
12575 dpyinfo
->mouse_face_window
= Qnil
;
12576 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
12577 dpyinfo
->mouse_face_defer
= 0;
12578 dpyinfo
->x_focus_frame
= 0;
12579 dpyinfo
->x_focus_event_frame
= 0;
12580 dpyinfo
->x_highlight_frame
= 0;
12581 dpyinfo
->image_cache
= make_image_cache ();
12584 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
12585 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
12586 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
12587 dpyinfo
->resy
= pixels
* 25.4 / mm
;
12588 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
12589 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
12590 dpyinfo
->resx
= pixels
* 25.4 / mm
;
12593 dpyinfo
->Xatom_wm_protocols
12594 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
12595 dpyinfo
->Xatom_wm_take_focus
12596 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
12597 dpyinfo
->Xatom_wm_save_yourself
12598 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
12599 dpyinfo
->Xatom_wm_delete_window
12600 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
12601 dpyinfo
->Xatom_wm_change_state
12602 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
12603 dpyinfo
->Xatom_wm_configure_denied
12604 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
12605 dpyinfo
->Xatom_wm_window_moved
12606 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
12607 dpyinfo
->Xatom_editres
12608 = XInternAtom (dpyinfo
->display
, "Editres", False
);
12609 dpyinfo
->Xatom_CLIPBOARD
12610 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
12611 dpyinfo
->Xatom_TIMESTAMP
12612 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
12613 dpyinfo
->Xatom_TEXT
12614 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
12615 dpyinfo
->Xatom_COMPOUND_TEXT
12616 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
12617 dpyinfo
->Xatom_DELETE
12618 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
12619 dpyinfo
->Xatom_MULTIPLE
12620 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
12621 dpyinfo
->Xatom_INCR
12622 = XInternAtom (dpyinfo
->display
, "INCR", False
);
12623 dpyinfo
->Xatom_EMACS_TMP
12624 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
12625 dpyinfo
->Xatom_TARGETS
12626 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
12627 dpyinfo
->Xatom_NULL
12628 = XInternAtom (dpyinfo
->display
, "NULL", False
);
12629 dpyinfo
->Xatom_ATOM_PAIR
12630 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
12631 /* For properties of font. */
12632 dpyinfo
->Xatom_PIXEL_SIZE
12633 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
12634 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
12635 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
12636 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
12637 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
12638 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
12639 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
12641 /* Ghostscript support. */
12642 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
12643 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
12645 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
12648 dpyinfo
->cut_buffers_initialized
= 0;
12650 connection
= ConnectionNumber (dpyinfo
->display
);
12651 dpyinfo
->connection
= connection
;
12656 null_bits
[0] = 0x00;
12658 dpyinfo
->null_pixel
12659 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
12660 null_bits
, 1, 1, (long) 0, (long) 0,
12665 extern int gray_bitmap_width
, gray_bitmap_height
;
12666 extern unsigned char *gray_bitmap_bits
;
12668 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
12670 gray_bitmap_width
, gray_bitmap_height
,
12671 (unsigned long) 1, (unsigned long) 0, 1);
12674 #ifdef subprocesses
12675 /* This is only needed for distinguishing keyboard and process input. */
12676 if (connection
!= 0)
12677 add_keyboard_wait_descriptor (connection
);
12680 #ifndef F_SETOWN_BUG
12682 #ifdef F_SETOWN_SOCK_NEG
12683 /* stdin is a socket here */
12684 fcntl (connection
, F_SETOWN
, -getpid ());
12685 #else /* ! defined (F_SETOWN_SOCK_NEG) */
12686 fcntl (connection
, F_SETOWN
, getpid ());
12687 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
12688 #endif /* ! defined (F_SETOWN) */
12689 #endif /* F_SETOWN_BUG */
12692 if (interrupt_input
)
12693 init_sigio (connection
);
12694 #endif /* ! defined (SIGIO) */
12697 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
12698 /* Make sure that we have a valid font for dialog boxes
12699 so that Xt does not crash. */
12701 Display
*dpy
= dpyinfo
->display
;
12702 XrmValue d
, fr
, to
;
12706 d
.addr
= (XPointer
)&dpy
;
12707 d
.size
= sizeof (Display
*);
12708 fr
.addr
= XtDefaultFont
;
12709 fr
.size
= sizeof (XtDefaultFont
);
12710 to
.size
= sizeof (Font
*);
12711 to
.addr
= (XPointer
)&font
;
12712 count
= x_catch_errors (dpy
);
12713 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
12715 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
12716 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
12717 x_uncatch_errors (dpy
, count
);
12727 /* Get rid of display DPYINFO, assuming all frames are already gone,
12728 and without sending any more commands to the X server. */
12731 x_delete_display (dpyinfo
)
12732 struct x_display_info
*dpyinfo
;
12734 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
12736 /* Discard this display from x_display_name_list and x_display_list.
12737 We can't use Fdelq because that can quit. */
12738 if (! NILP (x_display_name_list
)
12739 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
12740 x_display_name_list
= XCDR (x_display_name_list
);
12745 tail
= x_display_name_list
;
12746 while (CONSP (tail
) && CONSP (XCDR (tail
)))
12748 if (EQ (XCAR (XCDR (tail
)),
12749 dpyinfo
->name_list_element
))
12751 XCDR (tail
) = XCDR (XCDR (tail
));
12754 tail
= XCDR (tail
);
12758 if (x_display_list
== dpyinfo
)
12759 x_display_list
= dpyinfo
->next
;
12762 struct x_display_info
*tail
;
12764 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
12765 if (tail
->next
== dpyinfo
)
12766 tail
->next
= tail
->next
->next
;
12769 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
12770 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
12771 XrmDestroyDatabase (dpyinfo
->xrdb
);
12774 #ifdef MULTI_KBOARD
12775 if (--dpyinfo
->kboard
->reference_count
== 0)
12776 delete_kboard (dpyinfo
->kboard
);
12778 xfree (dpyinfo
->font_table
);
12779 xfree (dpyinfo
->x_id_name
);
12783 /* Set up use of X before we make the first connection. */
12785 static struct redisplay_interface x_redisplay_interface
=
12790 x_clear_end_of_line
,
12792 x_after_update_window_line
,
12793 x_update_window_begin
,
12794 x_update_window_end
,
12797 x_get_glyph_overhangs
,
12798 x_fix_overlapping_area
12804 rif
= &x_redisplay_interface
;
12806 clear_frame_hook
= x_clear_frame
;
12807 ins_del_lines_hook
= x_ins_del_lines
;
12808 change_line_highlight_hook
= x_change_line_highlight
;
12809 delete_glyphs_hook
= x_delete_glyphs
;
12810 ring_bell_hook
= XTring_bell
;
12811 reset_terminal_modes_hook
= XTreset_terminal_modes
;
12812 set_terminal_modes_hook
= XTset_terminal_modes
;
12813 update_begin_hook
= x_update_begin
;
12814 update_end_hook
= x_update_end
;
12815 set_terminal_window_hook
= XTset_terminal_window
;
12816 read_socket_hook
= XTread_socket
;
12817 frame_up_to_date_hook
= XTframe_up_to_date
;
12818 reassert_line_highlight_hook
= XTreassert_line_highlight
;
12819 mouse_position_hook
= XTmouse_position
;
12820 frame_rehighlight_hook
= XTframe_rehighlight
;
12821 frame_raise_lower_hook
= XTframe_raise_lower
;
12822 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
12823 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
12824 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
12825 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
12826 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
12828 scroll_region_ok
= 1; /* we'll scroll partial frames */
12829 char_ins_del_ok
= 0; /* just as fast to write the line */
12830 line_ins_del_ok
= 1; /* we'll just blt 'em */
12831 fast_clear_end_of_line
= 1; /* X does this well */
12832 memory_below_frame
= 0; /* we don't remember what scrolls
12837 last_tool_bar_item
= -1;
12838 any_help_event_p
= 0;
12840 /* Try to use interrupt input; if we can't, then start polling. */
12841 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
12843 #ifdef USE_X_TOOLKIT
12844 XtToolkitInitialize ();
12845 Xt_app_con
= XtCreateApplicationContext ();
12846 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
12849 /* Note that there is no real way portable across R3/R4 to get the
12850 original error handler. */
12851 XSetErrorHandler (x_error_handler
);
12852 XSetIOErrorHandler (x_io_error_quitter
);
12854 /* Disable Window Change signals; they are handled by X events. */
12856 signal (SIGWINCH
, SIG_DFL
);
12857 #endif /* ! defined (SIGWINCH) */
12859 signal (SIGPIPE
, x_connection_signal
);
12866 staticpro (&x_error_message_string
);
12867 x_error_message_string
= Qnil
;
12869 staticpro (&x_display_name_list
);
12870 x_display_name_list
= Qnil
;
12872 staticpro (&last_mouse_scroll_bar
);
12873 last_mouse_scroll_bar
= Qnil
;
12875 staticpro (&Qvendor_specific_keysyms
);
12876 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
12878 staticpro (&last_mouse_press_frame
);
12879 last_mouse_press_frame
= Qnil
;
12881 staticpro (&help_echo
);
12883 staticpro (&previous_help_echo
);
12884 previous_help_echo
= Qnil
;
12886 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
12887 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
12888 For example, if a block cursor is over a tab, it will be drawn as\n\
12889 wide as that tab on the display.");
12890 x_stretch_cursor_p
= 0;
12892 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
12893 "If not nil, Emacs uses toolkit scroll bars.");
12894 #if USE_TOOLKIT_SCROLL_BARS
12895 x_toolkit_scroll_bars_p
= 1;
12897 x_toolkit_scroll_bars_p
= 0;
12900 defsubr (&Sxt_process_timeouts
);
12901 staticpro (&last_mouse_motion_frame
);
12902 last_mouse_motion_frame
= Qnil
;
12905 #endif /* not HAVE_X_WINDOWS */